Skip to content

Commit

Permalink
Fix conversion of numpy_proxy to std::vector for non-trivial striding
Browse files Browse the repository at this point in the history
  • Loading branch information
Wentzell committed Jun 24, 2020
1 parent 57b25fb commit 7d5195d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions c++/cpp2py/converters/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ namespace cpp2py {
// Make a new vector from numpy view
template <typename T> std::vector<T> 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<T *>(p.data);
long size = p.extents[0];
long step = p.strides[0] / sizeof(T);

std::vector<T> v(size);
std::copy(data, data + size, begin(v));

T *data = static_cast<T *>(p.data);
for(long i = 0; i < size; ++i)
v[i] = *(data + i * step);

return v;
}

Expand Down

0 comments on commit 7d5195d

Please sign in to comment.