[NumPy-Tickets] [NumPy] #1691: PyArray_FromArray: Properly handle F_CONTIGUOUS with 1D-arrays
NumPy Trac
numpy-tickets@scipy....
Wed Dec 1 07:10:43 CST 2010
#1691: PyArray_FromArray: Properly handle F_CONTIGUOUS with 1D-arrays
--------------------+-------------------------------------------------------
Reporter: dagss | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.5.2
Component: Other | Version: 1.5.0
Keywords: |
--------------------+-------------------------------------------------------
When passing F_CONTIGUOUS to PyArray_FromArray, one is NOT guaranteed an
F_CONTIGUOUS array if ndim==1 (in that case one would have to pass
C_CONTIGUOUS instead). I find this highly confusing and hope my patch is
accepted.
I could not find a way to exercise this from Python, hence no test case
(the reason is that np.asfortranarray etc. seems to *always* copy, for
some reason...perhaps that should be fixed too). See a Cython test case
that gets fixed by this patch inline below.
Patch:
https://github.com/dagss/numpy/commit/c5f273898ccd4b4bd45715fdc54f629f6ee0532a
{{{
"""
>>> a = np.zeros(10)[::2]
>>> a = as_f_contiguous_1d(a)
>>> a.flags.f_contiguous
True
"""
cimport numpy as np
import numpy as np
np.import_array()
def as_f_contiguous_1d(arr):
return np.PyArray_FROMANY(arr, np.NPY_DOUBLE, 1, 1,
np.NPY_F_CONTIGUOUS)
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1691>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list