Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: Add missing Min/MaxNumber generic math APIs on TensorPrimitives #98862

Open
stephentoub opened this issue Feb 23, 2024 · 6 comments
Labels
api-approved API was approved in API review, it can be implemented area-System.Numerics.Tensors
Milestone

Comments

@stephentoub
Copy link
Member

stephentoub commented Feb 23, 2024

Background and motivation

These slipped through when aiming for parity.

API Proposal

namespace System.Numerics.Tensors;

public static class TensorPrimitives
{
    // Same surface area as Min/Max{Magnitude}, but for Min/Max{Magnitude}Number
+   public static int IndexOfMaxNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
+   public static int IndexOfMinNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
+   public static int IndexOfMaxMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
+   public static int IndexOfMinMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;

+   public static T MaxMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumberBase<T>;
+   public static void MaxMagnitudeNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, System.Span<T> destination) where T : INumberBase<T>;
+   public static void MaxMagnitudeNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumberBase<T>;

+   public static T MaxNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
+   public static void MaxNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : INumber<T>;
+   public static void MaxNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumber<T>;

+   public static T MinMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumberBase<T>;
+   public static void MinMagnitudeNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : INumberBase<T>;
+   public static void MinMagnitudeNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumberBase<T>;

+   public static T MinNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
+   public static void MinNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : INumber<T>;
+   public static void MinNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumber<T>;
}

API Usage

TensorPrimitives.MaxMagnitude(x, y, dest);

Alternative Designs

No response

Risks

No response

@stephentoub stephentoub added area-System.Numerics.Tensors api-ready-for-review API is ready for review, it is NOT ready for implementation labels Feb 23, 2024
@ghost
Copy link

ghost commented Feb 23, 2024

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

Issue Details

Background and motivation

These slipped through when aiming for parity.

API Proposal

namespace System.Numerics.Tensors;

public static class TensorPrimitives
{
    // Same surface area as Min/Max{Magnitude}, but for Min/Max{Magnitude}Number
+   public static int IndexOfMaxNumber<T>(System.ReadOnlySpan<T> x) where T : INumber<T>;
+   public static int IndexOfMinNumber<T>(System.ReadOnlySpan<T> x) where T : INumber<T>;
+   public static int IndexOfMaxMagnitudeNumber<T>(System.ReadOnlySpan<T> x) where T : INumber<T>;
+   public static int IndexOfMinMagnitudeNumber<T>(System.ReadOnlySpan<T> x) where T : INumber<T>;

+   public static T MaxMagnitudeNumber<T>(System.ReadOnlySpan<T> x) where T : INumberBase<T>;
+   public static void MaxMagnitudeNumber<T>(System.ReadOnlySpan<T> x, System.ReadOnlySpan<T> y, System.Span<T> destination) where T : INumberBase<T>;
+   public static void MaxMagnitudeNumber<T>(System.ReadOnlySpan<T> x, T y, System.Span<T> destination) where T : INumberBase<T>;

+   public static T MaxNumber<T>(System.ReadOnlySpan<T> x) where T : INumber<T>;
+   public static void MaxNumber<T>(System.ReadOnlySpan<T> x, System.ReadOnlySpan<T> y, System.Span<T> destination) where T : INumber<T>;
+   public static void MaxNumber<T>(System.ReadOnlySpan<T> x, T y, System.Span<T> destination) where T : INumber<T>;

+   public static T MinMagnitudeNumber<T>(System.ReadOnlySpan<T> x) where T : INumberBase<T>;
+   public static void MinMagnitudeNumber<T>(System.ReadOnlySpan<T> x, System.ReadOnlySpan<T> y, System.Span<T> destination) where T : INumberBase<T>;
+   public static void MinMagnitudeNumber<T>(System.ReadOnlySpan<T> x, T y, System.Span<T> destination) where T : INumberBase<T>;

+   public static T MinNumber<T>(System.ReadOnlySpan<T> x) where T : INumber<T>;
+   public static void MinNumber<T>(System.ReadOnlySpan<T> x, System.ReadOnlySpan<T> y, System.Span<T> destination) where T : INumber<T>;
+   public static void MinNumber<T>(System.ReadOnlySpan<T> x, T y, System.Span<T> destination) where T : INumber<T>;
}

API Usage

TensorPrimitives.MaxMagnitude(x, y, dest);

Alternative Designs

No response

Risks

No response

Author: stephentoub
Assignees: -
Labels:

area-System.Numerics.Tensors, api-ready-for-review

Milestone: -

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 23, 2024
@stephentoub stephentoub removed the untriaged New issue has not been triaged by the area owner label Feb 23, 2024
@eiriktsarpalis
Copy link
Member

The Number suffix feels redundant, is it intended to disambiguate from existing method groups?

@bartonjs
Copy link
Member

bartonjs commented Apr 11, 2024

Video

  • Looks good as proposed
namespace System.Numerics.Tensors;

public static class TensorPrimitives
{
    // Same surface area as Min/Max{Magnitude}, but for Min/Max{Magnitude}Number
    public static int IndexOfMaxNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMinNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMaxMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMinMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;

    public static T MaxMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumberBase<T>;
    public static void MaxMagnitudeNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, System.Span<T> destination) where T : INumberBase<T>;
    public static void MaxMagnitudeNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumberBase<T>;

    public static T MaxNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static void MaxNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : INumber<T>;
    public static void MaxNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumber<T>;

    public static T MinMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumberBase<T>;
    public static void MinMagnitudeNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : INumberBase<T>;
    public static void MinMagnitudeNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumberBase<T>;

    public static T MinNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static void MinNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : INumber<T>;
    public static void MinNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumber<T>;
}

@bartonjs bartonjs added api-approved API was approved in API review, it can be implemented and removed api-ready-for-review API is ready for review, it is NOT ready for implementation labels Apr 11, 2024
@stephentoub stephentoub self-assigned this Apr 23, 2024
@stephentoub stephentoub added this to the 9.0.0 milestone Apr 23, 2024
@stephentoub stephentoub removed their assignment Apr 23, 2024
@stephentoub
Copy link
Member Author

Remaining after #101435

public static class TensorPrimitives
{
    public static int IndexOfMaxNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMinNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMaxMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMinMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;

    public static T MaxMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumberBase<T>;
    public static void MaxMagnitudeNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, System.Span<T> destination) where T : INumberBase<T>;
    public static void MaxMagnitudeNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumberBase<T>;

    public static T MinMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumberBase<T>;
    public static void MinMagnitudeNumber<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : INumberBase<T>;
    public static void MinMagnitudeNumber<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumberBase<T>;
}

@tannergooding
Copy link
Member

These should be a little easier to implement with #103837 as well

@stephentoub
Copy link
Member Author

Remaining after #104651

public static class TensorPrimitives
{
    public static int IndexOfMaxNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMinNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMaxMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
    public static int IndexOfMinMagnitudeNumber<T>(ReadOnlySpan<T> x) where T : INumber<T>;
}

@stephentoub stephentoub modified the milestones: 9.0.0, 10.0.0 Jul 18, 2024
@stephentoub stephentoub removed their assignment Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-approved API was approved in API review, it can be implemented area-System.Numerics.Tensors
Projects
None yet
Development

No branches or pull requests

4 participants