Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Changsheng Jiang <jiangzuoyan@gm...>  20100128 07:04:58

Hi list, I am wrapping a function, which init resource and return according the parameters, for example svd(int m, int n, int k, double *A, double *U, double *S, double *V); U, S, V is argout, and inited according m, n and k, i.e., U is of size m*k, V is of size n*k, S is of size k. I have wrote %typemap(in,numinputs=0) double *U(PyObject *array = NULL) { npy_intp dims[1]; dims[0] = arg1 * arg3; array = PyArray_SimpleNew(1, dims, NPY_DOUBLE); $1 = array_data(array); } %typemap(argout) double *U { $result = SWIG_Python_AppendOutput($result, array$argnum); } It does not work, for, arg1 and arg3(relative to m, k, respectively.) are initialized after the insertion of the typemap(in) fragments. My question is as the subject: How to refer a parameters? Thanks. Changsheng Jiang 
From: William S Fulton <wsf@fu...>  20100204 21:57:25

Changsheng Jiang wrote: > Hi list, > > I am wrapping a function, which init resource and return according the > parameters, for example > > svd(int m, int n, int k, double *A, double *U, double *S, double *V); > > U, S, V is argout, and inited according m, n and k, i.e., U is of > size m*k, V is of size n*k, S is of size k. > > I have wrote > > %typemap(in,numinputs=0) double *U(PyObject *array = NULL) { > npy_intp dims[1]; > dims[0] = arg1 * arg3; > array = PyArray_SimpleNew(1, dims, NPY_DOUBLE); > $1 = array_data(array); > } > > %typemap(argout) double *U { > $result = SWIG_Python_AppendOutput($result, array$argnum); > } > > It does not work, for, arg1 and arg3(relative to m, k, respectively.) > are initialized after the insertion of the typemap(in) fragments. > > My question is as the subject: How to refer a parameters? > You can't as a typemap is for a type or types for which it is declared. Typemaps are independent of other parameters in a method unless you use multiargument typemaps where the linkage between the parameters is when they are adjacent to each other. See docs. You could try a multiargument typemap for all 5 parameters. William 
From: Changsheng Jiang <jiangzuoyan@gm...>  20100205 02:23:27
Attachments:
Message as HTML

Thanks for you reply. I am a newbie, sorry for the garrulous. Using multiarguments typemap, since the numinputs can only be 0 or 1, then we have to packed all arguments in script language to a list. That's not convenient. For example, We have to write in script svd((mat, k)), not svd(mat, k). Another problem of multiarguments typemap is that there will be too many typemaps, for every different parameter forms. small typemap can be flexible combined, but multiarguments typemap not. Changsheng Jiang On Fri, Feb 5, 2010 at 05:57, William S Fulton <wsf@...>wrote: > Changsheng Jiang wrote: > >> Hi list, >> >> I am wrapping a function, which init resource and return according the >> parameters, for example >> >> svd(int m, int n, int k, double *A, double *U, double *S, double *V); >> >> U, S, V is argout, and inited according m, n and k, i.e., U is of >> size m*k, V is of size n*k, S is of size k. >> >> I have wrote >> >> %typemap(in,numinputs=0) double *U(PyObject *array = NULL) { >> npy_intp dims[1]; >> dims[0] = arg1 * arg3; >> array = PyArray_SimpleNew(1, dims, NPY_DOUBLE); >> $1 = array_data(array); >> } >> >> %typemap(argout) double *U { >> $result = SWIG_Python_AppendOutput($result, array$argnum); >> } >> >> It does not work, for, arg1 and arg3(relative to m, k, respectively.) >> are initialized after the insertion of the typemap(in) fragments. >> >> My question is as the subject: How to refer a parameters? >> >> > You can't as a typemap is for a type or types for which it is declared. > Typemaps are independent of other parameters in a method unless you use > multiargument typemaps where the linkage between the parameters is when > they are adjacent to each other. See docs. You could try a multiargument > typemap for all 5 parameters. > > William > 
Sign up for the SourceForge newsletter:
No, thanks