support char arrays and complicated dtypes (structs) - #149
Merged
Merged
Conversation
Member
Author
|
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. |
wolfv
force-pushed
the
add_char_support
branch
2 times, most recently
from
June 20, 2018 18:53
cf2c721 to
03ecfcc
Compare
| xt::pyarray<B> dtype_from_python(xt::pyarray<B>& b) | ||
| { | ||
| if (b(0).a != 1 || b(0).b != 'p' || b(1).a != 123 || b(1).b != 'c') | ||
| throw std::runtime_error("FAIL"); |
| template <class T> | ||
| bool check_array(const pybind11::handle& src) | ||
| { | ||
| using is_arithmetic_type = std::integral_constant<bool, !!pybind11::detail::satisfies_any_of<T, std::is_arithmetic, xtl::is_complex>::value>; |
Member
There was a problem hiding this comment.
Could we convert to bool instead of doing !!?
| import os | ||
| import sys | ||
| import subprocess | ||
| import gc |
| ****************************************************************************/ | ||
|
|
||
| #include <numeric> | ||
| #include <limits> |
| # Useful for debugging any issues with conda | ||
| - conda info -a | ||
| - conda install pytest numpy pybind11==2.2.1 -c conda-forge | ||
| - conda install pytest numpy pybind11==2.2.3 -c conda-forge |
Member
There was a problem hiding this comment.
Do we need 2.2.3, (i.e. do we need to update the readme?)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds support for char arrays:
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_EquivTypesinstead 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