Graphitti
A toolkit/software architecture to ease creating high-performance neural network simulators
|
An efficient implementation of a dynamically-allocated 1D array. More...
#include <VectorMatrix.h>
Public Member Functions | |
VectorMatrix (string t="complete", string i="const", int r=1, int c=1, BGFLOAT m=0.0, string v="") | |
VectorMatrix (const VectorMatrix &oldV) | |
Copy constructor. Performs a deep copy. | |
virtual | ~VectorMatrix ()=default |
De-allocate storage. | |
const VectorMatrix & | operator= (BGFLOAT c) |
Set elements of vector to a constant. Doesn't change its size. | |
const VectorMatrix & | operator= (const VectorMatrix &rhs) |
Assignment operator. | |
virtual void | Print (ostream &os) const |
Polymorphic output. Produces text output on stream "os". | |
virtual string | toXML (string name="") const |
Produce XML representation of vector in string return value. | |
const BGFLOAT & | operator[] (int i) const |
Access element of a VectorMatrix. Zero-based index; constant-time. | |
const BGFLOAT & | at (int i) const |
access element of a VectorMatrix. Zero-based index; constant-time. | |
int | Size (void) const |
The length of a VectorMatrix elements. | |
BGFLOAT & | operator[] (int i) |
mutate element of a VectorMatrix. Zero-based index; constant time. | |
BGFLOAT & | at (int i) |
mutate element of a VectorMatrix. Zero-based index. | |
virtual const VectorMatrix | operator+ (const VectorMatrix &rhs) const |
Compute the sum of two VectorMatrices of the same length. | |
virtual const VectorMatrix | operator+ (BGFLOAT c) const |
vector plus a constant. Adds each element of the vector plus a constant. Method version (vector on LHS). | |
virtual BGFLOAT | operator* (const VectorMatrix &rhs) const |
There are two possible vector products. This is an inner product. | |
virtual const VectorMatrix | operator* (const CompleteMatrix &rhs) const |
Vector times a Complete Matrix. | |
virtual const VectorMatrix | ArrayMultiply (const VectorMatrix &rhs) const |
Element-by-element multiplication of two vectors. | |
virtual const VectorMatrix | operator* (BGFLOAT c) const |
Constant times a vector. Multiplies each element of the vector by a constant. Method version (vector on LHS) | |
virtual const VectorMatrix | operator/ (BGFLOAT c) const |
Vector divided by a constant. Divides each element of the vector by a constant. | |
virtual const VectorMatrix | Limit (BGFLOAT low, BGFLOAT high) const |
Limit values of a vector. Clip values to lie within range. | |
virtual BGFLOAT | Min (void) const |
Find minimum value of vector. | |
virtual BGFLOAT | Max (void) const |
Find maximum value of vector. | |
virtual const VectorMatrix & | operator+= (const VectorMatrix &rhs) |
Compute and assign the sum of two VectorMatrices of the same length. | |
template<class Archive > | |
void | serialize (Archive &archive) |
Cereal serialization method. | |
virtual int | getNumElements () const |
Interface for RecordableBase. | |
virtual void | startNewEpoch () |
virtual variantTypes | getElement (int index) const |
virtual void | setDataType () |
Set up a string representing the basic data type. | |
virtual const string & | getDataType () const override |
Get the run time data type info of the recordable variable. | |
![]() | |
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 VectorMatrix &source) |
Performs a deep copy. | |
void | alloc (int size) |
Allocates storage for internal Vector 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 | |
const VectorMatrix | operator* (BGFLOAT c, const VectorMatrix &rhs) |
Constant times a vector. | |
const VectorMatrix | operator* (const VectorMatrix &v, const SparseMatrix &m) |
Vector times sparse matrix. | |
const VectorMatrix | operator- (BGFLOAT c, const VectorMatrix &v) |
Constant minus a vector. Subtracts each element of the vector from a constant. | |
const VectorMatrix | operator/ (BGFLOAT c, const VectorMatrix &v) |
Constant divided by a vector. Divides the constant by each element of a vector. | |
const VectorMatrix | operator+ (BGFLOAT c, const VectorMatrix &rhs) |
Constant plus a vector. Adds each element of the vector and a constant. | |
const VectorMatrix | sqrt (const VectorMatrix &v) |
Element-wise square root of vector. Computes square root of each element of vector. | |
const VectorMatrix | exp (const VectorMatrix &v) |
Element-wise e^x for vector. Computes exp(v[i]) of each element of vector. | |
An efficient implementation of a dynamically-allocated 1D array.
This is a self-allocating and de-allocating 1D array that is optimized for numerical computation. A bit of trial and error went into this. Originally, the idea was to manipulate VectorMatrices 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. Note that, while this class keeps track of the number of rows and columns it has, no distinction is made between row and column vectors, and in fact it is treated as either, depending on the context of the mathematical operation.
Definition at line 56 of file VectorMatrix.h.
VectorMatrix::VectorMatrix | ( | string | t = "complete", |
string | i = "const", | ||
int | r = 1, | ||
int | c = 1, | ||
BGFLOAT | m = 0.0, | ||
string | values = "" ) |
Allocate storage and initialize attributes. Either "rows" or "columns" must be equal to 1. If "v" is not empty, it will be used as a source of data for initializing the vector (and must be a list of whitespace separated textual numeric data with the same number of elements as this VectorMatrix).
Matrix_bad_alloc | |
Matrix_invalid_argument |
t | Matrix type |
i | Matrix initialization |
r | rows in Matrix |
c | columns in Matrix |
m | multiplier used for initialization |
v | values for initializing VectorMatrix |
Definition at line 31 of file VectorMatrix.cpp.
VectorMatrix::VectorMatrix | ( | const VectorMatrix & | oldV | ) |
Copy constructor. Performs a deep copy.
oldV | The source VectorMatrix |
Definition at line 79 of file VectorMatrix.cpp.
|
protected |
Allocates storage for internal Vector storage.
Matrix_bad_alloc | |
MatrixException |
size | number of Vector elements |
|
virtual |
Element-by-element multiplication of two vectors.
Matrix_domain_error |
rhs | right-hand argument to the vector/matrix product. Must be same size as current vector |
Definition at line 203 of file VectorMatrix.cpp.
|
inline |
mutate element of a VectorMatrix. Zero-based index.
i | index |
Definition at line 143 of file VectorMatrix.h.
|
inline |
access element of a VectorMatrix. Zero-based index; constant-time.
i | index |
Definition at line 113 of file VectorMatrix.h.
|
protected |
Performs a deep copy.
source | VectorMatrix to copy from |
Definition at line 103 of file VectorMatrix.cpp.
|
inlineoverridevirtual |
Get the run time data type info of the recordable variable.
Implements RecordableBase.
Definition at line 307 of file VectorMatrix.h.
|
inlinevirtual |
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 295 of file VectorMatrix.h.
|
inlinevirtual |
Interface for RecordableBase.
Implements RecordableBase.
Definition at line 281 of file VectorMatrix.h.
|
virtual |
Limit values of a vector. Clip values to lie within range.
low | lower limit |
high | upper limit |
Definition at line 268 of file VectorMatrix.cpp.
|
virtual |
|
virtual |
|
virtual |
Constant times a vector. Multiplies each element of the vector by a constant. Method version (vector on LHS)
c | The constant |
Definition at line 220 of file VectorMatrix.cpp.
|
virtual |
Vector times a Complete Matrix.
Treats this vector as a row vector; multiplies by matrix with same number of rows as size of this vector to produce a new vector the same size as the number of columns of the matrix
Matrix_domain_error |
rhs | right-hand argument to the vector/matrix product |
Definition at line 185 of file VectorMatrix.cpp.
|
virtual |
There are two possible vector products. This is an inner product.
Matrix_domain_error |
rhs | right-hand argument to the inner product. |
Definition at line 167 of file VectorMatrix.cpp.
|
virtual |
vector plus a constant. Adds each element of the vector plus a constant. Method version (vector on LHS).
c | The constant |
Definition at line 155 of file VectorMatrix.cpp.
|
virtual |
Compute the sum of two VectorMatrices of the same length.
Matrix_domain_error |
rhs | right-hand argument to the addition. Must be same length as this. |
Definition at line 138 of file VectorMatrix.cpp.
|
virtual |
Compute and assign the sum of two VectorMatrices of the same length.
Matrix_domain_error |
rhs | right-hand argument to the addition. Must be same length as this. |
Definition at line 331 of file VectorMatrix.cpp.
|
virtual |
Vector divided by a constant. Divides each element of the vector by a constant.
c | The constant |
Definition at line 232 of file VectorMatrix.cpp.
const VectorMatrix & VectorMatrix::operator= | ( | BGFLOAT | c | ) |
Set elements of vector to a constant. Doesn't change its size.
c | the constant |
Definition at line 86 of file VectorMatrix.cpp.
const VectorMatrix & VectorMatrix::operator= | ( | const VectorMatrix & | rhs | ) |
Assignment operator.
rhs | right-hand side of assignment |
Definition at line 93 of file VectorMatrix.cpp.
|
inline |
mutate element of a VectorMatrix. Zero-based index; constant time.
i | index |
Definition at line 135 of file VectorMatrix.h.
|
inline |
Access element of a VectorMatrix. Zero-based index; constant-time.
i | index |
Definition at line 105 of file VectorMatrix.h.
|
virtual |
Polymorphic output. Produces text output on stream "os".
os | stream to output to |
Implements Matrix.
Definition at line 115 of file VectorMatrix.cpp.
void VectorMatrix::serialize | ( | Archive & | archive | ) |
Cereal serialization method.
Definition at line 354 of file VectorMatrix.h.
|
inlinevirtual |
Set up a string representing the basic data type.
Implements RecordableBase.
Definition at line 301 of file VectorMatrix.h.
|
inline |
The length of a VectorMatrix elements.
Definition at line 120 of file VectorMatrix.h.
|
inlinevirtual |
Start a new epoch for the recordable variable. This method is called at the beginning of each simulation epoch to prepare for recording new events.
Implements RecordableBase.
Definition at line 288 of file VectorMatrix.h.
|
virtual |
Produce XML representation of vector in string return value.
Definition at line 122 of file VectorMatrix.cpp.
|
friend |
Element-wise e^x for vector. Computes exp(v[i]) of each element of vector.
v | The vector |
Definition at line 320 of file VectorMatrix.cpp.
|
friend |
Constant times a vector.
Multiplies each element of the vector by a constant. Function version (constant on LHS)
c | The constant |
rhs | The vector |
Definition at line 232 of file VectorMatrix.h.
|
friend |
Vector times sparse matrix.
Size of v must equal to number of rows of m. Size of resultant vector is equal to number Of columns of m.
Matrix_domain_error |
Matrix times vector. Size of v must equal to number of rows of m. Size of resultant vector is equal to number Of columns of m.
Matrix_domain_error |
Definition at line 608 of file SparseMatrix.cpp.
|
friend |
Constant plus a vector. Adds each element of the vector and a constant.
c | The constant |
rhs | The vector |
Definition at line 261 of file VectorMatrix.h.
|
friend |
Constant minus a vector. Subtracts each element of the vector from a constant.
c | The constant |
v | The vector |
Definition at line 244 of file VectorMatrix.cpp.
|
friend |
Constant divided by a vector. Divides the constant by each element of a vector.
c | The constant |
v | The vector |
Definition at line 256 of file VectorMatrix.cpp.
|
friend |
Element-wise square root of vector. Computes square root of each element of vector.
v | The vector |
Definition at line 308 of file VectorMatrix.cpp.
|
protected |