Sturla Molden wrote: > > Buffers/ndarrays declared with mode="c" or mode="fortran" will only > accept C or Fortran contiguous buffers. But the generated C code does > not assume more than contiguity in the fastest varying dimension. > > With > > a = np.zeros((10,10)) > b = a[::2, :] > > the code generated for np.ndarray[double, ndim=2, mode="c"] would work > for both a and b. That is, > > >>> import numpy as np > >>> np.zeros((10,10))[:,:].strides > (80, 8) > >>> np.zeros((10,10))[::2,:].strides > (160, 8) > > But: > > >>> np.zeros((10,10))[::2,:].flags > C_CONTIGUOUS : False <<<<< Not C contiguous!!! > F_CONTIGUOUS : False > OWNDATA : False > WRITEABLE : True > ALIGNED : True > UPDATEIFCOPY : False > > Should the run-time type-check instead just check for the stride of the > fastest varying dimension? I.e. just assert that b.strides[1] == > sizeof(double)?
This could be exploited in some code to make sure a buffer is contiguous before handing it off to C or Fortran code. In that way it would break backwards compatability. Therefore I'm -1. The memoryviews (in gsoc-kurt branch) supports efficient access to buffers like np.zeros((10,10))[::2,:], so I'd rather push this question off until that is merged. Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
