Пример #1
0
  public Vector columnSums() throws MatricksException {
    Vector sums = new DenseDoubleVector(numCols());

    MatrixCursor cursor = cursor();
    while (cursor.next()) {
      sums.set(cursor.col(), cursor.val() + sums.get(cursor.col()));
    }

    return sums;
  }
Пример #2
0
  public Vector rowSums() throws MatricksException {
    // TODO: can change this to a lower level interface,
    // taking in an array of doubles and not allocating ... ?
    Vector sums = new DenseDoubleVector(numRows());

    // TODO: optimize out row() with local var? microopt, measure speed
    MatrixCursor cursor = cursor();
    while (cursor.next()) {
      sums.set(cursor.row(), cursor.val() + sums.get(cursor.row()));
    }

    return sums;
  }