From: Chris Barker <chris.bar...@noaa.gov>
Date: Fri, 27 Jul 2012 11:06:52 -0700
Local: Fri, Jul 27 2012 2:06 pm
Subject: Re: [cython-users] Re: Best Practices for passing numpy data pointer to C ?
On Fri, Jul 27, 2012 at 10:45 AM, Nader Al-Naji <iamnotna...@gmail.com> wrote:
what happens if a is not a numpy array? If you create it in your
> <dtype_t*> np.PyArray_DATA(arr) > is the right way to go. It is superior to the &a[0] solution because it
> a = np.arange(10, dtype=int)
> # This works even if a hasn't been casted yet.
Cython code, you can be confident that it is, but if it's passed in, who knows? and if you have to check, why not cast it? > Not having to cast the array before extracting the buffer is useful if one
you can cast it to a ndarray with unspecified type -- I suspect arr[0]
> knows the size of the elements one is dealing with, but not necessarily the > type. will work there, too. > So I think Sturla's solution is what we should use in the future. It has the
well, as Sturla points out, Cython essentially creates the same code
> same semantics as .data, which I think a lot of people really like, and it > won't be compromised if numpy changes. under the hood if you index the zeroth element anyway. My it's just aesthetics, but I like the more pyhtonic looking: &arr[0] -Chris
> Anyone have any other reasons why Sturla's solution might not be a good
> Thanks,
Christopher Barker, Ph.D.
Emergency Response Division
Chris.Bar...@noaa.gov
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||