Merge branch 'master' into smart_holder

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-06-08 12:05:19 -07:00
commit 48c7a3a68f
3 changed files with 26 additions and 2 deletions

View File

@ -1029,7 +1029,10 @@ struct npy_format_descriptor_name<T, enable_if_t<std::is_integral<T>::value>> {
template <typename T> template <typename T>
struct npy_format_descriptor_name<T, enable_if_t<std::is_floating_point<T>::value>> { struct npy_format_descriptor_name<T, enable_if_t<std::is_floating_point<T>::value>> {
static constexpr auto name = _<std::is_same<T, float>::value || std::is_same<T, double>::value>( static constexpr auto name = _<std::is_same<T, float>::value
|| std::is_same<T, const float>::value
|| std::is_same<T, double>::value
|| std::is_same<T, const double>::value>(
_("numpy.float") + _<sizeof(T)*8>(), _("numpy.longdouble") _("numpy.float") + _<sizeof(T)*8>(), _("numpy.longdouble")
); );
}; };
@ -1037,7 +1040,9 @@ struct npy_format_descriptor_name<T, enable_if_t<std::is_floating_point<T>::valu
template <typename T> template <typename T>
struct npy_format_descriptor_name<T, enable_if_t<is_complex<T>::value>> { struct npy_format_descriptor_name<T, enable_if_t<is_complex<T>::value>> {
static constexpr auto name = _<std::is_same<typename T::value_type, float>::value static constexpr auto name = _<std::is_same<typename T::value_type, float>::value
|| std::is_same<typename T::value_type, double>::value>( || std::is_same<typename T::value_type, const float>::value
|| std::is_same<typename T::value_type, double>::value
|| std::is_same<typename T::value_type, const double>::value>(
_("numpy.complex") + _<sizeof(typename T::value_type)*16>(), _("numpy.longcomplex") _("numpy.complex") + _<sizeof(typename T::value_type)*16>(), _("numpy.longcomplex")
); );
}; };

View File

@ -437,4 +437,10 @@ TEST_SUBMODULE(numpy_array, sm) {
sm.def("accept_double_f_style_forcecast_noconvert", sm.def("accept_double_f_style_forcecast_noconvert",
[](py::array_t<double, py::array::forcecast | py::array::f_style>) {}, [](py::array_t<double, py::array::forcecast | py::array::f_style>) {},
"a"_a.noconvert()); "a"_a.noconvert());
// Check that types returns correct npy format descriptor
sm.def("test_fmt_desc_float", [](py::array_t<float>) {});
sm.def("test_fmt_desc_double", [](py::array_t<double>) {});
sm.def("test_fmt_desc_const_float", [](py::array_t<const float>) {});
sm.def("test_fmt_desc_const_double", [](py::array_t<const double>) {});
} }

View File

@ -482,6 +482,19 @@ def test_index_using_ellipsis():
assert a.shape == (6,) assert a.shape == (6,)
@pytest.mark.parametrize(
"test_func",
[
m.test_fmt_desc_float,
m.test_fmt_desc_double,
m.test_fmt_desc_const_float,
m.test_fmt_desc_const_double,
],
)
def test_format_descriptors_for_floating_point_types(test_func):
assert "numpy.ndarray[numpy.float" in test_func.__doc__
@pytest.mark.parametrize("forcecast", [False, True]) @pytest.mark.parametrize("forcecast", [False, True])
@pytest.mark.parametrize("contiguity", [None, "C", "F"]) @pytest.mark.parametrize("contiguity", [None, "C", "F"])
@pytest.mark.parametrize("noconvert", [False, True]) @pytest.mark.parametrize("noconvert", [False, True])