From: William S F. <ws...@fu...> - 2010-02-04 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 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 |