27struct type_caster<E> {
28 using value_type =
typename E::value_type;
29 using array_type = xt::xarray<value_type>;
31 NB_TYPE_CASTER(array_type, const_name(
"numpy.ndarray"));
32 static handle from_cpp(
const E& expr, rv_policy, cleanup_list*) {
33 auto data = std::make_unique<array_type>(expr);
34 py::capsule owner(data.get(),
35 [](
void* pointer)
noexcept { delete static_cast<array_type*>(pointer); });
36 auto* array = data.release();
37 return py::ndarray<py::numpy, value_type>(array->data(), array->dimension(),
38 array->shape().data(), owner)
48class scoped_interpreter {
50 NB_INLINE scoped_interpreter() {
52 if (!py::register_module(initialize())) fail_initialization();
54 ~scoped_interpreter();
56 scoped_interpreter(
const scoped_interpreter&) =
delete;
57 scoped_interpreter& operator=(
const scoped_interpreter&) =
delete;
58 scoped_interpreter(scoped_interpreter&& other) noexcept
59 : m_active(std::exchange(other.m_active,
false)) {}
62 static NB_EXPORT py::module_ initialize();
63 [[noreturn]]
static void fail_initialization();
95class NB_EXPORT AxesSubPlot {
97 explicit AxesSubPlot(py::object axes) : m_obj(std::move(axes)) {}
99 DEFINE_PY_CLASS_METHOD_AUTO(scatter)
100 DEFINE_PY_CLASS_METHOD_AUTO(triplot)
101 DEFINE_PY_CLASS_METHOD_AUTO(tripcolor)
102 DEFINE_PY_CLASS_METHOD_AUTO(plot)
103 DEFINE_PY_CLASS_METHOD_AUTO(quiver)
104 DEFINE_PY_CLASS_METHOD_AUTO(text)
105 DEFINE_PY_CLASS_METHOD_AUTO(set_xlabel)
106 DEFINE_PY_CLASS_METHOD_AUTO(set_ylabel)
107 DEFINE_PY_CLASS_METHOD_AUTO(set_zlabel)
108 DEFINE_PY_CLASS_METHOD_AUTO(set_title)
109 DEFINE_PY_CLASS_METHOD_AUTO(set_aspect)
110 DEFINE_PY_CLASS_METHOD_AUTO(grid)
111 DEFINE_PY_CLASS_METHOD_AUTO(legend)
112 DEFINE_PY_CLASS_METHOD_AUTO(set_xlim)
113 DEFINE_PY_CLASS_METHOD_AUTO(set_ylim)
114 DEFINE_PY_CLASS_METHOD_AUTO(set_zlim)