Beispiel #1
0
        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];
            }
        }
Beispiel #2
0
        public static Tensor <T> Fill(Shape shape, T value)
        {
            T[] array = new T[shape.Volume];

            SimdOps <T> .Fill(array, value);

            return(FromRef(shape, array));
        }
Beispiel #3
0
        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));
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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));
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
 public T Average()
 {
     return(SimdOps <T> .Average(InternalArray));
 }
Beispiel #8
0
 public static bool operator >=(T left, Tensor <T> right)
 {
     return(SimdOps <T> .LessOrEqual(right.InternalArray, left));
 }
Beispiel #9
0
 public bool Equals(T value)
 {
     return(SimdOps <T> .Equals(InternalArray, value));
 }
Beispiel #10
0
        public static Tensor <T> operator -(T left, Tensor <T> right)
        {
            T[] result = SimdOps <T> .Subtract(left, right.InternalArray);

            return(FromRef(right.Shape, result));
        }
Beispiel #11
0
 public T Dot(Tensor <T> other)
 {
     return(SimdOps <T> .Dot(InternalArray, other.InternalArray));
 }
Beispiel #12
0
 public bool Contains(T value)
 {
     return(SimdOps <T> .Contains(InternalArray, value));
 }
Beispiel #13
0
        public static Tensor <T> operator -(Tensor <T> tensor)
        {
            T[] result = SimdOps <T> .Negate(tensor.InternalArray);

            return(FromRef(tensor.Shape, result));
        }
Beispiel #14
0
 public T Sum(Func <Vector <T>, Vector <T> > vSelector, Func <T, T> selector)
 {
     return(SimdOps <T> .Sum(InternalArray, vSelector.ToStruct(), selector.ToStruct()));
 }
Beispiel #15
0
 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()));
 }
Beispiel #16
0
 public T Sum()
 {
     return(SimdOps <T> .Sum(InternalArray));
 }
Beispiel #17
0
 public T Min()
 {
     return(SimdOps <T> .Min(InternalArray));
 }
Beispiel #18
0
 public T Max()
 {
     return(SimdOps <T> .Max(InternalArray));
 }
Beispiel #19
0
        public static Tensor <T> operator --(Tensor <T> tensor)
        {
            T[] result = SimdOps <T> .Subtract(tensor.InternalArray, One);

            return(FromRef(tensor.Shape, result));
        }
Beispiel #20
0
 public Tensor <T> Sqrt()
 {
     return(FromRef(Shape, SimdOps <T> .Sqrt(InternalArray)));
 }
Beispiel #21
0
        public static Tensor <T> operator +(T left, Tensor <T> right)
        {
            T[] result = SimdOps <T> .Add(right.InternalArray, left);

            return(FromRef(right.Shape, result));
        }
Beispiel #22
0
 public Tensor <T> Abs()
 {
     return(FromRef(Shape, SimdOps <T> .Abs(InternalArray)));
 }
Beispiel #23
0
 public void Foreach(Action <Vector <T> > vAction, Action <T> action)
 {
     SimdOps <T> .Foreach(InternalArray, vAction.ToStruct(), action.ToStruct());
 }
Beispiel #24
0
 public T Dot(T value)
 {
     return(SimdOps <T> .Dot(InternalArray, value));
 }
Beispiel #25
0
        public static Tensor <T> operator *(Tensor <T> left, T right)
        {
            T[] result = SimdOps <T> .Multiply(left.InternalArray, right);

            return(FromRef(left.Shape, result));
        }
Beispiel #26
0
 public int IndexOf(T value)
 {
     return(SimdOps <T> .IndexOf(InternalArray, value));
 }
Beispiel #27
0
 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())));
 }
Beispiel #28
0
 public int IndexOf(Func <Vector <T>, bool> vPredicate, Func <T, bool> predicate)
 {
     return(SimdOps <T> .IndexOf(InternalArray, vPredicate.ToStruct(), predicate.ToStruct()));
 }
Beispiel #29
0
 public bool All(Func <Vector <T>, bool> vPredicate, Func <T, bool> predicate)
 {
     return(SimdOps <T> .All(InternalArray, vPredicate.ToStruct(), predicate.ToStruct()));
 }
Beispiel #30
0
 public static bool operator >=(Tensor <T> left, T right)
 {
     return(SimdOps <T> .GreaterOrEqual(left.InternalArray, right));
 }