Graphitti
A toolkit/software architecture to ease creating high-performance neural network simulators
Loading...
Searching...
No Matches
CompleteMatrix Class Reference

An efficient implementation of a dynamically-allocated 2D array. More...

#include <CompleteMatrix.h>

Inheritance diagram for CompleteMatrix:
Collaboration diagram for CompleteMatrix:

Public Member Functions

 CompleteMatrix (string t="complete", string i="const", int r=2, int c=2, BGFLOAT m=0.0, string v="")
 
 CompleteMatrix (const CompleteMatrix &oldM)
 Copy constructor. Performs a deep copy.
 
virtual ~CompleteMatrix ()
 De-allocate storage.
 
CompleteMatrixoperator= (const CompleteMatrix &rhs)
 Assignment operator.
 
BGFLOAT & operator() (int row, int column)
 access element at (row, column) – mutator
 
virtual void Print (ostream &os) const
 Polymorphic output. Produces text output on stream os. Used by operator<<()
 
virtual string toXML (string name="") const
 Produce XML representation of Matrix in string return value.
 
virtual const CompleteMatrix operator+ (const CompleteMatrix &rhs) const
 Compute the sum of two CompleteMatrices of the same rows and columns.
 
virtual const CompleteMatrix operator* (const CompleteMatrix &rhs) const
 
template<class Archive >
void serialize (Archive &archive)
 Cereal serialization method.
 
int getNumElements () const override
 Interface for RecordableBase.
 
void startNewEpoch () override
 
variantTypes getElement (int index) const override
 
void setDataType () override
 Set up a string representing the basic data type.
 
const string & getDataType () const override
 
- Public Member Functions inherited from Matrix
virtual ~Matrix ()=default
 Virtual Destructor.
 
template<class Archive >
void serialize (Archive &archive)
 Cereal serialization method.
 
- Public Member Functions inherited from RecordableBase
template<class Archive >
void serialize (Archive &archive)
 Cereal serialization method.
 

Protected Member Functions

void clear (void)
 Frees up all dynamically allocated storage.
 
void copy (const CompleteMatrix &source)
 
void alloc (int rows, int cols)
 Allocates storage for internal Matrix storage.
 
- Protected Member Functions inherited from Matrix
 Matrix (string t="", string i="", int r=0, int c=0, BGFLOAT m=0.0)
 
void SetAttributes (string t, string i, int r, int c, BGFLOAT m, int d)
 Convenience mutator.
 
- Protected Member Functions inherited from RecordableBase
 RecordableBase ()=default
 prevents any code outside this class from creating a RecordableBase object
 

Protected Attributes

int columns
 Number of columns in Matrix (>0)
 
int dimensions
 One or two dimensional.
 
int rows
 Number of rows in Matrix (>0)
 
- Protected Attributes inherited from Matrix
string type
 
string init
 
int rows
 Number of rows in Matrix (>0)
 
int columns
 Number of columns in Matrix (>0)
 
BGFLOAT multiplier
 Constant used for initialization.
 
int dimensions
 One or two dimensional.
 
- Protected Attributes inherited from RecordableBase
std::string basicDataType_
 the basic data type in the recorded variable
 

Friends

class VectorMatrix
 
const CompleteMatrix sqrt (const CompleteMatrix &v)
 

Detailed Description

An efficient implementation of a dynamically-allocated 2D array.

This is a self-allocating and de-allocating 2D array that is optimized for numerical computation. A bit of trial and error went into this. Originally, the idea was to manipulate CompleteMatrices using superclass pointers, which would allow generic computation on mixtures of subclass objects. However, that doesn't work too well with numeric computation, because of the need to have "anonymous" intermediate results. So, instead this is implemented as most classes would be, with the hope that compilers will optimize out unnecessary copying of objects that are intermediate results in numerical computations.

Definition at line 39 of file CompleteMatrix.h.

Constructor & Destructor Documentation

◆ CompleteMatrix() [1/2]

CompleteMatrix::CompleteMatrix ( string t = "complete",
string i = "const",
int r = 2,
int c = 2,
BGFLOAT m = 0.0,
string values = "" )

Allocate storage and initialize attributes. If "v" (values) is not empty, it will be used as a source of data for initializing the matrix (and must be a list of whitespace separated textual numeric data with rows * columns elements, if "t" (type) is "complete", or number of elements in diagonal, if "t" is "diag").

If "i" (initialization) is "const", then "m" will be used to initialize either all elements (for a "complete" matrix) or diagonal elements (for "diag").

"random" initialization is not yet implemented.

Exceptions
Matrix_bad_alloc
Matrix_invalid_argument
Parameters
tMatrix type (defaults to "complete")
iMatrix initialization (defaults to "const")
rrows in Matrix (defaults to 2)
ccolumns in Matrix (defaults to 2)
mmultiplier used for initialization (defaults to zero)
vvalues for initializing CompleteMatrix (this string is parsed as a list of floating point numbers)

Definition at line 35 of file CompleteMatrix.cpp.

◆ CompleteMatrix() [2/2]

CompleteMatrix::CompleteMatrix ( const CompleteMatrix & oldM)

Copy constructor. Performs a deep copy.

Parameters
oldMThe source CompleteMatrix

Definition at line 97 of file CompleteMatrix.cpp.

◆ ~CompleteMatrix()

CompleteMatrix::~CompleteMatrix ( )
virtual

De-allocate storage.

Definition at line 104 of file CompleteMatrix.cpp.

Member Function Documentation

◆ alloc()

void CompleteMatrix::alloc ( int rows,
int columns )
protected

Allocates storage for internal Matrix storage.

Exceptions
Matrix_bad_alloc
MatrixException
Parameters
rowsnumber of Matrix rows
colsnumber of Matrix cols

Allocate internal storage

Note: If you are getting this memory allocaiton error:

" terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc "

Please refer to LIFModel::Connections()

Definition at line 160 of file CompleteMatrix.cpp.

◆ clear()

void CompleteMatrix::clear ( void )
protected

Frees up all dynamically allocated storage.

Definition at line 126 of file CompleteMatrix.cpp.

◆ copy()

void CompleteMatrix::copy ( const CompleteMatrix & source)
protected

Performs a deep copy. It is assumed that the storage allocate to theMatrix has already been deleted.

Parameters
sourceVectorMatrix to copy from

Definition at line 135 of file CompleteMatrix.cpp.

◆ getDataType()

const string & CompleteMatrix::getDataType ( ) const
inlineoverridevirtual

Get A string representing the data type of the recordable variable Dynamic or runtime type information of basic data type

Implements RecordableBase.

Definition at line 69 of file CompleteMatrix.h.

◆ getElement()

variantTypes CompleteMatrix::getElement ( int index) const
inlineoverridevirtual

Get the value of the recordable variable at the specified index.

Parameters
indexThe index of the recorded value to retrieve.
Returns
A variant representing the recorded value.

Implements RecordableBase.

Definition at line 57 of file CompleteMatrix.h.

◆ getNumElements()

int CompleteMatrix::getNumElements ( ) const
inlineoverridevirtual

Interface for RecordableBase.

Implements RecordableBase.

Definition at line 45 of file CompleteMatrix.h.

◆ operator()()

BGFLOAT & CompleteMatrix::operator() ( int row,
int column )
inline

access element at (row, column) – mutator

Parameters
rowelement row
columnelement column
Returns
reference to element (lvalue)

Definition at line 114 of file CompleteMatrix.h.

◆ operator*()

const CompleteMatrix CompleteMatrix::operator* ( const CompleteMatrix & rhs) const
virtual

Matrix product. Number of rows of "rhs" must equal to number of columns of this.

Exceptions
Matrix_domain_error
Parameters
rhsright-hand argument to the product.
Returns
A CompleteMatrix with number of rows equal to this and number of columns equal to "rhs".

Definition at line 221 of file CompleteMatrix.cpp.

◆ operator+()

const CompleteMatrix CompleteMatrix::operator+ ( const CompleteMatrix & rhs) const
virtual

Compute the sum of two CompleteMatrices of the same rows and columns.

Exceptions
Matrix_domain_error
Parameters
rhsright-hand argument to the addition. Must have same dimensions as this.
Returns
A new CompleteMatrix, with value equal to the sum of this one and rhs and rows and columns the same as both, returned by value.

Definition at line 204 of file CompleteMatrix.cpp.

◆ operator=()

CompleteMatrix & CompleteMatrix::operator= ( const CompleteMatrix & rhs)

Assignment operator.

Parameters
rhsright-hand side of assignment
Returns
returns reference to this CompleteMatrix (after assignment)

Definition at line 111 of file CompleteMatrix.cpp.

◆ Print()

void CompleteMatrix::Print ( ostream & os) const
virtual

Polymorphic output. Produces text output on stream os. Used by operator<<()

Parameters
osstream to output to

Implements Matrix.

Definition at line 174 of file CompleteMatrix.cpp.

◆ serialize()

template<class Archive >
void CompleteMatrix::serialize ( Archive & archive)

Cereal serialization method.

Definition at line 195 of file CompleteMatrix.h.

◆ setDataType()

void CompleteMatrix::setDataType ( )
inlineoverridevirtual

Set up a string representing the basic data type.

Implements RecordableBase.

Definition at line 63 of file CompleteMatrix.h.

◆ startNewEpoch()

void CompleteMatrix::startNewEpoch ( )
inlineoverridevirtual

Start a new epoch for the recordable variable. Called at the beginning of each simulation epoch to prepare for recording new events.

Implements RecordableBase.

Definition at line 51 of file CompleteMatrix.h.

◆ toXML()

string CompleteMatrix::toXML ( string name = "") const
virtual

Produce XML representation of Matrix in string return value.

Parameters
namename attribute for XML

Definition at line 184 of file CompleteMatrix.cpp.

Friends And Related Symbol Documentation

◆ sqrt

const CompleteMatrix sqrt ( const CompleteMatrix & v)
friend

Definition at line 227 of file CompleteMatrix.cpp.

◆ VectorMatrix

friend class VectorMatrix
friend

Definition at line 40 of file CompleteMatrix.h.

Member Data Documentation

◆ columns

int Matrix::columns
protected

Number of columns in Matrix (>0)

Definition at line 81 of file Matrix.h.

◆ dimensions

int Matrix::dimensions
protected

One or two dimensional.

Definition at line 83 of file Matrix.h.

◆ rows

int Matrix::rows
protected

Number of rows in Matrix (>0)

Definition at line 80 of file Matrix.h.


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