HILA
|
Class for coordinate vector useful in indexing lattice. More...
#include <coordinates.h>
Public Member Functions | |
auto | abs () const |
Returns absolute value of Matrix. | |
Rtype | adjoint () const |
Adjoint of matrix. | |
const Array< n, m, T > & | asArray () const |
Cast Matrix to Array. | |
const DiagonalMatrix< n, T > & | asDiagonalMatrix () const |
Cast Vector to DiagonalMatrix. | |
Vector< n, T > | column (int c) const |
Returns column vector as value at index c. | |
Matrix< n, m, T > | conj () const |
Returns complex conjugate of Matrix. | |
CoordinateVector_t (const Direction dir) | |
Construct from site index. | |
template<typename S , std::enable_if_t< hila::is_assignable< T &, S >::value, int > = 0> | |
CoordinateVector_t (std::initializer_list< S > rhs) | |
CoordinateVector_t (std::nullptr_t z) | |
Construct from 0, using nullptr_t autocast. | |
Rtype | dagger () const |
Hermitian conjugate of matrix. | |
T | det () const |
determinant function - if matrix size is < 5, use Laplace, otherwise LU | |
T | det_laplace () const |
Determinant of matrix, using Laplace method. | |
T | det_lu () const |
following calculate the determinant of a square matrix det() is the generic interface, using laplace for small matrices and LU for large | |
DiagonalMatrix< n, T > | diagonal () |
Return diagonal of square matrix. | |
R | dot (const Matrix< p, q, S > &rhs) const |
Dot product. | |
T | e (const int i) const |
Standard array indexing operation for vectors. | |
T | e (const int i, const int j) const |
Standard array indexing operation for matrices. | |
int | eigen_hermitean (DiagonalMatrix< n, Et > &eigenvalues, Matrix_t< n, n, Mt, MT > &eigenvectors, enum hila::sort sorted=hila::sort::unsorted) const |
Calculate eigenvalues and -vectors of an hermitean (or symmetric) matrix. | |
eigen_result< Matrix< n, m, T > > | eigen_hermitean (enum hila::sort sorted=hila::sort::unsorted) const |
eigenvalues and -vectors of hermitean/symmetric matrix, alternative interface | |
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. | |
const Matrix< n, m, T > & | fill (const S rhs) |
Matrix fill. | |
Matrix< n, m, T > & | gaussian_random (double width=1.0) |
Fills Matrix with gaussian random elements from gaussian distribution. | |
Matrix< n, m, hila::arithmetic_type< T > > | imag () const |
Returns imaginary part of Matrix or Vector. | |
T | max () const |
Find max of Matrix only for arithmetic types. | |
T | min () const |
Find min of Matrix only for arithmetic types. | |
CoordinateVector_t | mod (const CoordinateVector_t &m) const |
hila::type_mul< T, S > | mul_trace (const Matrix_t< p, q, S, MT > &rm) const |
Multiply with given matrix and compute trace of result. | |
void | mult_by_2x2_left (int p, int q, const Matrix_t< 2, 2, R, Mt > &M) |
Multiply \( n \times m \)-matrix from the left by \( n \times m \) matrix defined by \( 2 \times 2 \) sub matrix. | |
void | mult_by_2x2_right (int p, int q, const Matrix_t< 2, 2, R, Mt > &M) |
Multiply \( n \times m \)-matrix from the right by \( n \times m \) matrix defined by \( 2 \times 2 \) sub matrix. | |
hila::arithmetic_type< T > | norm () const |
Calculate vector norm - sqrt of squarenorm. | |
bool | operator!= (const Matrix< n, m, S > &rhs) const |
Boolean operator != to check if matrices are exactly different. | |
Rt | operator* (const Matrix< 1, m, T1 > &A, const Matrix< n, 1, T2 > &B) |
Multiplication operator RowVector * Vector. | |
Rt | operator* (const Mt &mat, const S &rhs) |
Multiplication operator Matrix * scalar. | |
Matrix< n, m, R > | operator* (const Mt1 &a, const Mt2 &b) |
Multiplication operator. | |
Rt | operator* (const S &rhs, const Mt &mat) |
Multiplication operator Scalar * Matrix. | |
Matrix< n, m, T > & | operator*= (const DiagonalMatrix< m, S > &rhs) |
Multiply assign operator for DiagonalMatrix to Matrix. | |
Matrix< n, m, T > & | operator*= (const Matrix_t< m, p, S, MT > &rhs) |
Multiply assign scalar or matrix. | |
Matrix< n, m, T > & | operator*= (const S rhs) |
Multiply assign operator scalar to Matrix. | |
Rtype | operator+ (const Matrix< n, m, T > &a, const S &b) |
Addition operator Matrix + scalar. | |
Rtype | operator+ (const Mtype1 &a, const Mtype2 &b) |
Addition operator Matrix + Matrix. | |
Rtype | operator+ (const S &b, const Matrix< n, m, T > &a) |
Addition operator scalar + Matrix. | |
Matrix< n, m, T > & | operator+= (const DiagonalMatrix< n, S > &rhs) |
Addition assign operator for DiagonalMatrix to Matrix. | |
Matrix< n, m, T > & | operator+= (const Matrix_t< n, m, S, MT > &rhs) |
Add assign operator Matrix to Matrix. | |
Matrix< n, m, T > & | operator+= (const S &rhs) |
Add assign operator scalar to Matrix. | |
Rtype | operator- (const Matrix< n, m, T > &a, const S &b) |
Subtraction operator Matrix - scalar. | |
Rtype | operator- (const Mtype1 &a, const Mtype2 &b) |
Subtraction operator Matrix - Matrix. | |
Rtype | operator- (const S &b, const Matrix< n, m, T > &a) |
Subtraction operator Scalar - Matrix. | |
Matrix< n, m, T > & | operator-= (const DiagonalMatrix< n, S > &rhs) |
Subtract assign operator for DiagonalMatrix to Matrix. | |
Matrix< n, m, T > & | operator-= (const Matrix_t< n, m, S, MT > &rhs) |
Subtract assign operator Matrix to MAtrix. | |
Matrix< n, m, T > & | operator-= (const S rhs) |
Subtract assign operator scalar to Matrix. | |
Rt | operator/ (const Mt &mat, const S &rhs) |
Division operator. | |
Matrix< n, m, T > & | operator/= (const DiagonalMatrix< m, S > &rhs) |
Divide assign operator for DiagonalMatrix to Matrix. | |
Matrix< n, m, T > & | operator/= (const S rhs) |
Divide assign oprator scalar with 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<typename S , std::enable_if_t< hila::is_assignable< T &, S >::value, int > = 0> | |
CoordinateVector_t & | operator= (std::initializer_list< S > rhs) |
Assign from initializer list. | |
CoordinateVector_t & | operator= (std::nullptr_t z) |
Assign from 0. | |
bool | operator== (const Matrix< n, m, S > &rhs) const |
Boolean operator == to determine if two matrices are exactly the same. | |
Matrix< n, p, R > | outer_product (const Matrix< p, q, S > &rhs) const |
Outer product. | |
Matrix< n, m, T > | permute (const Vector< N, int > &permutation) const |
Permute elements of vector. | |
Matrix< n, m, T > | permute_columns (const Vector< m, int > &permutation) const |
permute columns of Matrix | |
Matrix< n, m, T > | permute_rows (const Vector< n, int > &permutation) const |
permute rows of Matrix | |
Matrix< n, m, T > & | random () |
dot with matrix - matrix | |
Matrix< n, m, hila::arithmetic_type< T > > | real () const |
Returns real part of Matrix or Vector. | |
const RowVector< m, T > & | row (int r) const |
Return reference to row in a matrix. | |
void | set_column (int c, const Vector< n, S > &v) |
get column of a matrix | |
void | set_diagonal (const Vector< n, S > &v) |
Set diagonal of square matrix to Vector which is passed to the method. | |
void | set_row (int r, const RowVector< m, S > &v) |
Set row of Matrix with RowVector if types are assignable. | |
Matrix< n, m, T > | sort (hila::sort order=hila::sort::ascending) const |
Sort method for Vector. | |
Matrix< n, m, T > | sort (Vector< N, int > &permutation, hila::sort order=hila::sort::ascending) const |
Sort method for Vector which returns permutation order. | |
hila::arithmetic_type< T > | squarenorm () const |
Calculate square norm - sum of squared elements. | |
std::string | str (int prec=8, char separator=' ') const |
svd_result< Matrix< n, m, T > > | svd (enum hila::sort sorted=hila::sort::unsorted) const |
svd and svd_pivot - alternative interface | |
int | svd (Matrix_t< n, n, Mt, MT > &_U, DiagonalMatrix< n, Et > &_D, Matrix_t< n, n, Mt, MT > &_V, enum hila::sort sorted=hila::sort::unsorted) const |
Singular value decomposition: divide matrix A = U S V*, where U,V unitary and S diagonal matrix of real singular values. Unpivoted Jacobi rotations. | |
int | svd_pivot (Matrix_t< n, n, Mt, MT > &_U, DiagonalMatrix< n, Et > &_D, Matrix_t< n, n, Mt, MT > &_V, enum hila::sort sorted=hila::sort::unsorted) const |
Singular value decomposition: divide matrix A = U S V*, where U,V unitary and S diagonal matrix of real singular values. Fully pivoted Jacobi rotations. | |
T | trace () const |
Computes Trace for Matrix. | |
Rtype | transpose () const |
Transpose of matrix. | |
const RowVector< n, T > & | transpose () const |
Transpose of vector. | |
const Vector< n, T > & | transpose () const |
Transpose of RowVector. | |
Static Public Member Functions | |
static constexpr int | columns () |
Returns column length. | |
static constexpr bool | is_square () |
Returns true if matrix is a square matrix. | |
static constexpr bool | is_vector () |
Returns true if Matrix is a vector. | |
static constexpr int | rows () |
Define constant methods rows(), columns() - may be useful in template code. | |
static constexpr int | size () |
Returns size of Vector or square Matrix. | |
Public Attributes | |
T | c [n *m] |
The data as a one dimensional array. | |
Class for coordinate vector useful in indexing lattice.
Defined as Vector<NDIM, int> meaning that all operations from Matrix class are inherited
Note: this is defined as a template, with generic "int" type T, and the type is defined below as alias:
Reason for this is that if CoordinateVector is used in Field variables (Field<CoordinateVector>) hilapp is able to upgrade the int to vectorized int when vectorized compilation are used (AVX2, AVX512)
T | int |
Definition at line 254 of file coordinates.h.
|
inline |
Construct CV automatically from right-size initializer list This does not seem to be dangerous, so keep non-explicit
Definition at line 284 of file coordinates.h.
|
inlineinherited |
Returns column vector as value at index c.
c | index of column vector to be returned |
Determinant of matrix, using Laplace method.
Defined only for square matrices
For perfomance overloads exist for \( 1 \times 1 \), \( 2 \times 2 \) and \( 3 \times 3 \) matrices.
mat | matrix to compute determinant for |
Definition at line 1589 of file matrix_linalg.h.
following calculate the determinant of a square matrix det() is the generic interface, using laplace for small matrices and LU for large
Matrix determinant with LU decomposition.
Algorithm: numerical Recipes, 2nd ed. p. 47 ff Works for Real and Complex matrices Defined only for square matrices
Definition at line 1587 of file matrix_linalg.h.
|
inlineinherited |
Return diagonal of square matrix.
If called for non square matrix the program will throw an error.
|
inlineinherited |
Dot product.
Only works between two Vector objects
p | Row length for rhs |
q | Column length for rhs |
S | Type for rhs |
R | Gives resulting type of lhs and rhs multiplication |
rhs | Vector to compute dot product with |
Standard array indexing operation for vectors.
Accessing singular elements is insufficient, but Vector elements are often quite small.
q | Number of rows |
p | Number of columns |
i | Index |
|
inherited |
Calculate eigenvalues and -vectors of an hermitean (or symmetric) matrix.
Calculate eigenvalues and vectors of an hermitean or real symmetric matrix.
Returns the number of Jacobi iterations, or -1 if did not converge. Arguments will contain eigenvalues and eigenvectors in columns of the "eigenvectors" matrix. Computation is done in double precision despite the input matrix types.
eigenvaluevec | Vector of computed eigenvalue |
eigenvectors | Eigenvectors as columns of \( n \times n \) Matrix |
Algorithm uses fully pivoted Jacobi rotations.
Two interfaces:
H.eigen_hermitean(E, U, [optional: sort]); E: output is DiagnoalMatrix containing real eigenvalues U: nxn unitary matrix, columns are normalized eigenvectors
auto res = H.eigen_hermitean([optional: sort]); This saves the trouble of defining E and U (see below)
Thus, H = U E U^* and H U = U E
Both interfaces allow optional sorting according to eigenvalues: hila::sort::unsorted [default] hila::sort::ascending / descending
Example:
E | diagonal matrix of real eigenvalues |
U | Unitary nxn matrix of eigenvectors |
sorted | sorting of eigenvalues (default:unsorted) |
Definition at line 1605 of file matrix_linalg.h.
|
inherited |
eigenvalues and -vectors of hermitean/symmetric matrix, alternative interface
result = eigen_hermitean(hila::sort [optional]) returns struct eigen_result<Mtype>, with fields eigenvalues: DiagonalMatrix of eigenvalues eigenvectors: nxn unitary matrix of eigenvectors
Example:
This interface saves the trouble of defining the eigenvalue and -vector variables.
Definition at line 1609 of file matrix_linalg.h.
|
inlineinherited |
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 |
|
inlineinherited |
|
inlineinherited |
Fills Matrix with gaussian random elements from gaussian distribution.
width |
|
inlineinherited |
|
inline |
Positive mod for coordinate vector, see int mod(int a, int b). If 2nd argument m is lattice.size(), this mods the vector a to periodic lattice.
Definition at line 430 of file coordinates.h.
|
inlineinherited |
Multiply with given matrix and compute trace of result.
Slightly cheaper operation than
p | |
q | |
S | |
MT |
rm |
|
inlineinherited |
Multiply \( n \times m \)-matrix from the left by \( n \times m \) matrix defined by \( 2 \times 2 \) sub matrix.
The multiplication is defined as follows, let \(M\) as the \( 2 \times 2 \) input matrix and \(B\) be (this)
matrix, being the matrix stored in the object this method is called for. Let \(A = I\) be a \( n \times m \) unit matrix. We then set the values of A to be:
\begin{align} A_{p,p} = M_{0,0}, \hspace{5px} A_{p,q} = M_{0,1}, \hspace{5px} A_{q,p} = M_{1,0}, \hspace{5px} A_{q,q} = M_{1,1}. \end{align}
Then the resulting matrix will be:
\begin{align} B = A \cdot B \end{align}
R | Element type of M |
Mt | Matrix type of M |
p | First row and column |
q | Second row and column |
M | \( 2 \times 2\) Matrix to multiply with |
|
inlineinherited |
Multiply \( n \times m \)-matrix from the right by \( n \times m \) matrix defined by \( 2 \times 2 \) sub matrix.
See Matrix::mult_by_2x2_left, only difference being that the multiplication is from the right.
R | Element type of M |
Mt | Matrix type of M |
p | First row and column |
q | Second row and column |
M | \( 2 \times 2\) Matrix to multiply with |
|
inlineinherited |
Boolean operator != to check if matrices are exactly different.
if matrices are exactly the same then this will return false
S | Type for MAtrix which is being compared to |
rhs | right hand side Matrix which we are comparing |
Multiplication operator RowVector * Vector.
Defined as standard dot product between vectors as long as vectors are of same length
m | Dimensions of RowVector |
n | Dimension of Vector |
T1 | Element type of RowVector |
T2 | Element type of Vector |
Rt | Return type of T1 \( \cdot \) T2 product |
A | RowVector to multiply |
B | Vector to multiply |
|
inlineinherited |
|
inlineinherited |
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
Vector * RowVector is same as outer product which is equivalent to a matrix multiplication
|
inlineinherited |
|
inlineinherited |
Multiply assign operator for DiagonalMatrix to Matrix.
Simply defined as matrix multiplication, but since rhs is guaranteed to be diagonal the method is optimized to skip most of the elements.
S | Element type of rhs |
rhs | DiagonalMatrix to multiply |
|
inlineinherited |
Multiply assign scalar or matrix.
Multiplication works as defined for matrix multiplication
Matrix multiply assign only defined for square matrices, since the matrix dimensions would change otherwise.
rhs | Matrix to multiply with |
|
inlineinherited |
|
inlineinherited |
Addition operator Matrix + scalar.
Addition operator between matrix and scalar is defined in the usual way, where the scalar is added to the diagonal elements.
Mtype | Matrix type of b |
S | Type of scalar |
a | Matrix to add to |
b | Scalar to add |
|
inlineinherited |
|
inlineinherited |
Addition operator scalar + Matrix.
Addition operator between Scalar and Matrix is defined in the usual way, where the scalar is treated as diagonal matrix which is then added to. \( 2 + M = 2\cdot\mathbb{1} + M \)
Mtype | Matrix type of a |
S | scalar type of b |
b | Matrix to add |
a | Scalar to add to |
|
inlineinherited |
Addition assign operator for DiagonalMatrix to Matrix.
Works as long as Matrix to assign to is square
S | Element type of rhs |
rhs | DiagonalMatrix to add |
|
inlineinherited |
|
inlineinherited |
Add assign operator scalar to Matrix.
Adds scalar \( a \) to square matrix as \( M + a\cdot\mathbb{1} \)
S | Element type of scalar rhs |
rhs | Sclar to add |
|
inlineinherited |
Subtraction operator Matrix - scalar.
Subtraction operator between matrix and scalar is defined in the usual way, where the scalar is subtracted from the diagonal elements.
\( M - 2 = M - 2\cdot\mathbb{1} \)
Mtype | Matrix type of a |
S | Scalar type of b |
a | Matrix to subtract from |
b | Scalar to subtract |
|
inlineinherited |
|
inlineinherited |
Subtraction operator Scalar - Matrix.
Subtraction operator between Scalar and Matrix is defined in the usual way, where the scalar is treated as diagonal matrix which is then subtracted from.
\( 2 - M = 2\cdot\mathbb{1} - M \)
Mtype | Matrix type a |
S | Scalar type of b |
b | Scalar to subtract from |
a | Matrix to subtract |
|
inlineinherited |
Subtract assign operator for DiagonalMatrix to Matrix.
Works as long as Matrix to assign to is square
S | Element type of rhs |
rhs | DiagonalMatrix to add |
|
inlineinherited |
Subtract assign operator scalar to Matrix.
Subtract scalar \( a \) to square matrix as \( M - a\cdot\mathbb{1} \)
S | Element type of scalar rhs |
rhs | scalar to add |
|
inlineinherited |
|
inlineinherited |
Divide assign operator for DiagonalMatrix to Matrix.
Well defined since rhs is guaranteed to be Diagonal.
Let M be the Matrix which we divide and D be the DiagonalMatrix which we divide with then the operation is defined as \( M \cdot D^{-1} \).
S | Element type of rhs |
rhs | DiagonalMatrix to divide |
|
inlineinherited |
Divide assign oprator scalar with matrix.
Divide works as defined for scalar matrix division.
S | Scalar type of rhs |
rhs | Scalar to divide with |
|
inherited |
|
inlineinherited |
|
inlineinherited |
Outer product.
Only works between two Vector objects
p | Row length for rhs |
q | Column length for rhs |
S | Element type for rhs |
R | Type between lhs and rhs multiplication |
rhs | Vector to compute outer product with |
dot with matrix - matrix
Generate random elements
Fills Matrix with random elements from uniform distribution
|
inlineinherited |
|
inlineinherited |
Return reference to row in a matrix.
Since the Matrix data is ordered in a row major order accessing a row returns a reference to the row.
r | index of row to be referenced |
|
inlineinherited |
get column of a matrix
Set column of Matrix with Vector if types are assignable
S | Vector type |
c | Index of column to be set |
v | Vector to be set |
|
inlineinherited |
Set diagonal of square matrix to Vector which is passed to the method.
If called for non square matrix the program will throw an error.
Example:
S | type vector to assign values to |
v | Vector to assign to diagonal |
|
inlineinherited |
|
inlineinherited |
Sort method for Vector.
Order can be past as argument as either ascending (default) or descending
Ascending
Descending
order | Order to sort in |
|
inlineinherited |
Sort method for Vector which returns permutation order.
Order can be past as argument as either ascending (default) or descending
Ascending
Descending
N |
permutation | |
order |
|
inherited |
svd and svd_pivot - alternative interface
svd(hila::sort [optional]) returns struct svd_result<Mtype>, with fields U: nxn unitary matrix singularvalues: DiagonalMatrix of singular values (real, > 0) V: nxn unitary matrix
auto res = M.svd(); now res.U : nxn unitary res.singularvalues : DiagonalMatrix of singular values res.V : nxn unitary
result satifies M = res.U res.singularvalues res.V.dagger()
Definition at line 1630 of file matrix_linalg.h.
|
inherited |
Singular value decomposition: divide matrix A = U S V*, where U,V unitary and S diagonal matrix of real singular values. Unpivoted Jacobi rotations.
Unpivoted rotation is generally faster than pivoted (esp. on gpu), but a bit less accurate
Use: M.svd(U, S, V, [sorted]);
Result satisfies M = U S V.dagger()
The algorithm works by one-sided Jacobi rotations.
Definition at line 1626 of file matrix_linalg.h.
|
inherited |
Singular value decomposition: divide matrix A = U S V*, where U,V unitary and S diagonal matrix of real singular values. Fully pivoted Jacobi rotations.
Use: M.svd_pivot(U, S, V, [sorted]);
The algorithm works by one-sided Jacobi rotations.
U |
Definition at line 1635 of file matrix_linalg.h.