diff --git a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs index 84d727f4011b00..ebe7a37a7de8ed 100644 --- a/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs +++ b/src/libraries/System.Numerics.Tensors/ref/System.Numerics.Tensors.netcore.cs @@ -315,6 +315,8 @@ public static void BroadcastTo(this System.Numerics.Tensors.Tensor source, public static System.Numerics.Tensors.Tensor CreateFromShape(scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides, bool pinned = false) { throw null; } public static System.Numerics.Tensors.Tensor CreateFromShapeUninitialized(scoped System.ReadOnlySpan lengths, bool pinned = false) { throw null; } public static System.Numerics.Tensors.Tensor CreateFromShapeUninitialized(scoped System.ReadOnlySpan lengths, scoped System.ReadOnlySpan strides, bool pinned = false) { throw null; } + public static System.Numerics.Tensors.Tensor Decrement(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IDecrementOperators { throw null; } + public static ref readonly System.Numerics.Tensors.TensorSpan Decrement(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IDecrementOperators { throw null; } public static System.Numerics.Tensors.Tensor DegreesToRadians(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.ITrigonometricFunctions { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan DegreesToRadians(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.ITrigonometricFunctions { throw null; } public static T Distance(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan y) where T : System.Numerics.IRootFunctions { throw null; } @@ -385,6 +387,8 @@ public static void BroadcastTo(this System.Numerics.Tensors.Tensor source, public static ref readonly System.Numerics.Tensors.TensorSpan Ieee754Remainder(T x, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan y, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IFloatingPointIeee754 { throw null; } public static System.Numerics.Tensors.Tensor ILogB(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IFloatingPointIeee754 { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan ILogB(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IFloatingPointIeee754 { throw null; } + public static System.Numerics.Tensors.Tensor Increment(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IIncrementOperators { throw null; } + public static ref readonly System.Numerics.Tensors.TensorSpan Increment(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IIncrementOperators { throw null; } public static nint IndexOfMaxMagnitude(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.INumber { throw null; } public static nint IndexOfMax(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.INumber { throw null; } public static nint IndexOfMinMagnitude(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.INumber { throw null; } @@ -523,6 +527,12 @@ public static void ResizeTo(scoped in System.Numerics.Tensors.Tensor tenso public static bool SequenceEqual(this scoped in System.Numerics.Tensors.TensorSpan tensor, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan other) where T : System.IEquatable? { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan SetSlice(this in System.Numerics.Tensors.TensorSpan tensor, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan values, params scoped System.ReadOnlySpan ranges) { throw null; } public static System.Numerics.Tensors.Tensor SetSlice(this System.Numerics.Tensors.Tensor tensor, in System.Numerics.Tensors.ReadOnlyTensorSpan values, params scoped System.ReadOnlySpan ranges) { throw null; } + public static Tensor ShiftLeft(in ReadOnlyTensorSpan x, int shiftAmount) where T : IShiftOperators { throw null; } + public static ref readonly TensorSpan ShiftLeft(scoped in ReadOnlyTensorSpan x, int shiftAmount, in TensorSpan destination) where T : IShiftOperators { throw null; } + public static Tensor ShiftRightArithmetic(in ReadOnlyTensorSpan x, int shiftAmount) where T : IShiftOperators { throw null; } + public static ref readonly TensorSpan ShiftRightArithmetic(scoped in ReadOnlyTensorSpan x, int shiftAmount, in TensorSpan destination) where T : IShiftOperators { throw null; } + public static Tensor ShiftRightLogical(in ReadOnlyTensorSpan x, int shiftAmount) where T : IShiftOperators { throw null; } + public static ref readonly TensorSpan ShiftRightLogical(scoped in ReadOnlyTensorSpan x, int shiftAmount, in TensorSpan destination) where T : IShiftOperators { throw null; } public static System.Numerics.Tensors.Tensor Sigmoid(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IExponentialFunctions { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan Sigmoid(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IExponentialFunctions { throw null; } public static System.Numerics.Tensors.Tensor Sinh(in System.Numerics.Tensors.ReadOnlyTensorSpan x) where T : System.Numerics.IHyperbolicFunctions { throw null; } @@ -578,6 +588,318 @@ public static void ResizeTo(scoped in System.Numerics.Tensors.Tensor tenso public static ref readonly System.Numerics.Tensors.TensorSpan Xor(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, scoped in System.Numerics.Tensors.ReadOnlyTensorSpan y, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IBitwiseOperators { throw null; } public static System.Numerics.Tensors.Tensor Xor(in System.Numerics.Tensors.ReadOnlyTensorSpan x, T y) where T : System.Numerics.IBitwiseOperators { throw null; } public static ref readonly System.Numerics.Tensors.TensorSpan Xor(scoped in System.Numerics.Tensors.ReadOnlyTensorSpan x, T y, in System.Numerics.Tensors.TensorSpan destination) where T : System.Numerics.IBitwiseOperators { throw null; } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IAdditionOperators, System.Numerics.IAdditiveIdentity + { + public static System.Numerics.Tensors.Tensor operator +(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator +(in System.Numerics.Tensors.ReadOnlyTensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator +(TScalar left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IAdditionOperators, System.Numerics.IAdditiveIdentity + { + public static System.Numerics.Tensors.Tensor operator +(System.Numerics.Tensors.Tensor left, System.Numerics.Tensors.Tensor right) { throw null; } + public static System.Numerics.Tensors.Tensor operator +(System.Numerics.Tensors.Tensor left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator +(TScalar left, System.Numerics.Tensors.Tensor right) { throw null; } + public void operator +=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator +=(TScalar other) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IAdditionOperators, System.Numerics.IAdditiveIdentity + { + public static System.Numerics.Tensors.Tensor operator +(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator +(in System.Numerics.Tensors.TensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator +(TScalar left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public void operator +=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator +=(TScalar other) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator &(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator &(in System.Numerics.Tensors.ReadOnlyTensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator &(TScalar left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator &(System.Numerics.Tensors.Tensor left, System.Numerics.Tensors.Tensor right) { throw null; } + public static System.Numerics.Tensors.Tensor operator &(System.Numerics.Tensors.Tensor left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator &(TScalar left, System.Numerics.Tensors.Tensor right) { throw null; } + public void operator &=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator &=(TScalar other) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator &(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator &(in System.Numerics.Tensors.TensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator &(TScalar left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public void operator &=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator &=(TScalar other) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator |(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator |(in System.Numerics.Tensors.ReadOnlyTensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator |(TScalar left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator |(System.Numerics.Tensors.Tensor left, System.Numerics.Tensors.Tensor right) { throw null; } + public static System.Numerics.Tensors.Tensor operator |(System.Numerics.Tensors.Tensor left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator |(TScalar left, System.Numerics.Tensors.Tensor right) { throw null; } + public void operator |=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator |=(TScalar other) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator |(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator |(in System.Numerics.Tensors.TensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator |(TScalar left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public void operator |=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator |=(TScalar other) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) where TScalar : System.Numerics.IDecrementOperators + { + public void operator --() { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) where TScalar : System.Numerics.IDecrementOperators + { + public void operator --() { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IDivisionOperators + { + public static System.Numerics.Tensors.Tensor operator /(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator /(in System.Numerics.Tensors.ReadOnlyTensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator /(TScalar left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IDivisionOperators + { + public static System.Numerics.Tensors.Tensor operator /(System.Numerics.Tensors.Tensor left, System.Numerics.Tensors.Tensor right) { throw null; } + public static System.Numerics.Tensors.Tensor operator /(System.Numerics.Tensors.Tensor left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator /(TScalar left, System.Numerics.Tensors.Tensor right) { throw null; } + public void operator /=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator /=(TScalar other) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IDivisionOperators + { + public static System.Numerics.Tensors.Tensor operator /(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator /(in System.Numerics.Tensors.TensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator /(TScalar left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public void operator /=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator /=(TScalar other) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator ^(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator ^(in System.Numerics.Tensors.ReadOnlyTensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator ^(TScalar left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator ^(System.Numerics.Tensors.Tensor left, System.Numerics.Tensors.Tensor right) { throw null; } + public static System.Numerics.Tensors.Tensor operator ^(System.Numerics.Tensors.Tensor left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator ^(TScalar left, System.Numerics.Tensors.Tensor right) { throw null; } + public void operator ^=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator ^=(TScalar other) { throw null; } + } + + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator ^(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator ^(in System.Numerics.Tensors.TensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator ^(TScalar left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public void operator ^=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator ^=(TScalar other) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) where TScalar : System.Numerics.IIncrementOperators + { + public void operator ++() { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) where TScalar : System.Numerics.IIncrementOperators + { + public void operator ++() { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IShiftOperators + { + public static System.Numerics.Tensors.Tensor operator <<(in System.Numerics.Tensors.ReadOnlyTensorSpan tensor, int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.Tensor) + where TScalar : System.Numerics.IShiftOperators + { + public static System.Numerics.Tensors.Tensor operator <<(System.Numerics.Tensors.Tensor tensor, int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IShiftOperators + { + public void operator <<=(int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.TensorSpan) + where TScalar : System.Numerics.IShiftOperators + { + public static Tensor operator <<(in TensorSpan tensor, int shiftAmount) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IShiftOperators + { + public void operator <<=(int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IMultiplyOperators, System.Numerics.IMultiplicativeIdentity + { + public static System.Numerics.Tensors.Tensor operator *(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator *(in System.Numerics.Tensors.ReadOnlyTensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator *(TScalar left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IMultiplyOperators, System.Numerics.IMultiplicativeIdentity + { + public static System.Numerics.Tensors.Tensor operator *(System.Numerics.Tensors.Tensor left, System.Numerics.Tensors.Tensor right) { throw null; } + public static System.Numerics.Tensors.Tensor operator *(System.Numerics.Tensors.Tensor left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator *(TScalar left, System.Numerics.Tensors.Tensor right) { throw null; } + public void operator *=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator *=(TScalar other) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IMultiplyOperators, System.Numerics.IMultiplicativeIdentity + { + public static System.Numerics.Tensors.Tensor operator *(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator *(in System.Numerics.Tensors.TensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator *(TScalar left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public void operator *=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator *=(TScalar other) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator ~(in System.Numerics.Tensors.ReadOnlyTensorSpan tensor) { throw null; } + } + extension(System.Numerics.Tensors.Tensor) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator ~(in System.Numerics.Tensors.Tensor tensor) { throw null; } + } + extension(System.Numerics.Tensors.TensorSpan) + where TScalar : System.Numerics.IBitwiseOperators + { + public static System.Numerics.Tensors.Tensor operator ~(in System.Numerics.Tensors.TensorSpan tensor) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IShiftOperators + { + public static System.Numerics.Tensors.Tensor operator >>(in System.Numerics.Tensors.ReadOnlyTensorSpan tensor, int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.Tensor) + where TScalar : System.Numerics.IShiftOperators + { + public static System.Numerics.Tensors.Tensor operator >>(System.Numerics.Tensors.Tensor tensor, int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IShiftOperators + { + public void operator >>=(int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.TensorSpan) + where TScalar : System.Numerics.IShiftOperators + { + public static Tensor operator >>(in TensorSpan tensor, int shiftAmount) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IShiftOperators + { + public void operator >>=(int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.ISubtractionOperators + { + public static System.Numerics.Tensors.Tensor operator -(in System.Numerics.Tensors.ReadOnlyTensorSpan left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator -(in System.Numerics.Tensors.ReadOnlyTensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator -(TScalar left, in System.Numerics.Tensors.ReadOnlyTensorSpan right) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.ISubtractionOperators + { + public static System.Numerics.Tensors.Tensor operator -(System.Numerics.Tensors.Tensor left, System.Numerics.Tensors.Tensor right) { throw null; } + public static System.Numerics.Tensors.Tensor operator -(System.Numerics.Tensors.Tensor left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator -(TScalar left, System.Numerics.Tensors.Tensor right) { throw null; } + public void operator -=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator -=(TScalar other) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.ISubtractionOperators + { + public static System.Numerics.Tensors.Tensor operator -(in System.Numerics.Tensors.TensorSpan left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public static System.Numerics.Tensors.Tensor operator -(in System.Numerics.Tensors.TensorSpan left, TScalar right) { throw null; } + public static System.Numerics.Tensors.Tensor operator -(TScalar left, in System.Numerics.Tensors.TensorSpan right) { throw null; } + public void operator -=(in System.Numerics.Tensors.ReadOnlyTensorSpan other) { throw null; } + public void operator -=(TScalar other) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IUnaryNegationOperators + { + public static System.Numerics.Tensors.Tensor operator -(in System.Numerics.Tensors.ReadOnlyTensorSpan tensor) { throw null; } + } + extension(System.Numerics.Tensors.Tensor) + where TScalar : System.Numerics.IUnaryNegationOperators + { + public static System.Numerics.Tensors.Tensor operator -(in System.Numerics.Tensors.Tensor tensor) { throw null; } + } + extension(System.Numerics.Tensors.TensorSpan) + where TScalar : System.Numerics.IUnaryNegationOperators + { + public static System.Numerics.Tensors.Tensor operator -(in System.Numerics.Tensors.TensorSpan tensor) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IUnaryPlusOperators + { + public static System.Numerics.Tensors.ReadOnlyTensorSpan operator +(in System.Numerics.Tensors.ReadOnlyTensorSpan tensor) { throw null; } + } + extension(System.Numerics.Tensors.Tensor) + where TScalar : System.Numerics.IUnaryPlusOperators + { + public static System.Numerics.Tensors.Tensor operator +(System.Numerics.Tensors.Tensor tensor) { throw null; } + } + extension(System.Numerics.Tensors.TensorSpan) + where TScalar : System.Numerics.IUnaryPlusOperators + { + public static System.Numerics.Tensors.TensorSpan operator +(in System.Numerics.Tensors.TensorSpan tensor) { throw null; } + } + extension(System.Numerics.Tensors.ReadOnlyTensorSpan) + where TScalar : System.Numerics.IShiftOperators + { + public static System.Numerics.Tensors.Tensor operator >>>(in System.Numerics.Tensors.ReadOnlyTensorSpan tensor, int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.Tensor) + where TScalar : System.Numerics.IShiftOperators + { + public static System.Numerics.Tensors.Tensor operator >>>(System.Numerics.Tensors.Tensor tensor, int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.Tensor tensor) + where TScalar : System.Numerics.IShiftOperators + { + public void operator >>>=(int shiftAmount) { throw null; } + } + extension(System.Numerics.Tensors.TensorSpan) + where TScalar : System.Numerics.IShiftOperators + { + public static Tensor operator >>>(in TensorSpan tensor, int shiftAmount) { throw null; } + } + extension(ref System.Numerics.Tensors.TensorSpan tensor) + where TScalar : System.Numerics.IShiftOperators + { + public void operator >>>=(int shiftAmount) { throw null; } + } } public readonly ref partial struct TensorDimensionSpan { diff --git a/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml b/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml index 9c2a17e39157a9..b9631acb2d7041 100644 --- a/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml +++ b/src/libraries/System.Numerics.Tensors/src/CompatibilitySuppressions.xml @@ -841,6 +841,13 @@ lib/net8.0/System.Numerics.Tensors.dll true + + CP0017 + M:System.Numerics.Tensors.Tensor.OnesComplement``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,System.Numerics.Tensors.TensorSpan{``0}@)$0 + lib/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + true + CP0017 M:System.Numerics.Tensors.Tensor`1.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 @@ -1016,6 +1023,13 @@ lib/net9.0/System.Numerics.Tensors.dll true + + CP0017 + M:System.Numerics.Tensors.Tensor.OnesComplement``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,System.Numerics.Tensors.TensorSpan{``0}@)$0 + lib/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + true + CP0017 M:System.Numerics.Tensors.Tensor`1.AsReadOnlyTensorSpan(System.ReadOnlySpan{System.Buffers.NIndex})$0 @@ -1107,6 +1121,24 @@ lib/net9.0/System.Numerics.Tensors.dll true + + CP0017 + M:System.Numerics.Tensors.Tensor.OnesComplement``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,System.Numerics.Tensors.TensorSpan{``0}@)$0 + ref/net10.0/System.Numerics.Tensors.dll + lib/net10.0/System.Numerics.Tensors.dll + + + CP0017 + M:System.Numerics.Tensors.Tensor.OnesComplement``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,System.Numerics.Tensors.TensorSpan{``0}@)$0 + ref/net8.0/System.Numerics.Tensors.dll + lib/net8.0/System.Numerics.Tensors.dll + + + CP0017 + M:System.Numerics.Tensors.Tensor.OnesComplement``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,System.Numerics.Tensors.TensorSpan{``0}@)$0 + ref/net9.0/System.Numerics.Tensors.dll + lib/net9.0/System.Numerics.Tensors.dll + CP0021 M:System.Numerics.Tensors.Tensor.Average``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@)``0:T:System.Numerics.INumberBase{``0} diff --git a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj index 73464e9b6106ed..24fcfcbaf6225b 100644 --- a/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj +++ b/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj @@ -39,6 +39,21 @@ + + + + + + + + + + + + + + + @@ -149,6 +164,8 @@ + + diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs index bba7b8c07c050c..8bc145f8e0e042 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.cs @@ -2453,62 +2453,6 @@ public static ref readonly TensorSpan AcosPi(scoped in ReadOnlyTensorSpan< } #endregion - #region Add - /// - /// Adds each element of to each element of and returns a new with the result. - /// - /// The of values to add. - /// The second of values to add. - public static Tensor Add(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) - where T : IAdditionOperators, IAdditiveIdentity - { - TensorOperation.ValidateCompatibility(x, y, out Tensor destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Adds to each element of and returns a new with the result. - /// - /// The of values to add. - /// The to add to each element of . - public static Tensor Add(in ReadOnlyTensorSpan x, T y) - where T : IAdditionOperators, IAdditiveIdentity - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Adds each element of to each element of and returns a new with the result. - /// - /// The of values to add. - /// The second of values to add. - /// - public static ref readonly TensorSpan Add(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : IAdditionOperators, IAdditiveIdentity - { - TensorOperation.ValidateCompatibility(x, y, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Adds to each element of and returns a new with the result. - /// - /// The of values to add. - /// The to add to each element of . - /// - public static ref readonly TensorSpan Add(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) - where T : IAdditionOperators, IAdditiveIdentity - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - #endregion - #region Asin /// /// Takes the inverse sin of each element of the and returns a new with the result. @@ -2854,118 +2798,6 @@ public static T Average(scoped in ReadOnlyTensorSpan x) } #endregion - #region BitwiseAnd - /// - /// Computes the element-wise bitwise and of the two input and returns a new with the result. - /// - /// The left . - /// The right . - public static Tensor BitwiseAnd(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) - where T : IBitwiseOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Computes the element-wise bitwise and of the two input and returns a new with the result. - /// - /// The left . - /// The right . - /// - public static ref readonly TensorSpan BitwiseAnd(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : IBitwiseOperators - { - TensorOperation.ValidateCompatibility(x, y, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Computes the element-wise bitwise and of the two input and returns a new with the result. - /// - /// The left . - /// The second value. - public static Tensor BitwiseAnd(in ReadOnlyTensorSpan x, T y) - where T : IBitwiseOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Computes the element-wise bitwise and of the two input and returns a new with the result. - /// - /// The left . - /// The second value. - /// - public static ref readonly TensorSpan BitwiseAnd(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) - where T : IBitwiseOperators - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - #endregion - - #region BitwiseOr - /// - /// Computes the element-wise bitwise of of the two input and returns a new with the result. - /// - /// The left . - /// The right . - public static Tensor BitwiseOr(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) - where T : IBitwiseOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Computes the element-wise bitwise of of the two input and returns a new with the result. - /// - /// The left . - /// The right . - /// - public static ref readonly TensorSpan BitwiseOr(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : IBitwiseOperators - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Computes the element-wise bitwise or of the two input and returns a new with the result. - /// - /// The left . - /// The second value. - public static Tensor BitwiseOr(in ReadOnlyTensorSpan x, T y) - where T : IBitwiseOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Computes the element-wise bitwise or of the two input and returns a new with the result. - /// - /// The left . - /// The second value. - /// - public static ref readonly TensorSpan BitwiseOr(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) - where T : IBitwiseOperators - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - #endregion - #region CubeRoot /// /// Computes the element-wise cube root of the input and returns a new with the result. @@ -3329,91 +3161,6 @@ public static T Distance(scoped in ReadOnlyTensorSpan x, scoped in ReadOnl } #endregion - #region Divide - /// - /// Divides each element of by and returns a new with the result. - /// - /// Input . - /// The divisor - public static Tensor Divide(in ReadOnlyTensorSpan x, T y) - where T : IDivisionOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Divides by each element of and returns a new with the result."/> - /// - /// The value to be divided. - /// The divisor. - public static Tensor Divide(T x, in ReadOnlyTensorSpan y) - where T : IDivisionOperators - { - Tensor destination = CreateFromShapeUninitialized(y.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Divides each element of by its corresponding element in and returns - /// a new with the result. - /// - /// The to be divided. - /// The divisor. - public static Tensor Divide(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) - where T : IDivisionOperators - { - TensorOperation.ValidateCompatibility(x, y, out Tensor destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Divides each element of by and returns a new with the result. - /// - /// Input . - /// The divisor - /// - public static ref readonly TensorSpan Divide(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) - where T : IDivisionOperators - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Divides by each element of and returns a new with the result."/> - /// - /// The value to be divided. - /// The divisor. - /// - public static ref readonly TensorSpan Divide(T x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : IDivisionOperators - { - TensorOperation.ValidateCompatibility(y, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Divides each element of by its corresponding element in and returns - /// a new with the result. - /// - /// The to be divided. - /// The divisor. - /// - public static ref readonly TensorSpan Divide(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : IDivisionOperators - { - TensorOperation.ValidateCompatibility(x, y, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - #endregion - #region Dot /// /// Computes the dot product of two tensors containing numbers. @@ -4512,87 +4259,6 @@ public static ref readonly TensorSpan MinNumber(scoped in ReadOnlyTensorSp } #endregion - #region Multiply - /// - /// Multiplies each element of with and returns a new with the result. - /// - /// Input - /// value to multiply by. - public static Tensor Multiply(in ReadOnlyTensorSpan x, T y) - where T : IMultiplyOperators, IMultiplicativeIdentity - { - Tensor destination = CreateFromShape(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Multiplies each element of with and returns a new with the result. - /// If the shapes are not the same they are broadcast to the smallest compatible shape. - /// - /// Left for multiplication. - /// Right for multiplication. - public static Tensor Multiply(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) - where T : IMultiplyOperators, IMultiplicativeIdentity - { - TensorOperation.ValidateCompatibility(x, y, out Tensor destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Multiplies each element of with and returns a new with the result. - /// - /// Input - /// value to multiply by. - /// - public static ref readonly TensorSpan Multiply(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) - where T : IMultiplyOperators, IMultiplicativeIdentity - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Multiplies each element of with and returns a new with the result. - /// If the shapes are not the same they are broadcast to the smallest compatible shape. - /// - /// Left for multiplication. - /// Right for multiplication. - /// - public static ref readonly TensorSpan Multiply(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : IMultiplyOperators, IMultiplicativeIdentity - { - TensorOperation.ValidateCompatibility(x, y, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - #endregion - - #region Negate - /// Computes the element-wise negation of each number in the specified tensor. - /// The - public static Tensor Negate(in ReadOnlyTensorSpan x) - where T : IUnaryNegationOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, destination); - return destination; - } - - /// Computes the element-wise negation of each number in the specified tensor. - /// The - /// - public static ref readonly TensorSpan Negate(scoped in ReadOnlyTensorSpan x, in TensorSpan destination) - where T : IUnaryNegationOperators - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, destination); - return ref destination; - } - #endregion - #region Norm /// /// Takes the norm of the and returns the result. @@ -4607,29 +4273,6 @@ public static T Norm(scoped in ReadOnlyTensorSpan x) } #endregion - #region OnesComplement - /// Computes the element-wise one's complement of numbers in the specified tensor. - /// The - public static Tensor OnesComplement(in ReadOnlyTensorSpan x) - where T : IBitwiseOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, destination); - return destination; - } - - /// Computes the element-wise one's complement of numbers in the specified tensor. - /// The - /// - public static ref readonly TensorSpan OnesComplement(scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : IBitwiseOperators - { - TensorOperation.ValidateCompatibility(y, destination); - TensorOperation.Invoke, T, T>(y, destination); - return ref destination; - } - #endregion - #region PopCount /// Computes the element-wise population count of numbers in the specified tensor. /// The @@ -5125,89 +4768,6 @@ public static T StdDev(in ReadOnlyTensorSpan x) } #endregion - #region Subtract - /// - /// Subtracts from each element of and returns a new with the result. - /// - /// The . - /// The to subtract. - public static Tensor Subtract(in ReadOnlyTensorSpan x, T y) - where T : ISubtractionOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Subtracts each element of from and returns a new with the result. - /// - /// The to be subtracted from. - /// The of values to subtract. - public static Tensor Subtract(T x, in ReadOnlyTensorSpan y) - where T : ISubtractionOperators - { - Tensor destination = CreateFromShapeUninitialized(y.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Subtracts each element of from and returns a new with the result. - /// - /// The with values to be subtracted from. - /// The with values to subtract. - public static Tensor Subtract(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) - where T : ISubtractionOperators - { - TensorOperation.ValidateCompatibility(x, y, out Tensor destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Subtracts from each element of and returns a new with the result. - /// - /// The with values to be subtracted from. - /// The value to subtract. - /// - public static ref readonly TensorSpan Subtract(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) - where T : ISubtractionOperators - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Subtracts each element of from and returns a new with the result. - /// - /// The value to be subtracted from. - /// The values to subtract. - /// - public static ref readonly TensorSpan Subtract(T x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : ISubtractionOperators - { - TensorOperation.ValidateCompatibility(y, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Subtracts each element of from and returns a new with the result. - /// - /// The of values to be subtracted from. - /// The of values to subtract. - /// - public static ref readonly TensorSpan Subtract(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : ISubtractionOperators - { - TensorOperation.ValidateCompatibility(x, y, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - #endregion - #region Sum /// /// Sums the elements of the specified tensor. @@ -5352,58 +4912,6 @@ public static ref readonly TensorSpan Truncate(scoped in ReadOnlyTensorSpa return ref destination; } #endregion - - #region Xor - /// Computes the element-wise XOR of numbers in the specified tensors. - /// The left . - /// The right . - public static Tensor Xor(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) - where T : IBitwiseOperators - { - TensorOperation.ValidateCompatibility(x, y, out Tensor destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// Computes the element-wise XOR of numbers in the specified tensors. - /// The left . - /// The right . - /// - public static ref readonly TensorSpan Xor(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) - where T : IBitwiseOperators - { - TensorOperation.ValidateCompatibility(x, y, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - - /// - /// Computes the element-wise Xor of the two input and returns a new with the result. - /// - /// The left . - /// The second value. - public static Tensor Xor(in ReadOnlyTensorSpan x, T y) - where T : IBitwiseOperators - { - Tensor destination = CreateFromShapeUninitialized(x.Lengths); - TensorOperation.Invoke, T, T>(x, y, destination); - return destination; - } - - /// - /// Computes the element-wise Xor of the two input and returns a new with the result. - /// - /// The left . - /// The second value. - /// - public static ref readonly TensorSpan Xor(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) - where T : IBitwiseOperators - { - TensorOperation.ValidateCompatibility(x, destination); - TensorOperation.Invoke, T, T>(x, y, destination); - return ref destination; - } - #endregion #endregion } } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Addition.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Addition.cs new file mode 100644 index 00000000000000..1da8f2c678d998 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Addition.cs @@ -0,0 +1,132 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs element-wise addition between two tensors. + /// The type of the elements in the tensor. + /// The tensor to add with . + /// The tensor to add with . + /// A new tensor containing the result of + . + /// The shapes of and are not compatible. + public static Tensor Add(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) + where T : IAdditionOperators, IAdditiveIdentity + { + TensorOperation.ValidateCompatibility(x, y, out Tensor destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise addition between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to add with . + /// The scalar to add with . + /// A new tensor containing the result of + . + public static Tensor Add(in ReadOnlyTensorSpan x, T y) + where T : IAdditionOperators, IAdditiveIdentity + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise addition between two tensors. + /// The type of the elements in the tensor. + /// The tensor to add with . + /// The tensor to add with . + /// The destination where the result of + is written. + /// A reference to . + /// The shapes of , , and are not compatible. + public static ref readonly TensorSpan Add(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : IAdditionOperators, IAdditiveIdentity + { + TensorOperation.ValidateCompatibility(x, y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs element-wise addition between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to add with . + /// The scalar to add with . + /// The destination where the result of + is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Add(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) + where T : IAdditionOperators, IAdditiveIdentity + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IAdditionOperators, IAdditiveIdentity + { + /// Performs element-wise addition between two tensors. + /// The tensor to add with . + /// The tensor to add with . + /// A new tensor containing the result of + . + /// The shapes of and are not compatible. + public static Tensor operator +(in ReadOnlyTensorSpan left, in ReadOnlyTensorSpan right) => Add(left, right); + + /// Performs element-wise addition between a tensor and scalar. + /// The tensor to add with . + /// The scalar to add with . + /// A new tensor containing the result of + . + public static Tensor operator +(in ReadOnlyTensorSpan left, TScalar right) => Add(left, right); + + /// Performs element-wise addition between a tensor and scalar. + /// The scalar to add with . + /// The tensor to add with . + /// A new tensor containing the result of + . + public static Tensor operator +(TScalar left, in ReadOnlyTensorSpan right) => Add(right, left); + } + + /// The type of the elements in the tensor. + extension(Tensor tensor) + where TScalar : IAdditionOperators, IAdditiveIdentity + { + /// + public static Tensor operator +(Tensor left, Tensor right) => Add(left, right); + + /// + public static Tensor operator +(Tensor left, TScalar right) => Add(left, right); + + /// + public static Tensor operator +(TScalar left, Tensor right) => Add(right, left); + + /// + public void operator +=(in ReadOnlyTensorSpan other) => Add(tensor, other, tensor); + + /// + public void operator +=(TScalar other) => Add(tensor, other, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IAdditionOperators, IAdditiveIdentity + { + /// + public static Tensor operator +(in TensorSpan left, in TensorSpan right) => Add(left, right); + + /// + public static Tensor operator +(in TensorSpan left, TScalar right) => Add(left, right); + + /// + public static Tensor operator +(TScalar left, in TensorSpan right) => Add(right, left); + + /// Performs in-place element-wise addition between two tensors. + /// The tensor to add to the tensor being operated on. + public void operator +=(in ReadOnlyTensorSpan other) => Add(tensor, other, tensor); + + /// Performs in-place element-wise addition between a tensor and scalar. + /// The scalar to add to the tensor being operated on. + public void operator +=(TScalar other) => Add(tensor, other, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_BitwiseAnd.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_BitwiseAnd.cs new file mode 100644 index 00000000000000..dc2417aeb7db48 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_BitwiseAnd.cs @@ -0,0 +1,132 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs bitwise-and between two tensors. + /// The type of the elements in the tensor. + /// The tensor to bitwise-and with . + /// The tensor to bitwise-and with . + /// A new tensor containing the result of & . + /// The shapes of and are not compatible. + public static Tensor BitwiseAnd(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) + where T : IBitwiseOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs bitwise-and between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to bitwise-and with . + /// The scalar to bitwise-and with . + /// A new tensor containing the result of & . + public static Tensor BitwiseAnd(in ReadOnlyTensorSpan x, T y) + where T : IBitwiseOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs bitwise-and between two tensors. + /// The type of the elements in the tensor. + /// The tensor to bitwise-and with . + /// The tensor to bitwise-and with . + /// The destination where the result of & is written. + /// A reference to . + /// The shapes of , , and are not compatible. + public static ref readonly TensorSpan BitwiseAnd(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : IBitwiseOperators + { + TensorOperation.ValidateCompatibility(x, y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs bitwise-and between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to bitwise-and with . + /// The scalar to bitwise-and with . + /// The destination where the result of & is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan BitwiseAnd(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) + where T : IBitwiseOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IBitwiseOperators + { + /// Performs bitwise-and between two tensors. + /// The tensor to bitwise-and with . + /// The tensor to bitwise-and with . + /// A new tensor containing the result of & . + /// The shapes of and are not compatible. + public static Tensor operator &(in ReadOnlyTensorSpan left, in ReadOnlyTensorSpan right) => BitwiseAnd(left, right); + + /// Performs bitwise-and between a tensor and scalar. + /// The tensor to bitwise-and with . + /// The scalar to bitwise-and with . + /// A new tensor containing the result of & . + public static Tensor operator &(in ReadOnlyTensorSpan left, TScalar right) => BitwiseAnd(left, right); + + /// Performs bitwise-and between a tensor and scalar. + /// The scalar to bitwise-and with . + /// The tensor to bitwise-and with . + /// A new tensor containing the result of & . + public static Tensor operator &(TScalar left, in ReadOnlyTensorSpan right) => BitwiseAnd(right, left); + } + + /// The type of the elements in the tensor. + extension(Tensor tensor) + where TScalar : IBitwiseOperators + { + /// + public static Tensor operator &(Tensor left, Tensor right) => BitwiseAnd(left, right); + + /// + public static Tensor operator &(Tensor left, TScalar right) => BitwiseAnd(left, right); + + /// + public static Tensor operator &(TScalar left, Tensor right) => BitwiseAnd(right, left); + + /// + public void operator &=(in ReadOnlyTensorSpan other) => BitwiseAnd(tensor, other, tensor); + + /// + public void operator &=(TScalar other) => BitwiseAnd(tensor, other, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IBitwiseOperators + { + /// + public static Tensor operator &(in TensorSpan left, in TensorSpan right) => BitwiseAnd(left, right); + + /// + public static Tensor operator &(in TensorSpan left, TScalar right) => BitwiseAnd(left, right); + + /// + public static Tensor operator &(TScalar left, in TensorSpan right) => BitwiseAnd(right, left); + + /// Performs in-place bitwise-and between two tensors. + /// The tensor to bitwise-and with the tensor being operated on. + public void operator &=(in ReadOnlyTensorSpan other) => BitwiseAnd(tensor, other, tensor); + + /// Performs in-place bitwise-and between a tensor and scalar. + /// The scalar to bitwise-and with the tensor being operated on. + public void operator &=(TScalar other) => BitwiseAnd(tensor, other, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_BitwiseOr.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_BitwiseOr.cs new file mode 100644 index 00000000000000..f54f3600adeb12 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_BitwiseOr.cs @@ -0,0 +1,132 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs bitwise-or between two tensors. + /// The type of the elements in the tensor. + /// The tensor to bitwise-or with . + /// The tensor to bitwise-or with . + /// A new tensor containing the result of | . + /// The shapes of and are not compatible. + public static Tensor BitwiseOr(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) + where T : IBitwiseOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs bitwise-or between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to bitwise-or with . + /// The scalar to bitwise-or with . + /// A new tensor containing the result of | . + public static Tensor BitwiseOr(in ReadOnlyTensorSpan x, T y) + where T : IBitwiseOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs bitwise-or between two tensors. + /// The type of the elements in the tensor. + /// The tensor to bitwise-or with . + /// The tensor to bitwise-or with . + /// The destination where the result of | is written. + /// A reference to . + /// The shapes of , , and are not compatible. + public static ref readonly TensorSpan BitwiseOr(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : IBitwiseOperators + { + TensorOperation.ValidateCompatibility(x, y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs bitwise-or between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to bitwise-or with . + /// The scalar to bitwise-or with . + /// The destination where the result of | is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan BitwiseOr(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) + where T : IBitwiseOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IBitwiseOperators + { + /// Performs bitwise-or between two tensors. + /// The tensor to bitwise-or with . + /// The tensor to bitwise-or with . + /// A new tensor containing the result of | . + /// The shapes of and are not compatible. + public static Tensor operator |(in ReadOnlyTensorSpan left, in ReadOnlyTensorSpan right) => BitwiseOr(left, right); + + /// Performs bitwise-or between a tensor and scalar. + /// The tensor to bitwise-or with . + /// The scalar to bitwise-or with . + /// A new tensor containing the result of | . + public static Tensor operator |(in ReadOnlyTensorSpan left, TScalar right) => BitwiseOr(left, right); + + /// Performs bitwise-or between a tensor and scalar. + /// The scalar to bitwise-or with . + /// The tensor to bitwise-or with . + /// A new tensor containing the result of | . + public static Tensor operator |(TScalar left, in ReadOnlyTensorSpan right) => BitwiseOr(right, left); + } + + /// The type of the elements in the tensor. + extension(Tensor tensor) + where TScalar : IBitwiseOperators + { + /// + public static Tensor operator |(Tensor left, Tensor right) => BitwiseOr(left, right); + + /// + public static Tensor operator |(Tensor left, TScalar right) => BitwiseOr(left, right); + + /// + public static Tensor operator |(TScalar left, Tensor right) => BitwiseOr(right, left); + + /// + public void operator |=(in ReadOnlyTensorSpan other) => BitwiseOr(tensor, other, tensor); + + /// + public void operator |=(TScalar other) => BitwiseOr(tensor, other, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IBitwiseOperators + { + /// + public static Tensor operator |(in TensorSpan left, in TensorSpan right) => BitwiseOr(left, right); + + /// + public static Tensor operator |(in TensorSpan left, TScalar right) => BitwiseOr(left, right); + + /// + public static Tensor operator |(TScalar left, in TensorSpan right) => BitwiseOr(right, left); + + /// Performs in-place bitwise-or between two tensors. + /// The tensor to bitwise-or with the tensor being operated on. + public void operator |=(in ReadOnlyTensorSpan other) => BitwiseOr(tensor, other, tensor); + + /// Performs in-place bitwise-or between a tensor and scalar. + /// The scalar to bitwise-or with the tensor being operated on. + public void operator |=(TScalar other) => BitwiseOr(tensor, other, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Decrement.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Decrement.cs new file mode 100644 index 00000000000000..dbeace8824cc05 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Decrement.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs an decrement on a tensor. + /// The type of the elements in the tensor. + /// The tensor to decrement. + /// A new tensor containing the result of --. + public static Tensor Decrement(in ReadOnlyTensorSpan x) + where T : IDecrementOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, destination); + return destination; + } + + /// Performs an decrement on a tensor. + /// The type of the elements in the tensor. + /// The tensor to decrement. + /// The destination where the result of -- is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Decrement(scoped in ReadOnlyTensorSpan x, in TensorSpan destination) + where T : IDecrementOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(Tensor tensor) + where TScalar : IDecrementOperators + { + /// + public void operator --() => Decrement(tensor, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IDecrementOperators + { + /// Performs in-place decrement on a tensor. + public void operator --() => Decrement(tensor, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Division.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Division.cs new file mode 100644 index 00000000000000..7dc50d5959f349 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Division.cs @@ -0,0 +1,159 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs element-wise division between two tensors. + /// The type of the elements in the tensor. + /// The tensor dividend. + /// The tensor divisor. + /// A new tensor containing the result of / . + /// The shapes of and are not compatible. + public static Tensor Divide(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) + where T : IDivisionOperators + { + TensorOperation.ValidateCompatibility(x, y, out Tensor destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise division between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor dividend. + /// The scalar divisor. + /// A new tensor containing the result of / . + public static Tensor Divide(in ReadOnlyTensorSpan x, T y) + where T : IDivisionOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise division between a tensor and scalar. + /// The type of the elements in the tensor. + /// The scalar dividend. + /// The tensor divisor. + /// A new tensor containing the result of / . + public static Tensor Divide(T x, in ReadOnlyTensorSpan y) + where T : IDivisionOperators + { + Tensor destination = CreateFromShapeUninitialized(y.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise division between two tensors. + /// The type of the elements in the tensor. + /// The tensor dividend. + /// The tensor divisor. + /// The destination where the result of / is written. + /// A reference to . + /// The shapes of , , and are not compatible. + public static ref readonly TensorSpan Divide(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : IDivisionOperators + { + TensorOperation.ValidateCompatibility(x, y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs element-wise division between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor dividend. + /// The scalar divisor. + /// The destination where the result of / is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Divide(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) + where T : IDivisionOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs element-wise division between a tensor and scalar. + /// The type of the elements in the tensor. + /// The scalar dividend. + /// The tensor divisor. + /// The destination where the result of / is written. + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Divide(T x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : IDivisionOperators + { + TensorOperation.ValidateCompatibility(y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IDivisionOperators + { + /// Performs element-wise division between two tensors. + /// The tensor dividend. + /// The tensor divisor. + /// A new tensor containing the result of / . + /// The shapes of and are not compatible. + public static Tensor operator /(in ReadOnlyTensorSpan left, in ReadOnlyTensorSpan right) => Divide(left, right); + + /// Performs element-wise division between a tensor and scalar. + /// The tensor dividend. + /// The scalar divisor. + /// A new tensor containing the result of / . + public static Tensor operator /(in ReadOnlyTensorSpan left, TScalar right) => Divide(left, right); + + /// Performs element-wise division between a tensor and scalar. + /// The scalar dividend. + /// The tensor divisor. + /// A new tensor containing the result of / . + public static Tensor operator /(TScalar left, in ReadOnlyTensorSpan right) => Divide(left, right); + } + + /// The type of the elements in the tensor. + extension(Tensor tensor) + where TScalar : IDivisionOperators + { + /// + public static Tensor operator /(Tensor left, Tensor right) => Divide(left, right); + + /// + public static Tensor operator /(Tensor left, TScalar right) => Divide(left, right); + + /// + public static Tensor operator /(TScalar left, Tensor right) => Divide(left, right); + + /// + public void operator /=(in ReadOnlyTensorSpan other) => Divide(tensor, other, tensor); + + /// + public void operator /=(TScalar other) => Divide(tensor, other, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IDivisionOperators + { + /// + public static Tensor operator /(in TensorSpan left, in TensorSpan right) => Divide(left, right); + + /// + public static Tensor operator /(in TensorSpan left, TScalar right) => Divide(left, right); + + /// + public static Tensor operator /(TScalar left, in TensorSpan right) => Divide(left, right); + + /// Performs in-place element-wise division between two tensors. + /// The tensor divisor. + public void operator /=(in ReadOnlyTensorSpan other) => Divide(tensor, other, tensor); + + /// Performs in-place element-wise division between a tensor and scalar. + /// The scalar divisor. + public void operator /=(TScalar other) => Divide(tensor, other, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_ExclusiveOr.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_ExclusiveOr.cs new file mode 100644 index 00000000000000..867873be53aa24 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_ExclusiveOr.cs @@ -0,0 +1,132 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs exclusive-or between two tensors. + /// The type of the elements in the tensor. + /// The tensor to exclusive-or with . + /// The tensor to exclusive-or with . + /// A new tensor containing the result of ^ . + /// The shapes of and are not compatible. + public static Tensor Xor(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) + where T : IBitwiseOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs exclusive-or between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to exclusive-or with . + /// The scalar to exclusive-or with . + /// A new tensor containing the result of ^ . + public static Tensor Xor(in ReadOnlyTensorSpan x, T y) + where T : IBitwiseOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs exclusive-or between two tensors. + /// The type of the elements in the tensor. + /// The tensor to exclusive-or with . + /// The tensor to exclusive-or with . + /// The destination where the result of ^ is written. + /// A reference to . + /// The shapes of , , and are not compatible. + public static ref readonly TensorSpan Xor(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : IBitwiseOperators + { + TensorOperation.ValidateCompatibility(x, y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs exclusive-or between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to exclusive-or with . + /// The scalar to exclusive-or with . + /// The destination where the result of ^ is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Xor(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) + where T : IBitwiseOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IBitwiseOperators + { + /// Performs exclusive-or between two tensors. + /// The tensor to exclusive-or with . + /// The tensor to exclusive-or with . + /// A new tensor containing the result of ^ . + /// The shapes of and are not compatible. + public static Tensor operator ^(in ReadOnlyTensorSpan left, in ReadOnlyTensorSpan right) => Xor(left, right); + + /// Performs exclusive-or between a tensor and scalar. + /// The tensor to exclusive-or with . + /// The scalar to exclusive-or with . + /// A new tensor containing the result of ^ . + public static Tensor operator ^(in ReadOnlyTensorSpan left, TScalar right) => Xor(left, right); + + /// Performs exclusive-or between a tensor and scalar. + /// The scalar to exclusive-or with . + /// The tensor to exclusive-or with . + /// A new tensor containing the result of ^ . + public static Tensor operator ^(TScalar left, in ReadOnlyTensorSpan right) => Xor(right, left); + } + + /// The type of the elements in the tensor. + extension(Tensor tensor) + where TScalar : IBitwiseOperators + { + /// + public static Tensor operator ^(Tensor left, Tensor right) => Xor(left, right); + + /// + public static Tensor operator ^(Tensor left, TScalar right) => Xor(left, right); + + /// + public static Tensor operator ^(TScalar left, Tensor right) => Xor(right, left); + + /// + public void operator ^=(in ReadOnlyTensorSpan other) => Xor(tensor, other, tensor); + + /// + public void operator ^=(TScalar other) => Xor(tensor, other, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IBitwiseOperators + { + /// + public static Tensor operator ^(in TensorSpan left, in TensorSpan right) => Xor(left, right); + + /// + public static Tensor operator ^(in TensorSpan left, TScalar right) => Xor(left, right); + + /// + public static Tensor operator ^(TScalar left, in TensorSpan right) => Xor(right, left); + + /// Performs in-place exclusive-or between two tensors. + /// The tensor to exclusive-or with the tensor being operated on. + public void operator ^=(in ReadOnlyTensorSpan other) => Xor(tensor, other, tensor); + + /// Performs in-place exclusive-or between a tensor and scalar. + /// The scalar to exclusive-or with the tensor being operated on. + public void operator ^=(TScalar other) => Xor(tensor, other, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Increment.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Increment.cs new file mode 100644 index 00000000000000..5773aa51e86351 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Increment.cs @@ -0,0 +1,52 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs an increment on a tensor. + /// The type of the elements in the tensor. + /// The tensor to increment. + /// A new tensor containing the result of ++. + public static Tensor Increment(in ReadOnlyTensorSpan x) + where T : IIncrementOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, destination); + return destination; + } + + /// Performs an increment on a tensor. + /// The type of the elements in the tensor. + /// The tensor to increment. + /// The destination where the result of ++ is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Increment(scoped in ReadOnlyTensorSpan x, in TensorSpan destination) + where T : IIncrementOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(Tensor tensor) + where TScalar : IIncrementOperators + { + /// + public void operator ++() => Increment(tensor, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IIncrementOperators + { + /// Performs in-place increment on a tensor. + public void operator ++() => Increment(tensor, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_LeftShift.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_LeftShift.cs new file mode 100644 index 00000000000000..68f1e304e7c2f8 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_LeftShift.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs an element-wise left shift on a tensor. + /// The type of the elements in the tensor. + /// The tensor to left shift. + /// The amount to shift each element in . + /// A new tensor containing the result of << . + public static Tensor ShiftLeft(in ReadOnlyTensorSpan x, int shiftAmount) + where T : IShiftOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, int, T>(x, shiftAmount, destination); + return destination; + } + + /// Performs an element-wise left shift on a tensor. + /// The type of the elements in the tensor. + /// The tensor to left shift. + /// The amount to shift each element in . + /// The destination where the result of << is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan ShiftLeft(scoped in ReadOnlyTensorSpan x, int shiftAmount, in TensorSpan destination) + where T : IShiftOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, int, T>(x, shiftAmount, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IShiftOperators + { + /// Performs an element-wise left shift on a tensor. + /// The tensor to left shift. + /// The amount to shift each element in . + /// A new tensor containing the result of << . + public static Tensor operator <<(in ReadOnlyTensorSpan tensor, int shiftAmount) => ShiftLeft(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + extension(Tensor) + where TScalar : IShiftOperators + { + /// + public static Tensor operator <<(Tensor tensor, int shiftAmount) => ShiftLeft(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(Tensor tensor) + where TScalar : IShiftOperators + { + /// + public void operator <<=(int shiftAmount) => ShiftLeft(tensor, shiftAmount, tensor); + } + + /// The type of the elements in the tensor. + extension(TensorSpan) + where TScalar : IShiftOperators + { + /// + public static Tensor operator <<(in TensorSpan tensor, int shiftAmount) => ShiftLeft(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IShiftOperators + { + /// Performs in-place element-wise left shift on a tensor. + /// The amount to shift each element in the tensor. + public void operator <<=(int shiftAmount) => ShiftLeft(tensor, shiftAmount, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Multiply.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Multiply.cs new file mode 100644 index 00000000000000..ca38d7b970a1f8 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Multiply.cs @@ -0,0 +1,132 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs element-wise multiplication between two tensors. + /// The type of the elements in the tensor. + /// The tensor to multiply with . + /// The tensor to multiply with . + /// A new tensor containing the result of * . + /// The shapes of and are not compatible. + public static Tensor Multiply(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) + where T : IMultiplyOperators, IMultiplicativeIdentity + { + TensorOperation.ValidateCompatibility(x, y, out Tensor destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise multiplication between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to multiply with . + /// The scalar to multiply with . + /// A new tensor containing the result of * . + public static Tensor Multiply(in ReadOnlyTensorSpan x, T y) + where T : IMultiplyOperators, IMultiplicativeIdentity + { + Tensor destination = CreateFromShape(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise multiplication between two tensors. + /// The type of the elements in the tensor. + /// The tensor to multiply with . + /// The tensor to multiply with . + /// The destination where the result of * is written. + /// A reference to . + /// The shapes of , , and are not compatible. + public static ref readonly TensorSpan Multiply(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : IMultiplyOperators, IMultiplicativeIdentity + { + TensorOperation.ValidateCompatibility(x, y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs element-wise multiplication between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor to multiply with . + /// The scalar to multiply with . + /// The destination where the result of * is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Multiply(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) + where T : IMultiplyOperators, IMultiplicativeIdentity + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IMultiplyOperators, System.Numerics.IMultiplicativeIdentity + { + /// Performs element-wise multiplication between two tensors. + /// The tensor to multiply with . + /// The tensor to multiply with . + /// A new tensor containing the result of * . + /// The shapes of and are not compatible. + public static Tensor operator *(in ReadOnlyTensorSpan left, in ReadOnlyTensorSpan right) => Multiply(left, right); + + /// Performs element-wise multiplication between a tensor and scalar. + /// The tensor to multiply with . + /// The scalar to multiply with . + /// A new tensor containing the result of * . + public static Tensor operator *(in ReadOnlyTensorSpan left, TScalar right) => Multiply(left, right); + + /// Performs element-wise multiplication between a tensor and scalar. + /// The scalar to multiply with . + /// The tensor to multiply with . + /// A new tensor containing the result of * . + public static Tensor operator *(TScalar left, in ReadOnlyTensorSpan right) => Multiply(right, left); + } + + /// The type of the elements in the tensor. + extension(Tensor tensor) + where TScalar : IMultiplyOperators, System.Numerics.IMultiplicativeIdentity + { + /// + public static Tensor operator *(Tensor left, Tensor right) => Multiply(left, right); + + /// + public static Tensor operator *(Tensor left, TScalar right) => Multiply(left, right); + + /// + public static Tensor operator *(TScalar left, Tensor right) => Multiply(right, left); + + /// + public void operator *=(in ReadOnlyTensorSpan other) => Multiply(tensor, other, tensor); + + /// + public void operator *=(TScalar other) => Multiply(tensor, other, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IMultiplyOperators, System.Numerics.IMultiplicativeIdentity + { + /// + public static Tensor operator *(in TensorSpan left, in TensorSpan right) => Multiply(left, right); + + /// + public static Tensor operator *(in TensorSpan left, TScalar right) => Multiply(left, right); + + /// + public static Tensor operator *(TScalar left, in TensorSpan right) => Multiply(right, left); + + /// Performs in-place element-wise multiplication between two tensors. + /// The tensor used to multiply the tensor being operated on. + public void operator *=(in ReadOnlyTensorSpan other) => Multiply(tensor, other, tensor); + + /// Performs in-place element-wise multiplication between a tensor and scalar. + /// The scalar used to multiply the tensor being operated on. + public void operator *=(TScalar other) => Multiply(tensor, other, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_OnesComplement.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_OnesComplement.cs new file mode 100644 index 00000000000000..484a134d6548c6 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_OnesComplement.cs @@ -0,0 +1,60 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs a one's complement on a tensor. + /// The type of the elements in the tensor. + /// The tensor to one's complement. + /// A new tensor containing the result of ~. + public static Tensor OnesComplement(in ReadOnlyTensorSpan x) + where T : IBitwiseOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, destination); + return destination; + } + + /// Performs a one's complement on a tensor. + /// The type of the elements in the tensor. + /// The tensor to one's complement. + /// The destination where the result of ~ is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan OnesComplement(scoped in ReadOnlyTensorSpan x, in TensorSpan destination) + where T : IBitwiseOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IBitwiseOperators + { + /// Performs a one's complement on a tensor. + /// The tensor to one's complement. + /// A new tensor containing the result of ~. + public static Tensor operator ~(in ReadOnlyTensorSpan tensor) => OnesComplement(tensor); + } + + /// The type of the elements in the tensor. + extension(Tensor) + where TScalar : IBitwiseOperators + { + /// + public static Tensor operator ~(Tensor tensor) => OnesComplement(tensor); + } + + /// The type of the elements in the tensor. + extension(TensorSpan) + where TScalar : IBitwiseOperators + { + /// + public static Tensor operator ~(in TensorSpan tensor) => OnesComplement(tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_RightShift.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_RightShift.cs new file mode 100644 index 00000000000000..d61559441b96ec --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_RightShift.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs an element-wise arithmetic right shift on a tensor. + /// The type of the elements in the tensor. + /// The tensor to arithmetic right shift. + /// The amount to shift each element in . + /// A new tensor containing the result of >> . + public static Tensor ShiftRightArithmetic(in ReadOnlyTensorSpan x, int shiftAmount) + where T : IShiftOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, int, T>(x, shiftAmount, destination); + return destination; + } + + /// Performs an element-wise arithmetic right shift on a tensor. + /// The type of the elements in the tensor. + /// The tensor to arithmetic right shift. + /// The amount to shift each element in . + /// The destination where the result of >> is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan ShiftRightArithmetic(scoped in ReadOnlyTensorSpan x, int shiftAmount, in TensorSpan destination) + where T : IShiftOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, int, T>(x, shiftAmount, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IShiftOperators + { + /// Performs an element-wise arithmetic right shift on a tensor. + /// The tensor to arithmetic right shift. + /// The amount to shift each element in . + /// A new tensor containing the result of >> . + public static Tensor operator >>(in ReadOnlyTensorSpan tensor, int shiftAmount) => ShiftRightArithmetic(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + extension(Tensor) + where TScalar : IShiftOperators + { + /// + public static Tensor operator >>(Tensor tensor, int shiftAmount) => ShiftRightArithmetic(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(Tensor tensor) + where TScalar : IShiftOperators + { + /// + public void operator >>=(int shiftAmount) => ShiftRightArithmetic(tensor, shiftAmount, tensor); + } + + /// The type of the elements in the tensor. + extension(TensorSpan) + where TScalar : IShiftOperators + { + /// + public static Tensor operator >>(in TensorSpan tensor, int shiftAmount) => ShiftRightArithmetic(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IShiftOperators + { + /// Performs in-place element-wise arithmetic right shift on a tensor. + /// The amount to shift each element in the tensor. + public void operator >>=(int shiftAmount) => ShiftRightArithmetic(tensor, shiftAmount, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Subtraction.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Subtraction.cs new file mode 100644 index 00000000000000..dd8ea6c028e0b9 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_Subtraction.cs @@ -0,0 +1,160 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs element-wise subtraction between two tensors. + /// The type of the elements in the tensor. + /// The tensor from which to subtract . + /// The tensor to subtract from . + /// A new tensor containing the result of - . + /// The shapes of and are not compatible. + public static Tensor Subtract(in ReadOnlyTensorSpan x, in ReadOnlyTensorSpan y) + where T : ISubtractionOperators + { + TensorOperation.ValidateCompatibility(x, y, out Tensor destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise subtraction between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor from which to subtract . + /// The scalar to subtract from . + /// A new tensor containing the result of - . + public static Tensor Subtract(in ReadOnlyTensorSpan x, T y) + where T : ISubtractionOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise subtraction between a tensor and scalar. + /// The type of the elements in the tensor. + /// The scalar from which to subtract . + /// The tensor to subtract from . + /// A new tensor containing the result of - . + public static Tensor Subtract(T x, in ReadOnlyTensorSpan y) + where T : ISubtractionOperators + { + Tensor destination = CreateFromShapeUninitialized(y.Lengths); + TensorOperation.Invoke, T, T>(x, y, destination); + return destination; + } + + /// Performs element-wise subtraction between two tensors. + /// The type of the elements in the tensor. + /// The tensor from which to subtract . + /// The tensor to subtract from . + /// The destination where the result of - is written. + /// A reference to . + /// The shapes of , , and are not compatible. + public static ref readonly TensorSpan Subtract(scoped in ReadOnlyTensorSpan x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : ISubtractionOperators + { + TensorOperation.ValidateCompatibility(x, y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs element-wise subtraction between a tensor and scalar. + /// The type of the elements in the tensor. + /// The tensor from which to subtract . + /// The scalar to subtract from . + /// The destination where the result of - is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Subtract(scoped in ReadOnlyTensorSpan x, T y, in TensorSpan destination) + where T : ISubtractionOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// Performs element-wise subtraction between a tensor and scalar. + /// The type of the elements in the tensor. + /// The scalar from which to subtract . + /// The tensor to subtract from . + /// The destination where the result of - is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Subtract(T x, scoped in ReadOnlyTensorSpan y, in TensorSpan destination) + where T : ISubtractionOperators + { + TensorOperation.ValidateCompatibility(y, destination); + TensorOperation.Invoke, T, T>(x, y, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : ISubtractionOperators + { + /// Performs element-wise subtraction between two tensors. + /// The tensor from which to subtract . + /// The tensor to subtract from . + /// A new tensor containing the result of - . + /// The shapes of and are not compatible. + public static Tensor operator -(in ReadOnlyTensorSpan left, in ReadOnlyTensorSpan right) => Subtract(left, right); + + /// Performs element-wise subtraction between a tensor and scalar. + /// The tensor from which to subtract . + /// The scalar to subtract from . + /// A new tensor containing the result of - . + public static Tensor operator -(in ReadOnlyTensorSpan left, TScalar right) => Subtract(left, right); + + /// Performs element-wise subtraction between a tensor and scalar. + /// The scalar from which to subtract . + /// The tensor to subtract from . + /// A new tensor containing the result of - . + public static Tensor operator -(TScalar left, in ReadOnlyTensorSpan right) => Subtract(left, right); + } + + /// The type of the elements in the tensor. + extension(Tensor tensor) + where TScalar : ISubtractionOperators + { + /// + public static Tensor operator -(Tensor left, Tensor right) => Subtract(left, right); + + /// + public static Tensor operator -(Tensor left, TScalar right) => Subtract(left, right); + + /// + public static Tensor operator -(TScalar left, Tensor right) => Subtract(left, right); + + /// + public void operator -=(in ReadOnlyTensorSpan other) => Subtract(tensor, other, tensor); + + /// + public void operator -=(TScalar other) => Subtract(tensor, other, tensor); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : ISubtractionOperators + { + /// + public static Tensor operator -(in TensorSpan left, in TensorSpan right) => Subtract(left, right); + + /// + public static Tensor operator -(in TensorSpan left, TScalar right) => Subtract(left, right); + + /// + public static Tensor operator -(TScalar left, in TensorSpan right) => Subtract(left, right); + + /// Performs in-place element-wise subtraction between two tensors. + /// The tensor to subtract from the tensor being operated on. + public void operator -=(in ReadOnlyTensorSpan other) => Subtract(tensor, other, tensor); + + /// Performs in-place element-wise subtraction between a tensor and scalar. + /// The scalar to subtract from the tensor being operated on. + public void operator -=(TScalar other) => Subtract(tensor, other, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnaryNegation.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnaryNegation.cs new file mode 100644 index 00000000000000..261ed655688352 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnaryNegation.cs @@ -0,0 +1,58 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs element-wise unary negation on a tensor. + /// The tensor to negate. + /// A new tensor containing the result of -. + public static Tensor Negate(in ReadOnlyTensorSpan x) + where T : IUnaryNegationOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, T>(x, destination); + return destination; + } + + /// Performs element-wise unary negation on a tensor. + /// The tensor to negate. + /// The destination where the result of - is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan Negate(scoped in ReadOnlyTensorSpan x, in TensorSpan destination) + where T : IUnaryNegationOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, T>(x, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IUnaryNegationOperators + { + /// Performs element-wise unary negation on a tensor. + /// The tensor to negate. + /// A new tensor containing the result of -. + public static Tensor operator -(in ReadOnlyTensorSpan tensor) => Negate(tensor); + } + + /// The type of the elements in the tensor. + extension(Tensor) + where TScalar : IUnaryNegationOperators + { + /// + public static Tensor operator -(Tensor tensor) => Negate(tensor); + } + + /// The type of the elements in the tensor. + extension(TensorSpan) + where TScalar : IUnaryNegationOperators + { + /// + public static Tensor operator -(in TensorSpan tensor) => Negate(tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnaryPlus.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnaryPlus.cs new file mode 100644 index 00000000000000..db11f6d750c962 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnaryPlus.cs @@ -0,0 +1,34 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IUnaryPlusOperators + { + /// Performs element-wise unary plus on a tensor. + /// The tensor to return. + /// + public static ReadOnlyTensorSpan operator +(in ReadOnlyTensorSpan tensor) => tensor; + } + + /// The type of the elements in the tensor. + extension(Tensor) + where TScalar : IUnaryPlusOperators + { + /// + public static Tensor operator +(Tensor tensor) => tensor; + } + + /// The type of the elements in the tensor. + extension(TensorSpan) + where TScalar : IUnaryPlusOperators + { + /// + public static TensorSpan operator +(in TensorSpan tensor) => tensor; + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnsignedRightShift.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnsignedRightShift.cs new file mode 100644 index 00000000000000..19147047592fe0 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/Tensor.op_UnsignedRightShift.cs @@ -0,0 +1,82 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Numerics.Tensors +{ + public static partial class Tensor + { + /// Performs an element-wise logical right shift on a tensor. + /// The type of the elements in the tensor. + /// The tensor to logical right shift. + /// The amount to shift each element in . + /// A new tensor containing the result of >>> . + public static Tensor ShiftRightLogical(in ReadOnlyTensorSpan x, int shiftAmount) + where T : IShiftOperators + { + Tensor destination = CreateFromShapeUninitialized(x.Lengths); + TensorOperation.Invoke, T, int, T>(x, shiftAmount, destination); + return destination; + } + + /// Performs an element-wise logical right shift on a tensor. + /// The type of the elements in the tensor. + /// The tensor to logical right shift. + /// The amount to shift each element in . + /// The destination where the result of >>> is written. + /// A reference to . + /// The shapes of and are not compatible. + public static ref readonly TensorSpan ShiftRightLogical(scoped in ReadOnlyTensorSpan x, int shiftAmount, in TensorSpan destination) + where T : IShiftOperators + { + TensorOperation.ValidateCompatibility(x, destination); + TensorOperation.Invoke, T, int, T>(x, shiftAmount, destination); + return ref destination; + } + + /// The type of the elements in the tensor. + extension(ReadOnlyTensorSpan) + where TScalar : IShiftOperators + { + /// Performs an element-wise logical right shift on a tensor. + /// The tensor to logical right shift. + /// The amount to shift each element in . + /// A new tensor containing the result of >>> . + public static Tensor operator >>>(in ReadOnlyTensorSpan tensor, int shiftAmount) => ShiftRightLogical(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + extension(Tensor) + where TScalar : IShiftOperators + { + /// + public static Tensor operator >>>(Tensor tensor, int shiftAmount) => ShiftRightLogical(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(Tensor tensor) + where TScalar : IShiftOperators + { + /// + public void operator >>>=(int shiftAmount) => ShiftRightLogical(tensor, shiftAmount, tensor); + } + + /// The type of the elements in the tensor. + extension(TensorSpan) + where TScalar : IShiftOperators + { + /// + public static Tensor operator >>>(in TensorSpan tensor, int shiftAmount) => ShiftRightLogical(tensor, shiftAmount); + } + + /// The type of the elements in the tensor. + /// The tensor to operate on. + extension(ref TensorSpan tensor) + where TScalar : IShiftOperators + { + /// Performs in-place element-wise logical right shift on a tensor. + /// The amount to shift each element in the tensor. + public void operator >>>=(int shiftAmount) => ShiftRightLogical(tensor, shiftAmount, tensor); + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorOperation.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorOperation.cs index 42092b950a156f..227a8d95db58ed 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorOperation.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorOperation.cs @@ -949,6 +949,22 @@ public static void Invoke(ReadOnlySpan x, Span destination) } } + public readonly struct Decrement + : IUnaryOperation_Tensor + where T : IDecrementOperators + { + public static void Invoke(ref readonly T x, ref T destination) + { + T tmp = x; + destination = --tmp; + } + + public static void Invoke(ReadOnlySpan x, Span destination) + { + TensorPrimitives.Decrement(x, destination); + } + } + public readonly struct DegreesToRadians : IUnaryOperation_Tensor where T : ITrigonometricFunctions @@ -1186,6 +1202,22 @@ public static void Invoke(ReadOnlySpan x, Span destination) } } + public readonly struct Increment + : IUnaryOperation_Tensor + where T : IIncrementOperators + { + public static void Invoke(ref readonly T x, ref T destination) + { + T tmp = x; + destination = ++tmp; + } + + public static void Invoke(ReadOnlySpan x, Span destination) + { + TensorPrimitives.Increment(x, destination); + } + } + public readonly struct LeadingZeroCount : IUnaryOperation_Tensor where T : IBinaryInteger @@ -1831,6 +1863,51 @@ public static void Invoke(ReadOnlySpan x, Tuple y, Spa } } + public readonly struct ShiftLeft + : IBinaryOperation_Tensor_Scalar + where T : IShiftOperators + { + public static void Invoke(ref readonly T x, int shiftAmount, ref T destination) + { + destination = x << shiftAmount; + } + + public static void Invoke(ReadOnlySpan x, int shiftAmount, Span destination) + { + TensorPrimitives.ShiftLeft(x, shiftAmount, destination); + } + } + + public readonly struct ShiftRightArithmetic + : IBinaryOperation_Tensor_Scalar + where T : IShiftOperators + { + public static void Invoke(ref readonly T x, int shiftAmount, ref T destination) + { + destination = x >> shiftAmount; + } + + public static void Invoke(ReadOnlySpan x, int shiftAmount, Span destination) + { + TensorPrimitives.ShiftRightArithmetic(x, shiftAmount, destination); + } + } + + public readonly struct ShiftRightLogical + : IBinaryOperation_Tensor_Scalar + where T : IShiftOperators + { + public static void Invoke(ref readonly T x, int shiftAmount, ref T destination) + { + destination = x >>> shiftAmount; + } + + public static void Invoke(ReadOnlySpan x, int shiftAmount, Span destination) + { + TensorPrimitives.ShiftRightLogical(x, shiftAmount, destination); + } + } + public readonly struct Sigmoid : IUnaryOperation_Tensor where T : IExponentialFunctions diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftLeft.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftLeft.cs index 22d5ea4c268679..63b3ee4d101ee4 100644 --- a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftLeft.cs +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftLeft.cs @@ -22,36 +22,6 @@ public static void ShiftLeft(ReadOnlySpan x, int shiftAmount, Span dest where T : IShiftOperators => InvokeSpanIntoSpan(x, new ShiftLeftOperator(shiftAmount), destination); - /// Computes the element-wise arithmetic (signed) shifting right of numbers in the specified tensor by the specified shift amount. - /// The tensor, represented as a span. - /// The destination tensor, represented as a span. - /// The number of bits to shift, represented as a scalar. - /// Destination is too short. - /// and reference overlapping memory locations and do not begin at the same location. - /// - /// - /// This method effectively computes [i] = [i] >> . - /// - /// - public static void ShiftRightArithmetic(ReadOnlySpan x, int shiftAmount, Span destination) - where T : IShiftOperators => - InvokeSpanIntoSpan(x, new ShiftRightArithmeticOperator(shiftAmount), destination); - - /// Computes the element-wise logical (unsigned) shifting right of numbers in the specified tensor by the specified shift amount. - /// The tensor, represented as a span. - /// The destination tensor, represented as a span. - /// The number of bits to shift, represented as a scalar. - /// Destination is too short. - /// and reference overlapping memory locations and do not begin at the same location. - /// - /// - /// This method effectively computes [i] = [i] >>> . - /// - /// - public static void ShiftRightLogical(ReadOnlySpan x, int shiftAmount, Span destination) - where T : IShiftOperators => - InvokeSpanIntoSpan(x, new ShiftRightLogicalOperator(shiftAmount), destination); - /// T << amount private readonly struct ShiftLeftOperator(int amount) : IStatefulUnaryOperator where T : IShiftOperators { @@ -64,31 +34,5 @@ private readonly struct ShiftLeftOperator(int amount) : IStatefulUnaryOperato public Vector256 Invoke(Vector256 x) => x << _amount; public Vector512 Invoke(Vector512 x) => x << _amount; } - - /// T >> amount - private readonly struct ShiftRightArithmeticOperator(int amount) : IStatefulUnaryOperator where T : IShiftOperators - { - private readonly int _amount = amount; - - public static bool Vectorizable => true; - - public T Invoke(T x) => x >> _amount; - public Vector128 Invoke(Vector128 x) => x >> _amount; - public Vector256 Invoke(Vector256 x) => x >> _amount; - public Vector512 Invoke(Vector512 x) => x >> _amount; - } - - /// T >>> amount - private readonly struct ShiftRightLogicalOperator(int amount) : IStatefulUnaryOperator where T : IShiftOperators - { - private readonly int _amount = amount; - - public static bool Vectorizable => true; - - public T Invoke(T x) => x >>> _amount; - public Vector128 Invoke(Vector128 x) => x >>> _amount; - public Vector256 Invoke(Vector256 x) => x >>> _amount; - public Vector512 Invoke(Vector512 x) => x >>> _amount; - } } } diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftRightArithmetic.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftRightArithmetic.cs new file mode 100644 index 00000000000000..26c5bbe388e6cd --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftRightArithmetic.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Intrinsics; + +namespace System.Numerics.Tensors +{ + public static partial class TensorPrimitives + { + /// Computes the element-wise arithmetic (signed) shifting right of numbers in the specified tensor by the specified shift amount. + /// The tensor, represented as a span. + /// The destination tensor, represented as a span. + /// The number of bits to shift, represented as a scalar. + /// Destination is too short. + /// and reference overlapping memory locations and do not begin at the same location. + /// + /// + /// This method effectively computes [i] = [i] >> . + /// + /// + public static void ShiftRightArithmetic(ReadOnlySpan x, int shiftAmount, Span destination) + where T : IShiftOperators => + InvokeSpanIntoSpan(x, new ShiftRightArithmeticOperator(shiftAmount), destination); + + /// T >> amount + private readonly struct ShiftRightArithmeticOperator(int amount) : IStatefulUnaryOperator where T : IShiftOperators + { + private readonly int _amount = amount; + + public static bool Vectorizable => true; + + public T Invoke(T x) => x >> _amount; + public Vector128 Invoke(Vector128 x) => x >> _amount; + public Vector256 Invoke(Vector256 x) => x >> _amount; + public Vector512 Invoke(Vector512 x) => x >> _amount; + } + } +} diff --git a/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftRightLogical.cs b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftRightLogical.cs new file mode 100644 index 00000000000000..0b720c8e9fbf92 --- /dev/null +++ b/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorPrimitives.ShiftRightLogical.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.Intrinsics; + +namespace System.Numerics.Tensors +{ + public static partial class TensorPrimitives + { + /// Computes the element-wise logical (unsigned) shifting right of numbers in the specified tensor by the specified shift amount. + /// The tensor, represented as a span. + /// The destination tensor, represented as a span. + /// The number of bits to shift, represented as a scalar. + /// Destination is too short. + /// and reference overlapping memory locations and do not begin at the same location. + /// + /// + /// This method effectively computes [i] = [i] >>> . + /// + /// + public static void ShiftRightLogical(ReadOnlySpan x, int shiftAmount, Span destination) + where T : IShiftOperators => + InvokeSpanIntoSpan(x, new ShiftRightLogicalOperator(shiftAmount), destination); + + /// T >>> amount + private readonly struct ShiftRightLogicalOperator(int amount) : IStatefulUnaryOperator where T : IShiftOperators + { + private readonly int _amount = amount; + + public static bool Vectorizable => true; + + public T Invoke(T x) => x >>> _amount; + public Vector128 Invoke(Vector128 x) => x >>> _amount; + public Vector256 Invoke(Vector256 x) => x >>> _amount; + public Vector512 Invoke(Vector512 x) => x >>> _amount; + } + } +} diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs index 4321ff10aa688a..baa9daffcbccac 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/TrimAnalysis/TrimAnalysisVisitor.cs @@ -137,8 +137,18 @@ public override MultiValue VisitConversion(IConversionOperation operation, State public override MultiValue VisitParameterReference(IParameterReferenceOperation paramRef, StateValue state) { + IParameterSymbol parameter = paramRef.Parameter; + + if (parameter.ContainingSymbol is not IMethodSymbol) + { + // TODO: Extension members allows parameters to be on types, rather than methods. + // For example: `extension(ref T value) { }` will enumerate `value` where + // the containing symbol is a `NonErrorNamedTypeSymbol` + return TopValue; + } + // Reading from a parameter always returns the same annotated value. We don't track modifications. - return GetParameterTargetValue(paramRef.Parameter); + return GetParameterTargetValue(parameter); } public override MultiValue VisitInstanceReference(IInstanceReferenceOperation instanceRef, StateValue state)