8000 Fix slice offset computation for special cases by jturner314 · Pull Request #636 · rust-ndarray/ndarray · GitHub
[go: up one dir, main page]

Skip to content

Fix slice offset computation for special cases#636

Merged
jturner314 merged 1 commit intorust-ndarray:masterfrom
jturner314:fix-slice-offset
May 30, 2019
Merged

Fix slice offset computation for special cases#636
jturner314 merged 1 commit intorust-ndarray:masterfrom
jturner314:fix-slice-offset

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

0