[SciPy-user] weave and numpy
Robert Kern
robert.kern at gmail.com
Mon Aug 7 21:28:00 EDT 2006
Sebastian Haase wrote:
> On Monday 07 August 2006 17:50, Sebastian Haase wrote:
>> Hi,
>> if I pass a numpy array 'arr' as argument
>> a) how does the C code get arr.ndim ?
>> b) how does the C code get arr.shape[0],... ?
>> c) if the C code changes elements of arr, are those changes *on the
>> original data* ?
Yes.
> In other words, is weave.inline making a copy of arr ?
No.
>> I searched through
>> http://projects.scipy.org/scipy/scipy/browser/trunk/Lib/weave/doc/tutorial.
>> html?format=raw but did not find a definite answer. From
>> the 'array3d.py' example in weave in looks like Narr would contain the
>> shape !?
Yes. Specifically:
arr_array is the actual PyArrayObject* corresponding to the Python object.
Narr = arr_array->dimensions
Sarr = arr_array->strides
Darr = arr_array->nd
arr = arr_array->data
> Oh, and I forgot: How about non-contiguous arrays !?
Passed straight on through, just like contiguous arrays.
> In the case that these are handled - does that slow things down for proper
> aligned arrays, too !?
You will have to take the strides into account in your code.
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the SciPy-User
mailing list