/// <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); }
/// <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))); }
public static float[] Add(float[] a, float[] b) { ElementWiseOperation add = (_a, _b) => _a + _b; return(ElementWiseOperation(a, b, add)); }
public static float[] Divide(float[] a, float[] b) { ElementWiseOperation div = (_a, _b) => _a / _b; return(ElementWiseOperation(a, b, div)); }
public static float[] Multiply(float[] a, float[] b) { ElementWiseOperation mul = (_a, _b) => _a * _b; return(ElementWiseOperation(a, b, mul)); }
public static float[] Subtract(float[] a, float[] b) { ElementWiseOperation sub = (_a, _b) => _a - _b; return(ElementWiseOperation(a, b, sub)); }