public static Matrix operator -(Matrix mat1, Matrix mat2) { MatrixException.ThrowIf(mat1.RowCount != mat2.RowCount || mat1.ColumnCount != mat2.ColumnCount, "Inconsistent matrix sizes"); var result = new Matrix(mat1.RowCount, mat1.ColumnCount); for (int i = 0; i < result.Values.Length; i++) { result.Values[i] = mat1.Values[i] - mat2.Values[i]; } return(result); }
public static Matrix operator -( Matrix mat1, Matrix mat2) { MatrixException.ThrowIf(mat1.RowCount != mat2.RowCount || mat1.ColumnCount != mat2.ColumnCount, "Inconsistent matrix sizes"); var buf = new Matrix(mat1.RowCount, mat1.ColumnCount); for (int i = 0; i < buf.CoreArray.Length; i++) { buf.CoreArray[i] = mat1.CoreArray[i] - mat2.CoreArray[i]; } return(buf); }
/// <summary> /// Computes the sum A = A + s * B. /// </summary> /// <param name="matrix"></param> /// <param name="other"></param> /// <param name="s"></param> public static void AddToThis(this DenseColumnMajorStorage <double> matrix, Matrix other, double s) { int rows = matrix.RowCount; int columns = matrix.ColumnCount; MatrixException.ThrowIf(rows != other.RowCount || columns != other.ColumnCount, "Inconsistent matrix sizes"); int n = rows * columns; var values = matrix.Values; for (int i = 0; i < n; i++) { values[i] = values[i] + other.Values[i] * s; } }
public double this[int row, int column] { get { MatrixException.ThrowIf(row >= this.RowCount || column >= this.ColumnCount, "Invalid column or row specified"); return(this.CoreArray[column * this.rowCount + row]); } set { MatrixException.ThrowIf(row >= this.RowCount || column >= this.ColumnCount, "Invalid column or row specified"); this.CoreArray[column * this.rowCount + row] = value; } }