[Numpy-discussion] numpy ndarray questions
Jochen
cycomanic@gmail....
Mon Jan 26 18:26:21 CST 2009
Hi all,
I just wrote ctypes bindings to fftw3 (see
http://projects.scipy.org/pipermail/scipy-user/2009-January/019557.html
for the post to scipy).
Now I have a couple of numpy related questions:
In order to be able to use simd instructions I
create an ndarray subclass, which uses fftw_malloc to allocate the
memory and fftw_free to free the memory when the array is deleted. This
works fine for inplace operations however if someone does something like
this:
a = fftw3.AlignedArray(1024,complex)
a = a+1
a.ctypes.data points to a different memory location (this is actually an
even bigger problem when executing fftw plans), however
type(a) still gives me <class 'fftw3.planning.AlignedArray'>.
I think I understand the reason for this is that python does a copy
internally (it does not call the __copy__ or __deepcopy__ methods?). Is
there a way that I get a different object type? Or even better is there
a way to prevent operations like a=a+1 or make them automatically
in-place operations? I realise that I could change the __add__ ...
methods but that would also prevent b=a+1 operations.
My second comment is with respect to the documentation for
numpy.ctypeslib.ndpointer
The documentation says:
An ndpointer instance is used to describe an ndarray in restypes
and argtypes specifications.
however if I specify a restype to a function e.g.
clib.malloc.restype =
ctypeslib.ndpointer(flags='contiguous,aligned',shape=shape,dtype=dtype)
Calling clib.malloc(1024) results in a TypeError:
TypeError: default __new__ takes no parameters
Am I correct in assuming that the documentation is incorrect and
ndpointer can only be used for argtypes? Or am I missing something?
Cheers
Jochen
More information about the Numpy-discussion
mailing list