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

Allow aliasing in ArrayView::from_shape #1410

Merged
merged 1 commit into from
Aug 3, 2024
Merged

Allow aliasing in ArrayView::from_shape #1410

merged 1 commit into from
Aug 3, 2024

Conversation

bluss
Copy link
Member

@bluss bluss commented Aug 2, 2024

Changes the checks in the ArrayView::from_shape constructor so that it allows a few more cases: custom strides that lead to overlapping are allowed.

Before, both ArrayViewMut and ArrayView applied the same check, that the dimensions and strides must be such that no elements can be reached by more than one index.

However, this rule only applies for mutable data, for ArrayView we can allow this kind of aliasing. This is in fact how broadcasting works, where we use strides to repeat the same array data multiple times.

Fixes the second point in #919

Changes the checks in the ArrayView::from_shape constructor so that it
allows a few more cases: custom strides that lead to overlapping are
allowed.

Before, both ArrayViewMut and ArrayView applied the same check, that the
dimensions and strides must be such that no elements can be reached by
more than one index.

However, this rule only applies for mutable data, for ArrayView we can
allow this kind of aliasing. This is in fact how broadcasting works,
where we use strides to repeat the same array data multiple times.
@bluss bluss added this to the 0.16.0 milestone Aug 2, 2024
@bluss bluss added this pull request to the merge queue Aug 3, 2024
Merged via the queue into master with commit e9e8c9d Aug 3, 2024
11 checks passed
@bluss bluss deleted the aliasing-checks branch August 3, 2024 07:10
bluss added a commit that referenced this pull request Aug 3, 2024
It should deny overlapping indexes. Because it's an unsafe function and
we only do these checks on best-effort basis (caller has to ensure they
are correct), it's a debug assertion.

Removed the small addition to a doc comment that was done in a previous
PR (it was an unfinished idea).

Similar to pr #1410
Finishes and closes #919
bluss added a commit that referenced this pull request Aug 3, 2024
It should deny overlapping indexes. Because it's an unsafe function and
we only do these checks on best-effort basis (caller has to ensure they
are correct), it's a debug assertion.

Removed the small addition to a doc comment that was done in a previous
PR (it was an unfinished idea).

Similar to pr #1410
Finishes and closes #919
bluss added a commit that referenced this pull request Aug 3, 2024
It should deny overlapping indexes. Because it's an unsafe function and
we only do these checks on best-effort basis (caller has to ensure they
are correct), it's a debug assertion.

Removed the small addition to a doc comment that was done in a previous
PR (it was an unfinished idea).

Similar to pr #1410
Finishes and closes #919
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.

1 participant