internal override Entity InnerEval()
        {
            var r = DeepCopy() as Tensor;

            TensorFunctional.Apply(r, e => e.InnerEval());
            return(r);
        }
Пример #2
0
        /// <summary>
        /// Collapses the entire expression into a tensor if possible
        /// ( x y ) + 1 => ( x+1 y+1 )
        ///
        /// ( 1 2 ) + ( 3 4 ) => ( 4 6 ) vectors pointwise
        ///
        ///              (( 3 )
        /// (( 1 2 3 )) x ( 4 ) => (( 26 )) Matrices dot product
        ///               ( 5 ))
        ///
        /// ( 1 2 ) x ( 1 3 ) => ( 1 6 ) Vectors pointwise
        /// </summary>
        /// <returns></returns>
        public Tensor EvalTensor()
        {
            if (!IsTensoric())
            {
                throw new MathSException(
                          "To eval an expression as a tensor, it should contain at least one tensor (matrix, vector)");
            }
            if (entType == EntType.TENSOR)
            {
                Tensor result = this as Tensor;
                TensorFunctional.Apply(result, p => MathS.CanBeEvaluated(p) ? p.Eval() : p);
                return(result);
            }
            var r = DeepCopy();

            TensorFunctional.__EvalTensor(ref r);
            if (r.entType == EntType.TENSOR)
            {
                Tensor result = r as Tensor;
                TensorFunctional.Apply(result, p => MathS.CanBeEvaluated(p) ? p.Eval() : p);
                return(result);
            }
            else
            {
                throw new SysException("Unexpected behaviour");
            }
        }
Пример #3
0
        /// <summary>
        /// Compares two Tensors
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected override bool EqualsTo(Entity obj)
        {
            var t = obj as Tensor;

            if (!TensorFunctional.SameShape(this, t))
            {
                return(false);
            }
            for (int i = 0; i < Data.Length; i++)
            {
                if (Data[i] != t.Data[i])
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #4
0
 /// <summary>
 /// Returns scalar product of two matrices
 /// </summary>
 /// <param name="A"></param>
 /// <param name="B"></param>
 /// <returns></returns>
 public static Entity ScalarProduct(Tensor A, Tensor B) =>
 TensorFunctional.ScalarProduct(A, B);
Пример #5
0
 /// <summary>
 /// Returns dot product of two matrices
 /// </summary>
 /// <param name="A"></param>
 /// <param name="B"></param>
 /// <returns></returns>
 public static Tensor DotProduct(Tensor A, Tensor B) =>
 TensorFunctional.DotProduct(A, B);
Пример #6
0
 /// <summary>
 /// Creates an instance of vector
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public static Tensor Vector(params Entity[] values)
 => TensorFunctional.Vector(values);
Пример #7
0
 /// <summary>
 /// Creates an instance of Tensor: Matrix
 /// Usage example:
 /// var t = MathS.Matrix(5, 3,
 ///        10, 11, 12,
 ///        20, 21, 22,
 ///        30, 31, 32,
 ///        40, 41, 42,
 ///        50, 51, 52
 ///        );
 /// creates matrix 5x3 with the appropriate elements
 /// </summary>
 /// <param name="x"></param>
 /// <param name="y"></param>
 /// <returns></returns>
 public static Tensor Matrix(int rows, int columns, params Entity[] values)
 => TensorFunctional.Matrix(rows, columns, values);