Would it be okay to add an argument to ctypeslib.as_array() that allowed 
specifying that a pointer references column-major memory layout? 

Currently if we use ndarray.ctypes.data_as() to get a pointer to a 
Fortran-ordered array and then we use ctypeslib.as_array() to read that same 
array back in, we don't have a way of doing the round trip correctly.

For example:
>>> import ctypes as ct
>>> a = np.arange(6).reshape(2,3)    
>>> a = np.asfortranarray(a) 
>>> a
array([[0, 1, 2],
       [3, 4, 5]])
>>> a_ptr = a.ctypes.data_as(ct.POINTER(ct.c_int)) 
>>> b = np.ctypeslib.as_array(a_ptr, shape=a.shape) 
>>> b
array([[0, 3, 1],
       [4, 2, 5]])

The proposed function signature would be something like:
numpy.ctypeslib.as_array(obj, shape=None, order='None'), with order{ā€˜Cā€™, ā€˜Fā€™}, 
optional

Thanks,
Monte
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to