Ejemplo n.º 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];
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 7
0
 public T Average()
 {
     return(SimdOps <T> .Average(InternalArray));
 }
Ejemplo n.º 8
0
 public static bool operator >=(T left, Tensor <T> right)
 {
     return(SimdOps <T> .LessOrEqual(right.InternalArray, left));
 }
Ejemplo n.º 9
0
 public bool Equals(T value)
 {
     return(SimdOps <T> .Equals(InternalArray, value));
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 11
0
 public T Dot(Tensor <T> other)
 {
     return(SimdOps <T> .Dot(InternalArray, other.InternalArray));
 }
Ejemplo n.º 12
0
 public bool Contains(T value)
 {
     return(SimdOps <T> .Contains(InternalArray, value));
 }
Ejemplo n.º 13
0
        public static Tensor <T> operator -(Tensor <T> tensor)
        {
            T[] result = SimdOps <T> .Negate(tensor.InternalArray);

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

            return(FromRef(tensor.Shape, result));
        }
Ejemplo n.º 20
0
 public Tensor <T> Sqrt()
 {
     return(FromRef(Shape, SimdOps <T> .Sqrt(InternalArray)));
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 22
0
 public Tensor <T> Abs()
 {
     return(FromRef(Shape, SimdOps <T> .Abs(InternalArray)));
 }
Ejemplo n.º 23
0
 public void Foreach(Action <Vector <T> > vAction, Action <T> action)
 {
     SimdOps <T> .Foreach(InternalArray, vAction.ToStruct(), action.ToStruct());
 }
Ejemplo n.º 24
0
 public T Dot(T value)
 {
     return(SimdOps <T> .Dot(InternalArray, value));
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 26
0
 public int IndexOf(T value)
 {
     return(SimdOps <T> .IndexOf(InternalArray, value));
 }
Ejemplo n.º 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())));
 }
Ejemplo n.º 28
0
 public int IndexOf(Func <Vector <T>, bool> vPredicate, Func <T, bool> predicate)
 {
     return(SimdOps <T> .IndexOf(InternalArray, vPredicate.ToStruct(), predicate.ToStruct()));
 }
Ejemplo n.º 29
0
 public bool All(Func <Vector <T>, bool> vPredicate, Func <T, bool> predicate)
 {
     return(SimdOps <T> .All(InternalArray, vPredicate.ToStruct(), predicate.ToStruct()));
 }
Ejemplo n.º 30
0
 public static bool operator >=(Tensor <T> left, T right)
 {
     return(SimdOps <T> .GreaterOrEqual(left.InternalArray, right));
 }