Hi,

This is actually something I am wondering about as well, so I hope
it's okay to join the discussion.  My understanding is that when you
declare a variable to have a list, tuple, or dict type, then cython
optimizes it by using faster direct ways to accessing the elements
when you use them. However, since these containers always store the
elements as PyObject* pointers which hold any type, it's too difficult
to use element type information in a robust way.  Is that correct?

What is the most "cythonic" way to mimic the list functionality when
you do have homogeneous list content?  I have run into cases in
numerical calculations where I need to be append an arbitrary number
of numbers to a list (e.g. accumulating data statistics while
processing large amounts of data).  In such contexts, using a list is
too slow. One thing I've done is use a numpy array with a significant
amount of extra space, keep a separate counter to denote the end, and
access it through the nice buffer interface.  This works pretty well,
but seems quite clunky compared to how natural it is in python.  Doing
slicing and concatenation stuff would also be nice.

Personally, what I think would be really nice is a unified wrapper to
the C++ STL containers and some of the libraries with easy conversion
functions between the parallel python containers.  I know that
wrapping an STL vector is one of the examples given, so this shouldn't
be too hard.  I don't have time for at least a few weeks, and there
are several other important things on my to-do list, but I'll try to
look into it.

That said, I am pretty new still to cython, so please correct me if my
perspective on things is off or I'm just plain wrong.

Thanks,
--Hoyt






On Mon, Sep 1, 2008 at 8:42 AM, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> Hi,
>
> T J wrote:
>> New to cython, and I found the sphinx documentation very helpful.
>> However, I didn't find much about dictionaries and lists.  How does
>> cython handle these....
>
> It uses Python's list/dict type.
>
>
>> for example, if I were to have a list of
>> strings....is there a way to inform cython about this so that it could
>> be compiled?
>
> The creation of such a list runs in compiled code. But you cannot specify the
> type of the list content. And I don't see a use case for that.
>
>
>> I'm assuming non-homogeneous lists are not candidates
>> for optimizations (correct?).
>
> There is no difference between a list with homogeneous content and one with
> mixed content. What would you like to see 'optimised'?
>
>
>> In general, I guess I am looking for
>> more discussion/help about such topics.  Any pointers would be
>> appreciated.
>
> Maybe you could tell us what you want to achieve? That would make it easier to
> answer your question.
>
> Stefan
>
> _______________________________________________
> Cython-dev mailing list
> [email protected]
> http://codespeak.net/mailman/listinfo/cython-dev
>



-- 
+++++++++++++++++++++++++++++++++++
Hoyt Koepke
UBC Department of Computer Science
http://www.cs.ubc.ca/~hoytak/
[EMAIL PROTECTED]
+++++++++++++++++++++++++++++++++++
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to