public Shape(params int[] dims) { if (dims.Length == 0) { Rank = 0; Volume = 0; Dims = Array.Empty <int>(); return; } if (SimdOps <int> .Less(dims, 1)) { throw new ArgumentOutOfRangeException($"{nameof(dims)} must be in range >= 1."); } Rank = dims.Length; Dims = dims.AsSpan().ToArray(); Volume = 1; for (int i = 0; i < dims.Length; i++) { Volume *= dims[i]; } }
public static Tensor <T> Fill(Shape shape, T value) { T[] array = new T[shape.Volume]; SimdOps <T> .Fill(array, value); return(FromRef(shape, array)); }
public static bool operator <=(Tensor <T> left, Tensor <T> right) { if (left.Shape != right.Shape) { throw new ShapeMismatchException(nameof(right)); } return(SimdOps <T> .LessOrEqual(left.InternalArray, right.InternalArray)); }
public static Tensor <T> operator *(Tensor <T> left, Tensor <T> right) { if (left.Shape != right.Shape) { throw new ShapeMismatchException(nameof(right)); } T[] result = SimdOps <T> .Multiply(left.InternalArray, right.InternalArray); return(FromRef(left.Shape, result)); }
public bool Equals(Tensor <T>?tensor) { if (tensor is null) { return(false); } if (ReferenceEquals(this, tensor)) { return(true); } return(Shape == tensor.Shape && SimdOps <T> .Equals(InternalArray, tensor.InternalArray)); }
public bool Equals(Shape?shape) { if (shape is null) { return(false); } if (ReferenceEquals(this, shape)) { return(true); } if (Rank != shape.Rank) { return(false); } return(SimdOps <int> .Equal(Dims, shape.Dims)); }
public T Average() { return(SimdOps <T> .Average(InternalArray)); }
public static bool operator >=(T left, Tensor <T> right) { return(SimdOps <T> .LessOrEqual(right.InternalArray, left)); }
public bool Equals(T value) { return(SimdOps <T> .Equals(InternalArray, value)); }
public static Tensor <T> operator -(T left, Tensor <T> right) { T[] result = SimdOps <T> .Subtract(left, right.InternalArray); return(FromRef(right.Shape, result)); }
public T Dot(Tensor <T> other) { return(SimdOps <T> .Dot(InternalArray, other.InternalArray)); }
public bool Contains(T value) { return(SimdOps <T> .Contains(InternalArray, value)); }
public static Tensor <T> operator -(Tensor <T> tensor) { T[] result = SimdOps <T> .Negate(tensor.InternalArray); return(FromRef(tensor.Shape, result)); }
public T Sum(Func <Vector <T>, Vector <T> > vSelector, Func <T, T> selector) { return(SimdOps <T> .Sum(InternalArray, vSelector.ToStruct(), selector.ToStruct())); }
public T Aggregate(T seed, Func <Vector <T>, Vector <T>, Vector <T> > vAccumulator, Func <T, T, T> accumulator) { return(SimdOps <T> .Aggregate(InternalArray, seed, vAccumulator.ToStruct(), accumulator.ToStruct())); }
public T Sum() { return(SimdOps <T> .Sum(InternalArray)); }
public T Min() { return(SimdOps <T> .Min(InternalArray)); }
public T Max() { return(SimdOps <T> .Max(InternalArray)); }
public static Tensor <T> operator --(Tensor <T> tensor) { T[] result = SimdOps <T> .Subtract(tensor.InternalArray, One); return(FromRef(tensor.Shape, result)); }
public Tensor <T> Sqrt() { return(FromRef(Shape, SimdOps <T> .Sqrt(InternalArray))); }
public static Tensor <T> operator +(T left, Tensor <T> right) { T[] result = SimdOps <T> .Add(right.InternalArray, left); return(FromRef(right.Shape, result)); }
public Tensor <T> Abs() { return(FromRef(Shape, SimdOps <T> .Abs(InternalArray))); }
public void Foreach(Action <Vector <T> > vAction, Action <T> action) { SimdOps <T> .Foreach(InternalArray, vAction.ToStruct(), action.ToStruct()); }
public T Dot(T value) { return(SimdOps <T> .Dot(InternalArray, value)); }
public static Tensor <T> operator *(Tensor <T> left, T right) { T[] result = SimdOps <T> .Multiply(left.InternalArray, right); return(FromRef(left.Shape, result)); }
public int IndexOf(T value) { return(SimdOps <T> .IndexOf(InternalArray, value)); }
public Tensor <TRes> Concat <TRes>(Tensor <T> other, Func <Vector <T>, Vector <T>, Vector <TRes> > vSelector, Func <T, T, TRes> selector) where TRes : unmanaged { return(Tensor <TRes> .FromRef(Shape, SimdOps <T> .Concat <TRes, FWrapper <Vector <T>, Vector <T>, Vector <TRes> >, FWrapper <T, T, TRes> >(InternalArray, other.InternalArray, vSelector.ToStruct(), selector.ToStruct()))); }
public int IndexOf(Func <Vector <T>, bool> vPredicate, Func <T, bool> predicate) { return(SimdOps <T> .IndexOf(InternalArray, vPredicate.ToStruct(), predicate.ToStruct())); }
public bool All(Func <Vector <T>, bool> vPredicate, Func <T, bool> predicate) { return(SimdOps <T> .All(InternalArray, vPredicate.ToStruct(), predicate.ToStruct())); }
public static bool operator >=(Tensor <T> left, T right) { return(SimdOps <T> .GreaterOrEqual(left.InternalArray, right)); }