Jet  v1.3.3
matrix_expression.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_MATRIX_EXPRESSION_H_
8 #define INCLUDE_JET_MATRIX_EXPRESSION_H_
9 
10 #include <jet/size2.h>
11 #include <jet/vector_expression.h>
12 
13 namespace jet {
14 
15 // MARK: MatrixExpression
16 
25 template <typename T, typename E>
27  public:
29  Size2 size() const;
30 
32  size_t rows() const;
33 
35  size_t cols() const;
36 
38  const E& operator()() const;
39 };
40 
48 template <typename T>
49 class MatrixConstant : public MatrixExpression<T, MatrixConstant<T>> {
50  public:
52  MatrixConstant(size_t m, size_t n, const T& c);
53 
55  Size2 size() const;
56 
58  size_t rows() const;
59 
61  size_t cols() const;
62 
64  T operator()(size_t i, size_t j) const;
65 
66  private:
67  size_t _m;
68  size_t _n;
69  T _c;
70 };
71 
79 template <typename T>
80 class MatrixIdentity : public MatrixExpression<T, MatrixIdentity<T>> {
81  public:
83  MatrixIdentity(size_t m);
84 
86  Size2 size() const;
87 
89  size_t rows() const;
90 
92  size_t cols() const;
93 
95  T operator()(size_t i, size_t j) const;
96 
97  private:
98  size_t _m;
99 };
100 
101 // MARK: MatrixUnaryOp
102 
113 template <typename T, typename E, typename Op>
114 class MatrixUnaryOp : public MatrixExpression<T, MatrixUnaryOp<T, E, Op>> {
115  public:
117  MatrixUnaryOp(const E& u);
118 
120  Size2 size() const;
121 
123  size_t rows() const;
124 
126  size_t cols() const;
127 
129  T operator()(size_t i, size_t j) const;
130 
131  private:
132  const E& _u;
133  Op _op;
134 };
135 
145 template <typename T, typename E>
146 class MatrixDiagonal : public MatrixExpression<T, MatrixDiagonal<T, E>> {
147  public:
150  MatrixDiagonal(const E& u, bool isDiag);
151 
153  Size2 size() const;
154 
156  size_t rows() const;
157 
159  size_t cols() const;
160 
162  T operator()(size_t i, size_t j) const;
163 
164  private:
165  const E& _u;
166  bool _isDiag;
167 };
168 
178 template <typename T, typename E>
179 class MatrixTriangular : public MatrixExpression<T, MatrixTriangular<T, E>> {
180  public:
184  MatrixTriangular(const E& u, bool isUpper, bool isStrict);
185 
187  Size2 size() const;
188 
190  size_t rows() const;
191 
193  size_t cols() const;
194 
196  T operator()(size_t i, size_t j) const;
197 
198  private:
199  const E& _u;
200  bool _isUpper;
201  bool _isStrict;
202 };
203 
204 // MARK: MatrixUnaryOp Aliases
205 
207 template <typename T, typename E, typename U>
209 
210 // MARK: MatrixBinaryOp
211 
223 template <typename T, typename E1, typename E2, typename Op>
225  : public MatrixExpression<T, MatrixBinaryOp<T, E1, E2, Op>> {
226  public:
229  MatrixBinaryOp(const E1& u, const E2& v);
230 
232  Size2 size() const;
233 
235  size_t rows() const;
236 
238  size_t cols() const;
239 
241  T operator()(size_t i, size_t j) const;
242 
243  private:
244  const E1& _u;
245  const E2& _v;
246  Op _op;
247 };
248 
259 template <typename T, typename E, typename Op>
261  : public MatrixExpression<T, MatrixScalarBinaryOp<T, E, Op>> {
262  public:
264  MatrixScalarBinaryOp(const E& u, const T& v);
265 
267  Size2 size() const;
268 
270  size_t rows() const;
271 
273  size_t cols() const;
274 
276  T operator()(size_t i, size_t j) const;
277 
278  private:
279  const E& _u;
280  T _v;
281  Op _op;
282 };
283 
294 template <typename T, typename ME, typename VE>
295 class MatrixVectorMul : public VectorExpression<T, MatrixVectorMul<T, ME, VE>> {
296  public:
297  MatrixVectorMul(const ME& m, const VE& v);
298 
300  size_t size() const;
301 
303  T operator[](size_t i) const;
304 
305  private:
306  const ME& _m;
307  const VE& _v;
308 };
309 
320 template <typename T, typename E1, typename E2>
321 class MatrixMul : public MatrixExpression<T, MatrixMul<T, E1, E2>> {
322  public:
325  MatrixMul(const E1& u, const E2& v);
326 
328  Size2 size() const;
329 
331  size_t rows() const;
332 
334  size_t cols() const;
335 
337  T operator()(size_t i, size_t j) const;
338 
339  private:
340  const E1& _u;
341  const E2& _v;
342 };
343 
344 // MARK: MatrixBinaryOp Aliases
345 
347 template <typename T, typename E1, typename E2>
349 
351 template <typename T, typename E>
353 
355 template <typename T, typename E1, typename E2>
357 
359 template <typename T, typename E>
361 
363 template <typename T, typename E>
365 
367 template <typename T, typename E>
369 
371 template <typename T, typename E>
373 
375 template <typename T, typename E>
377 
378 // MARK: Operator overloadings
379 
381 template <typename T, typename E>
383 
385 template <typename T, typename E1, typename E2>
387  const MatrixExpression<T, E2>& b);
388 
390 template <typename T, typename E>
392 
394 template <typename T, typename E>
396 
398 template <typename T, typename E1, typename E2>
400  const MatrixExpression<T, E2>& b);
401 
403 template <typename T, typename E>
405 
407 template <typename T, typename E>
409 
411 template <typename T, typename E>
413 
415 template <typename T, typename E>
417 
419 template <typename T, typename ME, typename VE>
421  const VectorExpression<T, VE>& b);
422 
424 template <typename T, typename E1, typename E2>
426  const MatrixExpression<T, E2>& b);
427 
429 template <typename T, typename E>
431 
433 template <typename T, typename E>
435 
436 } // namespace jet
437 
438 #include "detail/matrix_expression-inl.h"
439 
440 #endif // INCLUDE_JET_MATRIX_EXPRESSION_H_
jet::MatrixVectorMul::operator[]
T operator[](size_t i) const
Returns vector element at i.
jet::MatrixMul::size
Size2 size() const
Size of the matrix.
jet::VectorExpression
Base class for vector expression.
Definition: vector_expression.h:25
jet::MatrixUnaryOp::MatrixUnaryOp
MatrixUnaryOp(const E &u)
Constructs unary operation expression for given input expression.
jet::MatrixConstant::MatrixConstant
MatrixConstant(size_t m, size_t n, const T &c)
Constructs m x n constant matrix expression.
jet::MatrixExpression::operator()
const E & operator()() const
Returns actual implementation (the subclass).
jet::MatrixBinaryOp::rows
size_t rows() const
Number of rows.
jet::MatrixBinaryOp::cols
size_t cols() const
Number of columns.
jet::MatrixMul::operator()
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
jet::MatrixConstant
Constant matrix expression.
Definition: matrix_expression.h:49
jet::MatrixMul::rows
size_t rows() const
Number of rows.
jet::MatrixVectorMul
Vector expression for matrix-vector multiplication.
Definition: matrix_expression.h:295
jet::MatrixScalarBinaryOp::operator()
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
jet::MatrixBinaryOp
Matrix expression for binary operation.
Definition: matrix_expression.h:225
jet::MatrixTriangular::cols
size_t cols() const
Number of columns.
jet::MatrixDiagonal::rows
size_t rows() const
Number of rows.
size2.h
jet::MatrixUnaryOp::cols
size_t cols() const
Number of columns.
jet::MatrixVectorMul::size
size_t size() const
Size of the vector.
jet::MatrixConstant::size
Size2 size() const
Size of the matrix.
jet::MatrixExpression::size
Size2 size() const
Size of the matrix.
jet::MatrixBinaryOp::operator()
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
jet::MatrixDiagonal::MatrixDiagonal
MatrixDiagonal(const E &u, bool isDiag)
jet::MatrixConstant::operator()
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
jet
Definition: advection_solver2.h:18
jet::MatrixVectorMul::MatrixVectorMul
MatrixVectorMul(const ME &m, const VE &v)
vector_expression.h
jet::MatrixExpression
Base class for matrix expression.
Definition: matrix_expression.h:26
jet::MatrixScalarBinaryOp::MatrixScalarBinaryOp
MatrixScalarBinaryOp(const E &u, const T &v)
Constructs a binary expression for given matrix and scalar.
jet::MatrixDiagonal::size
Size2 size() const
Size of the matrix.
jet::MatrixTriangular::rows
size_t rows() const
Number of rows.
jet::MatrixScalarBinaryOp::cols
size_t cols() const
Number of columns.
jet::MatrixIdentity::MatrixIdentity
MatrixIdentity(size_t m)
Constructs m x m identity matrix expression.
jet::MatrixExpression::cols
size_t cols() const
Number of columns.
jet::MatrixMul::MatrixMul
MatrixMul(const E1 &u, const E2 &v)
jet::MatrixScalarBinaryOp
Matrix expression for matrix-scalar binary operation.
Definition: matrix_expression.h:261
jet::MatrixIdentity::size
Size2 size() const
Size of the matrix.
jet::operator+
Matrix2x2< T > operator+(const Matrix2x2< T > &a, const Matrix2x2< T > &b)
Returns a + b (element-size).
jet::MatrixMul::cols
size_t cols() const
Number of columns.
jet::MatrixTriangular::MatrixTriangular
MatrixTriangular(const E &u, bool isUpper, bool isStrict)
jet::MatrixIdentity
Identity matrix expression.
Definition: matrix_expression.h:80
jet::MatrixUnaryOp::operator()
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
jet::Size2
2-D size class.
Definition: size2.h:19
jet::MatrixIdentity::rows
size_t rows() const
Number of rows.
jet::MatrixTriangular
Triangular matrix expression.
Definition: matrix_expression.h:179
jet::MatrixIdentity::cols
size_t cols() const
Number of columns.
jet::MatrixConstant::cols
size_t cols() const
Number of columns.
jet::MatrixDiagonal::cols
size_t cols() const
Number of columns.
jet::MatrixMul
Matrix expression for matrix-matrix multiplication.
Definition: matrix_expression.h:321
jet::MatrixTriangular::operator()
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
jet::operator/
Matrix2x2< T > operator/(const Matrix2x2< T > &a, T b)
Returns a' / b, where every element of matrix a' is a.
jet::MatrixDiagonal
Diagonal matrix expression.
Definition: matrix_expression.h:146
jet::MatrixUnaryOp::rows
size_t rows() const
Number of rows.
jet::MatrixUnaryOp
Matrix expression for unary operation.
Definition: matrix_expression.h:114
jet::operator-
Matrix2x2< T > operator-(const Matrix2x2< T > &a)
Returns a matrix with opposite sign.
jet::MatrixScalarBinaryOp::rows
size_t rows() const
Number of rows.
jet::MatrixExpression::rows
size_t rows() const
Number of rows.
jet::MatrixBinaryOp::size
Size2 size() const
Size of the matrix.
jet::MatrixScalarBinaryOp::size
Size2 size() const
Size of the matrix.
jet::MatrixUnaryOp::size
Size2 size() const
Size of the matrix.
jet::operator*
Matrix2x2< T > operator*(const Matrix2x2< T > &a, T b)
Returns a * b', where every element of matrix b' is b.
jet::MatrixConstant::rows
size_t rows() const
Number of rows.
jet::MatrixTriangular::size
Size2 size() const
Size of the matrix.
jet::MatrixIdentity::operator()
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
jet::MatrixDiagonal::operator()
T operator()(size_t i, size_t j) const
Returns matrix element at (i, j).
jet::MatrixBinaryOp::MatrixBinaryOp
MatrixBinaryOp(const E1 &u, const E2 &v)