Beispiel #1
0
  /**
   * Construct a sparse matrix from another sparse matrix
   *
   * @param mat the original sparse matrix
   * @param deap whether to copy the CCS structures
   */
  public SparseMatrix(SparseMatrix mat, boolean deap) {
    numRows = mat.numRows;
    numColumns = mat.numColumns;

    copyCRS(mat.rowData, mat.rowPtr, mat.colInd);

    if (deap && mat.isCCSUsed) copyCCS(mat.colData, mat.colPtr, mat.rowInd);
  }
Beispiel #2
0
  /** @return the transpose of current matrix */
  public SparseMatrix transpose() {
    if (isCCSUsed) {
      SparseMatrix tr = new SparseMatrix(numColumns, numRows);

      tr.copyCRS(this.rowData, this.rowPtr, this.colInd);
      tr.copyCCS(this.colData, this.colPtr, this.rowInd);

      return tr;
    } else {
      Table<Integer, Integer, Double> dataTable = HashBasedTable.create();
      for (MatrixEntry me : this) dataTable.put(me.column(), me.row(), me.get());
      return new SparseMatrix(numColumns, numRows, dataTable);
    }
  }