diff options
author | Clément DAVID <clement.david@3ds.com> | 2023-04-19 09:32:02 +1200 |
---|---|---|
committer | Olly Betts <olly@survex.com> | 2023-04-19 09:32:41 +1200 |
commit | e1d59d0016f65cc4b15f0f1840b3beef5555267a (patch) | |
tree | 967f6cbe4855ad00f232d587bfa19840254c57a3 | |
parent | 5c165f5cc86a0906570f430ffe150ded072f78c9 (diff) | |
download | swig-e1d59d0016f65cc4b15f0f1840b3beef5555267a.tar.gz |
[scilab] Extract values with ":"
Fixes #894
-rw-r--r-- | CHANGES.current | 3 | ||||
-rw-r--r-- | Examples/scilab/matrix2/example.c | 30 | ||||
-rw-r--r-- | Examples/scilab/matrix2/example.i | 4 | ||||
-rw-r--r-- | Examples/scilab/matrix2/runme.sci | 8 | ||||
-rw-r--r-- | Lib/scilab/scidouble.swg | 14 | ||||
-rw-r--r-- | Lib/scilab/sciint.swg | 5 | ||||
-rw-r--r-- | Lib/scilab/scimatrixdouble.swg | 12 | ||||
-rw-r--r-- | Lib/scilab/scimatrixint.swg | 12 |
8 files changed, 78 insertions, 10 deletions
diff --git a/CHANGES.current b/CHANGES.current index e427e60f6..458b1b91e 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.2.0 (in progress) =========================== +2023-04-18: davidcl + [Scilab] #894 extract values with ":" for typemap (int* IN, int IN_SIZE) + 2023-04-14: olly [PHP7] Support for PHP7 has been removed. PHP7 security support ended 2022-11-28 so it doesn't make sense to include support for diff --git a/Examples/scilab/matrix2/example.c b/Examples/scilab/matrix2/example.c index 476067df9..232c88824 100644 --- a/Examples/scilab/matrix2/example.c +++ b/Examples/scilab/matrix2/example.c @@ -29,12 +29,12 @@ void squareDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, double** resu } } -void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) +void getDoubleMatrix(int nbRow, int nbCol, double **resultMatrix, int *nbRowRes, int *nbColRes) { int i; int size; - *nbRowRes = 5; - *nbColRes = 3; + *nbRowRes = nbRow; + *nbColRes = nbCol; size = (*nbRowRes) * (*nbColRes); *resultMatrix = (double*) malloc(size * sizeof(double)); for (i=0; i<size; i++) @@ -43,6 +43,30 @@ void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) } } +void extractDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, int* indexes, int nbIndexes, double **resultMatrix, int *nbRowRes, int *nbColRes) +{ + if (nbIndexes < 0) + { + int sz = nbRow * nbCol; + *nbRowRes = sz; + *nbColRes = 1; + + *resultMatrix = malloc(sz * sizeof(double)); + memcpy(*resultMatrix, inputMatrix, sz * sizeof(double)); + } else { + int i; + + *nbRowRes = nbIndexes; + *nbColRes = 1; + + *resultMatrix = malloc(nbIndexes * sizeof(double)); + for (i = 0; i < nbIndexes; i++) + { + (*resultMatrix)[i] = inputMatrix[indexes[i]]; + } + } +} + // Integer matrix functions int sumIntegerMatrix(int *inputMatrix, int nbRow, int nbCol) diff --git a/Examples/scilab/matrix2/example.i b/Examples/scilab/matrix2/example.i index e37cd116c..1584691cc 100644 --- a/Examples/scilab/matrix2/example.i +++ b/Examples/scilab/matrix2/example.i @@ -4,6 +4,7 @@ %apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *inputMatrix, int nbRow, int nbCol) } %apply (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (double **resultMatrix, int *nbRowRes, int *nbColRes) } +%apply (int *IN, int IN_SIZE) { (int* indexes, int nbIndexes) } %apply (int *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (int *inputMatrix, int nbRow, int nbCol) } %apply (int **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (int **resultMatrix, int *nbRowRes, int *nbColRes) } @@ -14,7 +15,8 @@ %inline %{ extern double sumDoubleMatrix(double *inputMatrix, int nbRow, int nbCol); extern void squareDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, double **resultMatrix, int *nbRowRes, int *nbColRes); - extern void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes); + extern void getDoubleMatrix(int nbRow, int nbCol,double **resultMatrix, int *nbRowRes, int *nbColRes); + extern void extractDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, int* indexes, int nbIndexes, double **resultMatrix, int *nbRowRes, int *nbColRes); extern int sumIntegerMatrix(int *inputMatrix, int nbRow, int nbCol); extern void squareIntegerMatrix(int *inputMatrix, int nbRow, int nbCol, int **resultMatrix, int *nbRowRes, int *nbColRes); diff --git a/Examples/scilab/matrix2/runme.sci b/Examples/scilab/matrix2/runme.sci index 0af7df4e7..4264991e8 100644 --- a/Examples/scilab/matrix2/runme.sci +++ b/Examples/scilab/matrix2/runme.sci @@ -8,7 +8,7 @@ end // Test lib double matrix functions disp("Call lib function getDoubleMatrix()"); -doubleMatrix = getDoubleMatrix(); +doubleMatrix = getDoubleMatrix(5, 3); disp(doubleMatrix); disp("Call lib function sumDoubleMatrix()"); @@ -19,6 +19,12 @@ disp("Call lib function squareDoubleMatrix()"); sqrd = squareDoubleMatrix(doubleMatrix); disp(sqrd); +disp("Extract various indexes"); +disp(extractDoubleMatrix(doubleMatrix, 2)); +disp(extractDoubleMatrix(doubleMatrix, 2:5)); +disp(extractDoubleMatrix(doubleMatrix, :)); + + // Test lib integer matrix functions diff --git a/Lib/scilab/scidouble.swg b/Lib/scilab/scidouble.swg index 1b8263306..e14c84647 100644 --- a/Lib/scilab/scidouble.swg +++ b/Lib/scilab/scidouble.swg @@ -56,6 +56,7 @@ SWIG_SciDouble_FromDouble(void *pvApiCtx, int iVarOut, double dblValue, char *fn SWIGINTERN int SWIG_SciDouble_AsDoubleArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, double **pdValue, char *fname) { SciErr sciErr; + int iType = 0; int *piAddrVar = NULL; sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar); @@ -64,13 +65,24 @@ SWIG_SciDouble_AsDoubleArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *i return SWIG_ERROR; } - if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) { + sciErr = getVarType(pvApiCtx, piAddrVar, &iType); + if (sciErr.iErr) { + printError(&sciErr, 0); + return SWIG_ERROR; + } + + if (iType == sci_matrix && !isVarComplex(pvApiCtx, piAddrVar)) { sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, pdValue); if (sciErr.iErr) { printError(&sciErr, 0); return SWIG_ERROR; } } + else if (iType == sci_implicit_poly) { + *iRows = -1; + *iCols = 0; + *pdValue = NULL; + } else { Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), fname, iVar); return SWIG_ERROR; diff --git a/Lib/scilab/sciint.swg b/Lib/scilab/sciint.swg index 2d6993569..b7b2563e8 100644 --- a/Lib/scilab/sciint.swg +++ b/Lib/scilab/sciint.swg @@ -157,6 +157,11 @@ SWIG_SciDoubleOrInt32_AsIntArrayAndSize(void *pvApiCtx, int iVar, int *iRows, in return SWIG_ERROR; } } + else if (iType == sci_implicit_poly) { + *iRows = -1; + *iCols = 0; + *piValue = NULL; + } else { Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A 32-bit signed integer or a double matrix expected.\n"), fname, iVar); return SWIG_ERROR; diff --git a/Lib/scilab/scimatrixdouble.swg b/Lib/scilab/scimatrixdouble.swg index 9444a8078..bb9403edd 100644 --- a/Lib/scilab/scimatrixdouble.swg +++ b/Lib/scilab/scimatrixdouble.swg @@ -28,7 +28,11 @@ %typemap(in, noblock=1, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (double *IN, int IN_SIZE) (int rowCount, int colCount) { if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) == SWIG_OK) { - $2 = rowCount * colCount; + if (rowCount < 0) { + $2 = rowCount; + } else { + $2 = rowCount * colCount; + } } else { return SWIG_ERROR; @@ -40,7 +44,11 @@ %typemap(in, noblock=1, fragment="SWIG_SciDouble_AsDoubleArrayAndSize") (int IN_SIZE, double *IN) (int rowCount, int colCount) { if (SWIG_SciDouble_AsDoubleArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) == SWIG_OK) { - $1 = rowCount * colCount; + if (rowCount < 0) { + $1 = rowCount; + } else { + $1 = rowCount * colCount; + } } else { return SWIG_ERROR; diff --git a/Lib/scilab/scimatrixint.swg b/Lib/scilab/scimatrixint.swg index e304d4f64..057710725 100644 --- a/Lib/scilab/scimatrixint.swg +++ b/Lib/scilab/scimatrixint.swg @@ -30,7 +30,11 @@ %typemap(in, noblock=1, fragment="SWIG_SciDoubleOrInt32_AsIntArrayAndSize") (int *IN, int IN_SIZE) (int rowCount, int colCount) { if (SWIG_SciDoubleOrInt32_AsIntArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$1, fname) == SWIG_OK) { - $2 = rowCount * colCount; + if (rowCount < 0) { + $2 = rowCount; + } else { + $2 = rowCount * colCount; + } } else { return SWIG_ERROR; @@ -43,7 +47,11 @@ %typemap(in, noblock=1, fragment="SWIG_SciDoubleOrInt32_AsIntArrayAndSize") (int IN_SIZE, int *IN) (int rowCount, int colCount) { if (SWIG_SciDoubleOrInt32_AsIntArrayAndSize(pvApiCtx, $input, &rowCount, &colCount, &$2, fname) == SWIG_OK) { - $1 = rowCount * colCount; + if (rowCount < 0) { + $1 = rowCount; + } else { + $1 = rowCount * colCount; + } } else { return SWIG_ERROR; |