Skip to content

Commit

Permalink
do not copy data of points, in immutable
Browse files Browse the repository at this point in the history
* fixes #367
* very gross; need to use pybind11::detail to be able to touch the flags
  • Loading branch information
mgeplf committed Jan 10, 2022
1 parent 3ba82b5 commit c695bb8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions binds/python/bind_immutable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ void bind_immutable_module(py::module& m) {
// Property accessors
.def_property_readonly(
"points",
[](morphio::Morphology* morpho) {
const auto& data = morpho->points();
return py::array(static_cast<py::ssize_t>(data.size()), data.data());
[](const morphio::Morphology& morpho) {
const auto& data = morpho.points();
auto res =
py::array(static_cast<py::ssize_t>(data.size()), data.data(), py::none());
py::detail::array_proxy(res.ptr())->flags &=
~py::detail::npy_api::NPY_ARRAY_WRITEABLE_;
return res;
},
"Returns a list with all points from all sections (soma points are not included)\n"
"Note: points belonging to the n'th section are located at indices:\n"
Expand Down
1 change: 1 addition & 0 deletions tests/test_4_immut.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_components():
for cell in CELLS.values():
assert cell.n_points == len(cell.points)
assert cell.section(0).n_points == len(cell.section(0).points)
assert not cell.points.flags.writeable


def test_is_root():
Expand Down

0 comments on commit c695bb8

Please sign in to comment.