CubbyFlow::MatrixMxN< T > Class Template Referencefinal

M x N matrix class. More...

#include <Core/Matrix/MatrixMxN.h>

Inheritance diagram for CubbyFlow::MatrixMxN< T >:
CubbyFlow::MatrixExpression< T, MatrixMxN< T > >

Public Types

using ContainerType = Array2< T >
 
using Iterator = typename ContainerType::Iterator
 
using ConstIterator = typename ContainerType::ConstIterator
 

Public Member Functions

 MatrixMxN ()
 Constructs an empty matrix. More...
 
 MatrixMxN (size_t m, size_t n, const T &s=T(0))
 Constructs m x n constant value matrix. More...
 
 MatrixMxN (const std::initializer_list< std::initializer_list< T >> &list)
 Constructs a matrix with given initializer list list. More...
 
template<typename E >
 MatrixMxN (const MatrixExpression< T, E > &other)
 Constructs a matrix with expression template. More...
 
 MatrixMxN (size_t m, size_t n, const T *arr)
 
 MatrixMxN (const MatrixMxN &other)
 Copy constructor. More...
 
 MatrixMxN (MatrixMxN &&other) noexcept
 Move constructor. More...
 
void Resize (size_t m, size_t n, const T &s=T(0))
 Resizes to m x n matrix with initial value s. More...
 
void Set (const T &s)
 Sets whole matrix with input scalar. More...
 
void Set (const std::initializer_list< std::initializer_list< T >> &list)
 Sets a matrix with given initializer list list. More...
 
template<typename E >
void Set (const MatrixExpression< T, E > &other)
 Copies from input matrix expression. More...
 
void Set (size_t m, size_t n, const T *arr)
 
void SetDiagonal (const T &s)
 Sets diagonal elements with input scalar. More...
 
void SetOffDiagonal (const T &s)
 Sets off-diagonal elements with input scalar. More...
 
template<typename E >
void SetRow (size_t i, const VectorExpression< T, E > &row)
 Sets i-th row with input vector. More...
 
template<typename E >
void SetColumn (size_t j, const VectorExpression< T, E > &col)
 Sets j-th column with input vector. More...
 
template<typename E >
bool IsEqual (const MatrixExpression< T, E > &other) const
 
template<typename E >
bool IsSimilar (const MatrixExpression< T, E > &other, double tol=std::numeric_limits< double >::epsilon()) const
 
bool IsSquare () const
 Returns true if this matrix is a square matrix. More...
 
Size2 size () const
 Returns the size of this matrix. More...
 
size_t Rows () const
 Returns number of rows of this matrix. More...
 
size_t Cols () const
 Returns number of columns of this matrix. More...
 
T * data ()
 Returns data pointer of this matrix. More...
 
const T * data () const
 Returns constant pointer of this matrix. More...
 
Iterator begin ()
 Returns the begin iterator of the matrix. More...
 
ConstIterator begin () const
 Returns the begin const iterator of the matrix. More...
 
Iterator end ()
 Returns the end iterator of the matrix. More...
 
ConstIterator end () const
 Returns the end const iterator of the matrix. More...
 
MatrixScalarAdd< T, MatrixMxNAdd (const T &s) const
 Returns this matrix + input scalar. More...
 
template<typename E >
MatrixAdd< T, MatrixMxN, E > Add (const E &m) const
 Returns this matrix + input matrix (element-wise). More...
 
MatrixScalarSub< T, MatrixMxNSub (const T &s) const
 Returns this matrix - input scalar. More...
 
template<typename E >
MatrixSub< T, MatrixMxN, E > Sub (const E &m) const
 Returns this matrix - input matrix (element-wise). More...
 
MatrixScalarMul< T, MatrixMxNMul (const T &s) const
 Returns this matrix * input scalar. More...
 
template<typename VE >
MatrixVectorMul< T, MatrixMxN, VE > Mul (const VectorExpression< T, VE > &v) const
 Returns this matrix * input vector. More...
 
template<typename E >
MatrixMul< T, MatrixMxN, E > Mul (const E &m) const
 Returns this matrix * input matrix. More...
 
MatrixScalarDiv< T, MatrixMxNDiv (const T &s) const
 Returns this matrix / input scalar. More...
 
MatrixScalarAdd< T, MatrixMxNRAdd (const T &s) const
 Returns input scalar + this matrix. More...
 
template<typename E >
MatrixAdd< T, MatrixMxN, E > RAdd (const E &m) const
 Returns input matrix + this matrix (element-wise). More...
 
MatrixScalarRSub< T, MatrixMxNRSub (const T &s) const
 Returns input scalar - this matrix. More...
 
template<typename E >
MatrixSub< T, MatrixMxN, E > RSub (const E &m) const
 Returns input matrix - this matrix (element-wise). More...
 
MatrixScalarMul< T, MatrixMxNRMul (const T &s) const
 Returns input scalar * this matrix. More...
 
template<typename E >
MatrixMul< T, E, MatrixMxNRMul (const E &m) const
 Returns input matrix * this matrix. More...
 
MatrixScalarRDiv< T, MatrixMxNRDiv (const T &s) const
 Returns input matrix / this scalar. More...
 
void IAdd (const T &s)
 Adds input scalar to this matrix. More...
 
template<typename E >
void IAdd (const E &m)
 Adds input matrix to this matrix (element-wise). More...
 
void ISub (const T &s)
 Subtracts input scalar from this matrix. More...
 
template<typename E >
void ISub (const E &m)
 Subtracts input matrix from this matrix (element-wise). More...
 
void IMul (const T &s)
 Multiplies input scalar to this matrix. More...
 
template<typename E >
void IMul (const E &m)
 Multiplies input matrix to this matrix. More...
 
void IDiv (const T &s)
 Divides this matrix with input scalar. More...
 
void Transpose ()
 Transposes this matrix. More...
 
void Invert ()
 Inverts this matrix. More...
 
Sum () const
 Returns sum of all elements. More...
 
Avg () const
 Returns average of all elements. More...
 
Min () const
 Returns minimum among all elements. More...
 
Max () const
 Returns maximum among all elements. More...
 
AbsMin () const
 Returns absolute minimum among all elements. More...
 
AbsMax () const
 Returns absolute maximum among all elements. More...
 
Trace () const
 
Determinant () const
 Returns determinant of this matrix. More...
 
MatrixDiagonal< T, MatrixMxNDiagonal () const
 Returns diagonal part of this matrix. More...
 
MatrixDiagonal< T, MatrixMxNOffDiagonal () const
 Returns off-diagonal part of this matrix. More...
 
MatrixTriangular< T, MatrixMxNStrictLowerTri () const
 Returns strictly lower triangle part of this matrix. More...
 
MatrixTriangular< T, MatrixMxNStrictUpperTri () const
 Returns strictly upper triangle part of this matrix. More...
 
MatrixTriangular< T, MatrixMxNLowerTri () const
 Returns lower triangle part of this matrix (including the diagonal). More...
 
MatrixTriangular< T, MatrixMxNUpperTri () const
 Returns upper triangle part of this matrix (including the diagonal). More...
 
MatrixMxN Transposed () const
 Returns transposed matrix. More...
 
MatrixMxN Inverse () const
 Returns inverse matrix. More...
 
template<typename U >
MatrixTypeCast< U, MatrixMxN, T > CastTo () const
 Type-casts to different value-typed matrix. More...
 
template<typename E >
MatrixMxNoperator= (const E &m)
 Assigns input matrix. More...
 
MatrixMxNoperator= (const MatrixMxN &other)
 Copies to this matrix. More...
 
MatrixMxNoperator= (MatrixMxN &&other) noexcept
 Moves to this matrix. More...
 
MatrixMxNoperator+= (const T &s)
 Addition assignment with input scalar. More...
 
template<typename E >
MatrixMxNoperator+= (const E &m)
 Addition assignment with input matrix (element-wise). More...
 
MatrixMxNoperator-= (const T &s)
 Subtraction assignment with input scalar. More...
 
template<typename E >
MatrixMxNoperator-= (const E &m)
 Subtraction assignment with input matrix (element-wise). More...
 
MatrixMxNoperator*= (const T &s)
 Multiplication assignment with input scalar. More...
 
template<typename E >
MatrixMxNoperator*= (const E &m)
 Multiplication assignment with input matrix. More...
 
MatrixMxNoperator/= (const T &s)
 Division assignment with input scalar. More...
 
T & operator[] (size_t i)
 Returns reference of i-th element. More...
 
const T & operator[] (size_t i) const
 Returns constant reference of i-th element. More...
 
T & operator() (size_t i, size_t j)
 Returns reference of (i,j) element. More...
 
const T & operator() (size_t i, size_t j) const
 Returns constant reference of (i,j) element. More...
 
template<typename E >
bool operator== (const MatrixExpression< T, E > &m) const
 Returns true if is equal to m. More...
 
template<typename E >
bool operator!= (const MatrixExpression< T, E > &m) const
 Returns true if is not equal to m. More...
 
template<typename Callback >
void ForEach (Callback func) const
 Iterates the matrix and invoke given func for each index. More...
 
template<typename Callback >
void ForEachIndex (Callback func) const
 Iterates the matrix and invoke given func for each index. More...
 
template<typename Callback >
void ParallelForEach (Callback func)
 Iterates the matrix and invoke given func for each index in parallel. More...
 
template<typename Callback >
void ParallelForEachIndex (Callback func) const
 Iterates the matrix and invoke given func for each index in parallel using multi-threading. More...
 
template<typename E >
MatrixAdd< T, MatrixMxN< T >, E > Add (const E &m) const
 
template<typename E >
MatrixSub< T, MatrixMxN< T >, E > Sub (const E &m) const
 
template<typename VE >
MatrixVectorMul< T, MatrixMxN< T >, VE > Mul (const VectorExpression< T, VE > &v) const
 
template<typename E >
MatrixMul< T, MatrixMxN< T >, E > Mul (const E &m) const
 
template<typename E >
MatrixAdd< T, MatrixMxN< T >, E > RAdd (const E &m) const
 
template<typename E >
MatrixSub< T, MatrixMxN< T >, E > RSub (const E &m) const
 
template<typename E >
MatrixMul< T, E, MatrixMxN< T > > RMul (const E &m) const
 
template<typename U >
MatrixTypeCast< U, MatrixMxN< T >, T > CastTo () const
 
template<typename E >
MatrixMxN< T > & operator= (const E &m)
 
template<typename E >
MatrixMxN< T > & operator+= (const E &m)
 
template<typename E >
MatrixMxN< T > & operator-= (const E &m)
 
template<typename E >
MatrixMxN< T > & operator*= (const E &m)
 
- Public Member Functions inherited from CubbyFlow::MatrixExpression< T, MatrixMxN< T > >
Size2 size () const
 Size of the matrix. More...
 
size_t Rows () const
 Number of rows. More...
 
size_t Cols () const
 Number of columns. More...
 
const MatrixMxN< T > & operator() () const
 Returns actual implementation (the subclass). More...
 

Static Public Member Functions

static MatrixConstant< T > MakeZero (size_t m, size_t n)
 Makes a m x n matrix with zeros. More...
 
static MatrixIdentity< T > MakeIdentity (size_t m)
 Makes a m x m matrix with all diagonal elements to 1, and other elements to 0. More...
 

Detailed Description

template<typename T>
class CubbyFlow::MatrixMxN< T >

M x N matrix class.

This class defines M x N row-major matrix.

Template Parameters
TType of the element.

Member Typedef Documentation

◆ ConstIterator

template<typename T>
using CubbyFlow::MatrixMxN< T >::ConstIterator = typename ContainerType::ConstIterator

◆ ContainerType

template<typename T>
using CubbyFlow::MatrixMxN< T >::ContainerType = Array2<T>

◆ Iterator

template<typename T>
using CubbyFlow::MatrixMxN< T >::Iterator = typename ContainerType::Iterator

Constructor & Destructor Documentation

◆ MatrixMxN() [1/7]

template<typename T >
CubbyFlow::MatrixMxN< T >::MatrixMxN ( )

Constructs an empty matrix.

◆ MatrixMxN() [2/7]

template<typename T >
CubbyFlow::MatrixMxN< T >::MatrixMxN ( size_t  m,
size_t  n,
const T &  s = T(0) 
)

Constructs m x n constant value matrix.

◆ MatrixMxN() [3/7]

template<typename T >
CubbyFlow::MatrixMxN< T >::MatrixMxN ( const std::initializer_list< std::initializer_list< T >> &  list)

Constructs a matrix with given initializer list list.

This constructor will build a matrix with given initializer list list such as

MatrixMxN<float> mat =
{
{1.f, 2.f, 4.f, 3.f},
{9.f, 3.f, 5.f, 1.f},
{4.f, 8.f, 1.f, 5.f}
};

Note the initializer has 4x3 structure which will create 4x3 matrix.

Parameters
listInitializer list that should be copy to the new matrix.

◆ MatrixMxN() [4/7]

template<typename T >
template<typename E >
CubbyFlow::MatrixMxN< T >::MatrixMxN ( const MatrixExpression< T, E > &  other)

Constructs a matrix with expression template.

◆ MatrixMxN() [5/7]

template<typename T >
CubbyFlow::MatrixMxN< T >::MatrixMxN ( size_t  m,
size_t  n,
const T *  arr 
)

Constructs a m x n matrix with input array.

Warning
Ordering of the input elements is row-major.

◆ MatrixMxN() [6/7]

template<typename T >
CubbyFlow::MatrixMxN< T >::MatrixMxN ( const MatrixMxN< T > &  other)

Copy constructor.

◆ MatrixMxN() [7/7]

template<typename T >
CubbyFlow::MatrixMxN< T >::MatrixMxN ( MatrixMxN< T > &&  other)
noexcept

Move constructor.

Member Function Documentation

◆ AbsMax()

template<typename T >
T CubbyFlow::MatrixMxN< T >::AbsMax ( ) const

Returns absolute maximum among all elements.

◆ AbsMin()

template<typename T >
T CubbyFlow::MatrixMxN< T >::AbsMin ( ) const

Returns absolute minimum among all elements.

◆ Add() [1/3]

template<typename T >
MatrixScalarAdd< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::Add ( const T &  s) const

Returns this matrix + input scalar.

◆ Add() [2/3]

template<typename T>
template<typename E >
MatrixAdd<T, MatrixMxN, E> CubbyFlow::MatrixMxN< T >::Add ( const E &  m) const

Returns this matrix + input matrix (element-wise).

◆ Add() [3/3]

template<typename T>
template<typename E >
MatrixAdd<T, MatrixMxN<T>, E> CubbyFlow::MatrixMxN< T >::Add ( const E &  m) const

◆ Avg()

template<typename T >
T CubbyFlow::MatrixMxN< T >::Avg ( ) const

Returns average of all elements.

◆ begin() [1/2]

template<typename T >
MatrixMxN< T >::Iterator CubbyFlow::MatrixMxN< T >::begin ( )

Returns the begin iterator of the matrix.

◆ begin() [2/2]

template<typename T >
MatrixMxN< T >::ConstIterator CubbyFlow::MatrixMxN< T >::begin ( ) const

Returns the begin const iterator of the matrix.

◆ CastTo() [1/2]

template<typename T>
template<typename U >
MatrixTypeCast<U, MatrixMxN, T> CubbyFlow::MatrixMxN< T >::CastTo ( ) const

Type-casts to different value-typed matrix.

◆ CastTo() [2/2]

template<typename T>
template<typename U >
MatrixTypeCast<U, MatrixMxN<T>, T> CubbyFlow::MatrixMxN< T >::CastTo ( ) const

◆ Cols()

template<typename T >
size_t CubbyFlow::MatrixMxN< T >::Cols ( ) const

Returns number of columns of this matrix.

◆ data() [1/2]

template<typename T >
T * CubbyFlow::MatrixMxN< T >::data ( )

Returns data pointer of this matrix.

◆ data() [2/2]

template<typename T >
const T * CubbyFlow::MatrixMxN< T >::data ( ) const

Returns constant pointer of this matrix.

◆ Determinant()

template<typename T >
T CubbyFlow::MatrixMxN< T >::Determinant ( ) const

Returns determinant of this matrix.

◆ Diagonal()

template<typename T >
MatrixDiagonal< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::Diagonal ( ) const

Returns diagonal part of this matrix.

◆ Div()

template<typename T >
MatrixScalarDiv< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::Div ( const T &  s) const

Returns this matrix / input scalar.

◆ end() [1/2]

template<typename T >
MatrixMxN< T >::Iterator CubbyFlow::MatrixMxN< T >::end ( )

Returns the end iterator of the matrix.

◆ end() [2/2]

template<typename T >
MatrixMxN< T >::ConstIterator CubbyFlow::MatrixMxN< T >::end ( ) const

Returns the end const iterator of the matrix.

◆ ForEach()

template<typename T >
template<typename Callback >
void CubbyFlow::MatrixMxN< T >::ForEach ( Callback  func) const

Iterates the matrix and invoke given func for each index.

This function iterates the matrix elements and invoke the callback function func. The callback function takes matrix's element as its input. The order of execution will be the same as the nested for-loop below:

MatrixMxN<double> mat(100, 200, 4.0);
for (size_t i = 0; i < mat.Rows(); ++i)
{
for (size_t j = 0; j < mat.Cols(); ++j)
{
func(mat(i, j));
}
}

Below is the sample usage:

MatrixMxN<double> mat(100, 200, 4.0);
mat.ForEach([](double elem)
{
printf("%d\n", elem);
});

◆ ForEachIndex()

template<typename T >
template<typename Callback >
void CubbyFlow::MatrixMxN< T >::ForEachIndex ( Callback  func) const

Iterates the matrix and invoke given func for each index.

This function iterates the matrix elements and invoke the callback function func. The callback function takes two parameters which are the (i, j) indices of the matrix. The order of execution will be the same as the nested for-loop below:

MatrixMxN<double> mat(100, 200, 4.0);
for (size_t i = 0; i < mat.Rows(); ++i)
{
for (size_t j = 0; j < mat.Cols(); ++j)
{
func(i, j);
}
}

Below is the sample usage:

MatrixMxN<double> mat(100, 200, 4.0);
mat.ForEachIndex([&](size_t i, size_t j)
{
mat(i, j) = 4.0 * i + 7.0 * j + 1.5;
});

◆ IAdd() [1/2]

template<typename T >
void CubbyFlow::MatrixMxN< T >::IAdd ( const T &  s)

Adds input scalar to this matrix.

◆ IAdd() [2/2]

template<typename T >
template<typename E >
void CubbyFlow::MatrixMxN< T >::IAdd ( const E &  m)

Adds input matrix to this matrix (element-wise).

◆ IDiv()

template<typename T >
void CubbyFlow::MatrixMxN< T >::IDiv ( const T &  s)

Divides this matrix with input scalar.

◆ IMul() [1/2]

template<typename T >
void CubbyFlow::MatrixMxN< T >::IMul ( const T &  s)

Multiplies input scalar to this matrix.

◆ IMul() [2/2]

template<typename T >
template<typename E >
void CubbyFlow::MatrixMxN< T >::IMul ( const E &  m)

Multiplies input matrix to this matrix.

◆ Inverse()

template<typename T >
MatrixMxN< T > CubbyFlow::MatrixMxN< T >::Inverse ( ) const

Returns inverse matrix.

◆ Invert()

template<typename T >
void CubbyFlow::MatrixMxN< T >::Invert ( )

Inverts this matrix.

This function computes the inverse using Gaussian elimination method.

◆ IsEqual()

template<typename T >
template<typename E >
bool CubbyFlow::MatrixMxN< T >::IsEqual ( const MatrixExpression< T, E > &  other) const

◆ IsSimilar()

template<typename T >
template<typename E >
bool CubbyFlow::MatrixMxN< T >::IsSimilar ( const MatrixExpression< T, E > &  other,
double  tol = std::numeric_limits<double>::epsilon() 
) const

Returns true if this matrix is similar to the input matrix within the given tolerance.

◆ IsSquare()

template<typename T >
bool CubbyFlow::MatrixMxN< T >::IsSquare ( ) const

Returns true if this matrix is a square matrix.

◆ ISub() [1/2]

template<typename T >
void CubbyFlow::MatrixMxN< T >::ISub ( const T &  s)

Subtracts input scalar from this matrix.

◆ ISub() [2/2]

template<typename T >
template<typename E >
void CubbyFlow::MatrixMxN< T >::ISub ( const E &  m)

Subtracts input matrix from this matrix (element-wise).

◆ LowerTri()

template<typename T >
MatrixTriangular< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::LowerTri ( ) const

Returns lower triangle part of this matrix (including the diagonal).

◆ MakeIdentity()

template<typename T >
MatrixIdentity< T > CubbyFlow::MatrixMxN< T >::MakeIdentity ( size_t  m)
static

Makes a m x m matrix with all diagonal elements to 1, and other elements to 0.

◆ MakeZero()

template<typename T >
MatrixConstant< T > CubbyFlow::MatrixMxN< T >::MakeZero ( size_t  m,
size_t  n 
)
static

Makes a m x n matrix with zeros.

◆ Max()

template<typename T >
T CubbyFlow::MatrixMxN< T >::Max ( ) const

Returns maximum among all elements.

◆ Min()

template<typename T >
T CubbyFlow::MatrixMxN< T >::Min ( ) const

Returns minimum among all elements.

◆ Mul() [1/5]

template<typename T >
MatrixScalarMul< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::Mul ( const T &  s) const

Returns this matrix * input scalar.

◆ Mul() [2/5]

template<typename T>
template<typename VE >
MatrixVectorMul<T, MatrixMxN, VE> CubbyFlow::MatrixMxN< T >::Mul ( const VectorExpression< T, VE > &  v) const

Returns this matrix * input vector.

◆ Mul() [3/5]

template<typename T>
template<typename E >
MatrixMul<T, MatrixMxN, E> CubbyFlow::MatrixMxN< T >::Mul ( const E &  m) const

Returns this matrix * input matrix.

◆ Mul() [4/5]

template<typename T>
template<typename VE >
MatrixVectorMul<T, MatrixMxN<T>, VE> CubbyFlow::MatrixMxN< T >::Mul ( const VectorExpression< T, VE > &  v) const

◆ Mul() [5/5]

template<typename T>
template<typename E >
MatrixMul<T, MatrixMxN<T>, E> CubbyFlow::MatrixMxN< T >::Mul ( const E &  m) const

◆ OffDiagonal()

template<typename T >
MatrixDiagonal< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::OffDiagonal ( ) const

Returns off-diagonal part of this matrix.

◆ operator!=()

template<typename T >
template<typename E >
bool CubbyFlow::MatrixMxN< T >::operator!= ( const MatrixExpression< T, E > &  m) const

Returns true if is not equal to m.

◆ operator()() [1/2]

template<typename T >
T & CubbyFlow::MatrixMxN< T >::operator() ( size_t  i,
size_t  j 
)

Returns reference of (i,j) element.

◆ operator()() [2/2]

template<typename T >
const T & CubbyFlow::MatrixMxN< T >::operator() ( size_t  i,
size_t  j 
) const

Returns constant reference of (i,j) element.

◆ operator*=() [1/3]

template<typename T >
MatrixMxN< T > & CubbyFlow::MatrixMxN< T >::operator*= ( const T &  s)

Multiplication assignment with input scalar.

◆ operator*=() [2/3]

template<typename T>
template<typename E >
MatrixMxN& CubbyFlow::MatrixMxN< T >::operator*= ( const E &  m)

Multiplication assignment with input matrix.

◆ operator*=() [3/3]

template<typename T>
template<typename E >
MatrixMxN<T>& CubbyFlow::MatrixMxN< T >::operator*= ( const E &  m)

◆ operator+=() [1/3]

template<typename T >
MatrixMxN< T > & CubbyFlow::MatrixMxN< T >::operator+= ( const T &  s)

Addition assignment with input scalar.

◆ operator+=() [2/3]

template<typename T>
template<typename E >
MatrixMxN& CubbyFlow::MatrixMxN< T >::operator+= ( const E &  m)

Addition assignment with input matrix (element-wise).

◆ operator+=() [3/3]

template<typename T>
template<typename E >
MatrixMxN<T>& CubbyFlow::MatrixMxN< T >::operator+= ( const E &  m)

◆ operator-=() [1/3]

template<typename T >
MatrixMxN< T > & CubbyFlow::MatrixMxN< T >::operator-= ( const T &  s)

Subtraction assignment with input scalar.

◆ operator-=() [2/3]

template<typename T>
template<typename E >
MatrixMxN& CubbyFlow::MatrixMxN< T >::operator-= ( const E &  m)

Subtraction assignment with input matrix (element-wise).

◆ operator-=() [3/3]

template<typename T>
template<typename E >
MatrixMxN<T>& CubbyFlow::MatrixMxN< T >::operator-= ( const E &  m)

◆ operator/=()

template<typename T >
MatrixMxN< T > & CubbyFlow::MatrixMxN< T >::operator/= ( const T &  s)

Division assignment with input scalar.

◆ operator=() [1/4]

template<typename T>
template<typename E >
MatrixMxN& CubbyFlow::MatrixMxN< T >::operator= ( const E &  m)

Assigns input matrix.

◆ operator=() [2/4]

template<typename T >
MatrixMxN< T > & CubbyFlow::MatrixMxN< T >::operator= ( const MatrixMxN< T > &  other)

Copies to this matrix.

◆ operator=() [3/4]

template<typename T >
MatrixMxN< T > & CubbyFlow::MatrixMxN< T >::operator= ( MatrixMxN< T > &&  other)
noexcept

Moves to this matrix.

◆ operator=() [4/4]

template<typename T>
template<typename E >
MatrixMxN<T>& CubbyFlow::MatrixMxN< T >::operator= ( const E &  m)

◆ operator==()

template<typename T >
template<typename E >
bool CubbyFlow::MatrixMxN< T >::operator== ( const MatrixExpression< T, E > &  m) const

Returns true if is equal to m.

◆ operator[]() [1/2]

template<typename T >
T & CubbyFlow::MatrixMxN< T >::operator[] ( size_t  i)

Returns reference of i-th element.

◆ operator[]() [2/2]

template<typename T >
const T & CubbyFlow::MatrixMxN< T >::operator[] ( size_t  i) const

Returns constant reference of i-th element.

◆ ParallelForEach()

template<typename T >
template<typename Callback >
void CubbyFlow::MatrixMxN< T >::ParallelForEach ( Callback  func)

Iterates the matrix and invoke given func for each index in parallel.

This function iterates the matrix elements and invoke the callback function func. The callback function takes matrix's element as its input. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:

MatrixMxN<double> mat(100, 200, 4.0);
mat.ParallelForEach([](double& elem)
{
elem *= 2.0;
});

The parameter type of the callback function doesn't have to be T&, but const T& or T can be used as well.

◆ ParallelForEachIndex()

template<typename T >
template<typename Callback >
void CubbyFlow::MatrixMxN< T >::ParallelForEachIndex ( Callback  func) const

Iterates the matrix and invoke given func for each index in parallel using multi-threading.

This function iterates the matrix elements and invoke the callback function func in parallel using multi-threading. The callback function takes two parameters which are the (i, j) indices of the matrix. The order of execution will be non-deterministic since it runs in parallel. Below is the sample usage:

MatrixMxN<double> mat(100, 200, 4.0);
mat.ParallelForEachIndex([&](size_t i, size_t j)
{
mat(i, j) *= 2;
});

◆ RAdd() [1/3]

template<typename T >
MatrixScalarAdd< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::RAdd ( const T &  s) const

Returns input scalar + this matrix.

◆ RAdd() [2/3]

template<typename T>
template<typename E >
MatrixAdd<T, MatrixMxN, E> CubbyFlow::MatrixMxN< T >::RAdd ( const E &  m) const

Returns input matrix + this matrix (element-wise).

◆ RAdd() [3/3]

template<typename T>
template<typename E >
MatrixAdd<T, MatrixMxN<T>, E> CubbyFlow::MatrixMxN< T >::RAdd ( const E &  m) const

◆ RDiv()

template<typename T >
MatrixScalarRDiv< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::RDiv ( const T &  s) const

Returns input matrix / this scalar.

◆ Resize()

template<typename T >
void CubbyFlow::MatrixMxN< T >::Resize ( size_t  m,
size_t  n,
const T &  s = T(0) 
)

Resizes to m x n matrix with initial value s.

◆ RMul() [1/3]

template<typename T >
MatrixScalarMul< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::RMul ( const T &  s) const

Returns input scalar * this matrix.

◆ RMul() [2/3]

template<typename T>
template<typename E >
MatrixMul<T, E, MatrixMxN> CubbyFlow::MatrixMxN< T >::RMul ( const E &  m) const

Returns input matrix * this matrix.

◆ RMul() [3/3]

template<typename T>
template<typename E >
MatrixMul<T, E, MatrixMxN<T> > CubbyFlow::MatrixMxN< T >::RMul ( const E &  m) const

◆ Rows()

template<typename T >
size_t CubbyFlow::MatrixMxN< T >::Rows ( ) const

Returns number of rows of this matrix.

◆ RSub() [1/3]

template<typename T >
MatrixScalarRSub< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::RSub ( const T &  s) const

Returns input scalar - this matrix.

◆ RSub() [2/3]

template<typename T>
template<typename E >
MatrixSub<T, MatrixMxN, E> CubbyFlow::MatrixMxN< T >::RSub ( const E &  m) const

Returns input matrix - this matrix (element-wise).

◆ RSub() [3/3]

template<typename T>
template<typename E >
MatrixSub<T, MatrixMxN<T>, E> CubbyFlow::MatrixMxN< T >::RSub ( const E &  m) const

◆ Set() [1/4]

template<typename T >
void CubbyFlow::MatrixMxN< T >::Set ( const T &  s)

Sets whole matrix with input scalar.

◆ Set() [2/4]

template<typename T >
void CubbyFlow::MatrixMxN< T >::Set ( const std::initializer_list< std::initializer_list< T >> &  list)

Sets a matrix with given initializer list list.

This function will fill the matrix with given initializer list list such as

MatrixMxN<float> mat;
mat.set(
{
{1.f, 2.f, 4.f, 3.f},
{9.f, 3.f, 5.f, 1.f},
{4.f, 8.f, 1.f, 5.f}
});

Note the initializer has 4x3 structure which will resize to 4x3 matrix.

Parameters
listInitializer list that should be copy to the new matrix.

◆ Set() [3/4]

template<typename T >
template<typename E >
void CubbyFlow::MatrixMxN< T >::Set ( const MatrixExpression< T, E > &  other)

Copies from input matrix expression.

◆ Set() [4/4]

template<typename T >
void CubbyFlow::MatrixMxN< T >::Set ( size_t  m,
size_t  n,
const T *  arr 
)

Copies from input array.

Warning
Ordering of the input elements is row-major.

◆ SetColumn()

template<typename T >
template<typename E >
void CubbyFlow::MatrixMxN< T >::SetColumn ( size_t  j,
const VectorExpression< T, E > &  col 
)

Sets j-th column with input vector.

◆ SetDiagonal()

template<typename T >
void CubbyFlow::MatrixMxN< T >::SetDiagonal ( const T &  s)

Sets diagonal elements with input scalar.

◆ SetOffDiagonal()

template<typename T >
void CubbyFlow::MatrixMxN< T >::SetOffDiagonal ( const T &  s)

Sets off-diagonal elements with input scalar.

◆ SetRow()

template<typename T >
template<typename E >
void CubbyFlow::MatrixMxN< T >::SetRow ( size_t  i,
const VectorExpression< T, E > &  row 
)

Sets i-th row with input vector.

◆ size()

template<typename T >
Size2 CubbyFlow::MatrixMxN< T >::size ( ) const

Returns the size of this matrix.

◆ StrictLowerTri()

template<typename T >
MatrixTriangular< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::StrictLowerTri ( ) const

Returns strictly lower triangle part of this matrix.

◆ StrictUpperTri()

template<typename T >
MatrixTriangular< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::StrictUpperTri ( ) const

Returns strictly upper triangle part of this matrix.

◆ Sub() [1/3]

template<typename T >
MatrixScalarSub< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::Sub ( const T &  s) const

Returns this matrix - input scalar.

◆ Sub() [2/3]

template<typename T>
template<typename E >
MatrixSub<T, MatrixMxN, E> CubbyFlow::MatrixMxN< T >::Sub ( const E &  m) const

Returns this matrix - input matrix (element-wise).

◆ Sub() [3/3]

template<typename T>
template<typename E >
MatrixSub<T, MatrixMxN<T>, E> CubbyFlow::MatrixMxN< T >::Sub ( const E &  m) const

◆ Sum()

template<typename T >
T CubbyFlow::MatrixMxN< T >::Sum ( ) const

Returns sum of all elements.

◆ Trace()

template<typename T >
T CubbyFlow::MatrixMxN< T >::Trace ( ) const

Returns sum of all diagonal elements.

Warning
Should be a square matrix.

◆ Transpose()

template<typename T >
void CubbyFlow::MatrixMxN< T >::Transpose ( )

Transposes this matrix.

◆ Transposed()

template<typename T >
MatrixMxN< T > CubbyFlow::MatrixMxN< T >::Transposed ( ) const

Returns transposed matrix.

◆ UpperTri()

template<typename T >
MatrixTriangular< T, MatrixMxN< T > > CubbyFlow::MatrixMxN< T >::UpperTri ( ) const

Returns upper triangle part of this matrix (including the diagonal).


The documentation for this class was generated from the following files: