Sparse matrix reading (Scilab gateway) — How to read sparse matric in a gateway.
Input argument profile:
SciErr getSparseMatrix(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, int* _piNbItem, int** _piNbItemRow, int** _piColPos, double** _pdblReal)
SciErr getComplexSparseMatrix(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, int* _piNbItem, int** _piNbItemRow, int** _piColPos, double** _pdblReal, double** _pdblImg)
Named variable profile:
SciErr readNamedSparseMatrix(void* _pvCtx, char* _pstName, int* _piRows, int* _piCols, int* _piNbItem, int* _piNbItemRow, int* _piColPos, double* _pdblReal)
SciErr readNamedComplexSparseMatrix(void* _pvCtx, char* _pstName, int* _piRows, int* _piCols, int* _piNbItem, int* _piNbItemRow, int* _piColPos, double* _pdblReal, double* _pdblImg)
Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h.
Address of the Scilab variable.
Name of the variable for "named" functions.
Return number of rows.
Return number of columns.
Return number of non zero value.
Return number of item in each rows (size: _iRows).
Return column position for each item (size: _iNbItem).
Return address of real data array (size: _iCols * _iRows)
Return address of imaginary data array (size: _iCols * _iRows)
Error structure where is stored errors messages history and first error number.
int read_sparse(char *fname,unsigned long fname_len) { SciErr sciErr; int i,j,k; int* piAddr = NULL; int iRows = 0; int iCols = 0; int iNbItem = 0; int* piNbItemRow = NULL; int* piColPos = NULL; double* pdblReal = NULL; double* pdblImg = NULL; CheckRhs(1,1); sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } if(isVarComplex(pvApiCtx, piAddr)) { sciErr = getComplexSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &iNbItem, &piNbItemRow, &piColPos, &pdblReal, &pdblImg); } else { sciErr = getSparseMatrix(pvApiCtx, piAddr, &iRows, &iCols, &iNbItem, &piNbItemRow, &piColPos, &pdblReal); } if(sciErr.iErr) { printError(&sciErr, 0); return 0; } sciprint("Sparse %d item(s)\n", iNbItem); k = 0; for(i = 0 ; i < iRows ; i++) { for(j = 0 ; j < piNbItemRow[i] ; j++) { sciprint("(%d,%d) = %f", i+1, piColPos[k], pdblReal[k]); if(isVarComplex(pvApiCtx, piAddr)) { sciprint(" %+fi", pdblImg[k]); } sciprint("\n"); k++; } } //assign allocated variables to Lhs position LhsVar(1) = 0; return 0; }