Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion envpool/core/py_envpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ struct ArrayToNumpyHelper {
auto capsule = py::capsule(ptr, [](void* ptr) {
delete reinterpret_cast<std::shared_ptr<char>*>(ptr);
});
return py::array(a.Shape(), reinterpret_cast<dtype*>(a.Data()), capsule);
// Calculate strides explicitly to ensure correct memory layout
std::vector<py::ssize_t> strides(a.Shape().size());
if (!strides.empty()) {
strides[strides.size() - 1] = sizeof(dtype);
for (int i = strides.size() - 2; i >= 0; --i) {
strides[i] = strides[i + 1] * a.Shape()[i + 1];
}
}
return py::array(py::dtype::of<dtype>(), a.Shape(), strides,
reinterpret_cast<dtype*>(a.Data()), capsule);
}
};

Expand Down
Loading