HILA
Loading...
Searching...
No Matches
matrix.h File Reference

Definition of Matrix types. More...

#include <type_traits>
#include <sstream>
#include "plumbing/defs.h"
#include "datatypes/cmplx.h"
#include "datatypes/array.h"
#include "datatypes/diagonal_matrix.h"
#include "datatypes/matrix_linalg.h"
Include dependency graph for matrix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  eigen_result< M >
 type to store the return value of eigen_hermitean(): {E, U} where E is nxn DiagonalMatrix containing eigenvalues and U nxn unitary matrix, with eigenvector columns More...
 
class  Matrix< n, m, T >
 \( n \times m \) Matrix class which defines matrix operations. More...
 
class  Matrix_t< n, m, T, Mtype >
 The main \( n \times m \) matrix type template Matrix_t. This is a base class type for "useful" types which are derived from this. More...
 
struct  svd_result< M >
 type to store the return combo of svd: {U, D, V} where U and V are nxn unitary / orthogonal, and D is real diagonal singular value matrices. More...
 

Namespaces

namespace  hila
 Invert diagonal + const. matrix using Sherman-Morrison formula.
 

Typedefs

template<int n, typename T >
using RowVector = Matrix< 1, n, T >
 RowVector is a 1-row Matrix.
 
template<int n, typename T >
using SquareMatrix = Matrix< n, n, T >
 Square matrix is defined as alias with special case of Matrix<n,n,T>
 
template<int n, typename T >
using Vector = Matrix< n, 1, T >
 Vector is defined as 1-column Matrix.
 

Functions

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto abs (const Mtype &arg)
 Return absolute value Matrix or Vector.
 
template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto adjoint (const Mtype &arg)
 Return adjoint Matrix.
 
template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto conj (const Mtype &arg)
 Return conjugate Matrix or Vector.
 
template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto dagger (const Mtype &arg)
 Return dagger of Matrix.
 
template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto imag (const Mtype &arg)
 Return imaginary of Matrix or Vector.
 
template<typename Mtype1 , typename Mtype2 , std::enable_if_t< Mtype1::is_matrix() &&Mtype2::is_matrix(), int > = 0>
auto mul_trace (const Mtype1 &a, const Mtype2 &b)
 Returns trace of product of two matrices.
 
template<typename Mt , std::enable_if_t< Mt::is_matrix(), int > = 0>
auto norm (const Mt &rhs)
 Returns vector norm of Matrix.
 
template<typename Mt , std::enable_if_t< Mt::is_matrix() &&Mt::rows()==Mt::columns(), int > = 0>
Mt operator* (const Mt &a, const Mt &b)
 Multiplication operator Square Matrix * Square Matrix.
 
template<typename Mtype1 , typename Mtype2 , std::enable_if_t< Mtype1::is_matrix() &&Mtype2::is_matrix(), int > = 0, typename Rtype = hila::mat_x_mat_type<Mtype1, Mtype2>, std::enable_if_t< std::is_same< Mtype1, Rtype >::value, int > = 0>
Rtype operator+ (Mtype1 a, const Mtype2 &b)
 Real micro-optimization Matrix + Matrix - no extra creation of variable and copy.
 
template<int n, int m, typename T , typename MT >
std::string hila::prettyprint (const Matrix_t< n, m, T, MT > &A, int prec=8)
 Formats Matrix_t object in a human readable way.
 
template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto real (const Mtype &arg)
 Return real of Matrix or Vector.
 
template<typename Mt , std::enable_if_t< Mt::is_matrix(), int > = 0>
auto squarenorm (const Mt &rhs)
 Returns square norm of Matrix.
 
template<int n, int m, typename T , typename MT >
std::string hila::to_string (const Matrix_t< n, m, T, MT > &A, int prec=8, char separator=' ')
 Converts Matrix_t object to string.
 
template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto trace (const Mtype &arg)
 Return trace of square Matrix.
 
template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto transpose (const Mtype &arg)
 Return transposed Matrix or Vector.
 

Detailed Description

Definition of Matrix types.

This file contains base matrix type Matrix_t which defines all general matrix type operations Matrix types are Matrix, Vector, RowVector, SquareMatrix of which Matrix is defined as a class and the rest are special cases of the Matrix class.

Definition in file matrix.h.

Function Documentation

◆ abs()

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto abs ( const Mtype arg)
inline

Return absolute value Matrix or Vector.

Wrapper around Matrix::abs

Can be called as:

M_abs = abs(M);
Matrix class which defines matrix operations.
Definition matrix.h:1679
T abs(const Complex< T > &a)
Return absolute value of Complex number.
Definition cmplx.h:1322
Template Parameters
MtypeMatrix type
Parameters
argObject to compute absolute value of
Returns
auto Mtype absolute value Matrix or Vector

Definition at line 1960 of file matrix.h.

◆ adjoint()

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto adjoint ( const Mtype arg)
inline

Return adjoint Matrix.

Wrapper around Matrix::adjoint

Can be called as:

Matrix<n,m,MyType> M,M_adjoint;
M_conjugate = adjoint(M);
Template Parameters
MtypeMatrix type
Parameters
argObject to compute adjoint of
Returns
auto Mtype adjoint matrix

Definition at line 1924 of file matrix.h.

◆ conj()

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto conj ( const Mtype arg)
inline

Return conjugate Matrix or Vector.

Wrapper around Matrix::conj

Can be called as:

Matrix<n,m,MyType> M,M_conjugate;
M_conjugate = conj(M);
Array< n, m, T > conj(const Array< n, m, T > &arg)
Return conjugate Array.
Definition array.h:648
Template Parameters
MtypeMatrix type
Parameters
argObject to be conjugated
Returns
auto Mtype conjugated matrix

Definition at line 1904 of file matrix.h.

◆ dagger()

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto dagger ( const Mtype arg)
inline

Return dagger of Matrix.

Wrapper around Matrix::adjoint

Same as adjoint

Template Parameters
MtypeMatrix type
Parameters
argObject to compute dagger of
Returns
auto Mtype dagger matrix

Definition at line 1940 of file matrix.h.

◆ imag()

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto imag ( const Mtype arg)
inline

Return imaginary of Matrix or Vector.

Wrapper around Matrix::imag

Can be called as:

M_imag = imag(M);
Array< n, m, hila::arithmetic_type< T > > imag(const Array< n, m, T > &arg)
Return imaginary part of Array.
Definition array.h:676
Template Parameters
MtypeMatrix type
Parameters
argObject to compute imag part of
Returns
auto Mtype imag part of arg

Definition at line 2021 of file matrix.h.

◆ mul_trace()

template<typename Mtype1 , typename Mtype2 , std::enable_if_t< Mtype1::is_matrix() &&Mtype2::is_matrix(), int > = 0>
auto mul_trace ( const Mtype1 &  a,
const Mtype2 &  b 
)
inline

Returns trace of product of two matrices.

Wrapper around Matrix::mul_trace in the form

mul_trace(a,b) // -> a.mul_trace(b)
auto mul_trace(const Mtype1 &a, const Mtype2 &b)
Returns trace of product of two matrices.
Definition matrix.h:2528
Template Parameters
Mtype1Matrix type for a
Mtype2Matrix type for b
Parameters
aLeft Matrix
bRight Matrix
Returns
auto Resulting trace

Definition at line 2528 of file matrix.h.

◆ norm()

template<typename Mt , std::enable_if_t< Mt::is_matrix(), int > = 0>
auto norm ( const Mt &  rhs)
inline

Returns vector norm of Matrix.

Wrapper around Matrix::norm - sqrt of sum of squared elements

Template Parameters
MtMatrix type
Parameters
rhsMatrix to compute norm of
Returns
auto

Definition at line 2692 of file matrix.h.

◆ real()

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto real ( const Mtype arg)
inline

Return real of Matrix or Vector.

Wrapper around Matrix::real

Can be called as:

M_real = real(M);
Array< n, m, hila::arithmetic_type< T > > real(const Array< n, m, T > &arg)
Return real part of Array.
Definition array.h:662
Template Parameters
MtypeMatrix type
Parameters
argObject to compute real part of
Returns
auto Mtype real part of arg

Definition at line 2001 of file matrix.h.

◆ squarenorm()

template<typename Mt , std::enable_if_t< Mt::is_matrix(), int > = 0>
auto squarenorm ( const Mt &  rhs)
inline

Returns square norm of Matrix.

Wrapper around Matrix::squarenorm - sum of squared elements

Can be called as:

auto a = squarenorm(M);
hila::arithmetic_type< T > squarenorm(const Array< n, m, T > &rhs)
Return square norm of Array.
Definition array.h:957
Template Parameters
MtMatrix type
Parameters
rhsMatrix to compute square norm of
Returns
auto

Definition at line 2678 of file matrix.h.

◆ trace()

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto trace ( const Mtype arg)
inline

Return trace of square Matrix.

Wrapper around Matrix::trace

Can be called as:

T = trace(M);
Complex definition.
Definition cmplx.h:50
Template Parameters
MtypeMatrix type
Parameters
argObject to compute trace of
Returns
auto Trace of Matrix

Definition at line 1981 of file matrix.h.

◆ transpose()

template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0>
auto transpose ( const Mtype arg)
inline

Return transposed Matrix or Vector.

Wrapper around Matrix::transpose

Can be called as:

Matrix<n,m,MyType> M,M_transposed;
M_transposed = transpose(M);
Template Parameters
MtypeMatrix type
Parameters
argObject to be transposed
Returns
auto Mtype transposed matrix

Definition at line 1884 of file matrix.h.