Skip to content

Commit

Permalink
Fix double matrix typemaps (add some typemaps) + move code in separat…
Browse files Browse the repository at this point in the history
…e file
  • Loading branch information
Simon Marchetto committed Jun 3, 2013
1 parent 2847765 commit 0531f30
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 44 deletions.
49 changes: 5 additions & 44 deletions Lib/scilab/matrix.i
@@ -1,48 +1,9 @@
%typemap(in) (double* matrixAsInput, int rows, int cols) {
int *piAddr = NULL;
SciErr sciErr;
sciErr = getVarAddressFromPosition(pvApiCtx, $input, &piAddr);
if (sciErr.iErr) {
printError(&sciErr, 0);
return 0;
}
sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &$2, &$3, &$1);
if (sciErr.iErr) {
printError(&sciErr, 0);
return 0;
}
}
/*
* Matrix typemaps
*
*/

%include <scimatrixdouble.swg>

%typemap(in,numinputs=0) (double** matrixAsArgOutput,int* rows, int* cols)
{
}

%typemap(arginit) (double** matrixAsArgOutput,int* rows, int* cols)
{
$1=(double**)malloc(16*sizeof(double*));
$2=(int*)malloc(sizeof(int));
$3=(int*)malloc(sizeof(int));
}

%typemap(freearg) (double** matrixAsArgOutput,int* rows, int* cols)
{
free(*$1);
free($1);
free($2);
free($3);
}

%typemap(argout) (double** matrixAsArgOutput,int* rows, int* cols)
{
SciErr sciErr;
sciErr = createMatrixOfDouble(pvApiCtx, Rhs +$result, *$2, *$3, (double *)*$1);
if (sciErr.iErr) {
printError(&sciErr, 0);
return 0;
}
AssignOutputVariable(pvApiCtx, outputPosition) = Rhs +$result;

}


180 changes: 180 additions & 0 deletions Lib/scilab/scimatrixdouble.swg
@@ -0,0 +1,180 @@
/*
* C-type: double array
* Scilab type: double matrix
*/

%include <scidouble.swg>

%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double* matrixAsInput, int rows, int cols)
{
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$2, &$3, &$1, fname) == SWIG_ERROR)
{
return SWIG_ERROR;
}
}

%typemap(in, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int rows, int cols, double* matrixAsInput)
{
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &$1, &$2, &$3, fname) == SWIG_ERROR)
{
return SWIG_ERROR;
}
}

%typemap(in) (double* matrixAsInput, int size)
{
int nbRows;
int nbCols;
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$1, fname) != SWIG_ERROR)
{
$2 = nbRows * nbCols;
}
else
{
return SWIG_ERROR;
}
}

%typemap(in) (int size, double* matrixAsInput)
{
int nbRows;
int nbCols;
if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &nbRows, &nbCols, &$2, fname) != SWIG_ERROR)
{
$1 = nbRows * nbCols;
}
else
{
return SWIG_ERROR;
}
}

%typemap(in, numinputs=0) (double** matrixAsOutput, int* rows, int* cols)
{
}

%typemap(arginit) (double** matrixAsOutput, int* rows, int* cols)
{
$1 = (double**) malloc(sizeof(double*));
$2 = (int*) malloc(sizeof(int));
$3 = (int*) malloc(sizeof(int));
}

%typemap(freearg) (double** matrixAsOutput, int* rows, int* cols)
{
free(*$1);
free($1);
free($2);
free($3);
}

%typemap(argout, fragment="SWIG_SciDouble_FromDoubleArrayAndSize") (double** matrixAsOutput, int* rows, int* cols)
{
if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$2, *$3, *$1) != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}

// (int* rows, int* cols, double** matrixAsOutput)

%typemap(in, numinputs=0) (int* rows, int* cols, double** matrixAsOutput)
{
}

%typemap(arginit) (int* rows, int* cols, double** matrixAsOutput)
{
$1 = (int*) malloc(sizeof(int));
$2 = (int*) malloc(sizeof(int));
$3 = (double**) malloc(sizeof(double*));
}

%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* rows, int* cols, double** matrixAsOutput)
{
if (SWIG_SciInt32_FromIntArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), *$1, *$2, *$3) != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}

%typemap(freearg) (int* rows, int* cols, double** matrixAsOutput)
{
free($1);
free($2);
free(*$3);
free($3);
}


// (double** matrixAsOutput, int* size)

%typemap(in, numinputs=0) (double** matrixAsOutput, int* size)
{
}

%typemap(arginit) (double** matrixAsOutput, int* size)
{
$1 = (double**) malloc(sizeof(double*));
$2 = (int*) malloc(sizeof(int));
}

%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (double** matrixAsOutput, int* size)
{

if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$2, *$1) != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}

%typemap(freearg) (double** matrixAsOutput, int* size)
{
free(*$1);
free($1);
free($2);
}


// (int* size, double** matrixAsOutput)

%typemap(in, numinputs=0) (int* size, double** matrixAsOutput)
{
}

%typemap(arginit) (int* size, double** matrixAsOutput)
{
$1 = (int*) malloc(sizeof(int));
$2 = (double**) malloc(sizeof(double*));
}

%typemap(argout, fragment="SWIG_SciInt32_FromIntArrayAndSize") (int* size, double** matrixAsOutput)
{

if (SWIG_SciDouble_FromDoubleArrayAndSize(pvApiCtx, SWIG_Scilab_GetOutputPosition(), 1, *$1, *$2) != SWIG_ERROR)
{
AssignOutputVariable(pvApiCtx, outputPosition) = nbInputArgument(pvApiCtx) + SWIG_Scilab_GetOutputPosition();
}
else
{
return SWIG_ERROR;
}
}

%typemap(freearg) (int* size, double** matrixAsOutput)
{
free($1);
free(*$2);
free($2);
}

0 comments on commit 0531f30

Please sign in to comment.