Sleipnir
|
Store a discrete symmetric matrix using the fewest possible bytes. More...
#include <compactmatrix.h>
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. |
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.
Definition at line 40 of file compactmatrix.h.
unsigned char Sleipnir::CCompactMatrix::Get | ( | size_t | iY, |
size_t | iX | ||
) | const [inline] |
Returns the value at the requested matrix position.
iY | Matrix row. |
iX | Matrix column. |
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.
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.
iSize | Number 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. |
cValues | Number of different values that each entry in the matrix can take. |
fClear | If 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.
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.
istm | Stream from which matrix is loaded. |
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.
pbData | Bytes corresponding to a saved compact half matrix. |
Definition at line 95 of file compactmatrix.cpp.
void Sleipnir::CCompactMatrix::Randomize | ( | ) | [inline] |
Pseudorandomize the compact half matrix.
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.
ostm | Stream to which matrix is saved. |
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.
iY | Matrix row. |
iX | Matrix column. |
cValue | Value to store. |
Reimplemented from Sleipnir::CCompactMatrixBase.
Definition at line 80 of file compactmatrix.h.
Referenced by Sleipnir::CDatasetCompact::Open().