operator + method

Matrix operator +(
  1. Matrix other
)

Add two matrices of same dimensions.

Throws MatrixInvalidDimensions if dimensions do not match.

Implementation

Matrix operator +(Matrix other) {
  if (this.m != other.m || this.n != other.n) throw new MatrixInvalidDimensions();
  Matrix toReturn = new Matrix.fill(m, n);
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      toReturn[i][j] = this[i][j] + other[i][j];
    }
  }
  return toReturn;
}