Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix double matrix typemaps (add some typemaps) + move code in separat…
…e file
- Loading branch information
Simon Marchetto
committed
Jun 3, 2013
1 parent
2847765
commit 0531f30
Showing
2 changed files
with
185 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |