From 7d5195d66b6188a4da49f690db6a0f8d414b6eaa Mon Sep 17 00:00:00 2001 From: Nils Wentzell Date: Wed, 24 Jun 2020 13:33:13 -0400 Subject: [PATCH] Fix conversion of numpy_proxy to std::vector for non-trivial striding --- c++/cpp2py/converters/vector.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/c++/cpp2py/converters/vector.hpp b/c++/cpp2py/converters/vector.hpp index 7a6f7c3..9529801 100644 --- a/c++/cpp2py/converters/vector.hpp +++ b/c++/cpp2py/converters/vector.hpp @@ -32,13 +32,17 @@ namespace cpp2py { // Make a new vector from numpy view template std::vector make_vector_from_numpy_proxy(numpy_proxy const &p) { EXPECTS(p.extents.size() == 1); - EXPECTS(p.strides == v_t{sizeof(T)}); + EXPECTS(p.strides[0] % sizeof(T) == 0); - T *data = static_cast(p.data); long size = p.extents[0]; + long step = p.strides[0] / sizeof(T); std::vector v(size); - std::copy(data, data + size, begin(v)); + + T *data = static_cast(p.data); + for(long i = 0; i < size; ++i) + v[i] = *(data + i * step); + return v; }