[C++-sig] boost::* standard python conversions
Ralf W. Grosse-Kunstleve
rwgk at yahoo.com
Tue Feb 15 12:38:49 CET 2005
--- Nicodemus <nicodemus at esss.com.br> wrote:
> Ralf W. Grosse-Kunstleve wrote:
> >I am actively
> >using four or five different approaches, depending on the usage patterns.
> >Hopefully in ten year, when computers are again 10 times faster and
> >as 32GB of RAM or more this will be a non-issue and we can simply throw in a
> >general solution for everything, even if the conversions are not used very
> >much. However given current technology I find it necessary to decide
> >case-by-case what is the best balance of compile-time/extension module size
> >run-time performance.
> Hi Ralph,
> I would be interested in hear the approaches you take to deal with this
I'll try a very brief summary of my array wrappers:
- The simplest approach: mapping from C++ containers to Python tuples and vice
versa. Main support header:
- The most comprehensive approach: fully loaded boost::python::class_<> based
N-dimensional arrays including all arithmetic (+-*/%) and boolean (<>=<=>==!=)
operators, math functions (sin, cos, floor, etc.), selection facilities
(generalized slicing) and full+fast+portable pickle support. The same Python
type can be converted to 20+ different but related C++ types; e.g. if the
multi-dimensional Python array is in fact just a 1-dim array it can be
converted to a 1-dim C++ type. -- This system is quite a beast. Compiling the
complete wrappers for the element type double takes about 45 seconds under
Redhat WS 3, 3GHz Xeon. Now consider that I also have wrappers for bool,
complex_double, float, int, long, size_t, std::string and a "vec3<double>" type
(triple of three doubles), plus a few domain-specific types.
- A simplified array wrapper for a reference-counted 1-dim array type, similar
to the vector indexing suite, but with a few extras to cooperate with the
"comprehensive wrappers" above, and a few omissions to keep compile times down.
- Simple wrappers for std::vector, std::set, std::map. Designed as thin as
possible to keep compile times down.
I am not sure how much any of this generalizes. I guess container_conversions.h
could be useful in many contexts, but the compromises I made in implementing
the other approaches may not work well in other environments. I am posting the
links here only as potential sources of ideas, for people who are not afraid of
looking at raw code.
Do you Yahoo!?
Yahoo! Mail - 250MB free storage. Do more. Manage less.
More information about the Cplusplus-sig