Skip to content
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

Panic in windows of a view with negative strides #953

Closed
cuviper opened this issue Mar 26, 2021 · 1 comment · Fixed by #957
Closed

Panic in windows of a view with negative strides #953

cuviper opened this issue Mar 26, 2021 · 1 comment · Fixed by #957

Comments

@cuviper
Copy link
Contributor

cuviper commented Mar 26, 2021

Here's a simple example:

use ndarray::prelude::*;

fn main() {
    let array = Array2::<i32>::eye(3);

    let _ = array.windows((2, 2)); // ok
    let _ = array.slice(s![.., ..; -1]).windows((2, 2)); // panics
}

This works fine with 0.14, but 0.15 panics:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ShapeError/Unsupported: unsupported operation', /home/jistone/rust/ndarray/src/impl_raw_views.rs:81:58
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: core::result::Result<T,E>::unwrap
             at /builddir/build/BUILD/rustc-1.51.0-src/library/core/src/result.rs:1037:23
   4: ndarray::impl_raw_views::<impl ndarray::ArrayBase<ndarray::RawViewRepr<*const A>,D>>::from_shape_ptr
             at ./src/impl_raw_views.rs:81:17
   5: ndarray::impl_views::constructors::<impl ndarray::ArrayBase<ndarray::ViewRepr<&A>,D>>::from_shape_ptr
             at ./src/impl_views/constructors.rs:109:9
   6: ndarray::iterators::windows::Windows<A,D>::new
             at ./src/iterators/windows.rs:44:23
   7: ndarray::impl_methods::<impl ndarray::ArrayBase<S,D>>::windows
             at ./src/impl_methods.rs:1191:9
   8: windows::main
             at ./examples/windows.rs:7:13
   9: core::ops::function::FnOnce::call_once
             at /builddir/build/BUILD/rustc-1.51.0-src/library/core/src/ops/function.rs:227:5

git bisect blames e6a4f10 of #885, although it's possible the functionality was changed in a neighboring commit, since the test code I used isn't actually doing anything with the windows.

@bluss
Copy link
Member

bluss commented Mar 27, 2021

Thanks, I agree about the cause. It's unfortunate we create this situation of not allowing negative strides in the public constructors. I can't see any other oversights like that (not with ArrayView::from_shape_ptr at least).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants