Skip to content

Commit

Permalink
Add most of the remaining methods from MathF
Browse files Browse the repository at this point in the history
Adds vectorized implementations everywhere
- CopySign
- Reciprocal{Sqrt}{Estimate}
- Sqrt

Adds vectorized implementations on .NET 7+ and scalar elsewhere
- Ceiling
- Floor
- Truncate

Adds scalar implementations everywhere:
- Log10
- Log(x, y) (with y as both span and scalar)
- Pow(x, y) (with y as both span and scalar)
- Cbrt
- IEEERemainder
- Acos
- Acosh
- Cos
- Asin
- Asinh
- Sin
- Atan
- Atan2
- Atanh
- Tan

There are several methods remaining on MathF that I've not included:
- Because they don't seem as relevant: BitDecrement/BitIncrement
- Because a non-floating point argument would be a new pattern: ScaleB
- Because a non-floating point result would be a new pattern: ILogB/Sign
- Because two destinations would be a new pattern: SinCos
- Because overloads with ints and enums would be a new pattern: Round
  • Loading branch information
stephentoub committed Sep 24, 2023
1 parent 4101144 commit ada9b18
Show file tree
Hide file tree
Showing 5 changed files with 1,525 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,40 @@ namespace System.Numerics.Tensors
public static partial class TensorPrimitives
{
public static void Abs(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Acos(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Acosh(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Add(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
public static void Add(System.ReadOnlySpan<float> x, float y, System.Span<float> destination) { }
public static void AddMultiply(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.ReadOnlySpan<float> multiplier, System.Span<float> destination) { }
public static void AddMultiply(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, float multiplier, System.Span<float> destination) { }
public static void AddMultiply(System.ReadOnlySpan<float> x, float y, System.ReadOnlySpan<float> multiplier, System.Span<float> destination) { }
public static void Asin(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Asinh(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Atan(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Atan2(System.ReadOnlySpan<float> y, System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Atanh(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Cbrt(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Ceiling(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void CopySign(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
public static void Cos(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Cosh(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static float CosineSimilarity(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y) { throw null; }
public static float Distance(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y) { throw null; }
public static void Divide(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
public static void Divide(System.ReadOnlySpan<float> x, float y, System.Span<float> destination) { }
public static float Dot(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y) { throw null; }
public static void Exp(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Floor(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void IEEERemainder(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
public static int IndexOfMax(System.ReadOnlySpan<float> x) { throw null; }
public static int IndexOfMaxMagnitude(System.ReadOnlySpan<float> x) { throw null; }
public static int IndexOfMin(System.ReadOnlySpan<float> x) { throw null; }
public static int IndexOfMinMagnitude(System.ReadOnlySpan<float> x) { throw null; }
public static float Norm(System.ReadOnlySpan<float> x) { throw null; }
public static void Log(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Log(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
public static void Log(System.ReadOnlySpan<float> x, float y, System.Span<float> destination) { }
public static void Log10(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Log2(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static float Max(System.ReadOnlySpan<float> x) { throw null; }
public static void Max(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { throw null; }
Expand All @@ -42,17 +58,27 @@ public static void MultiplyAdd(System.ReadOnlySpan<float> x, System.ReadOnlySpan
public static void MultiplyAdd(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, float addend, System.Span<float> destination) { }
public static void MultiplyAdd(System.ReadOnlySpan<float> x, float y, System.ReadOnlySpan<float> addend, System.Span<float> destination) { }
public static void Negate(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Pow(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
public static void Pow(System.ReadOnlySpan<float> x, float y, System.Span<float> destination) { }
public static float Product(System.ReadOnlySpan<float> x) { throw null; }
public static float ProductOfDifferences(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y) { throw null; }
public static float ProductOfSums(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y) { throw null; }
public static void Reciprocal(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void ReciprocalEstimate(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void ReciprocalSqrt(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void ReciprocalSqrtEstimate(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Sigmoid(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Sin(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Sinh(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void SoftMax(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Sqrt(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Subtract(System.ReadOnlySpan<float> x, System.ReadOnlySpan<float> y, System.Span<float> destination) { }
public static void Subtract(System.ReadOnlySpan<float> x, float y, System.Span<float> destination) { }
public static float Sum(System.ReadOnlySpan<float> x) { throw null; }
public static float SumOfMagnitudes(System.ReadOnlySpan<float> x) { throw null; }
public static float SumOfSquares(System.ReadOnlySpan<float> x) { throw null; }
public static void Tan(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Tanh(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
public static void Truncate(System.ReadOnlySpan<float> x, System.Span<float> destination) { }
}
}
Loading

0 comments on commit ada9b18

Please sign in to comment.