From: Changsheng J. <jia...@gm...> - 2010-02-05 02:23:27
|
Thanks for you reply. I am a newbie, sorry for the garrulous. Using multi-arguments 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 multi-arguments typemap is that there will be too many typemaps, for every different parameter forms. small typemap can be flexible combined, but multi-arguments typemap not. Changsheng Jiang On Fri, Feb 5, 2010 at 05:57, William S Fulton <ws...@fu...>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 init-ed 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 > multi-argument typemaps where the linkage between the parameters is when > they are adjacent to each other. See docs. You could try a multi-argument > typemap for all 5 parameters. > > William > |