Basic matrix interface. It holds
double
s in a rectangular 2D array, and it is used alongside
Vector
in numerical computations. Implementing classes decides on the actual storage.
Basic operations
Use numRows
and numColumns
to get the basic size of a matrix. get(int,int)
gets an element, and there are corresponding set(int,int,double)
and add(int,int,double)
methods as well. Note that matrix indices are zero-based (typical for Java and C). This means that the row-indices range from 0 to numRows-1
, likewise for the columns. It is legal to have numRows
or numColumns
equal zero.
Other basic operations are zero
which zeros all the entries of the matrix, which can be cheaper than either zeroing the matrix manually, or creating a new matrix, and the operation copy
which creates a deep copy of the matrix. This copy has separate storage, but starts with the same contents as the current matrix.
Iterators
The matrix interface extends Iterable
, and the iterator returns a MatrixEntry
which contains current index and entry value. Note that the iterator may skip non-zero entries. Using an iterator, many simple and efficient algorithms can be created. The iterator also permits changing values in the matrix, however only non-zero entries can be changed.
Basic linear algebra
A large selection of basic linear algebra operations are available. To ensure high efficiency, little or no internal memory allocation is done, and the user is required to supply the output arguments.
The operations available include:
- Additions
- Matrices can be added to each other, even if their underlying matrix structures are different.
- Multiplications
- A matrix can be multiplied with vectors and other matrices. For increased efficiency, a multiplication can be combined with addition and scaling, and transpose matrix multiplications are also available.
- Rank-updates
- A matrix can be efficiently updated using low-rank updates. The updates can be contained in both matrices or vectors.
- Transpositions
- In-place transpositions of square matrices is supported, and the transpose of a matrix can be stored in another matrix of compatible size (possibly non-rectangular)
- Solvers
- Many dense and structured sparse matrices have fast, direct solvers, and can be used to solve linear systems without creating a factorization. These solvers are typically backed by subroutines in LAPACK