Matrix

Functions

template<typename T , std::size_t N>
constexpr matrix< T, N, 1 > nil::crypto3::algebra::as_column (const vector< T, N > &v)
 converts a vector into a column vector More...
 
template<typename T , std::size_t N>
constexpr matrix< T, 1, N > nil::crypto3::algebra::as_row (const vector< T, N > &v)
 converts a vector into a row vector More...
 
template<typename T , typename U , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::cast (const matrix< U, N, M > &m)
 casts a vector to another type More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr matrix< T, M, N > nil::crypto3::algebra::conj (const matrix< T, M, N > &m)
 computes the elementwise complex conjugate More...
 
template<typename T , std::size_t M>
constexpr T nil::crypto3::algebra::det (const matrix< T, M, M > &m)
 Compute the determinant. More...
 
template<typename F , typename T , typename... Matrices, typename U = std::invoke_result_t<F, T, typename Matrices::value_type...>, std::size_t N = detail::all_same_value<std::size_t, Matrices::column_size...>::value, std::size_t M = detail::all_same_value<std::size_t, Matrices::row_size...>::value>
constexpr matrix< U, N, M > nil::crypto3::algebra::elementwise (F f, const matrix< T, N, M > &m, const Matrices &... matrices)
 applies a function elementwise between many matrices More...
 
template<std::size_t N, std::size_t M, typename T >
constexpr matrix< T, N, M > nil::crypto3::algebra::fill (T value)
 generates a matrix containing a single value More...
 
template<std::size_t N, std::size_t M, typename F >
constexpr decltype(auto) nil::crypto3::algebra::generate (F &&f)
 generates a matrix as a function of its indices More...
 
template<typename T , std::size_t N>
constexpr matrix< T, N, N > nil::crypto3::algebra::get_identity ()
 
template<typename T , std::size_t M, std::size_t N>
constexpr matrix< T, N, M > nil::crypto3::algebra::hermitian (const matrix< T, M, N > &m)
 computes the Hermitian transpose More...
 
template<std::size_t M, std::size_t N, std::size_t P, typename T >
constexpr matrix< T, M, N+P > nil::crypto3::algebra::horzcat (const matrix< T, M, N > &a, const matrix< T, M, P > &b)
 horizontally concatenates two matrices More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr matrix< detail::remove_complex_t< T >, M, N > nil::crypto3::algebra::imag (const matrix< T, M, N > &m)
 computes the elementwise imag More...
 
template<typename T , std::size_t M>
constexpr matrix< T, M, M > nil::crypto3::algebra::inverse (const matrix< T, M, M > &m)
 computes the matrix inverse More...
 
template<typename T , std::size_t M, std::size_t N, std::size_t P, std::size_t Q>
constexpr matrix< T, M *P, N *Q > nil::crypto3::algebra::kron (const matrix< T, M, N > &a, const matrix< T, P, Q > &b)
 Computes the kronecker tensor product. More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr T nil::crypto3::algebra::macs (const matrix< T, M, N > &m)
 Computes the maximum absolute column sum norm. More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr T nil::crypto3::algebra::mars (const matrix< T, M, N > &m)
 Computes the maximum absolute row sum norm. More...
 
template<typename T , std::size_t M, std::size_t N, std::size_t P>
constexpr matrix< T, M, P > nil::crypto3::algebra::matmul (const matrix< T, M, N > &a, const matrix< T, N, P > &b)
 computes the matrix product More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr vector< T, M > nil::crypto3::algebra::matvectmul (const matrix< T, M, N > &m, const vector< T, N > &v)
 computes the product of matrix and vector More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr bool nil::crypto3::algebra::operator!= (const matrix< T, N, M > &a, const matrix< T, N, M > &b)
 checks inequality of two matrices More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::operator* (const matrix< T, N, M > &a, const matrix< T, N, M > &b)
 computes the Hadamard product More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::operator* (const matrix< T, N, M > &m, T a)
 computes the product of a matrix and a scalar More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::operator* (T a, const matrix< T, N, M > &m)
 computes the product of a matrix and a scalar More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::operator+ (const matrix< T, N, M > &a, const matrix< T, N, M > &b)
 computes the matrix sum More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::operator+ (const matrix< T, N, M > &m, T a)
 computes the sum of a matrix and a scalar More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::operator+ (T a, const matrix< T, N, M > &m)
 computes the sum of a matrix and a scalar More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::operator/ (const matrix< T, N, M > &a, const matrix< T, N, M > &b)
 computes the elementwise matrix quotient More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr matrix< T, N, M > nil::crypto3::algebra::operator/ (T a, const matrix< T, N, M > &m)
 computes the quotient between a matrix and a scalar More...
 
template<typename T , std::size_t N, std::size_t M>
constexpr bool nil::crypto3::algebra::operator== (const matrix< T, N, M > &a, const matrix< T, N, M > &b)
 checks equality of two matrices More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr std::size_t nil::crypto3::algebra::rank (const matrix< T, M, N > &m)
 Compute the rank. More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr matrix< detail::remove_complex_t< T >, M, N > nil::crypto3::algebra::real (const matrix< T, M, N > &m)
 computes the elementwise real More...
 
template<std::size_t Row, std::size_t Col, std::size_t M, std::size_t N, typename T >
constexpr matrix< T, M *Row, N *Col > nil::crypto3::algebra::repmat (const matrix< T, M, N > &m)
 repeats a matrix More...
 
template<std::size_t P, std::size_t Q, std::size_t M, std::size_t N, typename T >
constexpr matrix< T, P, Q > nil::crypto3::algebra::reshape (const matrix< T, M, N > &m)
 reshapes a matrix More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr matrix< T, M, N > nil::crypto3::algebra::rref (const matrix< T, M, N > &m)
 Compute the reduced row echelon form. More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr matrix< T, M, N > nil::crypto3::algebra::rref (const matrix< T, M, N > &m, T tolerance)
 Compute the reduced row echelon form. More...
 
template<std::size_t P, std::size_t Q, std::size_t M, std::size_t N, typename T >
constexpr matrix< T, P, Q > nil::crypto3::algebra::submat (const matrix< T, M, N > &m, std::size_t a, std::size_t b)
 extracts the submatrix of a matrix More...
 
template<std::size_t M, std::size_t N, typename T >
constexpr matrix< T, M, N > nil::crypto3::algebra::swapcol (matrix< T, M, N > m, std::size_t a, std::size_t b)
 swaps columns of a matrix More...
 
template<std::size_t M, std::size_t N, typename T >
constexpr matrix< T, M, N > nil::crypto3::algebra::swaprow (matrix< T, M, N > m, std::size_t a, std::size_t b)
 swaps rows of a matrix More...
 
template<typename T , std::size_t M>
constexpr T nil::crypto3::algebra::trace (const matrix< T, M, M > &m)
 computes the trace More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr matrix< T, N, M > nil::crypto3::algebra::transpose (const matrix< T, M, N > &m)
 computes the transpose More...
 
template<typename T , std::size_t M, std::size_t N>
constexpr vector< T, N > nil::crypto3::algebra::vectmatmul (const vector< T, M > &v, const matrix< T, M, N > &m)
 computes the product of vector and matrix More...
 
template<std::size_t M, std::size_t N, std::size_t P, typename T >
constexpr matrix< T, M+N, P > nil::crypto3::algebra::vertcat (const matrix< T, M, P > &a, const matrix< T, N, P > &b)
 vertically concatenates two matrices More...
 

Variables

template<typename T , std::size_t N>
const matrix< T, N, N > nil::crypto3::algebra::identity
 the matrix identity More...
 

matrix deduction guides

template<typename T , std::size_t M, std::size_t N>
 nil::crypto3::algebra::matrix (const T(&)[M][N]) -> matrix< T, M, N >
 deduction guide for aggregate initialization More...
 
template<typename T , std::size_t M, std::size_t N>
 matrix (const T(&)[M][N]) -> matrix< T, M, N >
 deduction guide for aggregate initialization More...
 

Detailed Description

Function Documentation

◆ as_column()

template<typename T , std::size_t N>
constexpr matrix<T, N, 1> nil::crypto3::algebra::as_column ( const vector< T, N > &  v)
constexpr

converts a vector into a column vector

Parameters
van N-vector of type T
Returns
an $ N \times 1 $ matrix of type T

Converts a vector into a column vector.

◆ as_row()

template<typename T , std::size_t N>
constexpr matrix<T, 1, N> nil::crypto3::algebra::as_row ( const vector< T, N > &  v)
constexpr

converts a vector into a row vector

Parameters
van N-vector of type T
Returns
a $ 1 \times N $ matrix of type T

Converts a vector into a row vector.

◆ cast()

template<typename T , typename U , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::cast ( const matrix< U, N, M > &  m)
constexpr

casts a vector to another type

Parameters
man $ N \times M $ matrix of type U
Returns
an $ N \times M $ matrix of type T containing the casted elements of $ \textbf{M} $

Casts a matrix to another type by static_casting each element.

◆ conj()

template<typename T , std::size_t M, std::size_t N>
constexpr matrix<T, M, N> nil::crypto3::algebra::conj ( const matrix< T, M, N > &  m)
constexpr

computes the elementwise complex conjugate

Parameters
man $ M \times N $ matrix of type T
Returns
an $ M \times N $ matrix $\overline{\textbf{m}}$ of type T such that $ \left(\overline{\textbf{m}}\right)_{ij} = \overline{\textbf{m}_{ij}},\ \forall i,j $

Computes the elementwise complex conjugate of a matrix

◆ det()

template<typename T , std::size_t M>
constexpr T nil::crypto3::algebra::det ( const matrix< T, M, M > &  m)
constexpr

Compute the determinant.

Parameters
m$ M \times M $ matrix of type T
Returns
a scalar $ \left\lvert \textbf{m} \right\rvert $ of type T

Computes the determinant using the reduced row echelon form.

◆ elementwise()

template<typename F , typename T , typename... Matrices, typename U = std::invoke_result_t<F, T, typename Matrices::value_type...>, std::size_t N = detail::all_same_value<std::size_t, Matrices::column_size...>::value, std::size_t M = detail::all_same_value<std::size_t, Matrices::row_size...>::value>
constexpr matrix<U, N, M> nil::crypto3::algebra::elementwise ( f,
const matrix< T, N, M > &  m,
const Matrices &...  matrices 
)
constexpr

applies a function elementwise between many matrices

Parameters
fa function of type F that operates on many scalars of type T and returns a scalar of type U
man $ N \times M $ matrix of type T
matricesadditional $ N \times M $ matrices of type T
Returns
an $ N \times M $ matrix of type T with elements described by $ f\left(\textbf{m}_{ij}, \ldots\right) $

Applies a function elementwise between many matrices.

◆ fill()

template<std::size_t N, std::size_t M, typename T >
constexpr matrix<T, N, M> nil::crypto3::algebra::fill ( value)
constexpr

generates a matrix containing a single value

Parameters
valuethe scalar value of all elements
Returns
an $ N \times M $ matrix of type T such that $ \textbf{m}_{ij} = \textrm{value}\ \forall i,j $

Generates a matrix with all elements equal to a single value.

◆ generate()

template<std::size_t N, std::size_t M, typename F >
constexpr decltype(auto) nil::crypto3::algebra::generate ( F &&  f)
constexpr

generates a matrix as a function of its indices

Parameters
fa function that operates on two integer indices
Returns
an $ N \times M $ matrix with type matching the return type of f such that $ \textbf{m}_{ij} = f(i, j) $

Generates a matrix as a function of its indices.

◆ get_identity()

template<typename T , std::size_t N>
constexpr matrix<T, N, N> nil::crypto3::algebra::get_identity ( )
constexpr

◆ hermitian()

template<typename T , std::size_t M, std::size_t N>
constexpr matrix<T, N, M> nil::crypto3::algebra::hermitian ( const matrix< T, M, N > &  m)
constexpr

computes the Hermitian transpose

Parameters
man $ M \times N $ matrix of type T
Returns
an $ N \times M $ matrix $ \textbf{m}^{*} $ of type T such that $ \left(\textbf{m}^{*}\right)_{ij} = \overline{\textbf{m}_{ji}},\ \forall i,j $

Computes the Hermitian (conjugate) transpose.

◆ horzcat()

template<std::size_t M, std::size_t N, std::size_t P, typename T >
constexpr matrix<T, M, N + P> nil::crypto3::algebra::horzcat ( const matrix< T, M, N > &  a,
const matrix< T, M, P > &  b 
)
constexpr

horizontally concatenates two matrices

Parameters
aan $ M \times N $ matrix of type T
ban $ M \times P $ matrix of type T
Returns
an $ M \times \left(N+P\right) $ matrix of type T $ \left[\textbf{a} \textbf{b}\right] $ such that $ \left(\left[\textbf{a} \textbf{b}\right]\right)_{ij} = \begin{cases} \textbf{a}_{ij} & j < N\\ \textbf{b}_{i,\ \left(j - N\right)} & j \ge N \end{cases} $

Horizontally concatenates two matrices.

◆ imag()

template<typename T , std::size_t M, std::size_t N>
constexpr matrix<detail::remove_complex_t<T>, M, N> nil::crypto3::algebra::imag ( const matrix< T, M, N > &  m)
constexpr

computes the elementwise imag

Parameters
man $ M \times N $ matrix of type T
Returns
an $ M \times N $ matrix $\textbf{m}$ of type T such that $ \left(\textbf{m}}_{ij} = \mathbb{I}\{\textbf{m}_{ij}\},\ \forall i,j $

Computes the elementwise imag of a matrix

◆ inverse()

template<typename T , std::size_t M>
constexpr matrix<T, M, M> nil::crypto3::algebra::inverse ( const matrix< T, M, M > &  m)
constexpr

computes the matrix inverse

Parameters
man $ M \times M $ matrix of type T
Returns
The inverse of $ \textbf{m} $, $ \textbf{m}^{-1}$ such that $ \textbf{m}\textbf{m}^{-1} = \textbf{m}^{-1}\textbf{m} = \textbf{I}_{M} $

Computes the inverse of a matrix using the reduced row echelon form.

◆ kron()

template<typename T , std::size_t M, std::size_t N, std::size_t P, std::size_t Q>
constexpr matrix<T, M * P, N * Q> nil::crypto3::algebra::kron ( const matrix< T, M, N > &  a,
const matrix< T, P, Q > &  b 
)
constexpr

Computes the kronecker tensor product.

Parameters
aan $M \times N$ matrix
ban $P \times Q$ matrix
Returns
An $ MP \times NQ $ matrix $ \textbf{a}\otimes\textbf{b} $ of type T such that $ \left(\textbf{a}\otimes\textbf{b}\right)_{ij} = \textbf{a}_{\lfloor i/P \rfloor,\lfloor j/Q \rfloor}\textbf{b}_{i\textrm{%}P,j\textrm{%}Q} $ where $ i \textrm{%} P $ is the remainder of $ i/P $

Computes the kronecker tensor product of two matrices.

◆ macs()

template<typename T , std::size_t M, std::size_t N>
constexpr T nil::crypto3::algebra::macs ( const matrix< T, M, N > &  m)
constexpr

Computes the maximum absolute column sum norm.

Parameters
man $M \times N$ matrix
Returns
a scalar $ {\left\lVert \textbf{m} \right\rVert}_1 $ of type T such that $ {\left\lVert \textbf{m} \right\rVert}_1 = \max\limits_j \sum\limits_{i=1}^M \left\lvert \textbf{m}_{ij} \right\rvert $

Computes the maximum absolute column sum norm of a matrix.

◆ mars()

template<typename T , std::size_t M, std::size_t N>
constexpr T nil::crypto3::algebra::mars ( const matrix< T, M, N > &  m)
constexpr

Computes the maximum absolute row sum norm.

Parameters
man $M \times N$ matrix
Returns
a scalar $ {\left\lVert \textbf{m} \right\rVert}_\infty $ of type T such that $ {\left\lVert \textbf{m} \right\rVert}_\infty = \max\limits_i \sum\limits_{j=1}^N \left\lvert \textbf{m}_{ij} \right\rvert $

Computes the maximum absolute row sum norm of a matrix.

◆ matmul()

template<typename T , std::size_t M, std::size_t N, std::size_t P>
constexpr matrix<T, M, P> nil::crypto3::algebra::matmul ( const matrix< T, M, N > &  a,
const matrix< T, N, P > &  b 
)
constexpr

computes the matrix product

Parameters
aan $M \times N$ matrix
ban $N \times P$ matrix
Returns
an $ M \times P $ matrix $ \textbf{a}\textbf{b} $ of type T such that $ \left(\textbf{ab}\right)_{ij} = \sum\limits_{k=1}^{N}\textbf{a}_{ik}\textbf{b}_{kj} $

Computes the product of two matrices.

◆ matrix() [1/2]

template<typename T , std::size_t M, std::size_t N>
matrix ( const   T(&)[M][N]) -> matrix< T, M, N >

deduction guide for aggregate initialization

This deduction guide allows matrix to be constructed like this:

matrix m{{{1., 2.}, {3., 4.}}}; // deduces the type of m to be matrix<double, 2, 2>

◆ matrix() [2/2]

template<typename T , std::size_t M, std::size_t N>
matrix ( const   T(&)[M][N]) -> matrix< T, M, N >
related

deduction guide for aggregate initialization

This deduction guide allows matrix to be constructed like this:

matrix m{{{1., 2.}, {3., 4.}}}; // deduces the type of m to be matrix<double, 2, 2>

◆ matvectmul()

template<typename T , std::size_t M, std::size_t N>
constexpr vector<T, M> nil::crypto3::algebra::matvectmul ( const matrix< T, M, N > &  m,
const vector< T, N > &  v 
)
constexpr

computes the product of matrix and vector

Parameters
man $M \times N$ matrix
van N-vector
Returns
an M-vector of type T

◆ operator!=()

template<typename T , std::size_t N, std::size_t M>
constexpr bool nil::crypto3::algebra::operator!= ( const matrix< T, N, M > &  a,
const matrix< T, N, M > &  b 
)
constexpr

checks inequality of two matrices

Parameters
aan $ N \times M $ matrix of type T
ban $ N \times M $ matrix of type T
Returns
false if and only if $ \textbf{a}_{ij} = \textbf{b}_{ij}\ \forall i,j \in 1\ .. N $

Checks the inequality of two matrices.

◆ operator*() [1/3]

template<typename T , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::operator* ( const matrix< T, N, M > &  a,
const matrix< T, N, M > &  b 
)
constexpr

computes the Hadamard product

Parameters
aan $ N \times M $ matrix of type T
ban $ N \times M $ matrix of type T
Returns
$ \textbf{a} \circ \textbf{b} $ such that $ \left(\textbf{a} \circ \textbf{b}\right)_{ij} = \textbf{a}_{ij} \textbf{b}_{ij} $

Computes the Hadamard, or elementwise, product of two vectors.

◆ operator*() [2/3]

template<typename T , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::operator* ( const matrix< T, N, M > &  m,
a 
)
constexpr

computes the product of a matrix and a scalar

Parameters
man $ N \times M $ matrix of type T
aa scalar of type T
Returns
$ \textbf{m}a $ such that $ \left(\textbf{m} a\right)_{ij} = \textbf{m}_{ij} a $

