Skip to content

Commit 363f229

Browse files
committed
Use efficient buffer copy if the array strides indicate a contiguous 1D array
1 parent 39f5a77 commit 363f229

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

core/src/G3Vector.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ auto vector_from_python(const py::array_t<T> &buf) {
8080
if (buf.ndim() != 1)
8181
throw py::type_error("Only valid 1D buffers can be copied to a vector");
8282

83+
if (buf.strides(0) == sizeof(T))
84+
return std::make_shared<V>(buf.data(), buf.data() + buf.size());
85+
8386
auto rbuf = buf.template unchecked<1>();
8487
auto vec = std::make_shared<V>(rbuf.shape(0));
8588

0 commit comments

Comments
 (0)