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}
The RHS would be set literal syntax in Py3, which doesn't make sense here
at all.
>>> 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]
Here, the RHS makes sense to me. Would
cdef double *a = (0.5, 0.3, 0.1, 0.1)
also make sense to others? Or does this contradict 1WTDI? I wonder what
people think when they see both. I could imagine using a list RHS when I
consider changing the array in my function, while a tuple makes more sense
for immutable arrays. OTOH, I'm not sure users will bother with this
detail, they might just assume an assignment by value.
I assume this feature only works for initial assignments, right? Makes
perfect sense to me in the context of Cython.
I would personally prefer making the LHS
cdef double a[] = [0.5, 0.3, 0.1, 0.1]
but I'm not close to using this anyway, so I'm not bothered with the
details. It would be nice if both worked, since pointers and array names
are pretty much equivalent in C anyway.
Just my two Euro-cents...
Stefan
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev