-
Notifications
You must be signed in to change notification settings - Fork 46
Specialised matrices
Mike Anderson edited this page Jul 22, 2013
·
4 revisions
Vectorz supports a wide range of specialised matrix classes.
The reason for this is simple: specialised matrix classes provide much more efficient operations in certain situations. For example, multiplying a large vector by a diagonal matrix can easily be 100x faster using the specialised DiagonalMatrix
implementation.
Specialised matrices have both advantages and disadvantages: whether you use them or not is a judgement call. If in doubt, you should benchmark for your specific use case.
Pros:
- Use much less storage space: e.g. a diagonal n*n matrix requires only n elements of storage
- Provide fast, optimised operations
Cons:
- Elements are constrained, so specialised matrices are usually not fully mutable. Use the
isFullyMutable
method to check this property for a given matrix instance. - Slower for arbitrary operations not suited to this matrix type
Here are some of the specialised matrix classes available in Vectorz:
-
AMatrix
: base class for all matrix types -
Matrix
: general purpose matrix, backed by a fully packeddouble[]
array -
DiagonalMatrix
: a square diagonal matrix. all values not on the main diagonal are constrained to 0.0 -
StridedMatrix
: a matrix backed by adouble[]
array but supporting strided indexing and offsets into the array. Very useful for lightweight views / submatrices of a regularMatrix
. -
ZeroMatrix
: an immutable matrix filled with zeros. Requires no storage for elements, and supports very fast operations. -
IdentityMatrix
: an immutable identity matrix. Requires no storage for elements. Requires no storage for elements, and supports very fast operations. -
ScalarMatrix
: an efficient matrix which represents scaling by a single scalar value. -
PermutationMatrix
: a square matrix that permutes another matrix. Has a single1.0
in each row and column. Can be used to efficiently permute vectors or other matrices. -
RowMatrix
: an efficient lightweight matrix with a single row. -
ColumnMatrix
: an efficient lightweight matrix with a single column.