Scilab multiple (>3) matrix argument question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Scilab multiple (>3) matrix argument question

Alex Szakál
Hi SWIG experts!

I ran into a problem that I can't solve while interfacing Scilab with C. Please help!
I want to pass more than two matrices to a C function from Scilab. My example function for two matrices:


///// WORKING EXAMPLE WITH 2 ARGUMENTS //////
%module addMx

%include <matrix.i>

%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *matrix, int matrixNbRow, int matrixNbCol) };
%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *mx2,    int mx2NbRow,    int mx2NbCol   ) };
%apply (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) };

%inline %{

void addMx(double *matrix, int matrixNbRow, int matrixNbCol,
double *mx2,    int mx2NbRow,    int mx2NbCol,
double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) {
  
int i, j;
*outMatrixNbRow = matrixNbRow;
*outMatrixNbCol = matrixNbCol;
*outMatrix = malloc(matrixNbRow * matrixNbCol * sizeof(double));
for (i=0; i < matrixNbRow * matrixNbCol; i++) {
outMatrix[i] = matrix[i] + mx2[i];
}
}

%}

///// END NOT WORKING EXAMPLE WITH 3 ARGUMENTS /////

If I add one more input matrix I get an error message from scilab that the function needs only two arguments. The example file:

///// NOT WORKING EXAMPLE WITH 3 ARGUMENTS /////
%module addMx3

%include <matrix.i>

%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *matrix, int matrixNbRow, int matrixNbCol) };
%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *mx2,    int mx2NbRow,    int mx2NbCol   ) };
%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *mx3,    int mx3NbRow,    int mx3NbCol   ) };
%apply (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) };

%inline %{

void addMx3(double *matrix, int matrixNbRow, int matrixNbCol,
double *mx2,    int mx2NbRow,    int mx2NbCol,  
double *mx3,    int mx3NbRow,    int mx3NbCol,
double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) {
  
int i, j;
*outMatrixNbRow = matrixNbRow;
*outMatrixNbCol = matrixNbCol;
*outMatrix = malloc(matrixNbRow * matrixNbCol * sizeof(double));
for (i=0; i < matrixNbRow*matrixNbCol; i++) {
(*outMatrix)[i] = matrix[i] + mx2[i] + mx3[i];
}
}

%}
//////////////////////////// END NOT WORKING EXAMPLE WITH 3 ARGUMENTS /////////////////////////////////

Many thanks if you could help!
Best regards,
Alex Szakál

------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user
Reply | Threaded
Open this post in threaded view
|

Re: Scilab multiple (>3) matrix argument question

Simon Marchetto

Hello,

Your example succesfully works.
I haven't any error with the following command in Scilab 5.5.2 (on Linux)  :

--> addMax3([1 1], [1 2], [1 3])
  ans =

     3.     6.

which is the correct result.

Simon

Le 04/07/2016 à 17:56, Alex Szakál a écrit :
%module addMx3

%include <matrix.i>

%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *matrix, int matrixNbRow, int matrixNbCol) };
%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *mx2,    int mx2NbRow,    int mx2NbCol   ) };
%apply (double *IN, int IN_ROWCOUNT, int IN_COLCOUNT) { (double *mx3,    int mx3NbRow,    int mx3NbCol   ) };
%apply (double **OUT, int *OUT_ROWCOUNT, int *OUT_COLCOUNT) { (double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) };

%inline %{

void addMx3(double *matrix, int matrixNbRow, int matrixNbCol,
double *mx2,    int mx2NbRow,    int mx2NbCol,  
double *mx3,    int mx3NbRow,    int mx3NbCol,
double **outMatrix, int *outMatrixNbRow, int *outMatrixNbCol) {
  
int i, j;
*outMatrixNbRow = matrixNbRow;
*outMatrixNbCol = matrixNbCol;
*outMatrix = malloc(matrixNbRow * matrixNbCol * sizeof(double));
for (i=0; i < matrixNbRow*matrixNbCol; i++) {
(*outMatrix)[i] = matrix[i] + mx2[i] + mx3[i];
}
}

%}


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports.http://sdm.link/zohodev2dev
_______________________________________________
Swig-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/swig-user