Hi

I get an exception when numpy.float32 are passed to c++ functions that are
expecting a float. I have provided a trivial example

#include <boost/python/module.hpp>
> #include <boost/python/def.hpp>
> double sq(double x){ return x*x;}
> BOOST_PYTHON_MODULE(sq)
> {
>   boost::python::def("sq",sq);
> }
>

When i run it with :

from sq import sq

import numpy as np


> print sq(3.)  #fine

print sq(np.float64(3.)); #fine

print sq(np.float32(3.)); #dosn't work


I get:

9.0
> 9.0
> Traceback (most recent call last):
>   File "sq.py", line 6, in <module>
>     print sq(np.float32(3.)); #dosn't work
> Boost.Python.ArgumentError: Python argument types in
>     sq.sq(numpy.float32)
> did not match C++ signature:
>     sq(double)


I know these are different types and I can just recast the input to
float64, but I assumed that a float32->float64 conversion would be
automatic in this case. Is this the way it is supposed to work? Is there a
way to make an explicit conversion happen?

Thanks,
Kevin Meagher
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to