Skip to content

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
@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.

2 participants