Sleipnir
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
Sleipnir::CHalfMatrix< tType > Class Template Reference

A symmetric two-dimensional matrix. More...

#include <halfmatrix.h>

Inheritance diagram for Sleipnir::CHalfMatrix< tType >:
Sleipnir::CHalfMatrixBase

Public Member Functions

void Reset ()
 Empties the matrix and deallocates all associated memory.
tType * GetFullRow (size_t iY)
const tType * Get (size_t iY) const
 Return a single row of the matrix.
tType * Get (size_t iY)
 Return a single row of the matrix.
tType & Get (size_t iY, size_t iX) const
 Returns the value at the requested matrix position.
void Set (size_t iY, size_t iX, const tType &Value)
 Set the value at the requested matrix position.
void Set (size_t iY, const tType *aValues)
 Set a single row of the matrix.
void Initialize (const CHalfMatrix &Mat)
 Create a new matrix using a reference to the given matrix.
virtual void Initialize (size_t iSize, tType **aaData=NULL)
 Create a new matrix of the requested size and, optionally, referencing the given data.
size_t GetSize () const
 Return the number of elements (row/columns) of the matrix.
bool SetSize (size_t iSize, bool fClear=false)
void Clear ()
 Sets all entries of the matrix to 0 without changing its size.
bool Save (std::ostream &ostm, bool fBinary, char cSeparator= '\t') const
 Saves a matrix to the given stream in either binary or tab-delimited text format.

Static Public Member Functions

static size_t GetSpace (size_t iSize)
 Return the number of entries in a symmetric matrix of the given size.

Protected Member Functions

bool SaveBinary (std::ostream &ostm) const
 Saves a matrix to the given stream in binary format.
bool SaveText (std::ostream &ostm, char cSeparator) const
 Saves a matrix to the given stream in either binary or tab-delimited text format.

Protected Attributes

bool m_fMemory
 True if the matrix is responsible for disposing of the underlying memory.
tType ** m_aaData
 Two-dimensional array backing the symmetric matrix.

Detailed Description

template<class tType>
class Sleipnir::CHalfMatrix< tType >

A symmetric two-dimensional matrix.

Parameters:
tTypeType of element contained by the matrix.
Remarks:
Nothing is bounds checked to increase efficiency. Symmetric matrices consume half the space of a full matrix and guarantee that element i,j is always identical to element j,i. Everything is stored (and thus accessed most efficiently) in row-major order. Accessing elements on the diagonal generally doesn't work.
See also:
CCompactMatrix | CFullMatrix

Definition at line 48 of file halfmatrix.h.


Member Function Documentation

template<class tType>
const tType* Sleipnir::CHalfMatrix< tType >::Get ( size_t  iY) const [inline]

Return a single row of the matrix.

Parameters:
iYMatrix row.
Returns:
Requested matrix row.
Remarks:
For efficiency, no bounds checking is performed. The given row must be smaller than the size. The returned array will contain a number of elements equal to GetSize - iY - 1.
See also:
Set

Definition at line 123 of file halfmatrix.h.

Referenced by Sleipnir::CClustPivot::Cluster(), Sleipnir::CClustKMeans::Cluster(), Sleipnir::CClustQTC::Cluster(), Sleipnir::CDat::Get(), Sleipnir::CHalfMatrix< unsigned char >::SaveBinary(), and Sleipnir::CHalfMatrix< unsigned char >::SaveText().

template<class tType>
tType* Sleipnir::CHalfMatrix< tType >::Get ( size_t  iY) [inline]

Return a single row of the matrix.

Parameters:
iYMatrix row.
Returns:
Requested matrix row.
Remarks:
For efficiency, no bounds checking is performed. The given row must be smaller than the size. The returned array will contain a number of elements equal to GetSize - iY - 1.
See also:
Set

Definition at line 144 of file halfmatrix.h.

template<class tType>
tType& Sleipnir::CHalfMatrix< tType >::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.
See also:
Set

Reimplemented in Sleipnir::CBinaryMatrix.

Definition at line 168 of file halfmatrix.h.

template<class tType>
size_t Sleipnir::CHalfMatrix< tType >::GetSize ( ) const [inline]
template<class tType>
static size_t Sleipnir::CHalfMatrix< tType >::GetSpace ( size_t  iSize) [inline, static]

Return the number of entries in a symmetric matrix of the given size.

Parameters:
iSizeNumber of elements in a symmetric matrix for which the entries are calculated.
Returns:
Number of entries in a symmetric matrix of the given size.
Remarks:
A symmetric matrix over N elements always contains N(N-1)/2 entries.

Definition at line 63 of file halfmatrix.h.

template<class tType>
void Sleipnir::CHalfMatrix< tType >::Initialize ( const CHalfMatrix< tType > &  Mat) [inline]

Create a new matrix using a reference to the given matrix.

Parameters:
MatMatrix to duplicate in the created matrix.
Remarks:
A reference is held to the given matrix; it is not copied, so it should not be destroyed before the newly initialized matrix.

Definition at line 237 of file halfmatrix.h.

Referenced by Sleipnir::CHalfMatrix< unsigned char >::Initialize(), Sleipnir::CDat::Open(), and Sleipnir::CDatasetCompact::Open().

template<class tType>
virtual void Sleipnir::CHalfMatrix< tType >::Initialize ( size_t  iSize,
tType **  aaData = NULL 
) [inline, virtual]

Create a new matrix of the requested size and, optionally, referencing the given data.

Parameters:
iSizeMatrix elements.
aaDataIf non-null, the memory that will back the newly created matrix.
Remarks:
A reference is held to the given memory; it is not copied, so it should not be destroyed before the newly initialized matrix.

Definition at line 255 of file halfmatrix.h.

template<class tType>
bool Sleipnir::CHalfMatrix< tType >::Save ( std::ostream &  ostm,
bool  fBinary,
char  cSeparator = '\t' 
) const [inline]

Saves a matrix to the given stream in either binary or tab-delimited text format.

Parameters:
ostmStream to which matrix is saved.
fBinaryIf true, matrix is saved in binary format; otherwise, matrix is saved as tab-delimited text.
cSeparatorFor non-binary output, delimiter between matrix elements (tab by default).
Returns:
True if matrix was saved successfully.
Remarks:
A binary matrix is saved in row-major order; a text matrix is a simple tab-delimited file from which matrix elements are read using >>.

Definition at line 332 of file halfmatrix.h.

template<class tType>
bool Sleipnir::CHalfMatrix< tType >::SaveBinary ( std::ostream &  ostm) const [inline, protected]

Saves a matrix to the given stream in binary format.

Parameters:
ostmStream to which matrix is saved.
Returns:
True if matrix was saved successfully.
Remarks:
Saved in row-major order, with a four-byte initial integer encoding the number of elements n followed by rows of length n-1, n-2, and so forth.
See also:
Save

Definition at line 355 of file halfmatrix.h.

Referenced by Sleipnir::CHalfMatrix< unsigned char >::Save().

template<class tType>
bool Sleipnir::CHalfMatrix< tType >::SaveText ( std::ostream &  ostm,
char  cSeparator 
) const [inline, protected]

Saves a matrix to the given stream in either binary or tab-delimited text format.

Parameters:
ostmStream to which matrix is saved.
cSeparatorDelimiter saved between distinct values.
Returns:
True if matrix was saved successfully.
Remarks:
Saved in a simple tab-delimited file to which matrix elements are written using <<.
See also:
Save

Definition at line 386 of file halfmatrix.h.

Referenced by Sleipnir::CHalfMatrix< unsigned char >::Save().

template<class tType>
void Sleipnir::CHalfMatrix< tType >::Set ( size_t  iY,
size_t  iX,
const tType &  Value 
) [inline]

Set the value at the requested matrix position.

Parameters:
iYMatrix row.
iXMatrix column.
ValueValue to store.
Remarks:
For efficiency, no bounds checking is performed. The given row and column must be smaller than the size.
See also:
Get

Definition at line 197 of file halfmatrix.h.

Referenced by Sleipnir::CClustQTC::Cluster(), Sleipnir::CDatasetCompact::Open(), and Sleipnir::CDat::Set().

template<class tType>
void Sleipnir::CHalfMatrix< tType >::Set ( size_t  iY,
const tType *  aValues 
) [inline]

Set a single row of the matrix.

Parameters:
iYMatrix row.
aValuesData to be copied into the requested row.
Remarks:
For efficiency, no bounds checking is performed. The given row must be smaller than the size, and the given data array must contain at least GetSize - iY - 1 elements.
See also:
Get

Definition at line 222 of file halfmatrix.h.


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