speeding things up with C++

bullockbefriending bard kinch1967 at gmail.com
Thu May 31 06:45:32 EDT 2007


Thanks this is good news. I think my C/C++ background is sufficient to
manage to figure things out if I RTFM carefully.

Basically I want to pass in a Python list of integer tuples, create an
STL container full of equivalent tuples, apply some processor-
intensive algorithm to said list of tuples, and finally poke the
results back into another Python list of integer tuples and return it
to the calling Python environment. Data structures are well-defind and
simple, and the most complex case would be 3-deep nested list, so I
will seriously consider figuring out how to do it manually as you
suggest.

On May 31, 3:04 am, Jorgen Grahn <grahn+n... at snipabacken.dyndns.org>
wrote:
> On 26 May 2007 02:19:39 -0700, bullockbefriending bard <kinch1... at gmail.com> wrote:
> ...
>
> > Essentially, I need to pass a list of 6-tuples containing only
> > integers to my new sadly necessary super-fast compiled language
> > function which i am not looking forward to writing:
>
> > input: [(1,2,3,4,5,6), (7,8,9,10,11,12),...]
>
> > and after much thrashing of processor resources, return data which
> > looks like this to the Python calling environment:
>
> > output: [( (1, 2), (1,), (12,), (13), (1, 7, 11), (9,) ), (  another
> > nested tuple like preceding one  ), .... ]
> ...
> > However, I hope someone reading this will be able to tell me that I'm
> > being a total pessimist and that in fact it isn't very difficult to do
> > what I want to do using SWIG.
>
> You're talking about the actual conversion between Python data
> structures and C or C++ data structures?  That is easy to do even
> manually, IMHO -- provided a decent C background.
>
> Have a look in the Python/C API Reference Manual, and the mapping
> becomes clear. The PyListObject stuff for example, where there's a C
> function for every basic operation on lists, and where the elements
> have the C type PyObject. And so on.  Mapping to C is just a matter of
> walking a nested data structure, where you have a good idea what it is
> supposed to look like (a list of six-tuples of some kind of numbers).
>
> /Jorgen
>
> --
>   // Jorgen Grahn <grahn@        Ph'nglui mglw'nafh Cthulhu
> \X/     snipabacken.dyndns.org>  R'lyeh wgah'nagl fhtagn!





More information about the Python-list mailing list