[Numpy-discussion] SWIG, typemaps, 2D argout arrays
Christopher Barker
Chris.Barker@noaa....
Tue Oct 14 13:11:29 CDT 2008
T J wrote:
> I'm new to using SWIG and my reading of numpy_swig.pdf tells me that
> the following typemap does not exist:
>
> (int* ARGOUT_ARRAY2, int DIM1, int DIM2)
are you referring to this statement in the docs?
"""
Note that we support DATA_TYPE* argout typemaps in 1D, but not 2D or 3D.
This is because of a quirk with the SWIG typemap syntax and cannot be
avoided.
"""
> What is the recommended way to output a 2D array?
I wonder if SWIG has been improved in that regard? I might be worth a
post to the SWIG list. Otherwise, Bill Spotz is the guy to ask -- if he
doesn't reply to the soon, he may not be monitoring this list 00 you
might try contacting him directly.
> It seems like I should use:
>
> (int* ARGOUT_ARRAY1, int DIM1)
>
> and then provide a python function which reshapes the 1D array?
That probably would be the easiest way to do it.
> Is it
> correct that there will be insignificant performance disadvantages to
> this?
miniscule performance hit -- re-shaping if you aren't changing the data
is cheap.
> Also, is there any way to do this in an automated fashion?
yes -- my SWIG-foo is very rusty, but you can add python code in your
*.i file, so you could write the file that does that conversion, put it
there, and it would get added in by SWIG.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker@noaa.gov
More information about the Numpy-discussion
mailing list