Repository navigation
Conversation
xview_stepper is the stepper of views that are not strided, such as
views with keep or drop slices. It had three bugs.
step() and reset() received a dimension of the iterated shape but used
it as a view dimension. When the view is broadcast to a higher rank,
the first m_offset dimensions of that shape are not view dimensions,
so the stepper moved along the wrong axes. reset() did not even skip
them. With a = {{0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}},
zeros({2, 2, 2}) + view(a, keep(0, 2), keep(1, 3)) gave
{{1, 1}, {3, 3}} twice instead of {{1, 3}, {9, 11}}, and other shapes
read the strides of the underlying container out of bounds.
m_index_keeper is indexed like the slices in the constructor and in
to_end(), but step() and reset() indexed it by view dimension. The two
differ when an integral slice comes first, so view(a, 1, keep(0, 2, 3))
iterated backward from an uninitialized entry and crashed.
to_end() stepped back from the end of the underlying expression, which
leaves the stepper one past the last element along the last underlying
axis. That is not the innermost axis of the view when the last slice is
integral, when it is a newaxis or when the view has fewer slices than
dimensions, so rbegin() started at the wrong element or past the end.
The stepper now subtracts m_offset like xstepper, indexes
m_index_keeper by slice, delegates the dimensions without a slice to
the underlying stepper, and builds the end position from the begin
position, the way increment_stepper reaches it. to_begin() also moves
to the first element of the view, not of the underlying expression.
The reverse column major check in test_view_iter, disabled because it
failed for keep slices, now passes and is enabled again. The new
xview tests fail on master and pass with the fix, also under
AddressSanitizer and UBSan. This also removes the GCC -Warray-bounds
warnings reported in common_step_forward and common_reset.
Contributor
Merging this PR will not alter performance1 warning
Comparing |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Checklist
Description
xview_stepper, the stepper of views that are not strided (keep or drop slices), gave wrong results or read out of bounds in three cases:stepandresetignoredm_offset, so a view broadcast to a higher rank moved along the wrong axes.m_index_keeperwas indexed by slice in the constructor andto_end, but by view dimension instepandreset.to_endleft the stepper one past the last element along the last axis of the underlying expression. That is not the innermost axis of the view when the last slice is integral or a newaxis, or when some axes have no slice.The stepper now handles
m_offsetlikexstepper, indexesm_index_keeperby slice, and builds the end position from the begin position. The reverse column-major check intest_view_iter, commented out because it failed for keep slices, is enabled again.xview.keep_slice_reverse_iterationandxview.keep_broadcast_higher_rankfail on master and pass with the fix, also under AddressSanitizer and UBSan. The GCC 13/15-Warray-boundswarnings incommon_step_forwardandcommon_resetgo away too.