Skip to content

Commit

Permalink
Add lots more TensorPrimitives operations (#97192)
Browse files Browse the repository at this point in the history
* Add more TensorPrimitive operations

All are functional and tested, some are vectorized, others still need to be.

* Re-fix IndexOfXx operations

* Rename MultiplyAddEstimate to FusedMultiplyAdd

* Remove some NotSupportedException throws

* Simplify CopySignOperator

* Parameter renames

* Add scalar overloads of Atan2 and Atan2Pi

* Add CopySign scalar overload

* Add Ieee754Remainder scalar overloads

* Add Lerp scalar overloads

* Add Pow scalar overload

* Consolidate inverted operators

* Add missing Max/Min scalar overloads

* Use ElementWiseSelect
  • Loading branch information
stephentoub authored Jan 22, 2024
1 parent b8114f9 commit 8accd80
Show file tree
Hide file tree
Showing 10 changed files with 5,668 additions and 1,278 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public static void Exp(ReadOnlySpan<float> x, Span<float> destination) =>
/// </para>
/// </remarks>
public static int IndexOfMax(ReadOnlySpan<float> x) =>
IndexOfMinMaxCore<IndexOfMaxOperator_Single>(x);
IndexOfMinMaxCore<float, IndexOfMaxOperator_Single>(x);

/// <summary>Searches for the index of the single-precision floating-point number with the largest magnitude in the specified tensor.</summary>
/// <param name="x">The tensor, represented as a span.</param>
Expand All @@ -320,7 +320,7 @@ public static int IndexOfMax(ReadOnlySpan<float> x) =>
/// </para>
/// </remarks>
public static int IndexOfMaxMagnitude(ReadOnlySpan<float> x) =>
IndexOfMinMaxCore<IndexOfMaxMagnitudeOperator_Single>(x);
IndexOfMinMaxCore<float, IndexOfMaxMagnitudeOperator_Single>(x);

/// <summary>Searches for the index of the smallest single-precision floating-point number in the specified tensor.</summary>
/// <param name="x">The tensor, represented as a span.</param>
Expand All @@ -336,7 +336,7 @@ public static int IndexOfMaxMagnitude(ReadOnlySpan<float> x) =>
/// </para>
/// </remarks>
public static int IndexOfMin(ReadOnlySpan<float> x) =>
IndexOfMinMaxCore<IndexOfMinOperator_Single>(x);
IndexOfMinMaxCore<float, IndexOfMinOperator_Single>(x);

/// <summary>Searches for the index of the single-precision floating-point number with the smallest magnitude in the specified tensor.</summary>
/// <param name="x">The tensor, represented as a span.</param>
Expand All @@ -353,7 +353,7 @@ public static int IndexOfMin(ReadOnlySpan<float> x) =>
/// </para>
/// </remarks>
public static int IndexOfMinMagnitude(ReadOnlySpan<float> x) =>
IndexOfMinMaxCore<IndexOfMinMagnitudeOperator_Single>(x);
IndexOfMinMaxCore<float, IndexOfMinMagnitudeOperator_Single>(x);

/// <summary>Computes the element-wise natural (base <c>e</c>) logarithm of single-precision floating-point numbers in the specified tensor.</summary>
/// <param name="x">The tensor, represented as a span.</param>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// This file exists to enable TensorPrimitives.float.cs to be compiled for both
// This file exists to enable TensorPrimitives.Single.cs to be compiled for both
// netstandard2.0 and net8.0+ targets. It uses the XX_Single names and the operation
// methods tied to float, whereas the net8.0+ worker implementations use generic math.
// This file provides float-bound types and type defs that route one to the other.
Expand All @@ -14,6 +14,10 @@
global using DivideOperator_Single = System.Numerics.Tensors.TensorPrimitives.DivideOperator<float>;
global using MultiplyOperator_Single = System.Numerics.Tensors.TensorPrimitives.MultiplyOperator<float>;
global using ExpOperator_Single = System.Numerics.Tensors.TensorPrimitives.ExpOperator<float>;
global using IndexOfMaxOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMaxOperator<float>;
global using IndexOfMaxMagnitudeOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMaxMagnitudeOperator<float>;
global using IndexOfMinOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMinOperator<float>;
global using IndexOfMinMagnitudeOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMinMagnitudeOperator<float>;
global using LogOperator_Single = System.Numerics.Tensors.TensorPrimitives.LogOperator<float>;
global using Log2Operator_Single = System.Numerics.Tensors.TensorPrimitives.Log2Operator<float>;
global using MaxOperator_Single = System.Numerics.Tensors.TensorPrimitives.MaxOperator<float>;
Expand All @@ -33,12 +37,6 @@
global using SquaredOperator_Single = System.Numerics.Tensors.TensorPrimitives.SquaredOperator<float>;
global using TanhOperator_Single = System.Numerics.Tensors.TensorPrimitives.TanhOperator<float>;

// TODO: These should be made generic. Their implementations are still currently bound to float.
global using IndexOfMaxOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMaxOperator;
global using IndexOfMaxMagnitudeOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMaxMagnitudeOperator;
global using IndexOfMinOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMinOperator;
global using IndexOfMinMagnitudeOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMinMagnitudeOperator;

namespace System.Numerics.Tensors
{
public static unsafe partial class TensorPrimitives
Expand Down
Loading

0 comments on commit 8accd80

Please sign in to comment.