Skip to content

Commit 80c27d6

Browse files
authored
Drop NumPy build dependency (#751)
Partially addresses issue: rapidsai/build-planning#82 Even though cuCIM currently `#include`s `<pybind11/numpy.h>`, the actual C++ code appears not to use NumPy. So this attempts to drop the header and the NumPy build dependency. Authors: - https://github.com/jakirkham Approvers: - Mike Sarahan (https://github.com/msarahan) - Gigon Bae (https://github.com/gigony) URL: #751
1 parent 0e75c76 commit 80c27d6

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

conda/recipes/cucim/meta.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ requirements:
6363
{% endif %}
6464
- cupy >=12.0.0
6565
- libcucim ={{ version }}
66-
- numpy 1.23
6766
- python
6867
- rapids-build-backend >=0.3.0,<0.4.0.dev0
6968
- scikit-image >=0.19.0,<0.23.0a0
@@ -74,7 +73,7 @@ requirements:
7473
{% if cuda_major != "11" %}
7574
- cuda-cudart
7675
{% endif %}
77-
- {{ pin_compatible('numpy') }}
76+
- numpy >=1.23,<2.0a0
7877
- click
7978
- cupy >=12.0.0
8079
- lazy_loader >=0.1

python/pybind11/cucim_py.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919

2020
#include <fmt/format.h>
2121
#include <fmt/ranges.h>
22-
#include <pybind11/numpy.h>
22+
#include <Python.h>
23+
#include <pybind11/buffer_info.h>
2324
#include <pybind11/operators.h>
2425
#include <pybind11/pybind11.h>
26+
#include <pybind11/pytypes.h>
2527
#include <pybind11/stl.h>
2628

2729
#include <cucim/cuimage.h>
@@ -445,11 +447,30 @@ py::object py_read_region(const CuImage& cuimg,
445447
{
446448
py::gil_scoped_acquire scope_guard;
447449

448-
auto arr = pybind11::array_t<int64_t, py::array::c_style | py::array::forcecast>::ensure(location);
449-
if (arr) // fast copy
450+
py::object mv_obj = py::none();
451+
try
450452
{
451-
py::buffer_info buf = arr.request();
452-
int64_t* data_array = static_cast<int64_t*>(buf.ptr);
453+
mv_obj = py::cast<py::object>(py::memoryview(location));
454+
}
455+
catch (const std::exception& e)
456+
{
457+
}
458+
459+
if (!mv_obj.is_none()) // fast copy
460+
{
461+
py::memoryview mv(mv_obj);
462+
py::buffer_info buf(PyMemoryView_GET_BUFFER(mv.ptr()), false);
463+
464+
if (buf.format != py::format_descriptor<int64_t>::format())
465+
{
466+
throw std::invalid_argument("Expected int64 array-like");
467+
}
468+
if (PyBuffer_IsContiguous(buf.view(), 'C') == 0)
469+
{
470+
throw std::invalid_argument("Expected C-contiguous array-like");
471+
}
472+
473+
const int64_t* data_array = static_cast<const int64_t*>(buf.ptr);
453474
ssize_t data_size = buf.size;
454475
locations.reserve(data_size);
455476
locations.insert(locations.end(), &data_array[0], &data_array[data_size]);

0 commit comments

Comments
 (0)