Esempio n. 1
0
  public Matrix<T, A> multiply(Matrix<T, A> right) throws MatrixException {
    Matrix<T, A> temp = new Matrix<T, A>(arithmetics, rowSize, right.columnSize);

    if (columnSize != right.rowSize)
      throw new MatrixException("Cannot multiply matrices of incompatible sizes");

    setup(temp, rowSize, right.columnSize);

    for (int i = 0; i < rowSize; ++i) {
      for (int j = 0; j < right.columnSize; ++j) {
        T sum = arithmetics.zero();
        for (int k = 0; k < columnSize; ++k) {
          sum = arithmetics.add(sum, arithmetics.multiply(matrix[i][k], right.matrix[k][j]));
        }
        temp.matrix[i][j] = sum;
      }
    }

    return temp;
  }