private static bool BooleanOperator(MatrixOperations <T> matrix, bool op) { foreach (T element in matrix.matrix) { if (!element.Equals(default(T))) { return(op); } } return(!op); }
// (m1 * m2) public static MatrixOperations <T> operator *(MatrixOperations <T> matrix1, MatrixOperations <T> matrix2) { MatrixOperations <T> result = new MatrixOperations <T>(matrix1.Rows, matrix2.Columns); for (uint row = 0; row < result.Rows; row++) { for (uint col = 0; col < result.Columns; col++) { for (uint k = 0; k < matrix1.Columns; k++) { result[row, col] += (dynamic)matrix1[row, k] * matrix2[k, col]; } } } return(result); }
private static MatrixOperations <T> AdditionSubtraction(MatrixOperations <T> matrix1, MatrixOperations <T> matrix2, bool op) // true - addition { if (matrix1.Rows != matrix2.Rows || matrix1.Columns != matrix2.Columns) { throw new InvalidOperationException("Invalid operation! Matrices must be of one and same size..."); } MatrixOperations <T> result = new MatrixOperations <T>(matrix1.Rows, matrix1.Columns); for (uint row = 0; row < result.Rows; row++) { for (uint col = 0; col < result.Columns; col++) { result[row, col] = matrix1[row, col] + (op ? matrix2[row, col] : -(dynamic)matrix2[row, col]); } } return(result); }