
I would like to make a C++ data structure that internally has a contiguous buffer look like a Numpy array via the numpy ArrayInterface. I already have this structure wrapped and usable in Python and things seem fairly straight forward except I am not sure about the typekind field of the PyArrayInterface structure. In the documentation (here https://numpy.org/doc/stable/reference/c-api/types-and-structures.html#c.PyA...) I see that typekind is a char and that there are values for some but not all of the various C++ POD numeric types.. What typekind value should I use for single precision floating point, 8 bit ineteger, 16 bit integer, etc etc? Those types are all supported by Numpy, but I don't know what the typekind value should be. Can you point to a list of vlaues?

Thank you Matti. That is what I was looking for! However, I've since learned that it is not what is needed. I'm posting again because I found some aspects of the PyArrayInterface a bit inconsistent w/ other places in numpy and confusing. It may be the case that others in the future find this post helpful. Numpy's PyArrayInterface structure in its simplest use requires 3 fields to declare the type of data pointed to. ``` char typekind; // a code declaring the type, does not declare the size of the type. int itemsize; // the size of the type declared in typekind int flags; // flags that among other things declare endianness of the data pointed to ``` I needed all 3 of these, the flags field was needed to tell that the memory was in native machine order because that is not the default. Thanks for the help, I got it working

Thank you Matti. That is what I was looking for! However, I've since learned that it is not what is needed. I'm posting again because I found some aspects of the PyArrayInterface a bit inconsistent w/ other places in numpy and confusing. It may be the case that others in the future find this post helpful. Numpy's PyArrayInterface structure in its simplest use requires 3 fields to declare the type of data pointed to. ``` char typekind; // a code declaring the type, does not declare the size of the type. int itemsize; // the size of the type declared in typekind int flags; // flags that among other things declare endianness of the data pointed to ``` I needed all 3 of these, the flags field was needed to tell that the memory was in native machine order because that is not the default. Thanks for the help, I got it working
participants (2)
-
bloring@lbl.gov
-
Matti Picus