On Mon, Jun 8, 2009 at 1:53 PM, Dag Sverre
Seljebotn<[email protected]> wrote:
> 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 see now ;-)

>
> 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.

A possible problem I envision with keeping 'ndarray[int]' around
exactly as is (although I'm exposing my ignorance of the proposed
template usage): if using bracket-templates becomes fairly common in
Cython, won't people then start to see 'ndarray[int]' as another
template expression and *not* a (magic) buffer statement?  Or is it
obvious since 'ndarray' is special?  If someone created their own cdef
class with __cythonbufferdefaults__, wouldn't it mimick the template
bracket expression/statement and be quite confusing?

>>
>> 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.
>
>
[snip]
>>
>> 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.

I see.  Perhaps my above comment isn't such a concern, then.

Kurt
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to