![](https://secure.gravatar.com/avatar/f5e2eed5819807cb22e9d04eb66ab290.jpg?s=120&d=mm&r=g)
On Tue, 2009-01-27 at 12:49 +0900, David Cournapeau wrote:
Jochen wrote:
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 can't comment about subclassing ndarrays, but I can give you a hint about aligned allocator problem: you could maintain two list of cached plans, automatically detect whether your arrays are aligned or not, and use the appropriate list of plans; one list is for aligned arrays, one for unaligned. Before removing support for fftw, I played with some C++ code to do exactly that. You can tell fftw to create plans for unaligned arrays by using FFTW_UNALIGNED flag:
http://projects.scipy.org/scipy/scipy/browser/branches/refactor_fft/scipy/ff...
cheers,
David
Hi David, I have actually kept more closely to the fftw way of doing things, i.e. I create a plan python object from two arrays, it also stores the two arrays to prevent someone to delete the original arrays and then executing the plan. You can then either execute the plan object, which executes the fftw_plan, or you can call the fftw guru method fftw_execute_dft(inarray, outarray), where I don't do any checking on the arrays, to keep the performance high. I agree that such an approach is not quite as intuitive as x=fft(y), but for my application (propagation equations) I usually perform a large number of FFTs on two arrays, so I just opted for staying close to the fftw way of doing things. So my problem is not really so much with the alignment, it's more with executing the plans, even if someone has created a plan from two unaligned arrays, if he does something like x=x+1 somewhere in the calculations and later executes a plan which was created using x, x will not change because it's memory is not pointing to the original location. I was looking for some way to prevent this. Cheers Jochen
______________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion