diff --git a/src/python/corrade/containers.cpp b/src/python/corrade/containers.cpp index 8ada2f3..4621144 100644 --- a/src/python/corrade/containers.cpp +++ b/src/python/corrade/containers.cpp @@ -24,7 +24,6 @@ */ #include -#include /* so ArrayView is convertible from python array */ #include #include #include @@ -118,8 +117,6 @@ template void arrayView(py::class_, Containers /* Implicitly convertible from a buffer */ py::implicitly_convertible>(); - /* This is needed for implicit conversion from np.array */ - py::implicitly_convertible>(); c /* Constructor */ @@ -603,8 +600,6 @@ Containers::Pair accesso template void stridedArrayView(py::class_, Containers::PyArrayViewHolder>>& c) { /* Implicitly convertible from a buffer */ py::implicitly_convertible>(); - /* This is needed for implicit conversion from np.array */ - py::implicitly_convertible>(); c /* Constructor */ diff --git a/src/python/magnum/magnum.cpp b/src/python/magnum/magnum.cpp index ab145e0..58e89de 100644 --- a/src/python/magnum/magnum.cpp +++ b/src/python/magnum/magnum.cpp @@ -90,40 +90,19 @@ template void imageView(py::class_>& c) { py::implicitly_convertible, T>(); c - /* Constructors. The variants *not* taking an array view have to be - first, otherwise things fail on systems that don't have numpy - installed: - - =================================================================== - ERROR: test_init_empty (test.test.ImageView) - ------------------------------------------------------------------- - Traceback (most recent call last): - File ".../magnum/test/test.py", line 102, in test_init_empty - b = ImageView2D(storage, PixelFormat.R32F, (8, 8)) - ModuleNotFoundError: No module named 'numpy' - - This is because of the order in which pybind processes arguments --- - it would first try to match the (PixelFormat, Vector2i, ArrayView) - variant and *somehow* getting all the way to the third argument, - where, because ArrayView is marked as implicitly convertible from - py::array for numpy compatibility, it ends up doing this in numpy.h: - - module m = module::import("numpy.core.multiarray"); - auto c = m.attr("_ARRAY_API"); - - Wonderful, isn't it. */ - .def(py::init([](const PixelStorage& storage, PixelFormat format, const typename PyDimensionTraits::VectorType& size) { - return T{storage, format, size}; - }), "Construct an empty view") - .def(py::init([](PixelFormat format, const typename PyDimensionTraits::VectorType& size) { - return T{format, size}; - }), "Construct an empty view") + /* Constructors */ .def(py::init([](const PixelStorage& storage, PixelFormat format, const typename PyDimensionTraits::VectorType& size, const Containers::ArrayView& data) { return pyImageViewHolder(T{storage, format, size, data}, pyObjectHolderFor(data).owner); }), "Constructor") .def(py::init([](PixelFormat format, const typename PyDimensionTraits::VectorType& size, const Containers::ArrayView& data) { return pyImageViewHolder(T{format, size, data}, pyObjectHolderFor(data).owner); }), "Constructor") + .def(py::init([](const PixelStorage& storage, PixelFormat format, const typename PyDimensionTraits::VectorType& size) { + return T{storage, format, size}; + }), "Construct an empty view") + .def(py::init([](PixelFormat format, const typename PyDimensionTraits::VectorType& size) { + return T{format, size}; + }), "Construct an empty view") .def(py::init([](Image& image) { return pyImageViewHolder(T{image}, image.data() ? py::cast(image) : py::none{}); }), "Construct a view on an image")