[Numpy-discussion] Contiguous memory zone with C API

Marc.Poinot at onera.fr Marc.Poinot at onera.fr
Mon Oct 21 07:22:33 EDT 2013

Hi all,

I try to change my old C API numpy code to the 'new' API. I used to hack some internal stuff in Numpy (yes it's bad...) and I wonder now how to change it.

Let's take an example: I have ocount numpy arrays with data allocated elsewhere than numpy, the data pointer of the PyArrayObject is set with the malloc'd zone.
Now I select one of these array to be the memory base for all of them, then I realloc each data pointer to make sure the ocount of them have a contiguous zone.
The code is now 'rejected' by the new API, how can I do that without hacking into the PyArray_Object?

   for (j=1;j<ocount;j++)
((PyArrayObject*)first)->data=realloc(PyArray_DATA(first),psize); /* *** how to do that with the API ? */

I use that trick to make sure that separate numpy each representing a coordinate of a vector can be gather in a single array.
I've had a look at PyArray_resize but it requires a own_data flag which I do not have...
Any hint, remark?

-- ----------------------------------------------------------------------------
-- Marc POINOT [ONERA/DSNA] Tel:+  Fax:+
-- Avertissement/disclaimer http://www.onera.fr/en/emails-terms
-- ----------------------------------------------------------------------------

More information about the NumPy-Discussion mailing list