-
Notifications
You must be signed in to change notification settings - Fork 121
PyArray::to_owned_array() panics for reversed array #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Reverse arrays are broken, see PyO3/rust-numpy#151
Reverse arrays are broken, see PyO3/rust-numpy#151
It looks like the problem is in the last line of Lines 300 to 307 in 8c8c927
|
Thanks, I tested it now, and your observation looks correct 👍 |
Returning an error when the stride has negative integers would work, but seems like a hack. |
I don't know how to make it work with |
But I think its internal strides representation uses |
It looks like use ndarray::*;
fn main() {
const N: usize = 16;
let data: Vec<_> = (0..N).map(|i| i as f64).collect();
let a = ArrayView::from_shape(N, &data).unwrap();
let slice = a.slice(s![..; -1]);
println!("{:?}", slice);
}
|
Well but it actually holds strides as unsigned. See https://docs.rs/ndarray/0.13.1/src/ndarray/impl_methods.rs.html#119-123. So somehow we need to reverse the stride to allow negative stride, as |
Oh, I see. Thank you for your commitment to solve the problem! |
So... I noticed that this is due to the debug assertion and does not happen with let gil = pyo3::Python::acquire_gil();
let py = gil.python();
let arr = array![[2, 3], [4, 5u32]];
let pyarr = arr.to_pyarray(py);
let negstr_pyarr: &numpy::PyArray2<u32> = py
.eval("a[::-1]", Some([("a", pyarr)].into_py_dict(py)), None)
.unwrap()
.downcast()
.unwrap();
assert_eq!(negstr_pyarr.to_owned_array(), arr.slice(s![..;-1, ..])); I'm considering opening an upstream issue but not sure. |
I made #156 and will merge it before the next release (soon). |
Thank you so much! |
The text was updated successfully, but these errors were encountered: