fix matrix input issue
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@12124 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
090ec2d78c
commit
e16a959732
6 changed files with 317 additions and 100 deletions
|
|
@ -7,6 +7,17 @@ double sumitems(double *first, int nbRow, int nbCol) {
|
|||
return total;
|
||||
}
|
||||
|
||||
void sumitems_argoutput(double *first, int nbRow, int nbCol,double** result,int* nbrowres,int* nbcolsres) {
|
||||
int i;
|
||||
*nbrowres=nbRow;
|
||||
*nbcolsres=nbCol;
|
||||
*result=malloc(nbRow*nbCol*sizeof(double));
|
||||
for (i=0; i<(nbRow*nbCol); i++) {
|
||||
(*result)[i]=first[i]+first[i];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
double* getValues(int *numberOfRow, int *numberOfCol) {
|
||||
*numberOfRow=23; *numberOfCol=3;
|
||||
double *tempMatrix = (double*)malloc(sizeof(double) * *numberOfRow * *numberOfCol);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
%module matrixlib
|
||||
%include "matrix.i"
|
||||
extern double sumitems(double *, int, int);
|
||||
%typemap (in, numinputs=0) (int *numberOfRow, int *numberOfCol) {
|
||||
$1 = &iRowsOut;
|
||||
$2 = &iColsOut;
|
||||
}
|
||||
%include matrix.i
|
||||
|
||||
|
||||
|
||||
|
||||
%apply (double* matrixAsInput,int rows,int cols){(double *first, int nbRow, int nbCol)}
|
||||
%apply (double** matrixAsArgOutput,int* rows,int* cols){(double **result,int* nbRowOut,int* nbColOut)}
|
||||
%inline {
|
||||
extern double sumitems(double *first, int nbRow, int nbCol);
|
||||
extern void sumitems_argoutput(double *first, int nbRow, int nbCol,double **result,int* nbRowOut,int* nbColOut);
|
||||
extern double* getValues(int *numberOfRow, int *numberOfCol);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
%typemap(in) (double*, int, int) {
|
||||
%typemap(in) (double* matrixAsInput, int rows, int cols) {
|
||||
int *piAddr = NULL;
|
||||
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
|
||||
sciErr = getVarAddressFromPosition(pvApiCtx, ++scilabArgNumber, &piAddr);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return 0;
|
||||
|
|
@ -11,3 +11,28 @@
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%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(argout) (double** matrixAsArgOutput,int* rows, int* cols)
|
||||
{
|
||||
sciErr = createMatrixOfDouble(pvApiCtx, iVarOut, *$2, *$3, (double *)*$1);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LhsVar(iOutNum) = iVarOut;
|
||||
iOutNum++;
|
||||
iVarOut++;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -63,7 +63,7 @@ or you can use the %apply directive :
|
|||
int iType;
|
||||
double *_piData;
|
||||
int typearg;
|
||||
sciErr = getVarAddressFromPosition(pvApiCtx, $argnum, &piAddrVar);
|
||||
sciErr = getVarAddressFromPosition(pvApiCtx, ++scilabArgNumber, &piAddrVar);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return 0;
|
||||
|
|
@ -155,6 +155,8 @@ output values.
|
|||
printError(&sciErr, 0);
|
||||
return 0;
|
||||
}
|
||||
iOutNum++;
|
||||
iVarOut++;
|
||||
}
|
||||
|
||||
%typemap(argout) short *OUTPUT(int iRowsOut, int iColsOut),
|
||||
|
|
@ -166,6 +168,8 @@ output values.
|
|||
printError(&sciErr, 0);
|
||||
return 0;
|
||||
}
|
||||
iOutNum++;
|
||||
iVarOut++;
|
||||
}
|
||||
|
||||
%typemap(argout) int *OUTPUT(int iRowsOut,int iColsOut),
|
||||
|
|
@ -180,6 +184,8 @@ output values.
|
|||
printError(&sciErr, 0);
|
||||
return 0;
|
||||
}
|
||||
iOutNum++;
|
||||
iVarOut++;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -194,6 +200,8 @@ output values.
|
|||
printError(&sciErr, 0);
|
||||
return 0;
|
||||
}
|
||||
iOutNum++;
|
||||
iVarOut++;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -281,10 +281,10 @@ public:
|
|||
String *outarg = NewString("");
|
||||
for (p = l; p;) {
|
||||
if ((tm = Getattr(p, "tmap:argout"))) {
|
||||
if (out_required > 0) {
|
||||
Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
||||
Printf(f->code,"iOutNum ++;\niVarOut ++;\n");
|
||||
}
|
||||
//if (out_required > 0) {
|
||||
// Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
||||
// Printf(f->code,"iOutNum ++;\niVarOut ++;\n");
|
||||
//}
|
||||
Printv(outarg, tm, "\n", NIL);
|
||||
p = Getattr(p, "tmap:argout:next");
|
||||
out_required ++;
|
||||
|
|
@ -331,6 +331,8 @@ public:
|
|||
flag = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Insert the code checking the number of input */
|
||||
Printf(f->def, "CheckRhs(%d, %d);\n",num_required,num_arguments);
|
||||
Printf(f->def, "CheckLhs(%d, %d);\n",out_required,out_required);
|
||||
|
|
@ -339,10 +341,13 @@ public:
|
|||
/* Insert the order of output parameters*/
|
||||
if (flag)
|
||||
Printf(f->def, "\nint iOutNum = 1;\nint iVarOut = Rhs + 1;");
|
||||
|
||||
/* Insert the argument counter */
|
||||
Printf(f->def, "\nint scilabArgNumber=0;");
|
||||
|
||||
/* Finish the the code for the function */
|
||||
if (flag)
|
||||
Printf(f->code, "LhsVar(iOutNum) = iVarOut;\n");
|
||||
//if (flag)
|
||||
Printf(f->code, "//PutLhsVar();\n");
|
||||
Printf(f->code, "return 0;\n");
|
||||
Printf(f->code, "}\n");
|
||||
|
||||
|
|
@ -458,6 +463,8 @@ public:
|
|||
Printf(setf->def, "SciErr sciErr;\n");
|
||||
/* Add the local variable */
|
||||
Wrapper_add_local(setf, "piAddrVar", "int *piAddrVar");
|
||||
/* Insert the argument counter */
|
||||
Printf(setf->def, "\nint scilabArgNumber=0;");
|
||||
|
||||
/* Deal with the set function */
|
||||
if (is_assignable(n)) {
|
||||
|
|
@ -500,6 +507,8 @@ public:
|
|||
Printf(getf->def, "SciErr sciErr;\n");
|
||||
/* Insert the order of output parameters */
|
||||
Printf(getf->def, "\nint iOutNum=1;\nint iVarOut=Rhs+1;");
|
||||
/* Insert the argument counter */
|
||||
Printf(getf->def, "\nint scilabArgNumber=0;");
|
||||
|
||||
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
|
||||
Replaceall(tm, "$result", name);
|
||||
|
|
@ -572,6 +581,8 @@ public:
|
|||
Printf(getf->def, "SciErr sciErr;\n");
|
||||
/* Insert the order of output parameters*/
|
||||
Printf(getf->def, "\nint iOutNum=1;\nint iVarOut=Rhs+1;");
|
||||
/* Insert the argument counter */
|
||||
Printf(getf->def, "\nint scilabArgNumber=0;");
|
||||
|
||||
if ((tm = Swig_typemap_lookup("varout", n, name, 0))) {
|
||||
Replaceall(tm, "$result", value);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue