mu
matrix.h File Reference
#include <algorithm>
#include <array>
#include <cassert>
#include <type_traits>
#include <vector>
#include "mu/typetraits.h"
#include "mu/utility.h"
#include "vector.h"
Include dependency graph for matrix.h:

Go to the source code of this file.

Classes

class  mu::Matrix< N, M, T >
 A generic matrix. More...
 

Typedefs

template<std::size_t N, typename T >
using mu::MatrixNxN = Matrix< N, N, T >
 A symmetrical matrix. More...
 
template<typename T >
using mu::Matrix2x2 = Matrix< 2, 2, T >
 A 2x2 matrix. More...
 
template<typename T >
using mu::Matrix3x3 = Matrix< 3, 3, T >
 A 3x3 matrix. More...
 

Functions

template<std::size_t Nn, std::size_t Mm, class U >
std::ostream & mu::operator<< (std::ostream &os, const Matrix< Nn, Mm, U > &m)
 
template<std::size_t N, std::size_t M, class T , class U = T>
Matrix< N, M, T > mu::operator+ (const Matrix< N, M, T > &lhs, const Matrix< N, M, U > &rhs)
 plus operator More...
 
template<std::size_t N, std::size_t M, class T , class U = T>
Matrix< N, M, T > mu::operator- (const Matrix< N, M, T > &lhs, const Matrix< N, M, U > &rhs)
 minus operator More...
 
template<std::size_t N, std::size_t M, class T , class U = T>
Matrix< N, M, T > mu::operator* (const Matrix< N, M, T > &lhs, const Matrix< N, M, U > &rhs)
 multiplication operator More...
 
template<std::size_t N, std::size_t M, class T , class U = T>
Matrix< N, M, T > mu::operator/ (const Matrix< N, M, T > &lhs, const Matrix< N, M, U > &rhs)
 division operator More...
 
template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t< std::is_arithmetic< TScalar >::value, Matrix< N, M, T > > mu::operator+ (const Matrix< N, M, T > &lhs, const TScalar &rhs)
 matrix and scalar addition More...
 
template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t< std::is_arithmetic< TScalar >::value, Matrix< N, M, T > > mu::operator+ (const TScalar &lhs, const Matrix< N, M, T > &rhs)
 matrix and scalar addition More...
 
template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t< std::is_arithmetic< TScalar >::value, Matrix< N, M, T > > mu::operator- (const Matrix< N, M, T > &lhs, const TScalar &rhs)
 subtract a scalar from this matrix More...
 
template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t< std::is_arithmetic< TScalar >::value, Matrix< N, M, T > > mu::operator* (const Matrix< N, M, T > &lhs, const TScalar &rhs)
 matrix and scalar multiplication More...
 
template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t< std::is_arithmetic< TScalar >::value, Matrix< N, M, T > > mu::operator* (const TScalar &lhs, const Matrix< N, M, T > &rhs)
 matrix and scalar multiplication More...
 
template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t< std::is_arithmetic< TScalar >::value, Matrix< N, M, T > > mu::operator/ (const Matrix< N, M, T > &lhs, const TScalar &rhs)
 matrix and scalar division More...
 
template<std::size_t N, std::size_t M, class T >
mu::min (const Matrix< N, M, T > &m)
 
template<std::size_t N, std::size_t M, class T >
mu::max (const Matrix< N, M, T > &m)
 
template<std::size_t N, std::size_t M, class T >
mu::sum (const Matrix< N, M, T > &m)
 
template<class U = void, std::size_t N, std::size_t M, typename T >
std::conditional_t< std::is_same< U, void >::value, T, U > mu::mean (const Matrix< N, M, T > &m)
 

Detailed Description

Matrix class and free functions

Typedef Documentation

◆ Matrix2x2

template<typename T >
using mu::Matrix2x2 = typedef Matrix<2, 2, T>

A 2x2 matrix.

Template Parameters
T

◆ Matrix3x3

template<typename T >
using mu::Matrix3x3 = typedef Matrix<3, 3, T>

A 3x3 matrix.

Template Parameters
T

◆ MatrixNxN

template<std::size_t N, typename T >
using mu::MatrixNxN = typedef Matrix<N, N, T>

A symmetrical matrix.

Template Parameters
N
T

Function Documentation

◆ operator*() [1/3]

template<std::size_t N, std::size_t M, class T , class U = T>
Matrix<N, M, T> mu::operator* ( const Matrix< N, M, T > &  lhs,
const Matrix< N, M, U > &  rhs 
)
inline

multiplication operator

Template Parameters
N
M
T
U
Parameters
lhs
rhs
Returns
Matrix<N, M, T>
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator*() [2/3]

template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T> > mu::operator* ( const Matrix< N, M, T > &  lhs,
const TScalar &  rhs 
)
inline

matrix and scalar multiplication

see operator*=(scalar)

Template Parameters
N
T
TScalar
Parameters
lhs
rhs
Returns
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T>>
Here is the call graph for this function:

◆ operator*() [3/3]

template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T> > mu::operator* ( const TScalar &  lhs,
const Matrix< N, M, T > &  rhs 
)
inline

matrix and scalar multiplication

see operator*=(scalar)

Template Parameters
N
T
TScalar
Parameters
lhs
rhs
Returns
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T>>
Here is the call graph for this function:

◆ operator+() [1/3]

template<std::size_t N, std::size_t M, class T , class U = T>
Matrix<N, M, T> mu::operator+ ( const Matrix< N, M, T > &  lhs,
const Matrix< N, M, U > &  rhs 
)
inline

plus operator

Template Parameters
N
M
T
U
Parameters
lhs
rhs
Returns
Matrix<N, M, T>
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator+() [2/3]

template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T> > mu::operator+ ( const Matrix< N, M, T > &  lhs,
const TScalar &  rhs 
)
inline

matrix and scalar addition

see operator+=(scalar)

Template Parameters
N
T
TScalar
Parameters
lhs
rhs
Returns
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T>>
Here is the call graph for this function:

◆ operator+() [3/3]

template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T> > mu::operator+ ( const TScalar &  lhs,
const Matrix< N, M, T > &  rhs 
)
inline

matrix and scalar addition

see operator+=(scalar)

Template Parameters
N
T
TScalar
Parameters
lhs
rhs
Returns
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T>>
Here is the call graph for this function:

◆ operator-() [1/2]

template<std::size_t N, std::size_t M, class T , class U = T>
Matrix<N, M, T> mu::operator- ( const Matrix< N, M, T > &  lhs,
const Matrix< N, M, U > &  rhs 
)
inline

minus operator

Template Parameters
N
M
T
U
Parameters
lhs
rhs
Returns
Matrix<N, M, T>
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator-() [2/2]

template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T> > mu::operator- ( const Matrix< N, M, T > &  lhs,
const TScalar &  rhs 
)
inline

subtract a scalar from this matrix

Template Parameters
N
T
TScalar
Parameters
lhs
rhs
Returns
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T>>
Here is the call graph for this function:

◆ operator/() [1/2]

template<std::size_t N, std::size_t M, class T , class U = T>
Matrix<N, M, T> mu::operator/ ( const Matrix< N, M, T > &  lhs,
const Matrix< N, M, U > &  rhs 
)
inline

division operator

Template Parameters
N
M
T
U
Parameters
lhs
rhs
Returns
Matrix<N, M, T>
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator/() [2/2]

template<std::size_t N, std::size_t M, class T , class TScalar >
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T> > mu::operator/ ( const Matrix< N, M, T > &  lhs,
const TScalar &  rhs 
)
inline

matrix and scalar division

Template Parameters
N
T
TScalar
Parameters
lhs
rhs
Returns
std::enable_if_t<std::is_arithmetic<TScalar>::value, Matrix<N, M, T>>
Here is the call graph for this function:

◆ operator<<()

template<std::size_t Nn, std::size_t Mm, class U >
std::ostream& mu::operator<< ( std::ostream &  os,
const Matrix< Nn, Mm, U > &  m 
)

forwards Vector for every row

Example
mu::Matrix<2, 2, int> a{{2, 3}, {5, 7}};
// std::cout << a << std::endl;
// [ [ 2, 3 ],
// [ 5, 7 ] ]
Template Parameters
Nn
U
Parameters
os
v
Returns
std::ostream&