[Numpy-discussion] How Can I find out if an array is Contiguous in an extension module?

Chris Barker cbarker at jps.net
Thu Sep 28 18:31:14 EDT 2000

Hi all,

I'm writing an extension module that uses PyArrayObjects, and I want to
be able to tell if an array passed in is contiguous.

I know that I can use PyArray_ContiguousFromObject, and it will just
return a reference to the same array if it is contiguous, but I want to
know whether or not a new array has been created. I realize that most of
the time it doesn't matter, but in this case I am chaning the array in
place, and need to pass it to another function that is expecting a
standard C array, so I need to make sure the user has passed in a
contiguous array.

I was surprised to not find a "PyArray_Contiguous" function, or
something like it.

I see that there is a field in PyArrayObject (int flags) that has a bit
indicating whether a field is contiguous, but being a newbe to C as
well, I'm not sure how to get at it. I'd love a handy utility function,
but if one doesn't exist, can someone send me the code I need to check
that bit?



Christopher Barker,
cbarker at jps.net                      ---           ---           ---
http://www.jps.net/cbarker          -----@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Water Resources Engineering       ------   @    ------   @   ------   @
Coastal and Fluvial Hydrodynamics -------      ---------     --------    

More information about the NumPy-Discussion mailing list