Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.0 - 日本語

Scilab 6.1.0
Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
However, this page did not exist in the previous stable version.

Scilabヘルプ >> API Scilab > legacy > Low level functions > 論理値疎行列の読み込み (Scilabゲートウェイ)

論理値疎行列の読み込み (Scilabゲートウェイ)

ゲートウェイで論理値の疎行列を読み込む方法.

呼び出し手順

入力引数プロファイル:

SciErr getBooleanSparseMatrix(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, int* _piNbItem, int** _piNbItemRow, int** _piColPos)

名前指定変数プロファイル:

SciErr readNamedBooleanSparseMatrix(void* _pvCtx, const char* _pstName, int* _piRows, int* _piCols, int* _piNbItem, int* _piNbItemRow, int* _piColPos)

引数

_pvCtx

Scilab環境ポインタ, api_scilab.hで定義される "pvApiCtx" を指定

_piAddress

Scilab変数のアドレス.

_pstName

"名前指定" 関数の場合の変数名.

_piRows

変数の行の数.

_piCols

変数の列の数.

_piNbItem

返される非ゼロ値の数.

_piNbItemRow

返される各行の要素の数 (大きさ: _iRows). "名前指定" 関数の場合, 関数コールの前に _piNbItemRow のメモリを確保する必要があります.

_piColPos

返される各要素の列の位置 (大きさ: _iNbItem). "名前指定"関数の場合, 関数コール前に _piColPos のメモリを確保する必要があります.

SciErr

エラー構造体で,エラーメッセージ履歴と最初のエラー番号を保持します.

説明

このヘルプは論理値の疎行列を読み込む方法を説明します.

ゲートウェイのソース

#include "api_scilab.h"
int read_write_bsparse(char *fname,void* pvApiCtx)
{
    SciErr sciErr;
    int i                   = 0;
    int j                   = 0;
    int k                   = 0;
    // 最初の変数の情報 : doubleの実数行列
    int iRows               = 0;
    int iCols               = 0;
    int *piAddr             = NULL;
    int iNbItem             = 0;
    int* piNbItemRow        = NULL;
    int* piColPos           = NULL;
    int iCol                = 0;
    int iNewCol             = 0;
    int iNewItem            = 0;
    int* piNewRow           = NULL;
    int* piNewCol           = NULL;
    // 入力/出力引数を確認
    CheckInputArgument(pvApiCtx, 1, 1);
    CheckOutputArgument(pvApiCtx, 0, 1);
    // 最初の入力引数の変数アドレスを取得
    sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }
    // Scilabメモリから大きさとデータを取得
    sciErr = getBooleanSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &iNbItem, &piNbItemRow, &piColPos);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }
    // データで何か処理を行う
    // %T -> %F および %F -> %T の変換を行う
    iNewItem = (iRows * iCols) - iNbItem;
    piNewRow = (int*)MALLOC(sizeof(int) * iRows);
    piNewCol = (int*)MALLOC(sizeof(int) * iNewItem);
    for(i = 0 ; i < iRows ; i++)
    {
        piNewRow[i] = iCols - piNbItemRow[i];
        for(j = 0 ; j < iCols ; j++)
        {
            int iFind = 0;
            for(k = 0 ; k < piNbItemRow[i] ; k++)
            {
                if(piColPos[iCol + k] == (j + 1))
                {
                    iFind = 1;
                    break;
                }
            }
            if(iFind == 0)
            {
                piNewCol[iNewCol++] = (j + 1);
            }
        }
        iCol += piNbItemRow[i];
    }
    sciErr = createBooleanSparseMatrix(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, iNewItem, piNewRow, piNewCol);
    if(sciErr.iErr)
    {
        printError(&sciErr, 0);
        return 0;
    }
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
    return 0;
}

Scilabテストスクリプト

a = sparse([%t, %f, %t ; %f, %t, %f ; %t, %f, %t]);
a_ref = sparse([%f, %t, %f ; %t, %f, %t ; %f, %t, %f]);
b = read_write_bsparse(a);
if or(b <> a_ref) then error("failed");end
Report an issue
<< 論理値の書き込み (Scilabゲートウェイ) Low level functions 論理値の疎行列の書き込み (Scilabゲートウェイ) >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Tue Feb 25 08:53:30 CET 2020