Thea
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
VariantMatrix< T, DenseMatrixT, SparseMatrixT > Class Template Reference

A container holding either a dense or a sparse matrix (or null). More...

#include <VariantMatrix.hpp>

Inheritance diagram for VariantMatrix< T, DenseMatrixT, SparseMatrixT >:
IDenseMatrix< T > ICompressedSparseMatrix< T > Serializable IAddressableMatrix< T > IRowOrColumnMajorMatrix< T > ISparseMatrix< T > IRowOrColumnMajorMatrix< T > IMatrix< T > IMatrix< T > IMatrix< T > IMatrix< T >

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...
 
Valuedata ()
 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...
 
DensegetDense ()
 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...
 
SparsegetSparse ()
 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...
 
ValuegetValues ()
 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...
 
ValuemutableAt (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...
 

Detailed Description

template<typename T = Real, typename DenseMatrixT = MatrixX<T>, typename SparseMatrixT = SparseColumnMatrix<T>>
class Thea::VariantMatrix< T, DenseMatrixT, SparseMatrixT >

A container holding either a dense or a sparse matrix (or null).

Definition at line 37 of file VariantMatrix.hpp.

Member Typedef Documentation

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.

typedef T Value
inherited

Type of values stored in the matrix.

Definition at line 33 of file IMatrix.hpp.

typedef T value_type
inherited

Type of values stored in the matrix (STL convention).

Definition at line 34 of file IMatrix.hpp.

Constructor & Destructor Documentation

Default constructor.

Definition at line 81 of file VariantMatrix.hpp.

Member Function Documentation

IAddressableMatrix<Value> const* asAddressable ( ) const
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
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.

IAddressableMatrix<Value>* asAddressable ( )
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
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.

ICompressedSparseMatrix<Value> const* asCompressed ( ) const
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.

Note
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.

ICompressedSparseMatrix<Value>* asCompressed ( )
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.

Note
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.

IDenseMatrix<Value> const* asDense ( ) const
virtual

If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.

Else, return null.

Note
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.

IDenseMatrix<Value>* asDense ( )
virtual

If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.

Else, return null.

Note
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.

ISparseMatrix<Value> const* asSparse ( ) const
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
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.

ISparseMatrix<Value>* asSparse ( )
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.

Note
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.

Value const& at ( int64  row,
int64  col 
) const
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.

int64 cols ( ) const
virtual

Get the number of columns.

Implements IMatrix< T >.

Definition at line 120 of file VariantMatrix.hpp.

static TextInputStream::Settings const& configReadSettings ( )
staticinherited

Get the default settings for parsing configuration text files.

Definition at line 69 of file Serializable.hpp.

static TextOutputStream::Settings const& configWriteSettings ( )
staticinherited

Get the default settings for writing configuration text files.

Definition at line 76 of file Serializable.hpp.

Value const* data ( ) const
virtual

Get a pointer to the beginning of the matrix's data block.

Implements IDenseMatrix< T >.

Definition at line 151 of file VariantMatrix.hpp.

Value* data ( )
virtual

Get a pointer to the beginning of the matrix's data block.

Implements IDenseMatrix< T >.

Definition at line 152 of file VariantMatrix.hpp.

void fill ( Value  value)
virtual

Set all elements of the matrix to a given value.

Warning
This is safe to call across shared library boundaries only if T is a POD type.

Implements IDenseMatrix< T >.

Definition at line 153 of file VariantMatrix.hpp.

void getColumn ( int64  col,
Value values 
) const
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.

int32 getInnerIndexType ( ) const
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.

void const* getInnerIndices ( ) const
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.

void* getInnerIndices ( )
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.

void const* getNonZeroCounts ( ) const
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.

void* getNonZeroCounts ( )
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.

int32 getNonZeroCountType ( ) const
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.

int32 getOuterIndexType ( ) const
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.

void const* getOuterIndices ( ) const
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.

void* getOuterIndices ( )
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.

void getRow ( int64  row,
Value values 
) const
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.

Value const* getValues ( ) const
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.

Value* getValues ( )
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.

int64 innerSize ( ) const
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.

int8 isColumnMajor ( ) const
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.

int8 isFullyCompressed ( ) const
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.

int8 isResizable ( ) const
virtual

Check if the matrix can be freely resized.

Implements IMatrix< T >.

Definition at line 123 of file VariantMatrix.hpp.

int8 isRowMajor ( ) const
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.

Value& mutableAt ( int64  row,
int64  col 
)
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.

int64 numStoredElements ( ) const
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.

int64 outerSize ( ) const
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.

virtual void read ( TextInputStream input,
Codec const &  codec = CodecAuto() 
)
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.

void read ( BinaryInputStream input,
Codec const &  codec = CodecAuto(),
bool  read_block_header = false 
)
virtual

Read the object from a binary input stream.

Parameters
inputThe stream from which to read data.
codecThe codec to use. If set to CodecAuto(), the codec will be autodetected (if possible) from the input.
read_block_headerIf 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.

int8 resize ( int64  nrows,
int64  ncols 
)
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.

Returns
True if the final dimensions of the matrix are identical to the desired dimensions, else false.

Implements IMatrix< T >.

Definition at line 128 of file VariantMatrix.hpp.

int64 rows ( ) const
virtual

Get the number of rows.

Implements IMatrix< T >.

Definition at line 119 of file VariantMatrix.hpp.

void setColumn ( int64  col,
Value const *  values 
)
virtual

Set a column of the matrix.

values must contain rows() elements.

Implements IAddressableMatrix< T >.

Definition at line 160 of file VariantMatrix.hpp.

void setRow ( int64  row,
Value const *  values 
)
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.

void setZero ( )
virtual

Set all elements to zero.

Implements IMatrix< T >.

Definition at line 121 of file VariantMatrix.hpp.

virtual void write ( TextOutputStream output,
Codec const &  codec = CodecAuto() 
) const
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.

void write ( BinaryOutputStream output,
Codec const &  codec = CodecAuto(),
bool  write_block_header = false 
) const
virtual

Write the object to a binary output stream.

Parameters
outputThe stream to which data will be written.
codecThe codec to use. If set to CodecAuto(), an appropriate codec will be automatically selected.
write_block_headerIf 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.


The documentation for this class was generated from the following file: