On Oct 10, 2008, at 1:40 AM, Dag Sverre Seljebotn wrote:
> Robert Bradshaw wrote:
>> On Oct 2, 2008, at 2:03 PM, Gabriel Gellner wrote:
>>
>>
>>> On Thu, Oct 02, 2008 at 05:00:40PM -0400, Gabriel Gellner wrote:
>>>
>>>> is there any way to assign an cdef C array at assignment time?
>>>>
>>>> I want something like:
>>>>
>>>> cdef double a[4] = {0.5, 0.3, 0.1, 0.1}
>>>>
>>>> as anything like this possible in Cython? Or do I need to do
>>>> explicit
>>>> initialization.
>>>>
>>>>
>>> And if it is explicit is there any way to not just do (can I do
>>> some kind of
>>> block assignment?)
>>>
>>> a[0] = 0.5
>>> ...
>>> a[3] = 0.1
>>>
>>
>> This will now work
>>
>> cdef double *a = [0.5, 0.3, 0.1, 0.1]
>>
>> Note that it is still allocated on the stack, but a pointer type is
>> needed as arrays aren't lvalues.
> It looks a bit confusing...
>
> I mean, for a traditional Cython user it looks like a temporary Python
> list is coerced, meaning that a will point to deallocated memory.
Yes, it may look like that, but that's not what happens. The
traditional Cython user shouldn't have to think about allocation, so
I don't think they'll be worried...
> Ignoring that issue, what even happens if you reassign a to some other
> pointer? Or is that disallowed?
This is allowed, and works as expected.
> The initial syntax proposed avoids these problems. I understand that
> this was probably much easier, OTOH it might be better not to have a
> feature rather than having a confusing feature...
Yes, I'd like to support the original syntax too, but I think this
will be useful. I don't think it's too confusing.
- Robert
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev