diff --git a/conda/recipes/cucim/meta.yaml b/conda/recipes/cucim/meta.yaml index 47768a92f..ed800d086 100644 --- a/conda/recipes/cucim/meta.yaml +++ b/conda/recipes/cucim/meta.yaml @@ -63,7 +63,6 @@ requirements: {% endif %} - cupy >=12.0.0 - libcucim ={{ version }} - - numpy 1.23 - python - rapids-build-backend >=0.3.0,<0.4.0.dev0 - scikit-image >=0.19.0,<0.23.0a0 @@ -74,7 +73,7 @@ requirements: {% if cuda_major != "11" %} - cuda-cudart {% endif %} - - {{ pin_compatible('numpy') }} + - numpy >=1.23,<2.0a0 - click - cupy >=12.0.0 - lazy_loader >=0.1 diff --git a/python/pybind11/cucim_py.cpp b/python/pybind11/cucim_py.cpp index 62f041e2d..bb91b5c43 100644 --- a/python/pybind11/cucim_py.cpp +++ b/python/pybind11/cucim_py.cpp @@ -19,9 +19,11 @@ #include #include -#include +#include +#include #include #include +#include #include #include @@ -445,11 +447,30 @@ py::object py_read_region(const CuImage& cuimg, { py::gil_scoped_acquire scope_guard; - auto arr = pybind11::array_t::ensure(location); - if (arr) // fast copy + py::object mv_obj = py::none(); + try { - py::buffer_info buf = arr.request(); - int64_t* data_array = static_cast(buf.ptr); + mv_obj = py::cast(py::memoryview(location)); + } + catch (const std::exception& e) + { + } + + if (!mv_obj.is_none()) // fast copy + { + py::memoryview mv(mv_obj); + py::buffer_info buf(PyMemoryView_GET_BUFFER(mv.ptr()), false); + + if (buf.format != py::format_descriptor::format()) + { + throw std::invalid_argument("Expected int64 array-like"); + } + if (PyBuffer_IsContiguous(buf.view(), 'C') == 0) + { + throw std::invalid_argument("Expected C-contiguous array-like"); + } + + const int64_t* data_array = static_cast(buf.ptr); ssize_t data_size = buf.size; locations.reserve(data_size); locations.insert(locations.end(), &data_array[0], &data_array[data_size]);