HILA
|
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"
Go to the source code of this file.
Classes | |
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... | |
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_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... | |
class | Matrix< n, m, T > |
\( n \times m \) Matrix class which defines matrix operations. More... | |
Namespaces | |
namespace | hila |
Implement hila::swap for gauge fields. | |
Typedefs | |
template<int n, typename T > | |
using | Vector = Matrix< n, 1, T > |
Vector is defined as 1-column Matrix. | |
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> | |
Functions | |
template<typename Mtype , std::enable_if_t< Mtype::is_matrix(), int > = 0> | |
auto | transpose (const Mtype &arg) |
Return transposed Matrix or Vector. | |
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 | adjoint (const Mtype &arg) |
Return adjoint Matrix. | |
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 | abs (const Mtype &arg) |
Return absolute value Matrix or Vector. | |
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 | real (const Mtype &arg) |
Return real of Matrix or Vector. | |
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, typename Rtype = hila::mat_x_mat_type<Mtype1, Mtype2>, std::enable_if_t<!std::is_same< Mtype1, Rtype >::value, int > = 0> | |
Rtype | operator+ (const Mtype1 &a, const Mtype2 &b) |
Addition operator. | |
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>> | |
Rtype | operator- (const Mtype1 &a, const Mtype2 &b) |
Subtraction operator. | |
template<typename Mt1 , typename Mt2 , std::enable_if_t< Mt1::is_matrix() &&Mt2::is_matrix() &&!std::is_same< Mt1, Mt2 >::value, int > = 0, typename R = hila::type_mul<hila::number_type<Mt1>, hila::number_type<Mt2>>, int n = Mt1::rows(), int m = Mt2::columns()> | |
Matrix< n, m, R > | operator* (const Mt1 &a, const Mt2 &b) |
Multiplication operator. | |
template<typename Mt , typename S , std::enable_if_t<(Mt::is_matrix() &&hila::is_complex_or_arithmetic< S >::value), int > = 0, typename Rt = hila::mat_scalar_type<Mt, S>> | |
Rt | operator/ (const Mt &mat, const S &rhs) |
Division operator. | |
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() &&Mt::is_square(), int > = 0> | |
void | mult (const Mt &a, const Mt &b, Mt &res) |
compute product of two square matrices and write result to existing matrix | |
template<int n, int m, typename T , typename MT > | |
std::ostream & | operator<< (std::ostream &strm, const Matrix_t< n, m, T, MT > &A) |
Stream operator. | |
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<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 Mt , std::enable_if_t< Mt::is_matrix(), int > = 0> | |
auto | squarenorm (const Mt &rhs) |
Returns square norm of Matrix. | |
template<typename Mt , std::enable_if_t< Mt::is_matrix(), int > = 0> | |
auto | norm (const Mt &rhs) |
Returns vector norm of Matrix. | |
template<int n, int m, typename T , typename MT > | |
Matrix_t< n, m, T, MT > | exp (const Matrix_t< n, m, T, MT > &mat, const int order=20) |
Calculate exp of a square matrix. | |
template<int n, int m, typename T , typename MT > | |
void | chexp (const Matrix_t< n, m, T, MT > &mat, Matrix_t< n, m, T, MT > &omat, Matrix_t< n, m, T, MT >(&pl)[n+1]) |
Calculate exp of a square matrix. | |
template<int n, int m, typename T , typename MT > | |
Matrix_t< n, m, T, MT > | chsexp (const Matrix_t< n, m, T, MT > &mat) |
Calculate exp of a square matrix. | |
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.
|
inline |
Return absolute value Matrix or Vector.
Wrapper around Matrix::abs
Can be called as:
Mtype | Matrix type |
arg | Object to compute absolute value of |
|
inline |
Return adjoint Matrix.
Wrapper around Matrix::adjoint
Can be called as:
Mtype | Matrix type |
arg | Object to compute adjoint of |
|
inline |
Calculate exp of a square matrix.
Computation is done using iterative Cayley-Hamilton (cf. from arXiv:2404.07704)
mat | Matrix to compute exponential for |
omat | Matrix to which exponential of mat gets stored (optional) |
pl | array of n+1 temporary nxn Matrices (optional) |
|
inline |
Calculate exp of a square matrix.
Computation is done using iterative Cayley-Hamilton (cf. from arXiv:2404.07704) with minimal temporary storage
mat | Matrix to compute exponential for |
|
inline |
Return conjugate Matrix or Vector.
Wrapper around Matrix::conj
Can be called as:
Mtype | Matrix type |
arg | Object to be conjugated |
|
inline |
Return dagger of Matrix.
Wrapper around Matrix::adjoint
Same as adjoint
Mtype | Matrix type |
arg | Object to compute dagger of |
|
inline |
Calculate exp of a square matrix.
Computes up to certain order given as argument
Evaluation is done as:
\begin{align} \exp(H) &= 1 + H + \frac{H^2}{2!} + \frac{H^2}{2!} + \frac{H^3}{3!} \\ &= 1 + H\cdot(1 + (\frac{H}{2})\cdot (1 + (\frac{H}{3})\cdot(...))) \end{align}
Done backwards in order to reduce accumulation of errors
mat | Matrix to compute exponential for |
order | order to compute exponential to |
|
inline |
Return imaginary of Matrix or Vector.
Wrapper around Matrix::imag
Can be called as:
Mtype | Matrix type |
arg | Object to compute imag part of |
|
inline |
Returns trace of product of two matrices.
Wrapper around Matrix::mul_trace in the form
|
inline |
|
inline |
|
inline |
Multiplication operator.
Multiplication type depends on the original types of the multiplied matrices. Defined for the following operations.
Standard matrix multiplication where LHS columns must match RHS rows
RowVector * Vector / Vector * RowVector:
Defined as standard dot product between vectors as long as vectors are of same length
Vector * RowVector is same as outer product which is equivalent to a matrix multiplication
Matrix * Scalar / Scalar * Matrix:
Multiplication operator between Matrix and Scalar are defined in the usual way (element wise)
|
inline |
Addition operator.
Defined for the following operations
Addition operator between matrices is defined in the usual way (element wise).
NOTE: Matrices must share same dimensionality.
Scalar + Matrix / Matrix + Scalar:
Addition operator between matrix and scalar is defined in the usual way, where the scalar is added to the diagonal elements.
NOTE: Exact definition exist in overloaded functions that can be viewed in source code.
\( M + 2 = M + 2\cdot\mathbb{1} \)
a | Left matrix or scalar |
b | Right matrix or scalar |
|
inline |
Subtraction operator.
Defined for the following operations
Subtraction operator between matrices is defined in the usual way (element wise).
NOTE: Matrices must share same dimensionality.
Scalar - Matrix / Matrix - Scalar:
Subtraction operator between matrix and scalar is defined in the usual way, where the scalar is subtracted from the diagonal elements.
NOTE: Exact definition exist in overloaded functions that can be viewed in source code.
\( M - 2 = M - 2\cdot\mathbb{1} \)
a | Left matrix or scalar |
b | Right matrix or scalar |
|
inline |
Division operator.
Defined for following operations
__ Matrix / Scalar: __
Division operator between Matrix and Scalar are defined in the usual way (element wise)
Mt | Matrix type |
S | Scalar type |
mat | Matrix to divide scalar with |
rhs | Scalar to divide with |
std::ostream & operator<< | ( | std::ostream & | strm, |
const Matrix_t< n, m, T, MT > & | A | ||
) |
|
inline |
Return real of Matrix or Vector.
Wrapper around Matrix::real
Can be called as:
Mtype | Matrix type |
arg | Object to compute real part of |
|
inline |
Returns square norm of Matrix.
Wrapper around Matrix::squarenorm - sum of squared elements
Can be called as:
Mt | Matrix type |
rhs | Matrix to compute square norm of |
|
inline |
Return trace of square Matrix.
Wrapper around Matrix::trace
Can be called as:
Mtype | Matrix type |
arg | Object to compute trace of |
|
inline |
Return transposed Matrix or Vector.
Wrapper around Matrix::transpose
Can be called as:
Mtype | Matrix type |
arg | Object to be transposed |