Skip to content

Commit

Permalink
use shared_ptr to capture array in lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminum committed Aug 28, 2024
1 parent 945e35d commit 2222fcb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cpp/pybind/core/tensor_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ Tensor PyArrayToTensor(py::array array, bool inplace) {
Dtype dtype = pybind_utils::ArrayFormatToDtype(info.format, info.itemsize);
Device device("CPU:0");

array.inc_ref();
std::function<void(void*)> deleter = [array](void*) -> void {
auto shared_array = std::make_shared<py::array>(array);
std::function<void(void*)> deleter = [shared_array](void*) mutable -> void {
py::gil_scoped_acquire acquire;
array.dec_ref();
shared_array.reset();
};
auto blob = std::make_shared<Blob>(device, info.ptr, deleter);
Tensor t_inplace(shape, strides, info.ptr, dtype, blob);
Expand Down

0 comments on commit 2222fcb

Please sign in to comment.