Fix TensorPrimitives.IndexOfMax#127454
Merged
tannergooding merged 10 commits intodotnet:mainfrom May 6, 2026
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-numerics |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR refactors the IndexOfMin/Max* tensor primitives to fix incorrect indices (notably for small element sizes) by introducing a specialized min/max operator interface and a new IndexOfMinMaxCore implementation with multiple vectorized paths.
Changes:
- Replaced
IIndexOfOperatorwithIIndexOfMinMaxOperatorand moved/rewroteIndexOfMinMaxCoreinto shared code. - Implemented specialized Vector128/256/512 routines for
sizeof(T)= 1/2/4/8 plus a naive fallback. - Added regression tests for
IndexOfMaxonbyte/ushortwhen the correct index exceeds the element type’s max value.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Numerics.Tensors/tests/TensorPrimitives.Generic.cs | Adds regression tests for IndexOfMax returning indices > 255 and > 65535. |
| src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.IndexOfMinMagnitude.cs | Updates operator to the new interface and comparison/aggregation model. |
| src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.IndexOfMin.cs | Updates operator to the new interface and comparison/aggregation model. |
| src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.IndexOfMaxMagnitude.cs | Updates operator to the new interface and comparison/aggregation model. |
| src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.IndexOfMax.cs | Replaces per-method core logic with the shared core + new operator shape. |
| src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Common/TensorPrimitives.IIndexOfOperator.cs | Introduces IIndexOfMinMaxOperator and the new shared vectorized implementations. |
This was referenced Apr 28, 2026
tannergooding
approved these changes
May 5, 2026
tannergooding
approved these changes
May 6, 2026
This was referenced May 6, 2026
Open
Member
|
/ba-g networking test timeout |
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.
Fixes #124233
Fixes #127610
Tried to include feedback from #124274 (comment).
Summary of changes:
IIndexOfOperatorto specializedIIndexOfMinMaxOperator, where there areComparemethods that returns masks of results/indices.IndexOfMinMaxCoredelegates to ten different methods:IndexOfMinMaxVectorized128/256/512Size4Pluswhensizeof(T)is 4 or 8. The result index fits in one vector.IndexOfMinMaxVectorized128/256/512Size2whensizeof(T)is 2. The result index fits in two vectors.IndexOfMinMaxVectorized128/256/512Size1whensizeof(T)is 1. The result index fits in four vectors.IndexOfMinMaxFallbackas fallback.IndexLessThanmethodsIndexOfmethods