コード例 #1
0
  public void add(double a, Matrix B) throws MatricksException {
    if (B.numRows() != this.numRows() && B.numCols() != this.numCols()) {
      throw new MatricksException("incompatible size for addition");
    }

    MatrixCursor cursor = B.cursor();
    while (cursor.next()) {
      final int row = cursor.row();
      final int col = cursor.col();
      double v = a * cursor.val() + this.get(row, col);
      this.set(row, col, v);
    }
  }
コード例 #2
0
  /*
   * simple generic implementation, can take advantage of sparsity structor
   * of this matrix, but not the given one.
   * @see org.genemania.engine.matricks.Matrix#elementMultiplySum(org.genemania.engine.matricks.Matrix)
   */
  public double elementMultiplySum(Matrix m) {
    double sum = 0d;

    MatrixCursor cursor = this.cursor();
    while (cursor.next()) {
      sum += cursor.val() * m.get(cursor.row(), cursor.col());
    }

    return sum;
  }