Skip to content

[API Proposal]: TensorPrimitives brought up to par with Math and generic math interfaces #96451

@stephentoub

Description

@stephentoub

Background and motivation

As noted in #94553 (comment), for post-.NET 8, we're planning to augment TensorPrimitives in three ways:

  1. Generic versions of these methods in order to handle other numerical types beyond float
  2. Additional generic methods for all the operations on the generic math interfaces that aren't currently on TensorPrimitives
  3. Additional generic methods to have good coverage of further relevant operations ala BLAS / LAPACK

(1) was approved in #94553 and implemented in #94555.

This issue covers (2).

(3) still needs to be proposed subsequently.

API Proposal

namespace System.Numerics.Tensors

public static class TensorPrimitives
{
    // Methods without existing overloads
+   public static void Acos<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void AcosPi<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void Acosh<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IHyperbolicFunctions<T>;
+   public static void Asin<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void AsinPi<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void Asinh<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IHyperbolicFunctions<T>;
+   public static void Atan<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void AtanPi<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void Atan2<T>(ReadOnlySpan<T> y, ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void Atan2Pi<T>(ReadOnlySpan<T> y, ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void Atanh<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IHyperbolicFunctions<T>;
+   public static void BitwiseAnd<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : IBitwiseOperators<T, T, T>;
+   public static void BitwiseAnd<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : IBitwiseOperators<T, T, T>;
+   public static void BitwiseOr<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : IBitwiseOperators<T, T, T>;
+   public static void BitwiseOr<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : IBitwiseOperators<T, T, T>;
+   public static void Cbrt<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IRootFunctions<T>;
+   public static void Ceiling<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPoint<T>;
+   public static void ConvertChecked<TFrom, TTo>(ReadOnlySpan<TFrom> source, Span<TTo> destination) where TFrom : INumberBase<TFrom> where TTo : INumberBase<TTo>;
+   public static void ConvertSaturating<TFrom, TTo>(ReadOnlySpan<TFrom> source, Span<TTo> destination) where TFrom : INumberBase<TFrom> where TTo : INumberBase<TTo>;
+   public static void ConvertTruncating<TFrom, TTo>(ReadOnlySpan<TFrom> source, Span<TTo> destination) where TFrom : INumberBase<TFrom> where TTo : INumberBase<TTo>;
+   public static void CopySign<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> sign, Span<T> destination) where T : INumber<T>;
+   public static void CopySign<T>(ReadOnlySpan<T> x, T sign, Span<T> destination) where T : INumber<T>;
+   public static void Cos<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void CosPi<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void DegreesToRadians<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void ExpM1<T>(ReadOnlySpan<T> x) where T : IExponentialFunctions<TSelf>;
+   public static void Exp2<T>(ReadOnlySpan<T> x) where T : IExponentialFunctions<TSelf>;
+   public static void Exp2M1<T>(ReadOnlySpan<T> x) where T : IExponentialFunctions<TSelf>;
+   public static void Exp10<T>(ReadOnlySpan<T> x) where T : IExponentialFunctions<TSelf>;
+   public static void Exp10M1<T>(ReadOnlySpan<T> x) where T : IExponentialFunctions<TSelf>;
+   public static void Floor<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPoint<T>;
+   public static void FusedMultiplyAdd<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, ReadOnlySpan<T> addend, Span<T> destination) where T : IAdditionOperators<T, T, T>, IMultiplyOperators<T, T, T>;
+   public static void FusedMultiplyAdd<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, T addend, Span<T> destination) where T : IAdditionOperators<T, T, T>, IMultiplyOperators<T, T, T>;
+   public static void FusedMultiplyAdd<T>(ReadOnlySpan<T> x, T y, ReadOnlySpan<T> addend, Span<T> destination) where T : IAdditionOperators<T, T, T>, IMultiplyOperators<T, T, T>;
+   public static void Hypot<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : IRootFunctions<T>;
+   public static void Ieee754Remainder<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void Ieee754Remainder<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void Ieee754Remainder<T>(T x, ReadOnlySpan<T> y, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void LeadingZeroCount<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IBinaryInteger<T>;
+   public static void ILogB<T>(ReadOnlySpan<T> x, Span<int> destination) where T : IFloatingPointIeee754<T>;
+   public static void Lerp<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, ReadOnlySpan<T> amount, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void Lerp<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, T amount, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void Lerp<T>(ReadOnlySpan<T> x, T y, ReadOnlySpan<T> amount, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void Log<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : ILogarithmicFunctions<T>;
+   public static void Log<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : ILogarithmicFunctions<T>;
+   public static void Log10<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ILogarithmicFunctions<T>;
+   public static void LogP1<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ILogarithmicFunctions<T>;
+   public static void Log2P1<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ILogarithmicFunctions<T>;
+   public static void Log10P1<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ILogarithmicFunctions<T>;
+   public static void OnesComplement<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IBitwiseOperators<T, T, T>;
+   public static void PopCount<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IBinaryInteger<T>;
+   public static void Pow<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : IPowerFunctions<T>;
+   public static void Pow<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : IPowerFunctions<T>;
+   public static void Pow<T>(T x, ReadOnlySpan<T> y, Span<T> destination) where T : IPowerFunctions<T>;
+   public static void RadiansToDegrees<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void Reciprocal<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPoint<T>;
+   public static void ReciprocalEstimate<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void ReciprocalSqrt<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void ReciprocalSqrtEstimate<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void RootN<T>(ReadOnlySpan<T> x, int n, Span<T> destination) where T : IRootFunctions<T>;
+   public static void RotateLeft<T>(ReadOnlySpan<T> x, int rotateAmount, Span<T> destination) where T : IBinaryInteger<T>;
+   public static void RotateRight<T>(ReadOnlySpan<T> x, int rotateAmount, Span<T> destination) where T : IBinaryInteger<T>;
+   public static void Round<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPoint<T>;
+   public static void Round<T>(ReadOnlySpan<T> x, MidpointRounding mode, Span<T> destination) where T : IFloatingPoint<T>;
+   public static void Round<T>(ReadOnlySpan<T> x, int digits, Span<T> destination) where T : IFloatingPoint<T>;
+   public static void Round<T>(ReadOnlySpan<T> x, int digits, MidpointRounding mode, Span<T> destination) where T : IFloatingPoint<T>;
+   public static void ScaleB<T>(ReadOnlySpan<T> x, int n, Span<T> destination) where T : IFloatingPointIeee754<T>;
+   public static void ShiftLeft<T>(ReadOnlySpan<T> x, int shiftAmount, Span<T> destination) where T : IBinaryInteger<T>;
+   public static void ShiftRightArithmetic<T>(ReadOnlySpan<T> x, int shiftAmount, Span<T> destination) where T : IBinaryInteger<T>;
+   public static void ShiftRightLogical<T>(ReadOnlySpan<T> x, int shiftAmount, Span<T> destination) where T : IBinaryInteger<T>;
+   public static void Sin<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void SinCos<T>(ReadOnlySpan<T> x, Span<T> sinDestination, Span<T> cosDestination) where T : ITrigonometricFunctions<T>;
+   public static void SinCosPi<T>(ReadOnlySpan<T> x, Span<T> sinPiDestination, Span<T> cosPiDestination) where T : ITrigonometricFunctions<T>;
+   public static void SinPi<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void Sqrt<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IRootFunctions<T>;
+   public static void Tan<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void TanPi<T>(ReadOnlySpan<T> x, Span<T> destination) where T : ITrigonometricFunctions<T>;
+   public static void TrailingZeroCount<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IBinaryInteger<T>;
+   public static void Truncate<T>(ReadOnlySpan<T> x, Span<T> destination) where T : IFloatingPoint<T>;
+   public static void Xor<T>(ReadOnlySpan<T> x, ReadOnlySpan<T> y, Span<T> destination) where T : IBitwiseOperators<T, T, T>;
+   public static void Xor<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : IBitwiseOperators<T, T, T>;

    // Overloads of existing methods
+   public static void Divide<T>(T x, ReadOnlySpan<T> y, Span<T> destination) where T : IDivisionOperators<T, T, T>;
+   public static void Max<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumber<T>;
+   public static void MaxMagnitude<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumber<T>;
+   public static void Min<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumber<T>;
+   public static void MinMagnitude<T>(ReadOnlySpan<T> x, T y, Span<T> destination) where T : INumber<T>;
+   public static void Subtract<T>(T x, ReadOnlySpan<T> y, Span<T> destination) where T : ISubtractionOperators<T, T, T>;
}

API Usage

float[] values = ...;
float[] destination = ...;
TensorPrimitives.Log10(values, destination);

Alternative Designs

No response

Risks

No response

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions