Thea
|
A container holding either a dense or a sparse matrix (or null). More...
#include <VariantMatrix.hpp>
Classes | |
struct | Type |
Types of core matrices (enum class). More... | |
Public Types | |
typedef DenseMatrixT | Dense |
Dense matrix type. More... | |
typedef SparseMatrixT | Sparse |
Sparse matrix type. More... | |
typedef T | Value |
Type of values stored in the matrix. More... | |
typedef T | value_type |
Type of values stored in the matrix (STL convention). More... | |
Public Member Functions | |
IAddressableMatrix< Value > const * | asAddressable () const |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More... | |
IAddressableMatrix< Value > * | asAddressable () |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More... | |
ICompressedSparseMatrix< Value > const * | asCompressed () const |
If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access specific to that format. More... | |
ICompressedSparseMatrix< Value > * | asCompressed () |
If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access specific to that format. More... | |
IDenseMatrix< Value > const * | asDense () const |
If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access. More... | |
IDenseMatrix< Value > * | asDense () |
If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access. More... | |
ISparseMatrix< Value > const * | asSparse () const |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More... | |
ISparseMatrix< Value > * | asSparse () |
If the matrix is sparse, get a pointer to a derived interface giving sparse-specific access. More... | |
Value const & | at (int64 row, int64 col) const |
Get a read-only element. More... | |
void | clear () |
Clear all matrix data. More... | |
int64 | cols () const |
Get the number of columns. More... | |
Value const * | data () const |
Get a pointer to the beginning of the matrix's data block. More... | |
Value * | data () |
Get a pointer to the beginning of the matrix's data block. More... | |
void | fill (Value value) |
Set all elements of the matrix to a given value. More... | |
void | getColumn (int64 col, Value *values) const |
Get a column of the matrix. More... | |
Dense const & | getDense () const |
Get the underlying dense matrix. More... | |
Dense & | getDense () |
Get the underlying dense matrix. More... | |
int32 | getInnerIndexType () const |
The integer type used to store inner indices, as per the values in NumericType. More... | |
void const * | getInnerIndices () const |
Get the array of inner indices. More... | |
void * | getInnerIndices () |
Get the array of inner indices. More... | |
void const * | getNonZeroCounts () const |
Get the array of non-zero counts. More... | |
void * | getNonZeroCounts () |
Get the array of non-zero counts. More... | |
int32 | getNonZeroCountType () const |
The integer type used to store per-segment non-zero counts, as per the values in NumericType. More... | |
int32 | getOuterIndexType () const |
The integer type used to store outer indices, as per the values in NumericType. More... | |
void const * | getOuterIndices () const |
Get the array of outer indices. More... | |
void * | getOuterIndices () |
Get the array of outer indices. More... | |
void | getRow (int64 row, Value *values) const |
Get a row of the matrix. More... | |
Sparse const & | getSparse () const |
Get the underlying sparse matrix. More... | |
Sparse & | getSparse () |
Get the underlying sparse matrix. More... | |
Type | getType () const |
Get the type of the matrix (dense, sparse, or invalid). More... | |
Value const * | getValues () const |
Get the array storing the non-zero values. More... | |
Value * | getValues () |
Get the array storing the non-zero values. More... | |
int64 | innerSize () const |
Get the size of the matrix along the inner dimension (rows if column-major, or columns if row-major). More... | |
int8 | isColumnMajor () const |
Is the matrix stored in column-major format? More... | |
bool | isDense () const |
Check if the object stores a dense matrix (may be zero-sized) or not. More... | |
int8 | isFullyCompressed () const |
Make sure the matrix actually is fully compressed. More... | |
int8 | isResizable () const |
Check if the matrix can be freely resized. More... | |
int8 | isRowMajor () const |
Is the matrix stored in row-major format? More... | |
bool | isSparse () const |
Check if the object stores a sparse matrix (may be zero-sized) or not. More... | |
bool | isValid () const |
Check if the object stores a valid matrix (may be zero-sized) or not. More... | |
Value & | mutableAt (int64 row, int64 col) |
Get an element that can be directly modified. More... | |
int64 | numStoredElements () const |
Get the number of entries actually stored in the matrix. More... | |
int64 | outerSize () const |
Get the size of the matrix int64 the outer dimension (columns if column-major, or row if row-major). More... | |
virtual void | read (TextInputStream &input, Codec const &codec=CodecAuto()) |
Read the object from a text input stream. More... | |
void | read (BinaryInputStream &input, Codec const &codec=CodecAuto(), bool read_block_header=false) |
Read the object from a binary input stream. More... | |
int8 | resize (int64 nrows, int64 ncols) |
Resize the matrix to new dimensions, if isResizable() returns true. More... | |
int64 | rows () const |
Get the number of rows. More... | |
void | setColumn (int64 col, Value const *values) |
Set a column of the matrix. More... | |
void | setRow (int64 row, Value const *values) |
Set a row of the matrix. More... | |
void | setType (Type type_) |
Set the type of the matrix (dense, sparse, or invalid). More... | |
void | setZero () |
Set all elements to zero. More... | |
VariantMatrix () | |
Default constructor. More... | |
virtual void | write (TextOutputStream &output, Codec const &codec=CodecAuto()) const |
Write the object to a text output stream. More... | |
void | write (BinaryOutputStream &output, Codec const &codec=CodecAuto(), bool write_block_header=false) const |
Write the object to a binary output stream. More... | |
Static Public Member Functions | |
static TextInputStream::Settings const & | configReadSettings () |
Get the default settings for parsing configuration text files. More... | |
static TextOutputStream::Settings const & | configWriteSettings () |
Get the default settings for writing configuration text files. More... | |
A container holding either a dense or a sparse matrix (or null).
Definition at line 37 of file VariantMatrix.hpp.
typedef DenseMatrixT Dense |
Dense matrix type.
Definition at line 77 of file VariantMatrix.hpp.
typedef SparseMatrixT Sparse |
Sparse matrix type.
Definition at line 78 of file VariantMatrix.hpp.
|
inherited |
Type of values stored in the matrix.
Definition at line 33 of file IMatrix.hpp.
|
inherited |
Type of values stored in the matrix (STL convention).
Definition at line 34 of file IMatrix.hpp.
VariantMatrix | ( | ) |
Default constructor.
Definition at line 81 of file VariantMatrix.hpp.
|
virtual |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.
Else, return null.
dynamic_cast
does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast
is dangerous. Implements IMatrix< T >.
Definition at line 194 of file VariantMatrix.hpp.
|
virtual |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.
Else, return null.
dynamic_cast
does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast
is dangerous. Implements IMatrix< T >.
Definition at line 195 of file VariantMatrix.hpp.
|
virtual |
If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access specific to that format.
Else, return null.
dynamic_cast
does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast
is dangerous. Implements ISparseMatrix< T >.
Definition at line 200 of file VariantMatrix.hpp.
|
virtual |
If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access specific to that format.
Else, return null.
dynamic_cast
does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast
is dangerous. Implements ISparseMatrix< T >.
Definition at line 201 of file VariantMatrix.hpp.
|
virtual |
If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.
Else, return null.
dynamic_cast
does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast
is dangerous. Implements IAddressableMatrix< T >.
Definition at line 196 of file VariantMatrix.hpp.
|
virtual |
If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.
Else, return null.
dynamic_cast
does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast
is dangerous. Implements IAddressableMatrix< T >.
Definition at line 197 of file VariantMatrix.hpp.
|
virtual |
If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.
Else, return null.
dynamic_cast
does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast
is dangerous. Implements IMatrix< T >.
Definition at line 198 of file VariantMatrix.hpp.
|
virtual |
If the matrix is sparse, get a pointer to a derived interface giving sparse-specific access.
Else, return null. Note that a sparse matrix can still be addressable, e.g. if it is stored as a map of (row, col) –> value
pairs.
dynamic_cast
does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast
is dangerous. Implements IMatrix< T >.
Definition at line 199 of file VariantMatrix.hpp.
|
virtual |
Get a read-only element.
Most derived/underlying classes define operator() to access an element quicker, without the virtual function overhead. Use this function only in generic algorithms that need polymorphic access to matrices without using templates, or when accessing matrices across shared library boundaries.
Implements IAddressableMatrix< T >.
Definition at line 139 of file VariantMatrix.hpp.
void clear | ( | ) |
Clear all matrix data.
Definition at line 111 of file VariantMatrix.hpp.
|
virtual |
Get the number of columns.
Implements IMatrix< T >.
Definition at line 120 of file VariantMatrix.hpp.
|
staticinherited |
Get the default settings for parsing configuration text files.
Definition at line 69 of file Serializable.hpp.
|
staticinherited |
Get the default settings for writing configuration text files.
Definition at line 76 of file Serializable.hpp.
|
virtual |
Get a pointer to the beginning of the matrix's data block.
Implements IDenseMatrix< T >.
Definition at line 151 of file VariantMatrix.hpp.
|
virtual |
Get a pointer to the beginning of the matrix's data block.
Implements IDenseMatrix< T >.
Definition at line 152 of file VariantMatrix.hpp.
|
virtual |
Set all elements of the matrix to a given value.
Implements IDenseMatrix< T >.
Definition at line 153 of file VariantMatrix.hpp.
|
virtual |
Get a column of the matrix.
values must be preallocated with rows() elements.
Implements IAddressableMatrix< T >.
Definition at line 158 of file VariantMatrix.hpp.
Dense const& getDense | ( | ) | const |
Get the underlying dense matrix.
Definition at line 99 of file VariantMatrix.hpp.
Dense& getDense | ( | ) |
Get the underlying dense matrix.
Definition at line 102 of file VariantMatrix.hpp.
|
virtual |
The integer type used to store inner indices, as per the values in NumericType.
Implements ICompressedSparseMatrix< T >.
Definition at line 172 of file VariantMatrix.hpp.
|
virtual |
Get the array of inner indices.
The array has numStoredElements() meaningful entries, but these may not be contiguous if isFullyCompressed() is false. Convert to the correct integer type using getInnerIndexType().
Implements ICompressedSparseMatrix< T >.
Definition at line 178 of file VariantMatrix.hpp.
|
virtual |
Get the array of inner indices.
The array has numStoredElements() meaningful entries, but these may not be contiguous if isFullyCompressed() is false. Convert to the correct integer type using getInnerIndexType().
Implements ICompressedSparseMatrix< T >.
Definition at line 180 of file VariantMatrix.hpp.
|
virtual |
Get the array of non-zero counts.
Each entry is the number of actual non-zeros in the corresponding inner segment. The return value is undefined if isFullyCompressed() is true. Convert to the correct integer type using getNonZeroCountType().
Implements ICompressedSparseMatrix< T >.
Definition at line 186 of file VariantMatrix.hpp.
|
virtual |
Get the array of non-zero counts.
Each entry is the number of actual non-zeros in the corresponding inner segment. The return value is undefined if isFullyCompressed() is true. Convert to the correct integer type using getNonZeroCountType().
Implements ICompressedSparseMatrix< T >.
Definition at line 188 of file VariantMatrix.hpp.
|
virtual |
The integer type used to store per-segment non-zero counts, as per the values in NumericType.
Implements ICompressedSparseMatrix< T >.
Definition at line 176 of file VariantMatrix.hpp.
|
virtual |
The integer type used to store outer indices, as per the values in NumericType.
Implements ICompressedSparseMatrix< T >.
Definition at line 174 of file VariantMatrix.hpp.
|
virtual |
Get the array of outer indices.
The array has outerSize() + 1 entries. Convert to the correct integer type using getOuterIndexType().
Implements ICompressedSparseMatrix< T >.
Definition at line 182 of file VariantMatrix.hpp.
|
virtual |
Get the array of outer indices.
The array has outerSize() + 1 entries: if isFullyCompressed() is true, the last entry is the total number of non-zeros in the matrix. Convert to the correct integer type using getOuterIndexType().
Implements ICompressedSparseMatrix< T >.
Definition at line 184 of file VariantMatrix.hpp.
|
virtual |
Get a row of the matrix.
values must be preallocated with cols() elements.
Implements IAddressableMatrix< T >.
Definition at line 154 of file VariantMatrix.hpp.
Sparse const& getSparse | ( | ) | const |
Get the underlying sparse matrix.
Definition at line 105 of file VariantMatrix.hpp.
Sparse& getSparse | ( | ) |
Get the underlying sparse matrix.
Definition at line 108 of file VariantMatrix.hpp.
Type getType | ( | ) | const |
Get the type of the matrix (dense, sparse, or invalid).
Definition at line 84 of file VariantMatrix.hpp.
|
virtual |
Get the array storing the non-zero values.
The array has numStoredElements() meaningful entries, but these may not be contiguous if isFullyCompressed() is false.
Implements ICompressedSparseMatrix< T >.
Definition at line 190 of file VariantMatrix.hpp.
|
virtual |
Get the array storing the non-zero values.
The array has numStoredElements() meaningful entries, but these may not be contiguous if isFullyCompressed() is false.
Implements ICompressedSparseMatrix< T >.
Definition at line 191 of file VariantMatrix.hpp.
|
virtual |
Get the size of the matrix along the inner dimension (rows if column-major, or columns if row-major).
Implements ICompressedSparseMatrix< T >.
Definition at line 168 of file VariantMatrix.hpp.
|
virtual |
Is the matrix stored in column-major format?
Implements IRowOrColumnMajorMatrix< T >.
Definition at line 147 of file VariantMatrix.hpp.
bool isDense | ( | ) | const |
Check if the object stores a dense matrix (may be zero-sized) or not.
Definition at line 93 of file VariantMatrix.hpp.
|
virtual |
Make sure the matrix actually is fully compressed.
If not, it will be stored in Eigen's custom format which allows gaps between non-zeros. In the latter case, the array returned by getNonZeroCounts() contains the number of actual non-zeros in each inner segment.
Implements ICompressedSparseMatrix< T >.
Definition at line 170 of file VariantMatrix.hpp.
|
virtual |
Check if the matrix can be freely resized.
Implements IMatrix< T >.
Definition at line 123 of file VariantMatrix.hpp.
|
virtual |
Is the matrix stored in row-major format?
Implements IRowOrColumnMajorMatrix< T >.
Definition at line 145 of file VariantMatrix.hpp.
bool isSparse | ( | ) | const |
Check if the object stores a sparse matrix (may be zero-sized) or not.
Definition at line 96 of file VariantMatrix.hpp.
bool isValid | ( | ) | const |
Check if the object stores a valid matrix (may be zero-sized) or not.
Definition at line 90 of file VariantMatrix.hpp.
|
virtual |
Get an element that can be directly modified.
Most derived/underlying classes define operator() to access an element quicker, without the virtual function overhead. Use this function only in generic algorithms that need polymorphic access to matrices without using templates, or when accessing matrices across shared library boundaries.
Implements IAddressableMatrix< T >.
Definition at line 141 of file VariantMatrix.hpp.
|
virtual |
Get the number of entries actually stored in the matrix.
These are often called "non-zeros", though they may actually have the numeric value 0.
Implements ISparseMatrix< T >.
Definition at line 164 of file VariantMatrix.hpp.
|
virtual |
Get the size of the matrix int64 the outer dimension (columns if column-major, or row if row-major).
Implements ICompressedSparseMatrix< T >.
Definition at line 169 of file VariantMatrix.hpp.
|
virtualinherited |
Read the object from a text input stream.
Reimplemented in Pyramid3d, KMeans, Pyramid2d, HoughForest::Options, BagOfWords, KMeans::Options, and Pyramid1d.
Definition at line 61 of file Serializable.hpp.
|
virtual |
Read the object from a binary input stream.
input | The stream from which to read data. |
codec | The codec to use. If set to CodecAuto(), the codec will be autodetected (if possible) from the input. |
read_block_header | If true, a Codec::BlockHeader object containing information about the codec and size of the serialized block will be first read from the input, and used to aid codec detection etc. The implementation is free to ignore this directive, e.g. if the codec and input size can be detected through other means. This behavior must be synchronized with write(BinaryOutputStream &, Codec const &, bool): either both must omit block headers, or both must read/write them if directed to do so. |
Implements Serializable.
Definition at line 204 of file VariantMatrix.hpp.
|
virtual |
Resize the matrix to new dimensions, if isResizable() returns true.
Else, if the new dimensions are identical to the old dimensions, do nothing and return true, else return false. If the dimensions are changed, existing entries will in general not be preserved in the resized matrix.
Implements IMatrix< T >.
Definition at line 128 of file VariantMatrix.hpp.
|
virtual |
|
virtual |
Set a column of the matrix.
values must contain rows() elements.
Implements IAddressableMatrix< T >.
Definition at line 160 of file VariantMatrix.hpp.
|
virtual |
Set a row of the matrix.
values must contain cols() elements.
Implements IAddressableMatrix< T >.
Definition at line 156 of file VariantMatrix.hpp.
void setType | ( | Type | type_ | ) |
Set the type of the matrix (dense, sparse, or invalid).
Definition at line 87 of file VariantMatrix.hpp.
|
virtual |
Set all elements to zero.
Implements IMatrix< T >.
Definition at line 121 of file VariantMatrix.hpp.
|
virtualinherited |
Write the object to a text output stream.
Reimplemented in Pyramid3d, KMeans, Pyramid2d, HoughForest::Options, BagOfWords, KMeans::Options, and Pyramid1d.
Definition at line 65 of file Serializable.hpp.
|
virtual |
Write the object to a binary output stream.
output | The stream to which data will be written. |
codec | The codec to use. If set to CodecAuto(), an appropriate codec will be automatically selected. |
write_block_header | If true, a Codec::BlockHeader object containing information about the codec and size of the serialized block will be first written to the input. The implementation is free to ignore this directive, e.g. if the codec and input size are encoded through other means. This behavior must be synchronized with read(BinaryInputStream &, Codec const &, bool): either both must omit block headers, or both must read/write them if directed to do so. |
Implements Serializable.
Definition at line 229 of file VariantMatrix.hpp.