Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Getting a pointer to the memory behind a numpy structured dtype
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
mark florisson  
View profile  
 More options Aug 12 2012, 6:31 am
From: mark florisson <markflorisso...@gmail.com>
Date: Sun, 12 Aug 2012 11:31:02 +0100
Local: Sun, Aug 12 2012 6:31 am
Subject: Re: [cython-users] Getting a pointer to the memory behind a numpy structured dtype
On 11 August 2012 22:57, Nathaniel Smith <n...@vorpus.org> wrote:

> Hi all,

> I have a problem that's probably pretty simple, but I'm not sure how
> to go about it. I have a numpy array with an arbitrary structured
> dtype:

>   a = np.zeros(10, dtype=["i2,i4"])

> Each entry in this array is a packed struct -- a 2-byte integer
> followed by a 4-byte integer. But, I want to be able to handle
> arbitrary dtypes of this form, and don't care about their internal
> structure. I want to be able to take an index

>   a[i]

> and get a void* or char* to the 6 bytes representing that entry in the
> array, suitable for passing to memcmp() and such. Regardless of the
> actual dtype of the array.

> How do I efficiently, in Cython, convert an array of arbitrary dtype +
> an index into a void*?

> Cheers,
> -n

If the size of the dtype is variable it isn't really possible. If it's
static you can probably declare a (packed) struct of char[n] and use
the numpy view or astype method.

 
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.