xtensor-stack / xtensor-python

Python bindings for xtensor
BSD 3-Clause "New" or "Revised" License
347 stars 58 forks source link

support char arrays and complicated dtypes (structs) #149

Closed wolfv closed 6 years ago

wolfv commented 6 years ago

This adds support for char arrays:

arr = np.array(["hallo", "test", "123123"], dtype=np.dtype('|S20'))
void test_chars(xt::pyarray<char[20]>& arr)
{
    std::cout << arr(0) << std::endl;
}

It also adds some initial dtype support (i.e. you can declare structs, use them inside C++ and serialize them from numpy). However, pybind has a lot of code that deals with padding differences from C++ / NumPy which I haven't really looked at.

This code also removes our own typenum stuff as well as switching to use PyArray_EquivTypes instead of comparing the typenums. There is a good chance that comparing typenums is faster. Therefore, we could statically enable typenums if we know (from the C++ type) that a statically determinable typenum is available.

@iamthebot you might be interested in this based off of your question in #142

wolfv commented 6 years ago

The way it's implemented now, it falls back to the typenum check for arithmetic types, and checks dtypes for more complicated types (like arrays, or structs).

We reuse Pybind11s mechanism to bind struct arrays but that's experimental for now.