Idiomatic way to do list/dict in Cython?
Posted
by ramanujan
on Stack Overflow
See other posts from Stack Overflow
or by ramanujan
Published on 2009-10-06T23:37:44Z
Indexed on
2010/04/23
15:03 UTC
Read the original article
Hit count: 416
My problem: I've found that processing large data sets with raw C++ using the STL map and vector can often be considerably faster (and with lower memory footprint) than using Cython.
I figure that part of this speed penalty is due to using Python lists and dicts, and that there might be some tricks to use less encumbered data structures in Cython. For example, this page (http://wiki.cython.org/tutorials/numpy) shows how to make numpy arrays very fast in Cython by predefining the size and types of the ND array.
Question: Is there any way to do something similar with lists/dicts, e.g. by stating roughly how many elements or (key,value) pairs you expect to have in them? That is, is there an idiomatic way to convert lists/dicts to (fast) data structures in Cython?
If not I guess I'll just have to write it in C++ and wrap in a Cython import.
© Stack Overflow or respective owner