Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix contig check for single element arrays#1362

Merged
bluss merged 2 commits intomasterrust-ndarray/ndarray:masterfrom
contig-for-single-elementrust-ndarray/ndarray:contig-for-single-elementCopy head branch name to clipboard
Feb 26, 2024
Merged

Fix contig check for single element arrays#1362
bluss merged 2 commits intomasterrust-ndarray/ndarray:masterfrom
contig-for-single-elementrust-ndarray/ndarray:contig-for-single-elementCopy head branch name to clipboard

Conversation

@bluss
Copy link
Member

@bluss bluss commented Feb 26, 2024

When an array has 0 or 1 elements, strides don't matter anymore. The general case of this function handled this correctly, but the special case for ndim == 1 did not.

Fixes #1359

@bluss bluss force-pushed the contig-for-single-element branch from 96c74e6 to c4b0e7a Compare February 26, 2024 19:33
src/dimension/dimension_trait.rs Show resolved Hide resolved
src/split_at.rs Outdated Show resolved Hide resolved
@bluss bluss force-pushed the contig-for-single-element branch 2 times, most recently from 9f4cee3 to c033453 Compare February 26, 2024 19:46
bluss and others added 2 commits February 26, 2024 20:48
Co-authored-by: Adam Reichold <adamreichold@users.noreply.github.com>
When an array has 0 or 1 elements, strides don't matter anymore. The
general case of this function handled this correctly, but the special
case for ndim == 1 did not.
@bluss bluss force-pushed the contig-for-single-element branch from 3abf961 to b02ae59 Compare February 26, 2024 19:48

let arr2 = array![[1, 2, 3], [4, 5, 6]];
assert_matches!(arr2.slice(s![.., 2..3]).as_slice_memory_order(), None);
assert_matches!(arr2.slice(s![1, 2..3]).as_slice_memory_order(), Some(&[6]));
Copy link
Member Author

Choose a reason for hiding this comment

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

The 2D case was working correctly before this fix too.

@bluss
Copy link
Member Author

bluss commented Feb 26, 2024

thanks for checking. The lint fixes are helpful here too, best to get them in.

@bluss bluss merged commit 97ecc0d into master Feb 26, 2024
@bluss bluss deleted the contig-for-single-element branch February 26, 2024 20:31
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 this pull request may close these issues.

ArrayBase::as_slice_memory_order returns None when slice has a single element

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.