I have a custom float data type that emulates 128bit floats using two 64bit floats (the double-double class dd_real
from the QD library). From C++ I want to export an ndarray to python. I already know how to do this for 64bit floats, but for double-doubles I somehow need to specify my own custom dtype. How to do that?
Note: numpy has its own 128bit float (np.float128) unfortunately this maps to long double
in C/C++ which is merely an 80bit-float stored in 128bit (on all of my platforms).
In fact, one should be able to do this exactly in the same way that numpy exports np.float128 (I just don't know how that is done), with the only difference that it uses dd_real
on the C++ side instead of long double
.
If this helps, I already exported the C++ type dd_real
to python using boost::python
maybe this can be reused somehow.
So far I was able to research the following
The numpy documentation for dtypes refers to C-API for how to export custom dtypes, but that document somehow only explains the existing dtypes not how to create new ones.
When browsing stackoverflow I found this example, but I wonder if for
dd_real
this could be simpler. I also don't see where the dtype is actually generated. Maybe only in python __ init__ vianp.typeDict['quaternion'] = np.dtype(quaternion)
. How to use that dtype in C++ when I want to generate an ndarray?