Update testing code in examples/scilab/matrix2
This commit is contained in:
parent
dc852580d1
commit
ff10bf04b8
3 changed files with 41 additions and 10 deletions
|
|
@ -1,3 +1,4 @@
|
|||
#include <stdlib.h>
|
||||
double sumitems(double *first, int nbRow, int nbCol) {
|
||||
int i;
|
||||
double total;
|
||||
|
|
@ -14,14 +15,16 @@ void sumitems_argoutput(double *first, int nbRow, int nbCol,double** result,int*
|
|||
*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);
|
||||
double *tempMatrix ;
|
||||
int i;
|
||||
*numberOfRow=23; *numberOfCol=3;
|
||||
tempMatrix= (double*)malloc(sizeof(double )* *numberOfRow * *numberOfCol);
|
||||
|
||||
for (i=0; i<((*numberOfRow)*(*numberOfCol)); i++) {
|
||||
tempMatrix[i]=i*2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,41 @@
|
|||
%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 void sumitems_argoutput(double *first, int nbRow, int nbCol,double **result,int* nbRowOut,int* nbColOut);
|
||||
extern double* getValues(int *numberOfRow, int *numberOfCol);
|
||||
|
||||
%typemap(out) (double*)(int *nRow, int *nCol)
|
||||
{
|
||||
SciErr sciErr;
|
||||
sciErr = createMatrixOfDouble(pvApiCtx, Rhs+$result, *nRow, *nCol, (double *)$1);
|
||||
if (sciErr.iErr) {
|
||||
printError(&sciErr, 0);
|
||||
return 0;
|
||||
}
|
||||
AssignOutputVariable(pvApiCtx, outputPosition) = Rhs+$result;
|
||||
free($1);
|
||||
}
|
||||
%typemap (in,numinputs=0) (int *numberOfRow, int *numberOfCol)
|
||||
{
|
||||
}
|
||||
%typemap(arginit) (int *numberOfRow, int *numberOfCol)
|
||||
{
|
||||
$1 =(int*)malloc(sizeof(int));
|
||||
$2 =(int*)malloc(sizeof(int));
|
||||
nRow =$1;
|
||||
nCol =$2;
|
||||
}
|
||||
|
||||
%typemap(freearg) (int *numberOfRow, int *numberOfCol)
|
||||
{
|
||||
free($1);
|
||||
free($2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
%inline {
|
||||
extern void sumitems_argoutput(double *first, int nbRow, int nbCol,double **result,int* nbRowOut,int* nbColOut);
|
||||
extern double* getValues(int *numberOfRow, int *numberOfCol);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
exec loader.sce
|
||||
|
||||
myMatrix=[ 103 3 1 12;0 0 2043 1];
|
||||
sumitems(myMatrix)
|
||||
|
||||
m=sumitems_argoutput(myMatrix)
|
||||
myOtherMatrix=getValues();
|
||||
size(myOtherMatrix)
|
||||
disp(myOtherMatrix);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue