示例#1
0
        /// <summary>
        /// Perform an operation
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        public static float[] ElementWiseOperation(float[] a, float[] b, ElementWiseOperation operation)
        {
            if (!VectorCompare.SameLength(a, b))
            {
                throw new ArgumentException("Vectors are not of same length.");
            }

            float[] y = new float[a.Length];

            for (int i = 0; i < y.Length; i++)
            {
                y[i] = operation.Invoke(a[i], b[i]);
            }

            return(y);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        public static float[][] ElementWiseOperation(float[][] a, float[][] b, ElementWiseOperation operation)
        {
            if (!MatrixCompare.SameSize(a, b))
            {
                throw new ArgumentException("Matrices are not of same size.");
            }

            float[][] y = CreateMatrix(Rows(a), Columns(b));

            for (int i = 0; i < Rows(y); i++)
            {
                y[i] = VectorMath.ElementWiseOperation(a[i], b[i], operation);
            }

            return(y);
        }
示例#3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <param name="operation"></param>
 /// <returns></returns>
 public static Matrix ElementWiseOperation(Matrix a, Matrix b, ElementWiseOperation operation)
 {
     return(new Matrix(MatrixMath.ElementWiseOperation(a.Values, b.Values, operation)));
 }
示例#4
0
        public static float[] Add(float[] a, float[] b)
        {
            ElementWiseOperation add = (_a, _b) => _a + _b;

            return(ElementWiseOperation(a, b, add));
        }
示例#5
0
        public static float[] Divide(float[] a, float[] b)
        {
            ElementWiseOperation div = (_a, _b) => _a / _b;

            return(ElementWiseOperation(a, b, div));
        }
示例#6
0
        public static float[] Multiply(float[] a, float[] b)
        {
            ElementWiseOperation mul = (_a, _b) => _a * _b;

            return(ElementWiseOperation(a, b, mul));
        }
示例#7
0
        public static float[] Subtract(float[] a, float[] b)
        {
            ElementWiseOperation sub = (_a, _b) => _a - _b;

            return(ElementWiseOperation(a, b, sub));
        }