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
>>
>> Looking for magic :-)
>
> Nothing yet, I put up http://trac.cython.org/cython_trac/ticket/93
>
> Also, I would like to be able to use (literal) tuples/dicts to assign
> to structs (and vice-versa). Would non-literal tuples/dicts be going
> too far?
I think a default "literal struct constructor" might be more fitting?
And I see no reason it would need to be literal except for brevity of C
code.
A problem is with mutability though, if it is done using C static
allocation. I.e.:
def f(x):
cdef int a[3] = [1,2,3]
if x: a[2] = 1
print a[2]
f(True) # prints 1...
f(False) # likely prints 1 too!
This is consistent with what you expect from C but very contrary to what
Python users would expect.
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev