Template Struct matrix

Struct Documentation

template<typename T>
struct matrix

A general matrix class (of ints, double and Complex types).

Public Functions

inline auto data() -> decltype(v.data())
inline auto size() -> decltype(v.size())
inline matrix()

default constructor (private)

inline matrix(size_t _r)

constructor with a given size (square matrix)

inline matrix(size_t _r, size_t _c)

constructor with a given size (non square)

inline matrix(const size_t _r, const size_t _c, const vector<T> &_v)

constructor with a given size from a vector

inline matrix(const size_t _r, const vector<T> &_v)

constructor with a given size from a vector

inline matrix(const matrix<T> &A)

deep copy constructor

inline matrix(const matrix<T> &A, const matrix<T> &B)

concatenation constructor (puts the matrix side by side)

template<typename S>
inline matrix<T> &assign(const matrix<S> &A)

assignment operator

inline const T &operator()(const size_t &i, const size_t &j) const

element access (for rhs)

inline T &operator()(const size_t &i, const size_t &j)

element access (for lhs)

inline void concatenate(const matrix<T> &A, const matrix<T> &B)

concatenation (puts the matrix side by side)

inline void sub_matrix(size_t i, matrix<T> &A)

extracts a square submatrix A, starting at row i

template<typename S>
inline void move_sub_matrix(size_t R, size_t C, size_t i, size_t j, size_t I, size_t J, matrix<S> &A, double z = 1.0) const

extracts a rectangular submatrix of size (R,C), starting at (i,j) of this, and copies it to position (I, J) of A

template<typename S>
inline void move_sub_matrix_conjugate(size_t R, size_t C, size_t i, size_t j, size_t I, size_t J, matrix<S> &A, double z = 1.0) const

extracts a rectangular submatrix of size (R,C), starting at (i,j) of this, and copies its complex conjugate to position (I, J) of A

template<typename S>
inline void move_sub_matrix_HC(size_t R, size_t C, size_t i, size_t j, size_t I, size_t J, matrix<S> &A, double z = 1.0) const

extracts a rectangular submatrix of size (R,C), starting at (i,j) of this, and copies its hermitian conjugate to position (I, J) of A

template<typename S>
inline void move_sub_matrix_transpose(size_t R, size_t C, size_t i, size_t j, size_t I, size_t J, matrix<S> &A, double z = 1.0) const

extracts a rectangular submatrix of size (R,C), starting at (i,j) of this, and copies its transpose to position (I, J) of A

inline void insert_row(size_t i, const vector<T> &A)

inserts A as the ith row of the matrix

inline void insert_column(size_t i, const vector<T> &A)

inserts A as the ith column of the matrix

inline void extract_row(size_t i, vector<T> &A)

extracts a row into a vector

inline vector<T> extract_row(size_t i)

extracts a row

inline void extract_column(size_t i, vector<T> &A)

extracts a column into a vector

inline vector<T> extract_column(size_t i)
inline void zero()

sets to zero

inline void apply_mask(const vector<size_t> &mask)

sets to zero the components addressed by the mask

inline void set_size(size_t _r, size_t _c)

sets size and allocate

inline void set_size(size_t _r)
template<typename S>
inline void set_size(matrix<S> mat)
inline void import(T *x)

imports data to already allocated matrix

inline void real_part(const matrix<Complex> &A)

takes the real part of another matrix

inline void identity()

initializes to the identity matrix

template<typename S>
inline void diagonal(const vector<S> &x)

sets the diagonal of A equal to the vector x

template<typename S>
inline void add_to_diagonal(const S x)

adds a constant to the diagonal

template<typename S>
inline void add_to_diagonal(const vector<S> &x)

adds a vector to the diagonal

inline void transpose()

replaces the matrix by its transpose

inline void hermitian_conjugate()

replaces the matrix by its Hermitean conjugate

inline T trace()

computes the trace of a matrix

inline T trace(size_t start_row, size_t end_row)

computes the partial trace of a matrix

template<typename S>
inline T trace_product(matrix<S> A, bool transpose = false)

computes the trace of the product with a matrix A

template<typename S>
inline matrix<T> &operator-=(const S &a)

substraction of a number times the unit matrix

template<typename S>
inline matrix<T> &operator-=(const matrix<S> &A)

substraction of a matrix

template<typename S>
inline matrix<T> &operator+=(const S &a)

addition of a number times the unit matrix

template<typename S>
inline matrix<T> &operator+=(const matrix<S> &A)

addition of a matrix

inline double diff_sq(const matrix<T> &A, double a = 1.0)

calculates the squared difference between a matrix and this: |this -A|^2

template<typename S, typename U>
inline void product(const matrix<S> &A, const matrix<U> &B)

multiplies two matrices : this = A * B

template<typename S, typename U>
inline void product(const matrix<S> &A, const matrix<U> &B, size_t M)

multiplies two matrices : this = A * B with a bound on a the intermediate index

template<typename S, typename U>
inline void product_transpose(const matrix<S> &A, const matrix<U> &B)

multiplies two matrices : this = A * transpose(B)

template<typename S, typename U>
inline void product_hermitian_conjugate(const matrix<S> &A, const matrix<U> &B)

multiplies two matrices : this = A * hermitian(B)

inline void add(T d)

adds a number times the identity matrix

template<typename S, typename B>
inline void add(const matrix<S> &A, B d)

adds a number times another matrix

template<typename S>
inline void simil(const matrix<S> &A)

performs a similarity transformation : this = hermitian(A) * this * A

template<typename S>
inline void simil_inv(const matrix<S> &A)

performs a similarity transformation : this = A * this * hermitian(A)

template<typename S>
inline void simil_transpose(const matrix<S> &A)

performs a similarity transformation : this = transpose(A) * this * A

template<typename S>
inline void simil_conjugate(const matrix<S> &A)

performs a similarity transformation : this = hermitian(A) * this * conjugate(A)

template<typename S1, typename S2>
inline void simil(const matrix<S1> &A, const matrix<S2> &B)

performs a similarity transformation : this = hermitian(A) * B * A

inline void apply_add(T *x, T *y)

Application on an array : y += this * x.

inline void apply_add(const vector<T> &x, vector<T> &y) const
inline void apply(T *x, T *y)

Application on an array : y = this * x.

inline void apply(const vector<T> &x, vector<T> &y)
inline void left_apply_add(const vector<T> &x, vector<T> &y) const

Application on an array : y += conj(x) * this.

inline bool is_diagonal(double accuracy = 1.0e-8)

checks whether the matrix is diagonal

inline void cconjugate()

takes the complex conjugate

inline T qform(vector<T> &x, vector<T> &y)

quadratic form

inline bool printable()
inline bool is_unitary(double threshold)

returns true if the matrix is unitary or orthogonal

inline bool is_hermitian(double threshold = 1e-10)

returns true if the matrix is hermitian or real symmetric

inline bool Gram_Schmidt(const vector<T> &x, size_t col)

Performs the Gram-Schmidt procedure on an input vector x to produce the current matrix, with the vector x located in the column associated with its largest value.

inline void Cayley(const matrix<T> &A)

Builds the current matrix as $M=(1+A)(1-A)^(-1)$.

inline void Cayley_inverse(const matrix<T> &M)

Builds the current matrix as $A=(1+M)^(-1)(M-1)$.

inline void antisymmetrize()

Replaces the current matrix by its antihermitian (antisymmetric) part.

inline void symmetrize()

Replaces the current matrix by its hermitian (symmetric) part.

double norm()
double norm2()
void inverse()
T determinant()
void eigensystem(vector<double> &d, matrix<T> &U) const
void eigenvalues(vector<double> &d)
bool is_real(double accuracy = 1e-6)
bool is_orthogonal(double accuracy = 1e-6)
bool cholesky(matrix<double> &A)
bool triangular_inverse()

Public Members

size_t r

number of rows

size_t c

number of columns

vector<T> v

array of values (column ordered)

Friends

inline friend std::istream &operator>>(std::istream &flux, matrix<T> &A)
inline friend std::ostream &operator<<(std::ostream &flux, const matrix<T> &A)