Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop NumPy build dependency #751

Merged
merged 18 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions conda/recipes/cucim/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
31 changes: 26 additions & 5 deletions python/pybind11/cucim_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

#include <fmt/format.h>
#include <fmt/ranges.h>
#include <pybind11/numpy.h>
#include <Python.h>
#include <pybind11/buffer_info.h>
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/pytypes.h>
#include <pybind11/stl.h>

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

auto arr = pybind11::array_t<int64_t, py::array::c_style | py::array::forcecast>::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<int64_t*>(buf.ptr);
mv_obj = py::cast<py::object>(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<int64_t>::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<const int64_t*>(buf.ptr);
ssize_t data_size = buf.size;
locations.reserve(data_size);
locations.insert(locations.end(), &data_array[0], &data_array[data_size]);
Expand Down