Kurt Smith wrote:
> On Mon, May 4, 2009 at 2:37 PM, Robert Bradshaw
> <[email protected]> wrote:
>> On May 4, 2009, at 11:33 AM, Stéfan van der Walt wrote:
>>
>>> Hi all,
>>>
>>> Is there a way to tell Cython if you are using a homogeneous list?
>>> E.g.
>>>
>>> cdef list[int] my_list
>>>
>>> my_list.append(1)
>>> my_list.append(2)
>>>
>> No, there's not. It would be nice, but it would be hard to control
>> what people stick in the list (e.g. if you pass it off to another
>> routine). You might want to look at using NumPy arrays, which can
>> store lists of actual c ints, etc.
> 
> In addition to NumPy arrays, you might consider using array.array
> which support 'append' and other list methods.  They're basically
> homogeneous lists within the Python standard lib.  A bit more flexible
> but not as powerful as NumPy arrays.

The question then becomes: Do we support "array.array[int]"?

And I think the answer is that we actually might in Python 2.6+ due to 
PEP 3118 if you make a proper pxd for the array module, but as far as I 
know noone has tested it.

We could have basic support for this in older Python versions as well, 
somebody just has to write the pxd.

Using append at the same time would cause a lot of trouble though (but 
again, they might have changed append to raise an exception if a buffer 
is acquired in Py2.6+ -- I don't know).

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

Reply via email to