pyUni10.Block

class pyUni10.Block

Proxy of C++ uni10::Block class

Class for blocks

A Block holds a reference to a Matrix. The Block constructor does not allocate memory. Memory allocation should be done through Matrix.

If no datatype flag is specified, the constructors and member functions default to Real. To explicitly declare the data type, the class provides constructors and member functions with the following syntax:

func(RTYPE, ...) for Real datatype and func(CTYPE), ...) for Complex datatype.

pyUni10.Block(Rnum, Cnum, [elem, ]diag=False)
pyUni10.Block(Ma)

Creates a Block object

Parameters:
  • Rnum (int) – number of Rows
  • Cnum (int) – number of Columns
  • diag (bool) – Set True for a diagonal matrix
  • elem (iterable) – Matrix elements
  • Ma (Matrix) – another Matrix object
Returns:

a Block object

Return type:

Block

Methods

Matrix.col()

Returns the number of columns in Matrix

Returns:number of columns in Matrix
Return type:int
Matrix.eigh()

Diagonalizes a symmetric Matrix and returns a tuple of matrices (\(D, U\)), where \(D\) is a diagnoal matrix of eigenvalues and \(U\) is a matrix of row-vectors of eigenvectors.

Returns:
  • \(D\) : diagonal matrix of eigenvalues
  • \(U\) : matrix of eigenvectors
Return type:tuple of Matrix

Note

This function will not check wether the matrix is symmetric.

This is a wrapper of the LAPACK function dsyev()

Block.elemNum()

Returns the number of elements in Block

Returns:number of elements in Block
Return type:int
Block.getElem()

Returns the reference to the elements of Matrix

Returns:reference to the element of Matrix
Return type:float *
Block.isDiag()

Checks whether Block is diagonal

Returns:True or False
Return type:bool
Matrix.load(filename)

Loads Matrix from a binary file named filename

Parameters:filename (str) – input filename
Block.norm()

Returns \(L^2\) norm of Block

Returns:\(L^2\) norm of Block
Return type:float
Matrix.resize(Rnum, Cnum)

Set the dimensions of Matrix to (Rnum, Cnum)

Returns:Matrix of size (Rnum, Cnum)
Return type:Matrix
Matrix.row()

Returns the number of rows in Matrix

Returns:number of rows in Matrix
Return type:int
Matrix.save(filename)

Saves Matrix to a binary file named filename

Parameters:filename (str) – output filename
Matrix.setElem(elem)

Set elements of Matrix to elem

Parameters:elem (array of floats) – data
Matrix.set_zero()

Set elements of Matrix to zero

Parameters:elem (array of floats) – data
Matrix.sum()

Performs the summation of all elements in Matrix

Returns:sum of all elements in Matrix
Return type:float
Matrix.svd()

Performs SVD of Matrix

Factorizes the \(m \times n\) matrix \(A\) into two unitary matrices \(U\) and \(V^\dagger\), and a diagonal matrix \(\Sigma\) of singular values (real, non-negative) such that

\[A= U \Sigma V^{\dagger}\]
Returns:
  • \(U\) : a \(m \times n\) row-major matrix
  • \(\Sigma\) : a \(n \times n\) diagonal matrix
  • \(V^{\dagger}\): a \(n \times m\) row-major matrix
Return type:tuple of Matix

Note

This is a wrapper of the Lapack function dgesvd()

Matrix.trace()

Takes the trace of a square matrix Matrix

Returns:trace of a square matrix Matrix
Return type:float
Raise:RunTimeError if Matrix is not a square matrix
Matrix.transpose()

Performs in-place transpose of Matrix. The number of rows and the number of columns are exchanged.

Returns:Matrix
Return type:Matrix