Graphitti
A toolkit/software architecture to ease creating high-performance neural network simulators
|
An efficient implementation of a dynamically-allocated 2D array. More...
#include <CompleteMatrix.h>
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. | |
CompleteMatrix & | operator= (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 |
![]() | |
virtual | ~Matrix ()=default |
Virtual Destructor. | |
template<class Archive > | |
void | serialize (Archive &archive) |
Cereal serialization method. | |
![]() | |
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. | |
![]() | |
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. | |
![]() | |
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) | |
![]() | |
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. | |
![]() | |
std::string | basicDataType_ |
the basic data type in the recorded variable | |
Friends | |
class | VectorMatrix |
const CompleteMatrix | sqrt (const CompleteMatrix &v) |
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.
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.
Matrix_bad_alloc | |
Matrix_invalid_argument |
t | Matrix type (defaults to "complete") |
i | Matrix initialization (defaults to "const") |
r | rows in Matrix (defaults to 2) |
c | columns in Matrix (defaults to 2) |
m | multiplier used for initialization (defaults to zero) |
v | values for initializing CompleteMatrix (this string is parsed as a list of floating point numbers) |
Definition at line 35 of file CompleteMatrix.cpp.
CompleteMatrix::CompleteMatrix | ( | const CompleteMatrix & | oldM | ) |
Copy constructor. Performs a deep copy.
oldM | The source CompleteMatrix |
Definition at line 97 of file CompleteMatrix.cpp.
|
virtual |
De-allocate storage.
Definition at line 104 of file CompleteMatrix.cpp.
|
protected |
Allocates storage for internal Matrix storage.
Matrix_bad_alloc | |
MatrixException |
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.
|
protected |
Frees up all dynamically allocated storage.
Definition at line 126 of file CompleteMatrix.cpp.
|
protected |
Performs a deep copy. It is assumed that the storage allocate to theMatrix has already been deleted.
source | VectorMatrix to copy from |
Definition at line 135 of file CompleteMatrix.cpp.
|
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.
|
inlineoverridevirtual |
Get the value of the recordable variable at the specified index.
index | The index of the recorded value to retrieve. |
Implements RecordableBase.
Definition at line 57 of file CompleteMatrix.h.
|
inlineoverridevirtual |
Interface for RecordableBase.
Implements RecordableBase.
Definition at line 45 of file CompleteMatrix.h.
|
inline |
access element at (row, column) – mutator
row | element row |
column | element column |
Definition at line 114 of file CompleteMatrix.h.
|
virtual |
Matrix product. Number of rows of "rhs" must equal to number of columns of this.
Matrix_domain_error |
rhs | right-hand argument to the product. |
Definition at line 221 of file CompleteMatrix.cpp.
|
virtual |
Compute the sum of two CompleteMatrices of the same rows and columns.
Matrix_domain_error |
rhs | right-hand argument to the addition. Must have same dimensions as this. |
Definition at line 204 of file CompleteMatrix.cpp.
CompleteMatrix & CompleteMatrix::operator= | ( | const CompleteMatrix & | rhs | ) |
Assignment operator.
rhs | right-hand side of assignment |
Definition at line 111 of file CompleteMatrix.cpp.
|
virtual |
Polymorphic output. Produces text output on stream os. Used by operator<<()
os | stream to output to |
Implements Matrix.
Definition at line 174 of file CompleteMatrix.cpp.
void CompleteMatrix::serialize | ( | Archive & | archive | ) |
Cereal serialization method.
Definition at line 195 of file CompleteMatrix.h.
|
inlineoverridevirtual |
Set up a string representing the basic data type.
Implements RecordableBase.
Definition at line 63 of file CompleteMatrix.h.
|
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.
|
virtual |
Produce XML representation of Matrix in string return value.
name | name attribute for XML |
Definition at line 184 of file CompleteMatrix.cpp.
|
friend |
Definition at line 227 of file CompleteMatrix.cpp.
|
friend |
Definition at line 40 of file CompleteMatrix.h.
|
protected |