MachineIntelligenceCore:Algorithms
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mic::types::MatrixArray< T > Class Template Reference

A dynamic array of matrices. It's just what it looks like - std::vector<Matrix>; elements are are accessible by name with operator [] name needs to be given together with name in the main constructor. More...

#include <MatrixArray.hpp>

Public Member Functions

 MatrixArray ()=default
 
 MatrixArray (std::string name_)
 
 MatrixArray (std::string name_, std::initializer_list< std::tuple< std::string, size_t, size_t > > args_)
 
 MatrixArray (const MatrixArray &other)
 
MatrixArrayoperator= (const MatrixArray &other)
 
void add (std::initializer_list< std::tuple< std::string, size_t, size_t > > params_)
 
void add (std::tuple< std::string, size_t, size_t > param_)
 
void add (std::string name_, size_t input_, size_t output_)
 
void add (std::string name_, std::shared_ptr< mic::types::Matrix< T > > matrix_ptr_)
 
mic::types::MatrixPtr< T > & operator[] (size_t number_)
 
bool keyExists (char key_)
 
bool keyExists (std::string key_)
 
mic::types::MatrixPtr< T > & operator[] (char key_)
 
mic::types::MatrixPtr< T > & operator[] (std::string key_)
 
void setZero ()
 
std::string name ()
 
std::map< std::string, size_t > keys ()
 
size_t size ()
 

Protected Attributes

std::string array_name
 Name of the given vector of matrices. More...
 
std::vector
< mic::types::MatrixPtr< T > > 
matrices
 Vector of matrices. More...
 
std::map< std::string, size_t > keys_map
 Vector of names of consecutive matrices in the array. More...
 

Private Member Functions

template<class Archive >
void save (Archive &ar, const unsigned int version) const
 
template<class Archive >
void load (Archive &ar, const unsigned int version)
 

Friends

class boost::serialization::access
 
std::ostream & operator<< (std::ostream &os_, const MatrixArray &obj_)
 

Detailed Description

template<typename T>
class mic::types::MatrixArray< T >

A dynamic array of matrices. It's just what it looks like - std::vector<Matrix>; elements are are accessible by name with operator [] name needs to be given together with name in the main constructor.

An example:

m = MatrixArray(

{ "something" }, {

std::make_tuple("W", M, N),
std::make_tuple("U", X, Y),

} )

will make a 2 sub-matrices "W" and "U" of dimensions M x N and X x Y respectively;

later, m['W'] will return the first matrix and m['U'] the second one.

Other things are just implementations of operators and IO.

Template Parameters
TTemplate parameter denoting elementary type of data used (int, float, double etc.)
Date
Apr 11, 2016
Author
krocki/tkornuta

Definition at line 73 of file MatrixArray.hpp.

Constructor & Destructor Documentation

template<typename T>
mic::types::MatrixArray< T >::MatrixArray ( )
default

Default empty constructor.

template<typename T>
mic::types::MatrixArray< T >::MatrixArray ( std::string  name_)
inline

Simple constructor. Stores the name.

Parameters
name_Name of the array.

Definition at line 85 of file MatrixArray.hpp.

template<typename T>
mic::types::MatrixArray< T >::MatrixArray ( std::string  name_,
std::initializer_list< std::tuple< std::string, size_t, size_t > >  args_ 
)
inline

The main constructor. Adds parameters.

Parameters
name_Name of the array.
args_Vector of tuples containing <id, width, height>.

Definition at line 94 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::add().

Here is the call graph for this function:

Member Function Documentation

template<typename T>
void mic::types::MatrixArray< T >::add ( std::initializer_list< std::tuple< std::string, size_t, size_t > >  params_)
inline

Adds several matrices at once.

Parameters
params_Vector of tuples containing <id, width, height>.

Definition at line 141 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::keys_map, and mic::types::MatrixArray< T >::matrices.

Referenced by mic::types::MatrixArray< T >::MatrixArray(), and TEST().

template<typename T>
void mic::types::MatrixArray< T >::add ( std::tuple< std::string, size_t, size_t >  param_)
inline

Adds a single matrix to array.

Parameters
param_A tuple to be added.

Definition at line 152 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::keys_map, and mic::types::MatrixArray< T >::matrices.

template<typename T>
void mic::types::MatrixArray< T >::add ( std::string  name_,
size_t  input_,
size_t  output_ 
)
inline

Adds a single matrix to array.

Parameters
name_Name of the matrix.
input_Input length.
output_Output length.