Computes the sum of a matrix and a scalar.

◆ operator*() [3/3]

template<typename T , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::operator* ( a,
const matrix< T, N, M > &  m 
)
constexpr

computes the product of a matrix and a scalar

Parameters
aa scalar of type T
man $ N \times M $ matrix of type T
Returns
$ a\textbf{m} $ such that $ \left(a\textbf{m}\right)_{ij} = a\textbf{m}_{ij} $

Computes the sum of a matrix and a scalar.

◆ operator+() [1/3]

template<typename T , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::operator+ ( const matrix< T, N, M > &  a,
const matrix< T, N, M > &  b 
)
constexpr

computes the matrix sum

Parameters
aan $ N \times M $ matrix of type T
ban $ N \times M $ matrix of type T
Returns
$ \textbf{a} + \textbf{b} $ such that $ \left(\textbf{a} + \textbf{b}\right)_{ij} = \textbf{a}_{ij} + \textbf{b}_{ij} $

Computes the vector sum.

◆ operator+() [2/3]

template<typename T , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::operator+ ( const matrix< T, N, M > &  m,
a 
)
constexpr

computes the sum of a matrix and a scalar

Parameters
man $ N \times M $ matrix of type T
aa scalar of type T
Returns
$ \textbf{m} + a $ such that $ \left(\textbf{m} + a\right)_{ij} = \textbf{m}_{ij} + a $

Computes the sum of a matrix and a scalar.

◆ operator+() [3/3]

template<typename T , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::operator+ ( a,
const matrix< T, N, M > &  m 
)
constexpr

computes the sum of a matrix and a scalar

Parameters
aa scalar of type T
man $ N \times M $ matrix of type T
Returns
$ a + \textbf{m} $ such that $ \left(a + \textbf{m}\right)_{ij} = a + \textbf{m}_{ij} $

Computes the sum of a matrix and a scalar.

◆ operator/() [1/2]

template<typename T , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::operator/ ( const matrix< T, N, M > &  a,
const matrix< T, N, M > &  b 
)
constexpr

computes the elementwise matrix quotient

Parameters
aan $ N \times M $ matrix of type T
ban $ N \times M $ matrix of type T
Returns
$ \textbf{a} \circ \textbf{b}' $ such that $ {\textbf{b}_{ij}}' = \left(\textbf{b}_{ij}\right)^{-1}$ and $ \left(\textbf{a} \circ \textbf{b}'\right)_{ij} = \textbf{a}_{ij} {\textbf{b}'}_{ij} $

Computes elementwise division between two matrices

◆ operator/() [2/2]

template<typename T , std::size_t N, std::size_t M>
constexpr matrix<T, N, M> nil::crypto3::algebra::operator/ ( a,
const matrix< T, N, M > &  m 
)
constexpr

computes the quotient between a matrix and a scalar

Parameters
man $ N \times M $ matrix of type T
aa scalar of type T
Returns
$ \textbf{m}/a $ such that $ \left(\textbf{m}/a\right)_{ij} = \frac{\textbf{m}_{ij}}{a} $

Computes division between a matrix and a scalar.

◆ operator==()

template<typename T , std::size_t N, std::size_t M>
constexpr bool nil::crypto3::algebra::operator== ( const matrix< T, N, M > &  a,
const matrix< T, N, M > &  b 
)
constexpr

checks equality of two matrices

Parameters
aan $ N \times M $ matrix of type T
ban $ N \times M $ matrix of type T
Returns
true if and only if $ \textbf{a}_{ij} = \textbf{b}_{ij}\ \forall i,j \in 1\ .. N $

Checks the equality of two matrices.

◆ rank()

template<typename T , std::size_t M, std::size_t N>
constexpr std::size_t nil::crypto3::algebra::rank ( const matrix< T, M, N > &  m)
constexpr

Compute the rank.

Parameters
m$ M \times N $ matrix of type T
Returns
a scalar $ \textrm{rank}\left(\textbf{m}\right) $

