Uh oh!
There was an error while loading. Please reload this page.
Fix TensorPrimitives.IndexOfMax - #127454
Conversation
Tagging subscribers to this area: @dotnet/area-system-numerics |
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. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
tannergooding
commented
May 6, 2026
/ba-g networking test timeout |
Uh oh!
There was an error while loading. Please reload this page.
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