Definition at line 163 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::keys_map, and mic::types::MatrixArray< T >::matrices.

template<typename T>
void mic::types::MatrixArray< T >::add ( std::string  name_,
std::shared_ptr< mic::types::Matrix< T > >  matrix_ptr_ 
)
inline

Adds a pointer to an existing matrix to array.

Parameters
name_Name of the matrix.
matrix_ptr_Pointer to the existing array.

Definition at line 173 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::keys_map, and mic::types::MatrixArray< T >::matrices.

template<typename T>
bool mic::types::MatrixArray< T >::keyExists ( char  key_)
inline

Checks whether matrix indexed by a given key exists.

Parameters
key_Key as a single character.

Definition at line 194 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::keys_map.

Referenced by mic::types::MatrixArray< T >::operator[]().

template<typename T>
bool mic::types::MatrixArray< T >::keyExists ( std::string  key_)
inline

Checks whether matrix indexed by a given key exists.

Parameters
key_Key as string.

Definition at line 202 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::keys_map.

template<typename T>
std::map<std::string, size_t> mic::types::MatrixArray< T >::keys ( )
inline

Returns the name of the vector of matrices.

Definition at line 266 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::keys_map.

template<typename T>
template<class Archive >
void mic::types::MatrixArray< T >::load ( Archive &  ar,
const unsigned int  version 
)
inlineprivate

Serialization load - loads the matrix object to archive.

Parameters
arUsed archive.
versionVersion of the matrix class (not used currently).

Definition at line 316 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::array_name, mic::types::MatrixArray< T >::keys_map, mic::types::MatrixArray< T >::matrices, and mic::types::MatrixArray< T >::size().

Here is the call graph for this function:

template<typename T>
std::string mic::types::MatrixArray< T >::name ( )
inline

Returns the name of the vector of matrices.

Definition at line 259 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::array_name.

template<typename T>
MatrixArray& mic::types::MatrixArray< T >::operator= ( const MatrixArray< T > &  other)
inline
template<typename T>
mic::types::MatrixPtr<T>& mic::types::MatrixArray< T >::operator[] ( size_t  number_)
inline

Returns the matrix with given number.

Parameters
number_Number of the matrix.
Returns
Pointer to a matrix.

Definition at line 183 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::array_name, and mic::types::MatrixArray< T >::matrices.

template<typename T>
mic::types::MatrixPtr<T>& mic::types::MatrixArray< T >::operator[] ( char  key_)
inline

Returns the matrix with given key (id).

Parameters
number_Matrix key.
Returns
Pointer to a matrix.

Definition at line 212 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::array_name, and mic::types::MatrixArray< T >::keyExists().

Here is the call graph for this function:

template<typename T>
mic::types::MatrixPtr<T>& mic::types::MatrixArray< T >::operator[] ( std::string  key_)
inline

Returns the matrix with given key (id).

Parameters
number_Matrix key.
Returns
Pointer to a matrix.

Definition at line 224 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::array_name, mic::types::MatrixArray< T >::keyExists(), mic::types::MatrixArray< T >::keys_map, and mic::types::MatrixArray< T >::matrices.

Here is the call graph for this function:

template<typename T>
template<class Archive >
void mic::types::MatrixArray< T >::save ( Archive &  ar,
const unsigned int  version 
) const
inlineprivate

Serialization save - saves the matrix object to archive.

Parameters
arUsed archive.
versionVersion of the matrix class (not used currently).

Definition at line 298 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::array_name, mic::types::MatrixArray< T >::keys_map, mic::types::MatrixArray< T >::matrices, and mic::types::MatrixArray< T >::size().

Here is the call graph for this function:

template<typename T>
void mic::types::MatrixArray< T >::setZero ( )
inline

Zeroes all matrices.

Definition at line 250 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::matrices.

template<typename T>
size_t mic::types::MatrixArray< T >::size ( )
inline

Returns the size of vector.

Definition at line 273 of file MatrixArray.hpp.

References mic::types::MatrixArray< T >::matrices.

Referenced by mic::types::MatrixArray< T >::load(), and mic::types::MatrixArray< T >::save().

Friends And Related Function Documentation

template<typename T>
friend class boost::serialization::access
friend

Definition at line 290 of file MatrixArray.hpp.

template<typename T>
std::ostream& operator<< ( std::ostream &  os_,
const MatrixArray< T > &  obj_ 
)
friend

Stream operator enabling to print the array.

Parameters
os_Ostream object.
obj_Array object.

Definition at line 236 of file MatrixArray.hpp.

Member Data Documentation


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