Computes the rank using the reduced row echelon form.

◆ real()

template<typename T , std::size_t M, std::size_t N>
constexpr matrix<detail::remove_complex_t<T>, M, N> nil::crypto3::algebra::real ( const matrix< T, M, N > &  m)
constexpr

computes the elementwise real

Parameters
man $ M \times N $ matrix of type T
Returns
an $ M \times N $ matrix $\textbf{m}$ of type T such that $ \left(\textbf{m}}_{ij} = \mathbb{R}\{\textbf{m}_{ij}\},\ \forall i,j $

Computes the elementwise real of a matrix

◆ repmat()

template<std::size_t Row, std::size_t Col, std::size_t M, std::size_t N, typename T >
constexpr matrix<T, M * Row, N * Col> nil::crypto3::algebra::repmat ( const matrix< T, M, N > &  m)
constexpr

repeats a matrix

Template Parameters
Rowthe number of times to repeat in the row direction
Colthe number of times to repeat in the column direction
Parameters
man $ M \times N $ matrix of type T
Returns
an $ \left(M\times\textrm{Row}\right) \times \left(N\times\textrm{Col}\right) $ matrix $ \textbf{m}' $ of type T such that $ \textbf{m}'_{ij} = \textbf{m}_{\left(i\ \textrm{mod}\ M\right),\ \left(j\ \textrm{mod}\ N \right)} $

Repeats copies of a matrix.

◆ reshape()

template<std::size_t P, std::size_t Q, std::size_t M, std::size_t N, typename T >
constexpr matrix<T, P, Q> nil::crypto3::algebra::reshape ( const matrix< T, M, N > &  m)
constexpr

reshapes a matrix

Parameters
man $ M \times N $ matrix of type T
Returns
a $ P \times Q $ matrix of type T

Reshapes a matrix without changing the order of the elements in memory (in row-major order).

◆ rref() [1/2]

template<typename T , std::size_t M, std::size_t N>
constexpr matrix<T, M, N> nil::crypto3::algebra::rref ( const matrix< T, M, N > &  m)
constexpr

Compute the reduced row echelon form.

Parameters
man $ M \times N $ matrix of type T
Returns
an $ M \times N $ matrix of type T, the reduced row echelon form of $ \textbf{m} $

Computes the reduced row echelon form of a matrix using Gauss-Jordan elimination. The tolerance for determining negligible elements is $ \max\left(N, M\right) \cdot \epsilon \cdot {\left\lVert \textbf{m} \right\rVert}_\infty $.

◆ rref() [2/2]

template<typename T , std::size_t M, std::size_t N>
constexpr matrix<T, M, N> nil::crypto3::algebra::rref ( const matrix< T, M, N > &  m,
tolerance 
)
constexpr

Compute the reduced row echelon form.

Parameters
man $ M \times N $ matrix of type T
tolerancethe tolerance used to determine when an element is negligible (near zero)
Returns
an $ M \times N $ matrix of type T, the reduced row echelon form of $ \textbf{m} $

Computes the reduced row echelon form of a matrix using Gauss-Jordan elimination.

◆ submat()

template<std::size_t P, std::size_t Q, std::size_t M, std::size_t N, typename T >
constexpr matrix<T, P, Q> nil::crypto3::algebra::submat ( const matrix< T, M, N > &  m,
std::size_t  a,
std::size_t  b 
)
constexpr

extracts the submatrix of a matrix

Parameters
man $ M \times N $ matrix of type T
athe starting index into the rows
bthe starting index into the columns
Returns
an $ P \times Q $ submatrix $ \textbf{m}' $ of type T such that $ {\textbf{m}'}_{ij} = \textbf{m}_{\left(a + i\right),\ \left(b + j\right)} $

Extracts the submatrix of a matrix.

◆ swapcol()

template<std::size_t M, std::size_t N, typename T >
constexpr matrix<T, M, N> nil::crypto3::algebra::swapcol ( matrix< T, M, N >  m,
std::size_t  a,
std::size_t  b 
)
constexpr

swaps columns of a matrix

Parameters
man $ M \times N $ matrix of type T
athe index of a column to swap
bthe index of a column to swap
Returns
an $ M \times N $ matrix $ \textbf{m}' $ of type T such that $ {\textbf{m}'}_{ij} = \begin{cases} \textbf{m}_{ib} & j = a\\ \textbf{m}_{ia} & j = b\\ \textbf{m}_{ij} & \textrm{otherwise} \end{cases} $

Swap two rows of a matrix.

◆ swaprow()

template<std::size_t M, std::size_t N, typename T >
constexpr matrix<T, M, N> nil::crypto3::algebra::swaprow ( matrix< T, M, N >  m,
std::size_t  a,
std::size_t  b 
)
constexpr

swaps rows of a matrix

Parameters
man $ M \times N $ matrix of type T
athe index of a row to swap
bthe index of a row to swap
Returns
an $ M \times N $ matrix $ \textbf{m}' $ of type T such that $ {\textbf{m}'}_{ij} = \begin{cases} \textbf{m}_{bj} & i = a\\ \textbf{m}_{aj} & i = b\\ \textbf{m}_{ij} & \textrm{otherwise} \end{cases} $

Swap two rows of a matrix.

◆ trace()

template<typename T , std::size_t M>
constexpr T nil::crypto3::algebra::trace ( const matrix< T, M, M > &  m)
constexpr

computes the trace

Parameters
man $ M \times M $ matrix of type T
Returns
the trace of $ \textbf{m} $, $ \textrm{tr}\left(\textbf{m}\right) $ such that $ \textrm{tr}\left(\textbf{m}\right) = \sum\limits_{n=1}^{M} \textbf{m}_{nn} $

Computes the trace of a matrix.

◆ transpose()

template<typename T , std::size_t M, std::size_t N>
constexpr matrix<T, N, M> nil::crypto3::algebra::transpose ( const matrix< T, M, N > &  m)
constexpr

computes the transpose

Parameters
man $ M \times N $ matrix of type T
Returns
an $ N \times M $ matrix $ \textbf{m}^{\mathrm{T}} $ of type T such that $ \left(\textbf{m}^{\mathrm{T}}\right)_{ij} = \textbf{m}_{ji},\ \forall i,j $

Computes the matrix transpose.

◆ vectmatmul()

template<typename T , std::size_t M, std::size_t N>
constexpr vector<T, N> nil::crypto3::algebra::vectmatmul ( const vector< T, M > &  v,
const matrix< T, M, N > &  m 
)
constexpr

computes the product of vector and matrix

Parameters
van M-vector
man $M \times N$ matrix
Returns
an N-vector of type T

◆ vertcat()

template<std::size_t M, std::size_t N, std::size_t P, typename T >
constexpr matrix<T, M + N, P> nil::crypto3::algebra::vertcat ( const matrix< T, M, P > &  a,
const matrix< T, N, P > &  b 
)
constexpr

vertically concatenates two matrices

Parameters
aan $ M \times P $ matrix of type T
ban $ N \times P $ matrix of type T
Returns
an $ \left(M+N\right) \times P $ matrix of type T $ \left[\textbf{a}; \textbf{b}\right] $ such that $ \left(\left[\textbf{a}; \textbf{b}\right]\right)_{ij} = \begin{cases} \textbf{a}_{ij} & i < M\\ \textbf{b}_{\left(i - M\right),\ j} & i \ge M \end{cases} $

Vertically concatenates two matrices.

Variable Documentation

◆ identity

template<typename T , std::size_t N>
const matrix<T, N, N> nil::crypto3::algebra::identity
Initial value:
= generate<N, N>([](std::size_t i, std::size_t j) {
return T(i == j ? 1 : 0);
})

the matrix identity

The matrix identity $ I_N $.

matrix(const T(&)[M][N]) -> matrix< T, M, N >
deduction guide for aggregate initialization