Sturla Molden wrote: > On 3/8/2009 12:06 AM, Robert Bradshaw wrote: > > >> Very interesting, and I like the syntax for the most part (int >> [:,:,"fortran"] seems a bit odd to me, perhaps mode should be a >> keyword). >> > > I wonder if you would consider > > cdef int[::,:] arr > > to indicate that a dimension might have strides in the first dimension > different from 1. And similar > > cdef int[:,::] arr > cdef int[::,::] arr > > That would allow you to ignore strides and speed up indexing for most > arrays. The most common case is unit strides. > Hmm. Nice idea. I would turn it the other way around though;
cdef int[:,::1] for C ordering. Note the explicit "1" stride; I think "::" should always mean the same as ":" or there will be confusion. I think the "faster, more special case" route should always require more syntax knowledge than the "marginally slower generic case". The typical fast access will then look like cdef int[0:,0::1] Next: Would it be possible to incorporate other modes in a similar way? cdef int[::contiguous,::contiguous,::1] could mean C-contiguous 3D-array? What about full mode (i.e. where one on an arbitrary dimension can have pointer dereferences...) perhaps int[::(1,ptr),::contiguous,::1] to get a layout where the first dimension in a contiguous array of pointers to C-ordered 2D contiguous data? :-) All in all, the buffer PEP contains huge flexibility, and locking that flexibility down means more speed. Whether anyone will use it is another issue :-) I suppose int[:,::1] is enough for now. Long-term wishful thinking digression: In typical applications it may be that the compiler can make the decision as to whether one should copy or access in strided mode. For instance: def foo(int[:,:] arr): ... foo(myarr) # Contiguous use foo(myarr[:,::-2]) # Non-contiguous use Here, the compiler has essentially three options: a) "What it says" b) Wrap foo in a copy-in, copy-out wrapper, and also skip that wrapper in the middle line, and indeed if all uses use a contiguous array, skip the wrapper c) Generate one contiguous and one non-contiguous This is just to show the lengths it would be possible to go to. It also gives me an eerie feeling that replacing Fortran (which had had ages to think about stuff like this) will not be easy... Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
