24 #ifndef _MULTIMATRIXCHAIN_H_    25 #define _MULTIMATRIXCHAIN_H_    38     template <
typename _Scalar>
    49     typedef unique_ptr<EventIndMMC> pEventIndMMC;
    59     typedef unique_ptr<ProbMMC> pProbMMC;
    67     typedef seq_len_t error_num_t;
    70     typedef unique_ptr<ErrMMC> pErrMMC;
    79     template <
typename _Scalar>
   129             Node() : _n(0), _start_index(0), _rows(0), _cols(0)
   133             void init(
size_t start_index, matrix_ind_t n, dim_t rows, dim_t cols) {
   137                 _start_index = start_index;
   141             size_t operator() (matrix_ind_t mat, dim_t row, dim_t column)
 const {
   143                 if (!(mat >= 0 && mat < _n)) { 
throw(std::runtime_error(
"Matrix index check failed!")); }
   145                 if (!(row >= 0 && row < _rows && column >= 0 && column < _cols)) { 
throw(std::runtime_error(
"Rows / columns number check failed!")); }
   147                 return _start_index + mat * (_rows * _cols) + row * _cols + column;
   151             matrix_ind_t size()
 const { 
return _n; }
   153             dim_t rows()
 const { 
return _rows; }
   155             dim_t cols()
 const { 
return _cols; }
   157             size_t start()
 const { 
return _start_index; }
   159             size_t n_values()
 const { 
return _n * _rows * _cols; }
   173             _values.reserve(5000);
   194         void resize(node_ind_t n_nodes) {
   195             _chain.resize(n_nodes);
   199         node_ind_t chainSize()
 const { 
return _chain.size(); }
   203         matrix_ind_t nodeSize(node_ind_t node_i)
 const { 
return _chain[node_i].size(); }
   205         dim_t nodeRows(node_ind_t node_i)
 const { 
return _chain[node_i].rows(); }
   207         dim_t nodeColumns(node_ind_t node_i)
 const { 
return _chain[node_i].cols(); }
   221         _Scalar& operator()(node_ind_t node_i, matrix_ind_t mat_i, dim_t row, dim_t col) {
   224             if (node_i >= _chain.size()) { 
throw(std::runtime_error(
"Number of the Node is out of bounds."));}
   226             return _values[_chain[node_i](mat_i, row, col)];
   230         _Scalar operator()(node_ind_t node_i, matrix_ind_t mat_i, dim_t row, dim_t col)
 const {
   232             if (node_i >= _chain.size()) { 
throw (std::runtime_error(
"Number of the Node is out of bounds.")); }
   234             return _values[_chain[node_i](mat_i, row, col)];
   237         _Scalar& at(node_ind_t node_i, matrix_ind_t mat_i, dim_t row, dim_t col) {
   239             if (node_i >= _chain.size()) { 
throw(std::runtime_error(
"Number of the Node is out of bounds."));}
   241             return _values[_chain[node_i](mat_i, row, col)];
   245         _Scalar at(node_ind_t node_i, matrix_ind_t mat_i, dim_t row, dim_t col)
 const {
   247             if (node_i >= _chain.size()) { 
throw(std::runtime_error(
"Number of the Node is out of bounds."));}
   249             return _values[_chain[node_i](mat_i, row, col)];
   259             _chain.push_back(
Node());
   260             return _chain.size() - 1;
   263         node_ind_t 
addNode(matrix_ind_t n_matrices, dim_t rows, dim_t cols) {
   264             _chain.push_back(
Node());
   265             this->initNode(_chain.size() - 1, n_matrices, rows, cols);
   266             return _chain.size() - 1;
   271         void initNode(node_ind_t node_i, matrix_ind_t n_matrices, dim_t rows, dim_t cols) {
   272             size_t prev_node_size = _chain[node_i].n_values();
   273             _chain[node_i].init(_values.size(), n_matrices, rows, cols);
   274             _values.resize(_values.size() + _chain[node_i].n_values() - prev_node_size, 0);
   279             _chain.swap(other._chain);
   280             _values.swap(other._values);
   285             _chain.shrink_to_fit();
   286             _values.shrink_to_fit();
   292         void fill(node_ind_t node, matrix_ind_t mat, _Scalar val = 0) {
   293             for (dim_t r = 0; r < _chain[node].rows(); ++r) {
   294                 for (dim_t c = 0; c < _chain[node].cols(); ++c) {
   295                     _values[_chain[node](mat, r, c)] = val;
   301         matrix_t matrix(node_ind_t node, matrix_ind_t mat)
 const {
   302             matrix_t res(_chain[node].rows(), _chain[node].cols(), 0);
   303             for (dim_t r = 0; r < _chain[node].rows(); ++r) {
   304                 for (dim_t c = 0; c < _chain[node].cols(); ++c) {
   305                     res(r, c) = (*this)(node, mat, r, c);
   312         _Scalar operator[](
size_t index)
 const { 
return _values[index]; }
   315         size_t values_size()
 const { 
return _values.size(); }
   320         std::vector<Node> _chain;
   321         std::vector<_Scalar> _values;
 
Node in the chain. Stores one or more matrices with equal size. 
Definition: multimatrixchain.h:126
node_ind_t addNode()
Add new node with pattern matrix. 
Definition: multimatrixchain.h:258
Definition: maagforwardbackwardalgorithm.h:20
Simple matrix class. 
Definition: matrix.h:21
uint8_t node_ind_t
Node index type. 
Definition: multimatrixchain.h:91
seq_len_t dim_t
Type of dimensions of matrices (rows and columns). 
Definition: multimatrixchain.h:108
Class for storing lists of matrices, where one node in the list (called "chain") could contain more t...
Definition: multimatrixchain.h:39
uint8_t matrix_ind_t
Matrix index type. 
Definition: multimatrixchain.h:99
Matrix< _Scalar, dim_t > matrix_t
Type of matrices in the chain. 
Definition: multimatrixchain.h:117