[Numpy-discussion] order flag again

Travis Oliphant oliphant at ee.byu.edu
Mon Mar 27 16:29:06 CST 2006

Charles R Harris wrote:

> On 3/27/06, *Fernando Perez* <Fernando.Perez at colorado.edu 
> <mailto:Fernando.Perez at colorado.edu>> wrote:
>     Charles R Harris wrote:
>     > What purpose does ascontiguous serve?
>     One I can think of: making sure that C code of the type
>     double foo(double *array,long num_elements) { ... }
>     can be called in C as
>     foo((double *)numpy_arr->data,numpy_arr->dimensions[0]);
>     (the dims name in C may be different, I'm not looking at code
>     right now)
>     and be OK with walking the given memory region as a contiguous
>     chunk of
>     doubles, num_elements of them.
>     As long as foo() doesn't modify its input, this works fine and
>     it's nice to
>     have such guarantees: it makes writing extension code a lot easier.
> OK, it's an interface. Since getting stuff back from C will require a 
> copy if the original is not contiquous, a test involving  
> a.iscontiguous will be needed and ascontiguous can be dispensed with. 
> Isn't there a C version of this anyway? ISTR that numarray had one.
It think you are talking about the UPDATEIFCOPY requirements flag on the 
PyArray_FromAny C-API. Most aren't using this yet (and it's not directly 
exposed to Python).   But it's how you would get a copy of the array 
with the correct requirements, operate on it and then once you delete 
your reference have the information go back into the original array 
(this is true whether or not the array is contiguous).

The original array is also set to be read-only during the time that the 
copy is available so that you can't make changes to it (that are going 
to be lost).

Perhaps what we need to do is make this scheme available to the Python 
user as well.  


More information about the Numpy-discussion mailing list