: selection: bugfix reifying strided views #533
+102
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
fix two bugs
thanks go to pzhan9 for reporting these issues! (see D78298712)
(1) one in
reify_view
where views with strides were reified incorrectly. the old code assumed views could always be expressed as contiguousrange(start..start + len)
expressions, even when the view's stride differed from the base. this produced incorrect selections when the view was strided relative to the base layout.the fix is to recognize when a view is layout-aligned; that is, when each of its strides is an integer multiple of the corresponding base stride, including the unitary case; and to reify such views using
Range(start, Some(end), step)
expressions that preserve both shape and layout. previously, only the unitary case (step
= 1) was handled. this change extends support to non-unitary aligned views, such asstep
= 2, by correctly computing the step factor and corresponding end coordinate.if any dimension is not layout-aligned — that is, if
view_stride
%base_stride
≠ 0 — we conservatively fall back to enumerating all selected coordinates explicitly.(2) also fixes a bug in
Shape::select()
where the length of a strided range was computed using truncating division. this now correctly uses ceiling division to ensure all selected indices are included.Differential Revision: D78315005