[Numpy-discussion] Re: Numpy-discussion digest, Vol 1 #7 - 1 msg

Travis Oliphant Oliphant.Travis at mayo.edu
Fri Feb 4 15:49:34 EST 2000


> I'm having a problem with PyArray_Check.  If I just call
> PyArray_Check(args) I don't have a problem, but if I try to assign the
> result to anything, etc., it crashes (due to acces violation).  So, for
> example the code at the end of this note doesn't work, yet I know an array
> is being passed and I can, for example, calculate its trace correctly if I
> type cast it as a PyArrayObject*.
> 
> Also, a more general question: is this the recommended way to input numpy
> arrays when using swig, or do most people find it easier to use more
> elaborate typemaps, or something else?

I have some experience with SWIG but it is not my favorite method to use
Numerical Python with C, since you have so little control over how things
get allocated.

Your problem is probably due to the fact that you do not run
import_array() in the module header.  

There is a typemap in SWIG that let's you put commands to run at module
initialization.   Try this in your *.i file.

%init %{
        import_array();
%}

This may help.


Best,

Travis






More information about the NumPy-Discussion mailing list