Kurt Smith wrote: > On Mon, Jun 8, 2009 at 4:39 AM, Dag Sverre > Seljebotn<[email protected]> wrote: >> Dag Sverre Seljebotn wrote: > The new syntax is fine with me, but you already knew that, and I'd be > presuming a lot to say I'm a core developer ;-) I've some clarifying > questions below since my understanding of templates is fairly basic.
To be clear, I definitely want input from *everybody* (users too!) I didn't put it that well. >>> However this creates some syntax issues: >>> >>> A) Currently >>> >>> cdef object[int] arr = ... >>> >>> can be used for PEP 3118 access on a generic object. While not a >>> technical problem (object will never become a template), it looks a bit >>> odd when introducing with a template feature. >>> >>> B) How would a templated buffer type look like? MyType[int][float]? >>> >>> Proposal: >>> >>> The object[int] syntax is removed (are anyone using it?). This is >>> basically done by making any cdef class with the >>> __cythonbufferdefaults__ magic attribute become a "buffer template". >>> Such cdef classes cannot be templates. Any other class cannot be used >>> as >>> a buffer-supporting object. > > 'removed': so no one can use > > cdef object[int] foo = ... > > anymore? Or it has different semantics (must be a 'buffer template' > cdef class)? I presume all the current syntax for buffer indexing > will still be around for backwards compatibility. Removed, so noone can use cdef object[int] foo any more. To get that exact behaviour, one has to do cdef object foo cdef int[:] foo_buf = foo I think this is fair enough -- I'd like to see a real usecase for this syntax if the new one is introduced? ndarray[int] stays though. >>> This removes functionality (much numeric code could care less about >>> whether the underlying object is an ndarray). As a substitute, the main >>> idea in http://wiki.cython.org/enhancements/buffersyntax is accepted, >>> which is to use > > What functionality is removed exactly? The fast indexing with cdef > ints, and all buffer access is now through the object's __getitem__ > and __setitem__ only? Just removing object[type] by itself, without compensating, removes the possibility of writing functions which work across multiple buffers exporters. E.g. a single function which can handle both Image objects and ndarray objects through the buffer API. > >>> >>> cdef int[:] arr = ... >>> >>> for generic access, without any object access (this means that for now >>> only indexing and getting the shape is allowed at all.) >>> >>> I've been wondering a lot about whether this is the right way, and it >>> still seems so, even if it means that there will be (and likely >>> continue >>> to be) two different ways of accessing a buffer; one through an >>> explicit >>> "buffer type" and one through an "automatic template". > > Just to be clear: the "buffer type" is the cdef int[:], and the > 'automatic template' is the cdef MyObj[int]. Both will be indexable, > with the first using default 'fast' indexing on the buffer itself, and > the second indexing through the MyObj.__getitem__. Right? No. I was clumsy here. If MyObj defines __cythonbufferdefaults__, Cython treats it like ndarray is treated today. Otherwise, and when templates are implemented, the "int" is used in whatever way the MyObj template uses it. But what I mean is that in both cases, from the user's perspective one can look at MyObj as a template of sorts. However for writing more generic buffer code (where no knowledge of the type of the object is sometimes not needed at all) a different kind of concept is needed. object[int] used to provide this but I don't think many used it. Dag Sverre _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
