MatrixExpression.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: MatrixExpression.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Base class for matrix expression.
6 > Created Time: 2017/09/27
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_MATRIX_EXPRESSION_H
10 #define CUBBYFLOW_MATRIX_EXPRESSION_H
11 
12 #include <Core/Size/Size2.h>
14 
15 namespace CubbyFlow
16 {
17  // MARK: MatrixExpression
26  template <typename T, typename E>
28  {
29  public:
31  Size2 size() const;
32 
34  size_t Rows() const;
35 
37  size_t Cols() const;
38 
40  const E& operator()() const;
41  };
42 
50  template <typename T>
51  class MatrixConstant : public MatrixExpression<T, MatrixConstant<T>>
52  {
53  public:
55  MatrixConstant(size_t m, size_t n, const T& c);
56 
58  Size2 size() const;
59 
61  size_t Rows() const;
62 
64  size_t Cols() const;
65 
67  T operator()(size_t i, size_t j) const;
68 
69  private:
70  size_t m_m;
71  size_t m_n;
72  T m_c;
73  };
74 
82  template <typename T>
83  class MatrixIdentity : public MatrixExpression<T, MatrixIdentity<T>>
84  {
85  public:
87  MatrixIdentity(size_t m);
88 
90  Size2 size() const;
91 
93  size_t Rows() const;
94 
96  size_t Cols() const;
97 
99  T operator()(size_t i, size_t j) const;
100 
101  private:
102  size_t m_m;
103  };
104 
105  // MARK: MatrixUnaryOp
116  template <typename T, typename E, typename Op>
117  class MatrixUnaryOp : public MatrixExpression<T, MatrixUnaryOp<T, E, Op>>
118  {
119  public:
121  MatrixUnaryOp(const E& u);
122 
124  Size2 size() const;
125 
127  size_t Rows() const;
128 
130  size_t Cols() const;
131 
133  T operator()(size_t i, size_t j) const;
134 
135  private:
136  const E& m_u;
137  Op m_op;
138  };
139 
148  template <typename T, typename E>
149  class MatrixDiagonal : public MatrixExpression<T, MatrixDiagonal<T, E>>
150  {
151  public:
154  MatrixDiagonal(const E& u, bool isDiag);
155 
157  Size2 size() const;
158 
160  size_t Rows() const;
161 
163  size_t Cols() const;
164 
166  T operator()(size_t i, size_t j) const;
167 
168  private:
169  const E& m_u;
170  bool m_isDiag;
171  };
172 
181  template <typename T, typename E>
182  class MatrixTriangular : public MatrixExpression<T, MatrixTriangular<T, E>>
183  {
184  public:
188  MatrixTriangular(const E& u, bool isUpper, bool isStrict);
189 
191  Size2 size() const;
192 
194  size_t Rows() const;
195 
197  size_t Cols() const;
198 
200  T operator()(size_t i, size_t j) const;
201 
202  private:
203  const E& m_u;
204  bool m_isUpper;
205  bool m_isStrict;
206  };
207 
208  // MARK: MatrixUnaryOp Aliases
210  template <typename T, typename E, typename U>
212 
213  // MARK: MatrixBinaryOp
225  template <typename T, typename E1, typename E2, typename Op>
226  class MatrixBinaryOp : public MatrixExpression<T, MatrixBinaryOp<T, E1, E2, Op>>
227  {
228  public:
230  MatrixBinaryOp(const E1& u, const E2& v);
231 
233  Size2 size() const;
234 
236  size_t Rows() const;
237 
239  size_t Cols() const;
240 
242  T operator()(size_t i, size_t j) const;
243 
244  private:
245  const E1& m_u;
246  const E2& m_v;
247  Op m_op;
248  };
249 
260  template <typename T, typename E, typename Op>
261  class MatrixScalarBinaryOp : public MatrixExpression<T, MatrixScalarBinaryOp<T, E, Op>>
262  {
263  public:
265  MatrixScalarBinaryOp(const E& u, const T& v);
266 
268  Size2 size() const;
269 
271  size_t Rows() const;
272 
274  size_t Cols() const;
275 
277  T operator()(size_t i, size_t j) const;
278 
279  private:
280  const E& m_u;
281  T m_v;
282  Op m_op;
283  };
284 
295  template <typename T, typename ME, typename VE>
296  class MatrixVectorMul : public VectorExpression<T, MatrixVectorMul<T, ME, VE>>
297  {
298  public:
299  MatrixVectorMul(const ME& m, const VE& v);
300 
302  size_t size() const;
303 
305  T operator[](size_t i) const;
306 
307  private:
308  const ME& m_m;
309  const VE& m_v;
310  };
311 
322  template <typename T, typename E1, typename E2>
323  class MatrixMul : public MatrixExpression<T, MatrixMul<T, E1, E2>>
324  {
325  public:
327  MatrixMul(const E1& u, const E2& v);
328 
330  Size2 size() const;
331 
333  size_t Rows() const;
334 
336  size_t Cols() const;
337 
339  T operator()(size_t i, size_t j) const;
340 
341  private:
342  const E1& m_u;
343  const E2& m_v;
344  };
345 
346  // MARK: MatrixBinaryOp Aliases
348  template <typename T, typename E1, typename E2>
350 
352  template <typename T, typename E>
354 
356  template <typename T, typename E1, typename E2>
358 
360  template <typename T, typename E>
362 
364  template <typename T, typename E>
366 
368  template <typename T, typename E>
370 
372  template <typename T, typename E>
374 
376  template <typename T, typename E>
378 
379  // MARK: Operator overloadings
381  template <typename T, typename E>
383 
385  template <typename T, typename E1, typename E2>
387 
389  template <typename T, typename E>
391 
393  template <typename T, typename E>
395 
397  template <typename T, typename E1, typename E2>
399 
401  template <typename T, typename E>
403 
405  template <typename T, typename E>
407 
409  template <typename T, typename E>
411 
413  template <typename T, typename E>
415 
417  template <typename T, typename ME, typename VE>
419 
421  template <typename T, typename E1, typename E2>
423 
425  template <typename T, typename E>
427 
429  template <typename T, typename E>
431 }
432 
434 
435 #endif
MatrixBinaryOp(const E1 &u, const E2 &v)
Constructs binary operation expression for given input matrix expressions.
Definition: MatrixExpression-Impl.h:208
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:113
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:149
size_t size() const
Size of the vector.
Definition: MatrixExpression-Impl.h:275
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:185
Matrix< T, 2, 2 > operator+(const Matrix< T, 2, 2 > &a, const Matrix< T, 2, 2 > &b)
Returns a + b (element-size).
Definition: Matrix2x2-Impl.h:660
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:179
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:257
Matrix expression for matrix-scalar binary operation.
Definition: MatrixExpression.h:261
Base class for vector expression.
Definition: VectorExpression.h:28
MatrixIdentity(size_t m)
Constructs m x m identity matrix expression.
Definition: MatrixExpression-Impl.h:70
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:52
MatrixUnaryOp(const E &u)
Constructs unary operation expression for given input expression.
Definition: MatrixExpression-Impl.h:101
Matrix expression for unary operation.
Definition: MatrixExpression.h:117
Vector expression for matrix-vector multiplication.
Definition: MatrixExpression.h:296
2-D point class.
Definition: Point2.h:25
Identity matrix expression.
Definition: MatrixExpression.h:83
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:214
T operator[](size_t i) const
Returns vector element at i.
Definition: MatrixExpression-Impl.h:281
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:220
Triangular matrix expression.
Definition: MatrixExpression.h:182
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:308
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:119
Matrix< T, 2, 2 > operator/(const Matrix< T, 2, 2 > &a, T b)
Definition: Matrix2x2-Impl.h:720
Definition: pybind11Utils.h:24
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:46
MatrixTriangular(const E &u, bool isUpper, bool isStrict)
Definition: MatrixExpression-Impl.h:166
MatrixVectorMul(const ME &m, const VE &v)
Definition: MatrixExpression-Impl.h:269
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:88
MatrixConstant(size_t m, size_t n, const T &c)
Constructs m x n constant matrix expression.
Definition: MatrixExpression-Impl.h:40
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:16
MatrixScalarBinaryOp(const E &u, const T &v)
Constructs a binary expression for given matrix and scalar.
Definition: MatrixExpression-Impl.h:239
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:251
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:22
Matrix< T, 2, 2 > operator-(const Matrix< T, 2, 2 > &a)
Returns a matrix with opposite sign.
Definition: Matrix2x2-Impl.h:654
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:302
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:76
const E & operator()() const
Returns actual implementation (the subclass).
Definition: MatrixExpression-Impl.h:34
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:245
Base class for matrix expression.
Definition: MatrixExpression.h:27
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:137
Diagonal matrix expression.
Definition: MatrixExpression.h:149
Constant matrix expression.
Definition: MatrixExpression.h:51
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:82
MatrixMul(const E1 &u, const E2 &v)
Constructs matrix-matrix multiplication expression for given two input matrices.
Definition: MatrixExpression-Impl.h:296
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:58
MatrixDiagonal(const E &u, bool isDiag)
Definition: MatrixExpression-Impl.h:131
Vector< T, 3 > operator*(const Quaternion< T > &q, const Vector< T, 3 > &v)
Returns quaternion q * vector v.
Definition: Quaternion-Impl.h:481
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:173
Matrix expression for binary operation.
Definition: MatrixExpression.h:226
Size2 size() const
Size of the matrix.
Definition: MatrixExpression-Impl.h:107
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:28
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:226
size_t Rows() const
Number of rows.
Definition: MatrixExpression-Impl.h:143
size_t Cols() const
Number of columns.
Definition: MatrixExpression-Impl.h:314
Matrix expression for matrix-matrix multiplication.
Definition: MatrixExpression.h:323