Sleipnir
Public Member Functions
Sleipnir::CCompactMatrix Class Reference

Store a discrete symmetric matrix using the fewest possible bytes. More...

#include <compactmatrix.h>

Inheritance diagram for Sleipnir::CCompactMatrix:
Sleipnir::CCompactMatrixImpl

Public Member Functions

bool Open (std::istream &istm)
 Load a compact half matrix from the given binary stream.
const unsigned char * Open (const unsigned char *pbData)
 Initialize a new compact half matrix backed by the given bytes.
void Save (std::ostream &ostm) const
 Save a compact half matrix to the given binary stream.
void Randomize ()
 Pseudorandomize the compact half matrix.
void Set (size_t iY, size_t iX, unsigned char cValue)
 Set the value at the requested matrix position.
void Initialize (size_t iSize, unsigned char cValues, bool fClear)
 Initialize a new compact half matrix with the requested numbers of elements and discrete values.
size_t GetSize () const
 Returns the number of elements in the matrix.
unsigned char Get (size_t iY, size_t iX) const
 Returns the value at the requested matrix position.

Detailed Description

Store a discrete symmetric matrix using the fewest possible bytes.

Store a discrete symmetric matrix (also referred to as a half or triangular matrix) using the fewest possible bytes. This is done using sub-byte alignment, with each value occupying the smallest number of bits possible to store the total number of possible different values.

See also:
CCompactFullMatrix | CHalfMatrix

Definition at line 40 of file compactmatrix.h.


Member Function Documentation

unsigned char Sleipnir::CCompactMatrix::Get ( size_t  iY,
size_t  iX 
) const [inline]

Returns the value at the requested matrix position.

Parameters:
iYMatrix row.
iXMatrix column.
Returns:
Value at the requested matrix position.
Remarks:
For efficiency, no bounds checking is performed. The given row and column must be smaller than the size. As a symmetric matrix, the value at position XY will always equal the value at position YX.
See also:
Set

Reimplemented from Sleipnir::CCompactMatrixBase.

Definition at line 151 of file compactmatrix.h.

size_t Sleipnir::CCompactMatrix::GetSize ( ) const [inline]

Returns the number of elements in the matrix.

Returns:
Number of elements in the matrix.
Remarks:
Since a symmetric matrix must be square, the number of rows equals the number of columns and is thus referred to as the number of elements.

Definition at line 127 of file compactmatrix.h.

void Sleipnir::CCompactMatrix::Initialize ( size_t  iSize,
unsigned char  cValues,
bool  fClear 
) [inline]

Initialize a new compact half matrix with the requested numbers of elements and discrete values.

Parameters:
iSizeNumber of elements (rows/columns) in the matrix. As a symmetric matrix, the number of rows and columns is equal, so a single size is provided.
cValuesNumber of different values that each entry in the matrix can take.
fClearIf true, set each matrix entry to zero after allocation.

Allocates and, optionally, clears enough memory to store a symmetric matrix with the requested number of elements taking the requested number of different values. A symmetric matrix with iSize elements will have iSize * (iSize - 1) / 2 entries, each of which takes ceil(log2(cValues)) bits. This means that roughly ceil(4 * log2(cValues) * iSize * (iSize - 1)) bytes will be allocated for the entire half matrix.

Remarks:
cValues should be greater than one.

Definition at line 111 of file compactmatrix.h.

bool Sleipnir::CCompactMatrix::Open ( std::istream &  istm)

Load a compact half matrix from the given binary stream.

Parameters:
istmStream from which matrix is loaded.
Returns:
True if matrix was loaded successfully.
Remarks:
istm must be binary and contain a compact half matrix stored by CCompactMatrix::Save.

Definition at line 60 of file compactmatrix.cpp.

const unsigned char * Sleipnir::CCompactMatrix::Open ( const unsigned char *  pbData)

Initialize a new compact half matrix backed by the given bytes.

Parameters:
pbDataBytes corresponding to a saved compact half matrix.
Returns:
Pointer to the first byte of pbData not used by the compact half matrix. This can be used to store several compact matrices adjacently in memory and open them in serial.
Remarks:
pbData must correspond to a compact half matrix stored by CCompactMatrix::Save. This is useful for memory mapping a stored file, since the opened matrix will store a pointer to the given data rather than copying it.
See also:
CCompactMatrix::Open

Definition at line 95 of file compactmatrix.cpp.

Pseudorandomize the compact half matrix.

Remarks:
This doesn't really do a great job randomizing the data, since it ignores sub-byte alignment and just shuffles bytes, but it's good enough in a pinch.

Definition at line 54 of file compactmatrix.h.

void Sleipnir::CCompactMatrix::Save ( std::ostream &  ostm) const

Save a compact half matrix to the given binary stream.

Parameters:
ostmStream to which matrix is saved.
See also:
CCompactMatrix::Open

Definition at line 122 of file compactmatrix.cpp.

void Sleipnir::CCompactMatrix::Set ( size_t  iY,
size_t  iX,
unsigned char  cValue 
) [inline]

Set the value at the requested matrix position.

Parameters:
iYMatrix row.
iXMatrix column.
cValueValue to store.
Remarks:
For efficiency, no bounds checking is performed. The given value must be smaller than the maximum value with which the matrix was initialized, and the row and column must be smaller than the size. As a symmetric matrix, the value at position XY will always equal the value at position YX.
See also:
Get

Reimplemented from Sleipnir::CCompactMatrixBase.

Definition at line 80 of file compactmatrix.h.

Referenced by Sleipnir::CDatasetCompact::Open().


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