mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Improve consistency of array and array_t with regard to other pytypes
* `array_t(const object &)` now throws on error * `array_t::ensure()` is intended for casters —- old constructor is deprecated * `array` and `array_t` get default constructors (empty array) * `array` gets a converting constructor * `py::isinstance<array_T<T>>()` checks the type (but not flags) There is only one special thing which must remain: `array_t` gets its own `type_caster` specialization which uses `ensure` instead of a simple check.
This commit is contained in:
committed by
Wenzel Jakob
parent
c7ac16bb2e
commit
4de271027d
@@ -126,4 +126,28 @@ test_initializer numpy_array([](py::module &m) {
|
||||
);
|
||||
|
||||
sm.def("function_taking_uint64", [](uint64_t) { });
|
||||
|
||||
sm.def("isinstance_untyped", [](py::object yes, py::object no) {
|
||||
return py::isinstance<py::array>(yes) && !py::isinstance<py::array>(no);
|
||||
});
|
||||
|
||||
sm.def("isinstance_typed", [](py::object o) {
|
||||
return py::isinstance<py::array_t<double>>(o) && !py::isinstance<py::array_t<int>>(o);
|
||||
});
|
||||
|
||||
sm.def("default_constructors", []() {
|
||||
return py::dict(
|
||||
"array"_a=py::array(),
|
||||
"array_t<int32>"_a=py::array_t<std::int32_t>(),
|
||||
"array_t<double>"_a=py::array_t<double>()
|
||||
);
|
||||
});
|
||||
|
||||
sm.def("converting_constructors", [](py::object o) {
|
||||
return py::dict(
|
||||
"array"_a=py::array(o),
|
||||
"array_t<int32>"_a=py::array_t<std::int32_t>(o),
|
||||
"array_t<double>"_a=py::array_t<double>(o)
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user