Skip to content

Commit d79910c

Browse files
committed
Be efficient if possible
1 parent 49a7a5c commit d79910c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/src/G3Vector.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,13 @@ void G3Vector<int64_t>::save(A &ar, const unsigned v) const
7676
}
7777

7878
template <typename V, typename T=typename V::value_type>
79-
auto vector_from_python(const py::array_t<T> &buf) {
79+
auto vector_from_python(const py::array_t<T> &buf, bool contiguous=true) {
8080
if (buf.ndim() != 1)
8181
throw py::type_error("Only valid 1D buffers can be copied to a vector");
8282

83+
if (contiguous)
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

@@ -90,7 +93,7 @@ auto vector_from_python(const py::array_t<T> &buf) {
9093

9194
template <typename V>
9295
auto time_vector_from_python(const py::array &buf) {
93-
return vector_from_python<V, G3TimeStamp>(buf);
96+
return vector_from_python<V, G3TimeStamp>(buf, false);
9497
}
9598

9699
template <typename V>

0 commit comments

Comments
 (0)