[Numpy-discussion] order flag again

Charles R Harris charlesr.harris at gmail.com
Mon Mar 27 14:16:02 EST 2006


On 3/27/06, Fernando Perez <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.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060327/3addee19/attachment.html>


More information about the NumPy-Discussion mailing list