Skip to content

Commit

Permalink
do not transpose arrays that are wide but short for streams (#57)
Browse files Browse the repository at this point in the history
* do not transpose arrays that are wide but short for streams

* Fixed wrong width in transposed array tests

* Fixed dlpack copy routine for F-style arrays.
  • Loading branch information
inakleinbottle authored Dec 13, 2023
1 parent 7ffb57a commit 53d28a5
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 126 deletions.
18 changes: 11 additions & 7 deletions roughpy/src/args/strided_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ void rpy::python::stride_copy(
const auto* sptr = static_cast<const char*>(src);

if (ndim == 1) {
for (py::ssize_t i=0; i<shape_in[0]; ++i) {
std::memcpy(dptr + i*strides_out[0],
sptr + i*strides_in[0],
itemsize);
if (strides_in[0] == itemsize) {
std::memcpy(dptr, sptr, shape_in[0] * itemsize);
} else {
for (py::ssize_t i = 0; i < shape_in[0]; ++i) {
std::memcpy(dptr + i * strides_out[0],
sptr + i * strides_in[0],
itemsize);
}
}
} else if (transpose) {
for (py::ssize_t i=0; i<shape_in[0]; ++i) {
for (py::ssize_t j=0; j<shape_in[1]; ++j) {
for (py::ssize_t i = 0; i < shape_in[1]; ++i) {
for (py::ssize_t j = 0; j < shape_in[0]; ++j) {
std::memcpy(
dptr + j*strides_out[0] + i*strides_out[1],
sptr + i*strides_in[0] + j*strides_in[1],
sptr + i * strides_in[1] + j * strides_in[0],
itemsize
);
}
Expand Down
Loading

0 comments on commit 53d28a5

Please sign in to comment.