[Numpy-discussion] help with PyArrayInterface

2021-12-21 Thread bloring
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.PyArrayInterface)
 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?
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com


[Numpy-discussion] Re: help with PyArrayInterface

2021-12-27 Thread bloring
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
___
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com