[C++-sig] Trouble converting numpy.float32 to C++
Paul F. Kunz
Paul_Kunz at slac.stanford.edu
Thu Jul 30 18:39:25 CEST 2009
I'm using Boost.Python to wrap a C++ class that takes a
std::vector<double> & as argument..
Using scitbx/include/scitbx/boost_python/container_conversions.h as
suggested by the Boost.Python
FAQ, I can correctly convert and use a Python sequence generated by numpy with
numpy.arange(10, dtype=numpy.float64 )
But when I change float64 to float32 I get an exception with message
"No registered converter was able to produce a C++ rvalue of type
double from this Python object of type numpy.float32"
Disappointing but maybe understandable. So I change my C++ class to
accept vector <float> and still get
exception with
"No registered converter was able to produce a C++ rvalue of type
float from this Python object of type numpy.float32"
^^^^^
Strange, not the result I expected. Even stranger, if I change the
python sequence to float64 while keeping the C++ with vector<float> it
works fine; no exception.
Any suggestions on how to get numpy.float32 handled? Also
numpy.int64 converted to a double.
More information about the Cplusplus-sig
mailing list