![]() |
AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
|
Simple sparse matrix data structure. More...
Public Member Functions | |
SparseMatrixCS () | |
create empty matrix with "arbitrarily growing" dimensions More... | |
SparseMatrixCS (SparseMatrixCS< T > other) | |
copy constructor More... | |
int | nnz () |
get number of nonzero entries More... | |
int | getNumRows () |
computes from maximium row index [O(nnz )] More... | |
int | getMinRowIndex () |
get minimum row index [O(nnz )] More... | |
int | getNumColumns () |
computed from maximum column index [O(1)] More... | |
int | getMinColumnIndex () |
get minimum row index [O(1)] More... | |
T | get (int i, int j) |
get entry (i,j) [O(log(nnz ))] More... | |
T | set (int i, int j, T data) |
Set entry (i,j) to data [O(log(nnz ))]. More... | |
Vector< T > | getColumnEntries (int j) |
get entries in column j as array More... | |
int[] | getColumnRowIndices (int j) |
get row indices in column j as array More... | |
int | columnDegree (int j) |
get number of nonzero entries in column j More... | |
SparseMatrixCS< T > | getTransposed () |
get transposed matrix More... | |
SparseMatrixCS< Integer > | spones () |
Get nonzero pattern. More... | |
int[] | getRowIndices () |
Get array of row indices. More... | |
int[] | getColumnIndices () |
Get array of column indices in same order as for getRowIndices . More... | |
T[] | getValues () |
Get array of values in same order as for getRowIndices . More... | |
String | toString () |
String | toLaTeX (String name) |
get LaTeX code for displaying (TikZ) matrix More... | |
File | renderSpySVG (File svgfile, Colormap< T > colormap) |
String | spyTikZ (boolean rulers, Colormap< T > colormap) |
SVGViewer | spy (String caption, Colormap< T > colormap) |
render spy plot in new window More... | |
Protected Attributes | |
TreeMap< Coordinate, T > | mat_ |
Simple sparse matrix data structure.
This data structure is intended for sparse storage: it stores only non-null entries, i.e., the required amount of storage is O(nnz
) (not O(m*n))).
SparseMatrixCS stores and retrieves columns efficiently. The retrieval of rows is not supported.
The matrix has potentially infinite dimensions. (Dimension is determined by the maximium row and column indices for all entries. We don't require this property for adjacency matrices.
The implementation is based on a simplified compressed column storage (CCS) scheme based on sorted tuples in a
.
TreeMap
Definition at line 36 of file SparseMatrixCS.java.
create empty matrix with "arbitrarily growing" dimensions
Definition at line 42 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
aud.graph.matrix.SparseMatrixCS< T >.SparseMatrixCS | ( | SparseMatrixCS< T > | other | ) |
copy constructor
Definition at line 46 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
int aud.graph.matrix.SparseMatrixCS< T >.columnDegree | ( | int | j | ) |
get number of nonzero entries in column j
IndexOutOfBoundsException | on error (non-positive index) |
getColumnEntries
Definition at line 155 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.getColumnEntries().
Referenced by aud.test.SparseMatrixCSTest.testMatrix(), aud.test.SparseMatrixTest.testMatrix(), and aud.test.SparseMatrixTest.testSymmatrixMatrix().
T aud.graph.matrix.SparseMatrixCS< T >.get | ( | int | i, |
int | j | ||
) |
get entry (i,j) [O(log(nnz
))]
IndexOutOfBoundsException | (non-positive indices) |
null
Definition at line 90 of file SparseMatrixCS.java.
Referenced by aud.test.AdjacencyMatrixTest.testMatrix(), aud.test.SparseMatrixCSTest.testMatrix(), aud.test.SparseMatrixTest.testMatrix(), aud.test.AdjacencyMatrixTest.testSymmatrixMatrix(), and aud.test.SparseMatrixTest.testSymmatrixMatrix().
Vector< T > aud.graph.matrix.SparseMatrixCS< T >.getColumnEntries | ( | int | j | ) |
get entries in column j as array
IndexOutOfBoundsException | on error (non-positive index) |
Definition at line 123 of file SparseMatrixCS.java.
Referenced by aud.graph.matrix.SparseMatrixCS< T >.columnDegree(), aud.test.SparseMatrixCSTest.testMatrix(), aud.test.SparseMatrixTest.testMatrix(), and aud.test.SparseMatrixTest.testSymmatrixMatrix().
int[] aud.graph.matrix.SparseMatrixCS< T >.getColumnIndices | ( | ) |
Get array of column indices in same order as for getRowIndices
.
Definition at line 198 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_, and aud.graph.matrix.SparseMatrixCS< T >.nnz().
int[] aud.graph.matrix.SparseMatrixCS< T >.getColumnRowIndices | ( | int | j | ) |
get row indices in column j as array
IndexOutOfBoundsException | on error (non-positive index) |
Definition at line 138 of file SparseMatrixCS.java.
Referenced by aud.graph.AdjacencyMatrix< Edge >.clearColumnAndRow(), aud.test.SparseMatrixCSTest.testMatrix(), aud.test.SparseMatrixTest.testMatrix(), and aud.test.SparseMatrixTest.testSymmatrixMatrix().
int aud.graph.matrix.SparseMatrixCS< T >.getMinColumnIndex | ( | ) |
get minimum row index [O(1)]
Definition at line 74 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
Referenced by aud.test.SparseMatrixCSTest.testMatrix(), aud.test.SparseMatrixTest.testMatrix(), aud.test.SparseMatrixTest.testSymmatrixMatrix(), and aud.graph.matrix.SparseMatrixCS< T >.toLaTeX().
int aud.graph.matrix.SparseMatrixCS< T >.getMinRowIndex | ( | ) |
get minimum row index [O(nnz
)]
Reimplemented in aud.graph.matrix.SparseMatrix< T >.
Definition at line 63 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
Referenced by aud.test.SparseMatrixCSTest.testMatrix(), and aud.graph.matrix.SparseMatrixCS< T >.toLaTeX().
int aud.graph.matrix.SparseMatrixCS< T >.getNumColumns | ( | ) |
computed from maximum column index [O(1)]
Definition at line 72 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
Referenced by aud.graph.matrix.SparseMatrixCS< T >.renderSpySVG(), aud.graph.matrix.SparseMatrixCS< T >.spyTikZ(), aud.test.SparseMatrixCSTest.testMatrix(), aud.test.SparseMatrixTest.testMatrix(), aud.test.SparseMatrixTest.testSymmatrixMatrix(), and aud.graph.matrix.SparseMatrixCS< T >.toLaTeX().
int aud.graph.matrix.SparseMatrixCS< T >.getNumRows | ( | ) |
computes from maximium row index [O(nnz
)]
Reimplemented in aud.graph.matrix.SparseMatrix< T >.
Definition at line 54 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
Referenced by aud.graph.matrix.SparseMatrixCS< T >.renderSpySVG(), aud.graph.matrix.SparseMatrixCS< T >.spyTikZ(), aud.test.SparseMatrixCSTest.testMatrix(), and aud.graph.matrix.SparseMatrixCS< T >.toLaTeX().
int[] aud.graph.matrix.SparseMatrixCS< T >.getRowIndices | ( | ) |
Get array of row indices.
Definition at line 188 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_, and aud.graph.matrix.SparseMatrixCS< T >.nnz().
SparseMatrixCS< T > aud.graph.matrix.SparseMatrixCS< T >.getTransposed | ( | ) |
get transposed matrix
Reimplemented in aud.graph.matrix.SparseMatrix< T >.
Definition at line 159 of file SparseMatrixCS.java.
References aud.graph.matrix.Coordinate.i, aud.graph.matrix.Coordinate.j, and aud.graph.matrix.SparseMatrixCS< T >.mat_.
T[] aud.graph.matrix.SparseMatrixCS< T >.getValues | ( | ) |
Get array of values in same order as for getRowIndices
.
Definition at line 208 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_, and aud.graph.matrix.SparseMatrixCS< T >.nnz().
int aud.graph.matrix.SparseMatrixCS< T >.nnz | ( | ) |
get number of nonzero entries
Definition at line 51 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
Referenced by aud.graph.matrix.SparseMatrixCS< T >.getColumnIndices(), aud.graph.matrix.SparseMatrixCS< T >.getRowIndices(), aud.graph.matrix.SparseMatrixCS< T >.getValues(), aud.test.AdjacencyMatrixTest.testMatrix(), aud.test.SparseMatrixCSTest.testMatrix(), aud.test.SparseMatrixTest.testMatrix(), aud.test.AdjacencyMatrixTest.testSymmatrixMatrix(), and aud.test.SparseMatrixTest.testSymmatrixMatrix().
File aud.graph.matrix.SparseMatrixCS< T >.renderSpySVG | ( | File | svgfile, |
Colormap< T > | colormap | ||
) |
Definition at line 249 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.getNumColumns(), aud.graph.matrix.SparseMatrixCS< T >.getNumRows(), aud.util.Colormap< T >.getRGB(), and aud.graph.matrix.SparseMatrixCS< T >.mat_.
Referenced by aud.graph.matrix.SparseMatrixCS< T >.spy().
T aud.graph.matrix.SparseMatrixCS< T >.set | ( | int | i, |
int | j, | ||
T | data | ||
) |
Set entry (i,j) to data [O(log(nnz
))].
i | row index (>=0) |
j | column index (>=0) |
data | new value; if data==null , then the entry will be erased from the matrix. |
IndexOutOfBoundsException | on error (non-positive indices)a |
null
Reimplemented in aud.graph.matrix.SparseMatrix< T >.
Definition at line 102 of file SparseMatrixCS.java.
Referenced by aud.test.SparseMatrixCSTest.testMatrix().
SparseMatrixCS< Integer > aud.graph.matrix.SparseMatrixCS< T >.spones | ( | ) |
Get nonzero pattern.
Returns a matrix with integer entries that equal 1 for every nonzero entry. (Same as Matlab's spones).
Definition at line 173 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
Referenced by aud.test.SparseMatrixCSTest.testMatrix().
SVGViewer aud.graph.matrix.SparseMatrixCS< T >.spy | ( | String | caption, |
Colormap< T > | colormap | ||
) |
render spy plot in new window
Definition at line 348 of file SparseMatrixCS.java.
References aud.util.SVGViewer.displayWindow(), and aud.graph.matrix.SparseMatrixCS< T >.renderSpySVG().
Referenced by aud.graph.matrix.SparseMatrix< T >.main().
String aud.graph.matrix.SparseMatrixCS< T >.spyTikZ | ( | boolean | rulers, |
Colormap< T > | colormap | ||
) |
Definition at line 309 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.getNumColumns(), aud.graph.matrix.SparseMatrixCS< T >.getNumRows(), aud.util.Colormap< T >.getRGB(), and aud.graph.matrix.SparseMatrixCS< T >.mat_.
Referenced by aud.graph.matrix.SparseMatrix< T >.main().
String aud.graph.matrix.SparseMatrixCS< T >.toLaTeX | ( | String | name | ) |
get LaTeX code for displaying (TikZ) matrix
Definition at line 229 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.getMinColumnIndex(), aud.graph.matrix.SparseMatrixCS< T >.getMinRowIndex(), aud.graph.matrix.SparseMatrixCS< T >.getNumColumns(), and aud.graph.matrix.SparseMatrixCS< T >.getNumRows().
String aud.graph.matrix.SparseMatrixCS< T >.toString | ( | ) |
Definition at line 216 of file SparseMatrixCS.java.
References aud.graph.matrix.SparseMatrixCS< T >.mat_.
|
protected |
Definition at line 38 of file SparseMatrixCS.java.
Referenced by aud.graph.matrix.SparseMatrixCS< T >.getColumnIndices(), aud.graph.matrix.SparseMatrixCS< T >.getMinColumnIndex(), aud.graph.matrix.SparseMatrixCS< T >.getMinRowIndex(), aud.graph.matrix.SparseMatrixCS< T >.getNumColumns(), aud.graph.matrix.SparseMatrixCS< T >.getNumRows(), aud.graph.matrix.SparseMatrixCS< T >.getRowIndices(), aud.graph.matrix.SparseMatrixCS< T >.getTransposed(), aud.graph.matrix.SparseMatrixCS< T >.getValues(), aud.graph.AdjacencyMatrix< Edge >.iterator(), aud.graph.matrix.SparseMatrixCS< T >.nnz(), aud.graph.matrix.SparseMatrixCS< T >.renderSpySVG(), aud.graph.matrix.SparseMatrixCS< T >.SparseMatrixCS(), aud.graph.matrix.SparseMatrixCS< T >.spones(), aud.graph.matrix.SparseMatrixCS< T >.spyTikZ(), and aud.graph.matrix.SparseMatrixCS< T >.toString().