Go to the documentation of this file.
7 #ifndef INCLUDE_JET_MATRIX_H_
8 #define INCLUDE_JET_MATRIX_H_
14 #include <type_traits>
28 template <
typename T,
size_t M,
size_t N>
33 "Number of rows for static-sized matrix should be greater than zero.");
36 "Number of columns for static-sized matrix should be greater than "
38 static_assert(!(M == 2 && N == 2) && !(M == 3 && N == 3) &&
40 "Use specialized matrix for 2z2, 3x3, and 4x4 matricies.");
41 static_assert(std::is_floating_point<T>::value,
42 "Matrix only can be instantiated with floating point types");
45 typedef typename ContainerType::iterator
Iterator;
53 template <
typename... Params>
72 Matrix(
const std::initializer_list<std::initializer_list<T>>& lst);
84 void resize(
size_t m,
size_t n,
const T& s = T(0));
106 void set(
const std::initializer_list<std::initializer_list<T>>& lst);
109 template <
typename E>
119 template <
typename E>
123 template <
typename E>
127 template <
typename E>
132 template <
typename E>
134 double tol = std::numeric_limits<double>::epsilon())
const;
172 template <
typename E>
179 template <
typename E>
186 template <
typename VE>
201 template <
typename E>
208 template <
typename E>
227 template <
typename E>
234 template <
typename E>
241 template <
typename E>
309 template <
typename U>
315 template <
typename E>
325 template <
typename E>
332 template <
typename E>
339 template <
typename E>
360 template <
typename E>
364 template <
typename E>
395 template <
typename Callback>
424 template <
typename Callback>
439 template <
typename... Params>
440 void setRowAt(
size_t i, T v, Params... params);
441 void setRowAt(
size_t i, T v);
446 #include "detail/matrix-inl.h"
448 #endif // INCLUDE_JET_MATRIX_H_
Matrix(const std::initializer_list< std::initializer_list< T >> &lst)
Constructs a matrix with given initializer list lst.
ConstIterator begin() const
Returns the begin const iterator of the matrix.
Iterator end()
Returns the end iterator of the matrix.
T determinant() const
Returns determinant of this matrix.
void setOffDiagonal(const T &s)
Sets off-diagonal elements with input scalar.
constexpr Size2 size() const
Returns the size of this matrix.
Base class for vector expression.
Definition: vector_expression.h:25
T absmin() const
Returns absolute minimum among all elements.
void set(const T &s)
Sets whole matrix with input scalar.
Matrix & operator*=(const T &s)
Multiplication assignment with input scalar.
T sum() const
Returns sum of all elements.
void setRow(size_t i, const VectorExpression< T, E > &row)
Sets i-th row with input vector.
Static-sized M x N matrix class.
Definition: matrix.h:29
MatrixSub< T, Matrix, E > sub(const E &m) const
Returns this matrix - input matrix (element-wise).
ContainerType::iterator Iterator
Definition: matrix.h:45
Matrix(const Matrix &other)
Copy constructor.
Matrix & operator*=(const E &m)
Multiplication assignment with input matrix.
Constant matrix expression.
Definition: matrix_expression.h:49
MatrixTypeCast< U, Matrix, T > castTo() const
constexpr size_t cols() const
Returns number of columns of this matrix.
T * data()
Returns data pointer of this matrix.
MatrixTriangular< T, Matrix > strictLowerTri() const
Returns strictly lower triangle part of this matrix.
Vector expression for matrix-vector multiplication.
Definition: matrix_expression.h:295
Matrix expression for binary operation.
Definition: matrix_expression.h:225
void resize(size_t m, size_t n, const T &s=T(0))
Resizes to m x n matrix with initial value s.
MatrixMul< T, Matrix< T, N, L >, Matrix > rmul(const Matrix< T, N, L > &m) const
Returns input matrix * this matrix.
T & operator[](size_t i)
Returns reference of i-th element.
Matrix(const MatrixExpression< T, E > &other)
Constructs a matrix with expression template.
Iterator begin()
Returns the begin iterator of the matrix.
void transpose()
Transposes this matrix.
MatrixAdd< T, Matrix, E > radd(const E &m) const
Returns input matrix + this matrix (element-wise).
Matrix & operator-=(const E &m)
Subtraction assignment with input matrix (element-wise).
void set(const std::initializer_list< std::initializer_list< T >> &lst)
Sets a matrix with given initializer list lst.
bool isEqual(const MatrixExpression< T, E > &other) const
constexpr size_t rows() const
Returns number of rows of this matrix.
Matrix< T, N, M > transposed() const
Returns transposed matrix.
ConstIterator end() const
Returns the end const iterator of the matrix.
ContainerType::const_iterator ConstIterator
Definition: matrix.h:46
const T *const data() const
Returns constant pointer of this matrix.
static MatrixConstant< T > makeZero()
Makes a M x N matrix with zeros.
T & operator()(size_t i, size_t j)
Returns reference of (i,j) element.
void isub(const E &m)
Subtracts input matrix from this matrix (element-wise).
void iadd(const E &m)
Adds input matrix to this matrix (element-wise).
void set(const MatrixExpression< T, E > &other)
Copies from input matrix expression.
MatrixDiagonal< T, Matrix > diagonal() const
Returns diagonal part of this matrix.
Definition: advection_solver2.h:18
void imul(const T &s)
Multiplies input scalar to this matrix.
void idiv(const T &s)
Divides this matrix with input scalar.
void isub(const T &s)
Subtracts input scalar from this matrix.
Base class for matrix expression.
Definition: matrix_expression.h:26
Matrix(Params... params)
Constructs matrix instance with parameters.
Matrix & operator+=(const E &m)
Addition assignment with input matrix (element-wise).
Matrix inverse() const
Returns inverse matrix.
void iadd(const T &s)
Adds input scalar to this matrix.
const T & operator()(size_t i, size_t j) const
Returns constant reference of (i,j) element.
MatrixScalarAdd< T, Matrix > add(const T &s) const
Returns this matrix + input scalar.
MatrixMul< T, Matrix, Matrix< T, N, L > > mul(const Matrix< T, N, L > &m) const
Returns this matrix * input matrix.
const T & operator[](size_t i) const
Returns constant reference of i-th element.
Matrix expression for matrix-scalar binary operation.
Definition: matrix_expression.h:261
bool isSimilar(const MatrixExpression< T, E > &other, double tol=std::numeric_limits< double >::epsilon()) const
MatrixScalarRDiv< T, Matrix > rdiv(const T &s) const
Returns input matrix / this scalar.
MatrixVectorMul< T, Matrix, VE > mul(const VectorExpression< T, VE > &v) const
Returns this matrix * input vector.
void setDiagonal(const T &s)
Sets diagonal elements with input scalar.
Matrix & operator/=(const T &s)
Division assignment with input scalar.
MatrixScalarMul< T, Matrix > mul(const T &s) const
Returns this matrix * input scalar.
MatrixAdd< T, Matrix, E > add(const E &m) const
Returns this matrix + input matrix (element-wise).
T min() const
Returns minimum among all elements.
void invert()
Inverts this matrix.
constexpr bool isSquare() const
Returns true if this matrix is a square matrix.
void forEachIndex(Callback func) const
Iterates the matrix and invoke given func for each index.
Matrix & operator-=(const T &s)
Subtraction assignment with input scalar.
void forEach(Callback func) const
Iterates the matrix and invoke given func for each index.
Identity matrix expression.
Definition: matrix_expression.h:80
bool operator==(const MatrixExpression< T, E > &m) const
Returns true if is equal to m.
MatrixDiagonal< T, Matrix > offDiagonal() const
Returns off-diagonal part of this matrix.
MatrixScalarSub< T, Matrix > sub(const T &s) const
Returns this matrix - input scalar.
Matrix & operator=(const Matrix &other)
Copies to this matrix.
MatrixTriangular< T, Matrix > strictUpperTri() const
Returns strictly upper triangle part of this matrix.
2-D size class.
Definition: size2.h:19
MatrixTriangular< T, Matrix > upperTri() const
Returns upper triangle part of this matrix (including the diagonal).
bool operator!=(const MatrixExpression< T, E > &m) const
Returns true if is not equal to m.
Triangular matrix expression.
Definition: matrix_expression.h:179
Matrix & operator+=(const T &s)
Addition assignment with input scalar.
void imul(const E &m)
Multiplies input matrix to this matrix.
void setColumn(size_t j, const VectorExpression< T, E > &col)
Sets j-th column with input vector.
Matrix expression for matrix-matrix multiplication.
Definition: matrix_expression.h:321
MatrixScalarAdd< T, Matrix > radd(const T &s) const
Returns input scalar + this matrix.
MatrixTriangular< T, Matrix > lowerTri() const
Returns lower triangle part of this matrix (including the diagonal).
Diagonal matrix expression.
Definition: matrix_expression.h:146
std::array< T, M *N > ContainerType
Definition: matrix.h:33
Matrix & operator=(const E &m)
Assigns input matrix.
Matrix expression for unary operation.
Definition: matrix_expression.h:114
static MatrixIdentity< T > makeIdentity()
MatrixScalarMul< T, Matrix > rmul(const T &s) const
Returns input scalar * this matrix.
T absmax() const
Returns absolute maximum among all elements.
MatrixScalarDiv< T, Matrix > div(const T &s) const
Returns this matrix / input scalar.
T avg() const
Returns average of all elements.
MatrixSub< T, Matrix, E > rsub(const E &m) const
Returns input matrix - this matrix (element-wise).
T max() const
Returns maximum among all elements.
MatrixScalarRSub< T, Matrix > rsub(const T &s) const
Returns input scalar - this matrix.