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

Fix slice offset computation for special cases #636

Merged
merged 1 commit into from
May 30, 2019

Conversation

jturner314
Copy link
Member

With the old implementation, this resulted in undefined behavior in release mode and a panic in debug mode:

let mut arr = Array2::<i32>::zeros((5, 5));
arr.slice_axis_inplace(Axis(0), Slice::new(0, Some(0), -1));

as did this:

let mut arr = Array2::from_shape_vec((1, 1).strides((10, 1)), vec![5]).unwrap();
arr.slice_axis_inplace(Axis(0), Slice::new(1, Some(1), 1));

Now, both examples operate correctly.

With the old implementation, this resulted in undefined behavior in
release mode and a panic in debug mode:

```rust
let mut arr = Array2::<i32>::zeros((5, 5));
arr.slice_axis_inplace(Axis(0), Slice::new(0, Some(0), -1));
```

as did this:

```rust
let mut arr = Array2::from_shape_vec((1, 1).strides((10, 1)), vec![5]).unwrap();
arr.slice_axis_inplace(Axis(0), Slice::new(1, Some(1), 1));
```

Now, both examples operate correctly.
@jturner314 jturner314 added the bug label May 10, 2019
Copy link
Member

@LukeMathWalker LukeMathWalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks good and all the rationale is in the comments (plus we have a test to check for regressions). Happy to merge 👍

@jturner314 jturner314 merged commit d6ecbf2 into rust-ndarray:master May 30, 2019
@jturner314
Copy link
Member Author

Thanks for reviewing this @LukeMathWalker!

@jturner314 jturner314 deleted the fix-slice-offset branch May 30, 2019 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants