humoto
blockmatrix.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @copyright 2014-2017 INRIA. Licensed under the Apache License, Version 2.0.
5  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6 
7  @brief
8 */
9 
10 #pragma once
11 
12 /**
13  * @defgroup BlockMatrixOperators BlockMatrixOperators
14  * @brief Arithmetic operators for various block matrices
15  *
16  * @ingroup EigenTools
17  */
18 
19 namespace etools
20 {
21 #define EIGENTOOLS_CODE_GENERATOR(ClassName, MatrixType) \
22  template< int t_block_rows_num, \
23  int t_block_cols_num, \
24  MatrixSparsityType::Type t_sparsity_type> \
25  class EIGENTOOLS_VISIBILITY_ATTRIBUTE ClassName : \
26  public BlockMatrixBase<MatrixType, t_block_rows_num, t_block_cols_num, t_sparsity_type> \
27  {\
28  public:\
29  ClassName( MatrixType matrix,\
30  const std::ptrdiff_t block_rows_num = MatrixBlockSizeType::UNDEFINED,\
31  const std::ptrdiff_t block_cols_num = MatrixBlockSizeType::UNDEFINED)\
32  : BlockMatrixBase< MatrixType, \
33  t_block_rows_num, \
34  t_block_cols_num, \
35  t_sparsity_type>(matrix, block_rows_num, block_cols_num) {} \
36  };
37 
38 
39  /**
40  * @brief Provides block interface for arbitrary Matrix without copying it.
41  *
42  * @tparam t_block_rows_num number of rows in one block
43  * @tparam t_block_cols_num number of columns in one block
44  * @tparam t_sparsity_type sparsity type
45  */
47 
48  /// @copydoc ConstBlockMatrixInterface
50 #undef EIGENTOOLS_CODE_GENERATOR
51 
52 
53  // ===========================================================================
54  // ===========================================================================
55  // ===========================================================================
56 
57 
58 #define EIGENTOOLS_CODE_GENERATOR(class_name, sparsity_type) \
59  template< int t_block_rows_num,\
60  int t_block_cols_num>\
61  class EIGENTOOLS_VISIBILITY_ATTRIBUTE class_name \
62  : public BlockKroneckerProductBase< const DefaultDynamicMatrix &, \
63  t_block_rows_num, \
64  t_block_cols_num, \
65  sparsity_type> \
66  {\
67  public:\
68  class_name( const DefaultDynamicMatrix & matrix, \
69  const std::ptrdiff_t identity_size = 1, \
70  const std::ptrdiff_t block_rows_num = MatrixBlockSizeType::UNDEFINED, \
71  const std::ptrdiff_t block_cols_num = MatrixBlockSizeType::UNDEFINED) \
72  : BlockKroneckerProductBase<const DefaultDynamicMatrix &, \
73  t_block_rows_num, \
74  t_block_cols_num, \
75  sparsity_type>( matrix, \
76  identity_size, \
77  block_rows_num, \
78  block_cols_num) {};\
79  };
80  /**
81  * @brief A shorthand class for a specific sparsity type.
82  *
83  * @tparam t_block_rows_num number of rows in one block
84  * @tparam t_block_cols_num number of columns in one block
85  */
87  /// @copydoc GenericBlockMatrix
89  /// @copydoc GenericBlockMatrix
91 #undef EIGENTOOLS_CODE_GENERATOR
92 
93 
94  // ===========================================================================
95  // ===========================================================================
96  // ===========================================================================
97 
98 
99 #define EIGENTOOLS_PARENT_CLASS_SHORTHAND BlockMatrixBase< const Eigen::Map< const EIGENTOOLS_DYNAMIC_MATRIX(t_Scalar),\
100  t_alignment, \
101  t_Stride >, \
102  t_block_rows_num, t_block_cols_num, t_sparsity_type>
103  /**
104  * @brief Blocked access to an Eigen::Map. Quick hack -- use with care.
105  *
106  * @tparam t_block_rows_num number of rows in one block
107  * @tparam t_block_cols_num number of columns in one block
108  * @tparam t_sparsity_type sparsity type
109  */
110  template< typename t_Scalar,
111  int t_alignment,
112  class t_Stride,
113  int t_block_rows_num,
114  int t_block_cols_num,
115  MatrixSparsityType::Type t_sparsity_type>
117  {
118  protected:
119  using EIGENTOOLS_PARENT_CLASS_SHORTHAND::matrix_;
120  using EIGENTOOLS_PARENT_CLASS_SHORTHAND::block_rows_num_;
121  using EIGENTOOLS_PARENT_CLASS_SHORTHAND::block_cols_num_;
122 
123 
124  public:
125  typedef typename EIGENTOOLS_PARENT_CLASS_SHORTHAND::DecayedRawMatrix DecayedRawMatrix;
126 
128 
129 
130 
131  /**
132  * @brief Get block Kronecker product of this matrix
133  *
134  * @param[in] identity_size
135  *
136  * @return block Kronecker product
137  */
139  const Eigen::Map< const EIGENTOOLS_DYNAMIC_MATRIX(t_Scalar),
140  t_alignment,
141  t_Stride >,
142  t_block_rows_num,
143  t_block_cols_num,
144  t_sparsity_type>
145  getBlockKroneckerProduct (const std::ptrdiff_t identity_size) const
146  {
148  const Eigen::Map< const EIGENTOOLS_DYNAMIC_MATRIX(t_Scalar),
149  t_alignment,
150  t_Stride >,
151  t_block_rows_num,
152  t_block_cols_num,
153  t_sparsity_type> ( matrix_,
154  identity_size,
155  ((t_block_rows_num > 0) ? MatrixBlockSizeType::UNDEFINED : block_rows_num_),
156  ((t_block_cols_num > 0) ? MatrixBlockSizeType::UNDEFINED : block_cols_num_)));
157  }
158  };
159 #undef EIGENTOOLS_PARENT_CLASS_SHORTHAND
160 
161 
162  // ===========================================================================
163  // ===========================================================================
164  // ===========================================================================
165 
166 
167 #define EIGENTOOLS_PARENT_CLASS_SHORTHAND BlockMatrixBase<DefaultDynamicMatrix, t_block_rows_num, t_block_cols_num, t_sparsity_type>
168  /**
169  * @brief Block matrix, the raw matrix is stored inside (not a reference).
170  *
171  * @tparam t_block_rows_num number of rows in one block
172  * @tparam t_block_cols_num number of columns in one block
173  * @tparam t_sparsity_type sparsity type
174  */
175  template< int t_block_rows_num,
176  int t_block_cols_num,
177  MatrixSparsityType::Type t_sparsity_type>
179  {
180  protected:
181  using EIGENTOOLS_PARENT_CLASS_SHORTHAND::matrix_;
182  using EIGENTOOLS_PARENT_CLASS_SHORTHAND::block_rows_num_;
183  using EIGENTOOLS_PARENT_CLASS_SHORTHAND::block_cols_num_;
184 
185 
186  public:
187  typedef typename EIGENTOOLS_PARENT_CLASS_SHORTHAND::DecayedRawMatrix DecayedRawMatrix;
188 
190 
191 
192  typedef BlockMatrixMap< DefaultScalar,
193  Eigen::Unaligned,
194  Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>,
195  1,
196  t_block_cols_num,
197  t_sparsity_type> SelectionMap;
198 
199 
200  SelectionMap selectRowInBlocks(const std::ptrdiff_t row_in_a_block)
201  {
202  return (SelectionMap(etools::selectRows(matrix_,
204  row_in_a_block),
206  ((t_block_rows_num > 0) ? MatrixBlockSizeType::UNDEFINED : block_rows_num_)));
207  }
208 
209 
210 
211  /**
212  * @brief Get block Kronecker product of this matrix
213  *
214  * @param[in] identity_size
215  *
216  * @return block Kronecker product
217  */
219  const DecayedRawMatrix &,
220  t_block_rows_num,
221  t_block_cols_num,
222  t_sparsity_type>
223  getBlockKroneckerProduct (const std::ptrdiff_t identity_size) const
224  {
226  const DecayedRawMatrix &,
227  t_block_rows_num,
228  t_block_cols_num,
229  t_sparsity_type> ( matrix_,
230  identity_size,
231  ((t_block_rows_num > 0) ? MatrixBlockSizeType::UNDEFINED : block_rows_num_),
232  ((t_block_cols_num > 0) ? MatrixBlockSizeType::UNDEFINED : block_cols_num_)));
233  }
234  };
235 #undef EIGENTOOLS_PARENT_CLASS_SHORTHAND
236 
237 
238  // ===========================================================================
239  // ===========================================================================
240  // ===========================================================================
241 
242 #define EIGENTOOLS_CODE_GENERATOR(class_name, sparsity_type) \
243  template< int t_block_rows_num,\
244  int t_block_cols_num>\
245  class EIGENTOOLS_VISIBILITY_ATTRIBUTE class_name : public BlockMatrix<t_block_rows_num, t_block_cols_num, sparsity_type> \
246  {\
247  public:\
248  class_name( const std::ptrdiff_t block_rows_num = MatrixBlockSizeType::UNDEFINED, \
249  const std::ptrdiff_t block_cols_num = MatrixBlockSizeType::UNDEFINED) \
250  : BlockMatrix<t_block_rows_num, t_block_cols_num, sparsity_type>(block_rows_num, block_cols_num) {};\
251  class_name( const DefaultDynamicMatrix & matrix, \
252  const std::ptrdiff_t block_rows_num = MatrixBlockSizeType::UNDEFINED, \
253  const std::ptrdiff_t block_cols_num = MatrixBlockSizeType::UNDEFINED) \
254  : BlockMatrix<t_block_rows_num, t_block_cols_num, sparsity_type>(matrix, block_rows_num, block_cols_num) {};\
255  class_name( DefaultDynamicMatrix & matrix, \
256  const std::ptrdiff_t block_rows_num = MatrixBlockSizeType::UNDEFINED, \
257  const std::ptrdiff_t block_cols_num = MatrixBlockSizeType::UNDEFINED) \
258  : BlockMatrix<t_block_rows_num, t_block_cols_num, sparsity_type>(matrix, block_rows_num, block_cols_num) {};\
259  };
260  /**
261  * @brief A shorthand class for a specific sparsity type.
262  *
263  * @tparam t_block_rows_num number of rows in one block
264  * @tparam t_block_cols_num number of columns in one block
265  */
267  /// @copydoc GenericBlockMatrix
269  /// @copydoc GenericBlockMatrix
271 #undef EIGENTOOLS_CODE_GENERATOR
272 
273 } // etools
BlockKroneckerProductBase< const DecayedRawMatrix &, t_block_rows_num, t_block_cols_num, t_sparsity_type > getBlockKroneckerProduct(const std::ptrdiff_t identity_size) const
Get block Kronecker product of this matrix.
Definition: blockmatrix.h:223
Eigen::Matrix< etools::DefaultScalar, Eigen::Dynamic, Eigen::Dynamic > DefaultDynamicMatrix
Definition: eigentools.h:42
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:270
Blocked access to an Eigen::Map. Quick hack – use with care.
Definition: blockmatrix.h:116
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:90
Provides block interface for arbitrary Matrix without copying it.
Definition: blockmatrix.h:46
Block matrix, the raw matrix is stored inside (not a reference).
Definition: blockmatrix.h:178
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:268
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:88
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:86
#define EIGENTOOLS_VISIBILITY_ATTRIBUTE
Definition: eigentools.h:21
#define EIGENTOOLS_DEFINE_BLOCK_MATRIX_CONSTRUCTORS(class_name)
Eigen::Map< const Eigen::Matrix< typename Eigen::PlainObjectBase< t_Derived >::Scalar, Eigen::Dynamic, Eigen::Dynamic >, Eigen::Unaligned, Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > > EIGENTOOLS_VISIBILITY_ATTRIBUTE selectRows(const Eigen::PlainObjectBase< t_Derived > &matrix, const std::size_t row_step, const std::size_t first_row=0)
Select rows from a matrix, in Matlab notation the result is M(first:step:end, :). ...
Definition: eigentools.h:763
double DefaultScalar
Definition: eigentools.h:38
A shorthand class for a specific sparsity type.
Definition: blockmatrix.h:266
SelectionMap selectRowInBlocks(const std::ptrdiff_t row_in_a_block)
Definition: blockmatrix.h:200
BlockKroneckerProductBase< const Eigen::Map< const EIGENTOOLS_DYNAMIC_MATRIX(t_Scalar), t_alignment, t_Stride >, t_block_rows_num, t_block_cols_num, t_sparsity_type > getBlockKroneckerProduct(const std::ptrdiff_t identity_size) const
Get block Kronecker product of this matrix.
Definition: blockmatrix.h:145
BlockMatrixBase< const Eigen::Map< const EIGENTOOLS_DYNAMIC_MATRIX(t_Scalar), t_alignment, t_Stride >, t_block_rows_num, t_block_cols_num, t_sparsity_type >::DecayedRawMatrix DecayedRawMatrix
Definition: blockmatrix.h:125
#define EIGENTOOLS_DYNAMIC_MATRIX(Scalar)
Definition: eigentools.h:46
BlockMatrixBase< DefaultDynamicMatrix, t_block_rows_num, t_block_cols_num, t_sparsity_type >::DecayedRawMatrix DecayedRawMatrix
Definition: blockmatrix.h:187
#define EIGENTOOLS_PARENT_CLASS_SHORTHAND
Definition: blockmatrix.h:167
#define EIGENTOOLS_CODE_GENERATOR(ClassName, MatrixType)
Definition: blockmatrix.h:242
This namespace contains various functions operating on Eigen matrices and vectors.
Definition: blockmatrix.h:19
Sparsity type of a matrix.
#define EIGENTOOLS_BLOCKMATRIX_BLOCK_ROWS_NUM
Provides block interface for arbitrary Matrix without copying it.
Definition: blockmatrix.h:49
Represents block kronecker product "Identity(size) [X] Matrix".
BlockMatrixMap< DefaultScalar, Eigen::Unaligned, Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic >, 1, t_block_cols_num, t_sparsity_type > SelectionMap
Definition: blockmatrix.h:197