Skip to content

Commit 8accd80

Browse files
authored
Add lots more TensorPrimitives operations (#97192)
* 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
1 parent b8114f9 commit 8accd80

File tree

10 files changed

+5668
-1278
lines changed

10 files changed

+5668
-1278
lines changed

src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs

Lines changed: 94 additions & 2 deletions
Large diffs are not rendered by default.

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/TensorPrimitives.Single.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public static void Exp(ReadOnlySpan<float> x, Span<float> destination) =>
303303
/// </para>
304304
/// </remarks>
305305
public static int IndexOfMax(ReadOnlySpan<float> x) =>
306-
IndexOfMinMaxCore<IndexOfMaxOperator_Single>(x);
306+
IndexOfMinMaxCore<float, IndexOfMaxOperator_Single>(x);
307307

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

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

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

358358
/// <summary>Computes the element-wise natural (base <c>e</c>) logarithm of single-precision floating-point numbers in the specified tensor.</summary>
359359
/// <param name="x">The tensor, represented as a span.</param>

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.Single.netcore.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

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

36-
// TODO: These should be made generic. Their implementations are still currently bound to float.
37-
global using IndexOfMaxOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMaxOperator;
38-
global using IndexOfMaxMagnitudeOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMaxMagnitudeOperator;
39-
global using IndexOfMinOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMinOperator;
40-
global using IndexOfMinMagnitudeOperator_Single = System.Numerics.Tensors.TensorPrimitives.IndexOfMinMagnitudeOperator;
41-
4240
namespace System.Numerics.Tensors
4341
{
4442
public static unsafe partial class TensorPrimitives

0 commit comments

Comments
 (0)