[C++-sig] ANN: PyUblas -- Numpy+Boost.Ublas = happy

Ger van Diepen diepen at astron.nl
Wed May 14 16:10:29 CEST 2008


Hi Andreas,

I was busy (and had a few days off) in the past weeks, but today I returned to the array scalar problem.
I've implemented the conversion for array scalars in my code and it seems to work nicely.

However, I did it a bit different as I need the possibility to convert to an AnyValue object (a kind of any object). This is needed for a function which can accept any basic scalar (and array) type (thus has AnyValue in its signature).
I use
    boost::python::implicitly_convertible<AnyValue,int>();
to be able to convert a numpy array scalar to int for functions accepting an int.
Unfortunately the compiler complained about ambiguous constructors when using that for std::complex (e.g. double, complex<float> and complex<double> for complex<double>). I have to see if I can work around that problem, but I'm afraid the problem is fundamental.

Furthermore we have the possibility to convert a Python sequence to std::vector. I still have to add the code to accept numpy array scalars in such python sequences, so one can do in python something like:
    obj.func ([arr1[0], arr2[0]])

Note that using int64 numpy on a 32 bit system gives the same problem as int32 on a 64 bit system. The same problems arise for int16, float32, etc.
I was wondering if your solution can convert a numpy int16 to a C++ int (on a 32 or 64 bit system) as it looks to me that only one PyTypeObject matches a C++ type.

Cheers,
Ger





More information about the Cplusplus-sig mailing list