Skip to content

TensorPrimitives.IndexOfMaxMagnitude can't handle signed min values #127610

Closed

Description

@lilinus

Description

Current implementation of TensorPrimitives.IndexOfMaxMagnitude (and IndexOfMinMagnitude) does not handle signed minimum values (e.g. int.MinValue) since the Abs operator is overflowing.

Reproduction Steps

var len = 500;
var x = new int[len];
x[0] = int.MinValue;
x[^1] = int.MinValue;
var i = TensorPrimitives.IndexOfMaxMagnitude(x);
Console.WriteLine(i);

Expected behavior

Should print 0

Actual behavior

Either gives wrong answer (1) when on vectorized path and throws OverflowException on non-vectorized path.

Regression?

No

Known Workarounds

No response

Configuration

.NET 10 and .NET 11

Other information

No response

Activity

  1. dotnet-policy-service commented on Apr 30, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-numerics-tensors
    See info in area-owners.md if you want to be subscribed.

  2. added a commit that references this issue on May 6, 2026
    a0694cd
  3. locked and limited conversation to collaborators on Jun 6, 2026
  4. added a commit that references this issue on Jul 15, 2026
    0804ade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions