Cytnx v0.7.4
Loading...
Searching...
No Matches
Functions
cytnx::linalg Namespace Reference

linear algebra related functions. More...

Functions

cytnx::UniTensor Add (const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
 element-wise add
 
template<class T >
cytnx::UniTensor Add (const T &lc, const cytnx::UniTensor &Rt)
 
template<class T >
cytnx::UniTensor Add (const cytnx::UniTensor &Lt, const T &rc)
 
cytnx::UniTensor Sub (const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
 element-wise subtract
 
template<class T >
cytnx::UniTensor Sub (const T &lc, const cytnx::UniTensor &Rt)
 
template<class T >
cytnx::UniTensor Sub (const cytnx::UniTensor &Lt, const T &rc)
 
cytnx::UniTensor Mul (const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
 element-wise subtract
 
template<class T >
cytnx::UniTensor Mul (const T &lc, const cytnx::UniTensor &Rt)
 
template<class T >
cytnx::UniTensor Mul (const cytnx::UniTensor &Lt, const T &rc)
 
cytnx::UniTensor Div (const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
 element-wise divide
 
template<class T >
cytnx::UniTensor Div (const T &lc, const cytnx::UniTensor &Rt)
 
template<class T >
cytnx::UniTensor Div (const cytnx::UniTensor &Lt, const T &rc)
 
cytnx::UniTensor Mod (const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
 element-wise modulo
 
template<class T >
cytnx::UniTensor Mod (const T &lc, const cytnx::UniTensor &Rt)
 
template<class T >
cytnx::UniTensor Mod (const cytnx::UniTensor &Lt, const T &rc)
 
std::vector< cytnx::UniTensorSvd (const cytnx::UniTensor &Tin, const bool &is_U=true, const bool &is_vT=true)
 
std::vector< cytnx::UniTensorSvd_truncate (const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim, const double &err=0, const bool &is_U=true, const bool &is_vT=true, const bool &return_err=false)
 
std::vector< cytnx::UniTensorHosvd (const cytnx::UniTensor &Tin, const std::vector< cytnx_uint64 > &mode, const bool &is_core=true, const bool &is_Ls=false, const std::vector< cytnx_int64 > &trucate_dim=std::vector< cytnx_int64 >())
 
cytnx::UniTensor ExpH (const cytnx::UniTensor &Tin, const double &a=1, const double &b=0)
 
cytnx::UniTensor ExpM (const cytnx::UniTensor &Tin, const double &a=1, const double &b=0)
 
cytnx::UniTensor Trace (const cytnx::UniTensor &Tin, const cytnx_int64 &a=0, const cytnx_int64 &b=1, const bool &by_label=false)
 
std::vector< cytnx::UniTensorQr (const cytnx::UniTensor &Tin, const bool &is_tau=false)
 
std::vector< cytnx::UniTensorQdr (const cytnx::UniTensor &Tin, const bool &is_tau=false)
 
UniTensor Pow (const UniTensor &Tin, const double &p)
 take power p on all the elements in UniTensor.
 
void Pow_ (UniTensor &Tin, const double &p)
 inplace perform power on all the elements in UniTensor.
 
Tensor Add (const Tensor &Lt, const Tensor &Rt)
 
template<class T >
Tensor Add (const T &lc, const Tensor &Rt)
 
template<class T >
Tensor Add (const Tensor &Lt, const T &rc)
 
void iAdd (Tensor &Lt, const Tensor &Rt)
 
Tensor Sub (const Tensor &Lt, const Tensor &Rt)
 element-wise subtract
 
template<class T >
Tensor Sub (const T &lc, const Tensor &Rt)
 
template<class T >
Tensor Sub (const Tensor &Lt, const T &rc)
 
void iSub (Tensor &Lt, const Tensor &Rt)
 
Tensor Mul (const Tensor &Lt, const Tensor &Rt)
 element-wise subtract
 
template<class T >
Tensor Mul (const T &lc, const Tensor &Rt)
 
template<class T >
Tensor Mul (const Tensor &Lt, const T &rc)
 
void iMul (Tensor &Lt, const Tensor &Rt)
 
Tensor Div (const Tensor &Lt, const Tensor &Rt)
 element-wise divide
 
template<class T >
Tensor Div (const T &lc, const Tensor &Rt)
 
template<class T >
Tensor Div (const Tensor &Lt, const T &rc)
 
void iDiv (Tensor &Lt, const Tensor &Rt)
 
Tensor Mod (const Tensor &Lt, const Tensor &Rt)
 element-wise divide
 
template<class T >
Tensor Mod (const T &lc, const Tensor &Rt)
 
template<class T >
Tensor Mod (const Tensor &Lt, const T &rc)
 
Tensor Cpr (const Tensor &Lt, const Tensor &Rt)
 element-wise compare
 
template<class T >
Tensor Cpr (const T &lc, const Tensor &Rt)
 
template<class T >
Tensor Cpr (const Tensor &Lt, const T &rc)
 
Tensor Norm (const Tensor &Tl)
 calculate the norm of a tensor.
 
Tensor Det (const Tensor &Tl)
 calculate the determinant of a tensor.
 
std::vector< TensorSvd (const Tensor &Tin, const bool &is_U=true, const bool &is_vT=true)
 Perform Singular-Value decomposition on a rank-2 Tensor.
 
std::vector< TensorSvd_truncate (const Tensor &Tin, const cytnx_uint64 &keepdim, const double &err=0, const bool &is_U=true, const bool &is_vT=true, const bool &return_err=false)
 
std::vector< TensorHosvd (const Tensor &Tin, const std::vector< cytnx_uint64 > &mode, const bool &is_core=true, const bool &is_Ls=false, const std::vector< cytnx_int64 > &trucate_dim=std::vector< cytnx_int64 >())
 
std::vector< TensorQr (const Tensor &Tin, const bool &is_tau=false)
 Perform QR decomposition on a rank-2 Tensor.
 
std::vector< TensorQdr (const Tensor &Tin, const bool &is_tau=false)
 Perform QDR decomposition on a rank-2 Tensor.
 
std::vector< TensorEigh (const Tensor &Tin, const bool &is_V=true, const bool &row_v=false)
 eigen-value decomposition for Hermitian matrix
 
std::vector< TensorEig (const Tensor &Tin, const bool &is_V=true, const bool &row_v=false)
 eigen-value decomposition for generic square matrix
 
Tensor Trace (const Tensor &Tn, const cytnx_uint64 &axisA=0, const cytnx_uint64 &axisB=1)
 perform trace over index.
 
Tensor Min (const Tensor &Tn)
 get the minimum element.
 
Tensor Max (const Tensor &Tn)
 get the maximum element.
 
Tensor Sum (const Tensor &Tn)
 get the sum of all the elements.
 
Tensor Matmul (const Tensor &TL, const Tensor &TR)
 perform matrix multiplication on two tensors.
 
Tensor Matmul_dg (const Tensor &Tl, const Tensor &Tr)
 perform matrix multiplication on two Tensors with one rank-1 and the other rank-2 where the rank-1 represent the diagonal elements of the specific tensor.
 
Tensor InvM (const Tensor &Tin)
 Matrix inverse.
 
void InvM_ (Tensor &Tin)
 inplace perform Matrix inverse.
 
Tensor Inv (const Tensor &Tin, const double &clip)
 Element-wise inverse with clip.
 
void Inv_ (Tensor &Tin, const double &clip)
 inplace perform Element-wise inverse with clip.
 
Tensor Conj (const Tensor &Tin)
 Conjugate all the element in Tensor.
 
void Conj_ (Tensor &Tin)
 inplace perform Conjugate on all the element in Tensor.
 
Tensor Exp (const Tensor &Tin)
 Exponential all the element in Tensor.
 
Tensor Expf (const Tensor &Tin)
 Exponential all the element in Tensor.
 
void Exp_ (Tensor &Tin)
 inplace perform Exponential on all the element in Tensor.
 
void Expf_ (Tensor &Tin)
 inplace perform Exponential on all the element in Tensor.
 
Tensor Pow (const Tensor &Tin, const double &p)
 take power p on all the elements in Tensor.
 
void Pow_ (Tensor &Tin, const double &p)
 inplace perform power on all the elements in Tensor.
 
Tensor Abs (const Tensor &Tin)
 Elementwise absolute value.
 
void Abs_ (Tensor &Tin)
 inplace perform elementwiase absolute value.
 
Tensor Diag (const Tensor &Tin)
 return a diagonal tensor with diagonal elements provided as Tin.
 
Tensor Tensordot (const Tensor &Tl, const Tensor &Tr, const std::vector< cytnx_uint64 > &idxl, const std::vector< cytnx_uint64 > &idxr, const bool &cacheL=false, const bool &cacheR=false)
 perform tensor dot by sum out the indices assigned of two Tensors.
 
Tensor Tensordot_dg (const Tensor &Tl, const Tensor &Tr, const std::vector< cytnx_uint64 > &idxl, const std::vector< cytnx_uint64 > &idxr, const bool &diag_L)
 perform tensor dot by sum out the indices assigned of two Tensors, with either one of them to be a rank-2 diagonal tensor represented by a rank-2 tensor.
 
Tensor Outer (const Tensor &Tl, const Tensor &Tr)
 perform outer produces of two rank-1 Tensor.
 
Tensor Kron (const Tensor &Tl, const Tensor &Tr, const bool &Tl_pad_left=false, const bool &Tr_pad_left=false)
 perform kronecker produces of two Tensor.
 
Tensor Vectordot (const Tensor &Tl, const Tensor &Tr, const bool &is_conj=false)
 perform inner product of vectors
 
Tensor Dot (const Tensor &Tl, const Tensor &Tr)
 dot product of two arrays.
 
std::vector< TensorTridiag (const Tensor &Diag, const Tensor &Sub_diag, const bool &is_V=true, const bool &is_row=false)
 perform diagonalization of symmetric tri-diagnoal matrix.
 
Tensor ExpH (const Tensor &in, const cytnx_double &a=1, const cytnx_double &b=0)
 perform matrix exponential for Hermitian matrix
 
Tensor ExpM (const Tensor &in, const cytnx_double &a=1, const cytnx_double &b=0)
 perform matrix exponential for generic matrix
 
std::vector< TensorLanczos_ER (LinOp *Hop, const cytnx_uint64 &k=1, const bool &is_V=true, const cytnx_uint64 &maxiter=10000, const double &CvgCrit=1.0e-14, const bool &is_row=false, const Tensor &Tin=Tensor(), const cytnx_uint32 &max_krydim=4, const bool &verbose=false)
 perform Lanczos for hermitian/symmetric matrices or linear function.
 
std::vector< TensorLanczos_Gnd (LinOp *Hop, const double &CvgCrit=1.0e-14, const bool &is_V=true, const Tensor &Tin=Tensor(), const bool &verbose=false, const unsigned int &Maxiter=100000)
 perform Lanczos for hermitian/symmetric matrices or linear function to get ground state and lowest eigen value
 
std::vector< UniTensorLanczos_Gnd_Ut (LinOp *Hop, const UniTensor &Tin, const double &CvgCrit=1.0e-14, const bool &is_V=true, const bool &verbose=false, const unsigned int &Maxiter=100000)
 perform Lanczos for hermitian/symmetric matrices or linear function to get ground state and lowest eigen value
 
std::vector< TensorLstsq (const Tensor &A, const Tensor &b, const float &rcond=-1)
 Return the least-squares solution to a linear matrix equation.
 

Detailed Description

linear algebra related functions.

Function Documentation

◆ Abs()

Tensor cytnx::linalg::Abs ( const Tensor Tin)

Elementwise absolute value.

Parameters
Tintensor.
Returns
[Tensor]

◆ Abs_()

void cytnx::linalg::Abs_ ( Tensor Tin)

inplace perform elementwiase absolute value.

Parameters
Tin,theinput Tensor.

description: on return, the elements in Tin will be modified to it's absolute value. Note that if the input tensor is complex, it will be modified to real type.

◆ Add() [1/6]

cytnx::UniTensor cytnx::linalg::Add ( const cytnx::UniTensor Lt,
const cytnx::UniTensor Rt 
)

element-wise add

◆ Add() [2/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Add ( const cytnx::UniTensor Lt,
const T &  rc 
)

◆ Add() [3/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Add ( const T &  lc,
const cytnx::UniTensor Rt 
)

◆ Add() [4/6]

template<class T >
Tensor cytnx::linalg::Add ( const T &  lc,
const Tensor Rt 
)

◆ Add() [5/6]

template<class T >
Tensor cytnx::linalg::Add ( const Tensor Lt,
const T &  rc 
)

◆ Add() [6/6]

Tensor cytnx::linalg::Add ( const Tensor Lt,
const Tensor Rt 
)

◆ Conj()

Tensor cytnx::linalg::Conj ( const Tensor Tin)

Conjugate all the element in Tensor.

Returns
[Tensor]

[Note]

  1. if the input Tensor is complex, then return a new Tensor with all the elements are conjugated.
  2. if the input Tensor is real, then return a copy of input Tensor.

◆ Conj_()

void cytnx::linalg::Conj_ ( Tensor Tin)

inplace perform Conjugate on all the element in Tensor.

[Note]

  1. if the input Tensor is complex, the elements of input Tensor will all be conjugated.
  2. if the input Tensor is real, then nothing act.

◆ Cpr() [1/3]

template<class T >
Tensor cytnx::linalg::Cpr ( const T &  lc,
const Tensor Rt 
)

◆ Cpr() [2/3]

template<class T >
Tensor cytnx::linalg::Cpr ( const Tensor Lt,
const T &  rc 
)

◆ Cpr() [3/3]

Tensor cytnx::linalg::Cpr ( const Tensor Lt,
const Tensor Rt 
)

element-wise compare

◆ Det()

Tensor cytnx::linalg::Det ( const Tensor Tl)

calculate the determinant of a tensor.

Parameters
Tlinput Tensor
Returns
Tensor

[Note]

  1. input tensor should be a NxN rank-2 Tensor.

◆ Diag()

Tensor cytnx::linalg::Diag ( const Tensor Tin)

return a diagonal tensor with diagonal elements provided as Tin.

Returns
[Tensor]

description: the return Tensor will be rank-2, with shape=(L, L); where L is the number of elements in Tin.

[Note] Tin should be a rank-1 Tensor.

◆ Div() [1/6]

cytnx::UniTensor cytnx::linalg::Div ( const cytnx::UniTensor Lt,
const cytnx::UniTensor Rt 
)

element-wise divide

◆ Div() [2/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Div ( const cytnx::UniTensor Lt,
const T &  rc 
)

◆ Div() [3/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Div ( const T &  lc,
const cytnx::UniTensor Rt 
)

◆ Div() [4/6]

template<class T >
Tensor cytnx::linalg::Div ( const T &  lc,
const Tensor Rt 
)

◆ Div() [5/6]

template<class T >
Tensor cytnx::linalg::Div ( const Tensor Lt,
const T &  rc 
)

◆ Div() [6/6]

Tensor cytnx::linalg::Div ( const Tensor Lt,
const Tensor Rt 
)

element-wise divide

◆ Dot()

Tensor cytnx::linalg::Dot ( const Tensor Tl,
const Tensor Tr 
)

dot product of two arrays.

Parameters
TlTensor #1
TrTensor #2
Returns
[Tensor]

description:

  1. if both Tl and Tr are 1d arrays, it is inner product of vectors (no complex conj), it calls linalg.Vectordot with is_conj=false.
  2. if both Tl and Tr are 2d arrays, it calls linalg.Matmul to compute the matrix multiplication
  3. if Tl is Nd array (with N>=2, and Tr is 1-D array, it is sum product over the last axis of a with b

[Note] performance tune: This function have better performance when two arrays with same types, and are one of following type: cytnx_double, cytnx_float, cytnx_complex64 or cytnx_complex128.

[Python] In Python API, operator@ is overloaded as a shorthand of linalg::Dot.

◆ Eig()

std::vector< Tensor > cytnx::linalg::Eig ( const Tensor Tin,
const bool &  is_V = true,
const bool &  row_v = false 
)

eigen-value decomposition for generic square matrix

Parameters
TinThe Tensor
is_Vreturn eigen vectors
row_Vif set to ture, the return eigen vectors will be row form.

[Note] the Tin should be a rank-2 Tensor.

◆ Eigh()

std::vector< Tensor > cytnx::linalg::Eigh ( const Tensor Tin,
const bool &  is_V = true,
const bool &  row_v = false 
)

eigen-value decomposition for Hermitian matrix

Parameters
TinThe Tensor
is_Vreturn eigen vectors
row_Vif set to ture, the return eigen vectors will be row form. [Note] the Tin should be a rank-2 Tensor.

◆ Exp()

Tensor cytnx::linalg::Exp ( const Tensor Tin)

Exponential all the element in Tensor.

Returns
[Double Tensor] or [ComplexDouble Tensor]

◆ Exp_()

void cytnx::linalg::Exp_ ( Tensor Tin)

inplace perform Exponential on all the element in Tensor.

Parameters
Tin,theinput Tensor.

description:

  1. on return, the elements in Tin will be modified to it's exponetial value.
  2. For Real, if the type is not Double, change the type of the input tensor to Double.
  3. For Complex, if input is ComplexFloat, promote to ComplexDouble.

◆ Expf()

Tensor cytnx::linalg::Expf ( const Tensor Tin)

Exponential all the element in Tensor.

Returns
[Float Tensor] or [ComplexFloat Tensor]

◆ Expf_()

void cytnx::linalg::Expf_ ( Tensor Tin)

inplace perform Exponential on all the element in Tensor.

Parameters
Tin,theinput Tensor.

description:

  1. on return, the elements in Tin will be modified to it's exponetial value.
  2. For Real, if the type is not Float, change the type of the input tensor to Float.
  3. For Complex, if input is ComplexDouble, promote to ComplexFloat.

◆ ExpH() [1/2]

cytnx::UniTensor cytnx::linalg::ExpH ( const cytnx::UniTensor Tin,
const double &  a = 1,
const double &  b = 0 
)

◆ ExpH() [2/2]

Tensor cytnx::linalg::ExpH ( const Tensor in,
const cytnx_double a = 1,
const cytnx_double b = 0 
)

perform matrix exponential for Hermitian matrix

Parameters
ininput Tensor, should be Hermitian
arescale factor
bbias
Returns
[Tensor]

description:
perform matrix exponential with \(O = \exp{aM + b}\).

◆ ExpM() [1/2]

cytnx::UniTensor cytnx::linalg::ExpM ( const cytnx::UniTensor Tin,
const double &  a = 1,
const double &  b = 0 
)

◆ ExpM() [2/2]

Tensor cytnx::linalg::ExpM ( const Tensor in,
const cytnx_double a = 1,
const cytnx_double b = 0 
)

perform matrix exponential for generic matrix

Parameters
ininput Tensor, should be a square rank-2.
arescale factor
bbias
Returns
[Tensor]

description:
perform matrix exponential with \(O = \exp{aM + b}\).

◆ Hosvd() [1/2]

std::vector< cytnx::UniTensor > cytnx::linalg::Hosvd ( const cytnx::UniTensor Tin,
const std::vector< cytnx_uint64 > &  mode,
const bool &  is_core = true,
const bool &  is_Ls = false,
const std::vector< cytnx_int64 > &  trucate_dim = std::vector< cytnx_int64 >() 
)

◆ Hosvd() [2/2]

std::vector< Tensor > cytnx::linalg::Hosvd ( const Tensor Tin,
const std::vector< cytnx_uint64 > &  mode,
const bool &  is_core = true,
const bool &  is_Ls = false,
const std::vector< cytnx_int64 > &  trucate_dim = std::vector< cytnx_int64 >() 
)

◆ iAdd()

void cytnx::linalg::iAdd ( Tensor Lt,
const Tensor Rt 
)

◆ iDiv()

void cytnx::linalg::iDiv ( Tensor Lt,
const Tensor Rt 
)

◆ iMul()

void cytnx::linalg::iMul ( Tensor Lt,
const Tensor Rt 
)

◆ Inv()

Tensor cytnx::linalg::Inv ( const Tensor Tin,
const double &  clip 
)

Element-wise inverse with clip.

Returns
[Tensor]

description: Performs Elementwise inverse with clip. if A[i] < clip, then 1/A[i] = 0 will be set.

[Note] For complex type Tensors, the square norm is used to determine the clip.

◆ Inv_()

void cytnx::linalg::Inv_ ( Tensor Tin,
const double &  clip 
)

inplace perform Element-wise inverse with clip.

Returns
[Tensor]

description:

  1. Performs Elementwise inverse with clip. if A[i] < clip, then 1/A[i] = 0 will be set.
  2. on return, all the elements will be modified to it's inverse. if Tin is integer type, it will automatically promote to Type.Double.

[Note] For complex type Tensors, the square norm is used to determine the clip.

◆ InvM()

Tensor cytnx::linalg::InvM ( const Tensor Tin)

Matrix inverse.

Returns
[Tensor]

[Note] the Tin should be a rank-2 Tensor.

◆ InvM_()

void cytnx::linalg::InvM_ ( Tensor Tin)

inplace perform Matrix inverse.

description: on return, the Tin will be modified to it's inverse.

[Note] the Tin should be a rank-2 Tensor.

◆ iSub()

void cytnx::linalg::iSub ( Tensor Lt,
const Tensor Rt 
)

◆ Kron()

Tensor cytnx::linalg::Kron ( const Tensor Tl,
const Tensor Tr,
const bool &  Tl_pad_left = false,
const bool &  Tr_pad_left = false 
)

perform kronecker produces of two Tensor.

Parameters
Tlrank-n Tensor #1
Trrank-m Tensor #2
Tl_pad_leftThe padding scheme for Tl if Tl.rank != Tr.rank
Tr_pad_leftThe padding scheme for Tr if Tl.rank != Tr.rank
Returns
[Tensor]

description: The function assume two tensor has the same rank. In case where two tensors have different ranks, the small one will be extend by adding redundant dimension to the beginning of axis (T<x>_pad_right=true) or by adding redundant dim to the last axis (if T<x>_pad_left=false [default]). if the Tensor #1 has shape=(i1,j1,k1,l1...), and Tensor #2 has shape=(i2,j2,k2,l2...); then the return Tensor will have shape=(i1*i2,j1*j2,k1*k2...)

[Note] two tensor should on same device.

◆ Lanczos_ER()

std::vector< Tensor > cytnx::linalg::Lanczos_ER ( LinOp Hop,
const cytnx_uint64 k = 1,
const bool &  is_V = true,
const cytnx_uint64 maxiter = 10000,
const double &  CvgCrit = 1.0e-14,
const bool &  is_row = false,
const Tensor Tin = Tensor(),
const cytnx_uint32 max_krydim = 4,
const bool &  verbose = false 
)

perform Lanczos for hermitian/symmetric matrices or linear function.

Parameters
Hopthe Linear Operator defined by LinOp class or it's inheritance (see LinOp).
kthe number of lowest k eigen values.
is_Vif set to true, the eigen vectors will be returned.
maxiterthe maximum interation steps for each k.
CvgCritthe convergence criterion of the energy.
is_rowwhether the return eigen vectors should be in row-major form.
Tinthe initial vector, this should be rank-1
max_krydimthe maximum krylov subspace dimension for each iteration.
verboseprint out iteration info.
Returns
[eigvals (Tensor), eigvecs (Tensor)(option)]

#description: This function calculate the eigen value problem using explicitly restarted Lanczos.

#Performance tune: For small linear dimension, try to reduce max_krydim.

#[Note] To use, define a linear operator with LinOp class either by assign a custom function or create a class that inherit LinOp (see LinOp for further details)

◆ Lanczos_Gnd()

std::vector< Tensor > cytnx::linalg::Lanczos_Gnd ( LinOp Hop,
const double &  CvgCrit = 1.0e-14,
const bool &  is_V = true,
const Tensor Tin = Tensor(),
const bool &  verbose = false,
const unsigned int &  Maxiter = 100000 
)

perform Lanczos for hermitian/symmetric matrices or linear function to get ground state and lowest eigen value

Parameters
Hopthe Linear Operator defined by LinOp class or it's inheritance (see LinOp).
CvgCritthe convergence criterion of the energy.
is_Vif set to true, the eigen vectors will be returned.
Tinthe initial vector, this should be rank-1
verboseprint out iteration info.
maxiterthe maximum interation steps for each k.
Returns
[eigvals (Tensor), eigvecs (Tensor)(option)]

#description: This function calculate the eigen value problem using naive Lanczos to get ground state and lowest eigen value.

#[Note] To use, define a linear operator with LinOp class either by assign a custom function or create a class that inherit LinOp (see LinOp for further details)

◆ Lanczos_Gnd_Ut()

std::vector< UniTensor > cytnx::linalg::Lanczos_Gnd_Ut ( LinOp Hop,
const UniTensor Tin,
const double &  CvgCrit = 1.0e-14,
const bool &  is_V = true,
const bool &  verbose = false,
const unsigned int &  Maxiter = 100000 
)

perform Lanczos for hermitian/symmetric matrices or linear function to get ground state and lowest eigen value

Parameters
Hopthe Linear Operator defined by LinOp class or it's inheritance (see LinOp).
CvgCritthe convergence criterion of the energy.
is_Vif set to true, the eigen vectors will be returned.
Tinthe initial vector, this should be a UniTensor.
verboseprint out iteration info.
maxiterthe maximum interation steps for each k.
Returns
[eigvals (UniTensor::Dense), eigvecs (UniTensor)(option)]

#description: This function calculate the eigen value problem using naive Lanczos to get ground state and lowest eigen value.

#[Note] To use, define a linear operator with LinOp class either by assign a custom function or create a class that inherit LinOp (see LinOp for further details)

◆ Lstsq()

std::vector< Tensor > cytnx::linalg::Lstsq ( const Tensor A,
const Tensor b,
const float &  rcond = -1 
)

Return the least-squares solution to a linear matrix equation.

Parameters
A“Coefficient” matrix, must be two-dimensional.
bOrdinate or “dependent variable” values, must be two-dimensional, the least-squares solution is calculated for each of the K columns of b.
rcondCut-off ratio for small singular values of a. For the purposes of rank determination, singular values are treated as zero if they are smaller than rcond times the largest singular value of A, If it is negative, the machine precision is used.
Returns
[std::vector<Tensors>]
1. the first tensor is least-squares solutions in the K columns.
2. the second tensor is the sums of squared residuals: Squared Euclidean 2-norm for each column in b - a @ x. If the rank of a is < N or M <= N, this is a zero Tensor.
3. the third tensor is the rank of matrix A.
4. the forth tensor is singular values of A.
#description: Computes the vector x that approximatively solves the equation A @ x = b. The equation may be under-, well-, or over-determined independent columns. If a is square and of full rank, then x (but for round-off error) is the “exact” solution of the equation. Else, x minimizes the Euclidean 2-norm || b - a x ||.

[Ke]

◆ Matmul()

Tensor cytnx::linalg::Matmul ( const Tensor TL,
const Tensor TR 
)

perform matrix multiplication on two tensors.

[Note] the TL and TR should be both rank-2 Tensor.

◆ Matmul_dg()

Tensor cytnx::linalg::Matmul_dg ( const Tensor Tl,
const Tensor Tr 
)

perform matrix multiplication on two Tensors with one rank-1 and the other rank-2 where the rank-1 represent the diagonal elements of the specific tensor.

[Note] the TL and TR one of them should be rank-1 Tensor and the other should be rank-2 Tensor.

◆ Max()

Tensor cytnx::linalg::Max ( const Tensor Tn)

get the maximum element.

[Note] For complex TN, only real part is compared.

◆ Min()

Tensor cytnx::linalg::Min ( const Tensor Tn)

get the minimum element.

[Note] For complex TN, only real part is compared.

◆ Mod() [1/6]

cytnx::UniTensor cytnx::linalg::Mod ( const cytnx::UniTensor Lt,
const cytnx::UniTensor Rt 
)

element-wise modulo

◆ Mod() [2/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Mod ( const cytnx::UniTensor Lt,
const T &  rc 
)

◆ Mod() [3/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Mod ( const T &  lc,
const cytnx::UniTensor Rt 
)

◆ Mod() [4/6]

template<class T >
Tensor cytnx::linalg::Mod ( const T &  lc,
const Tensor Rt 
)

◆ Mod() [5/6]

template<class T >
Tensor cytnx::linalg::Mod ( const Tensor Lt,
const T &  rc 
)

◆ Mod() [6/6]

Tensor cytnx::linalg::Mod ( const Tensor Lt,
const Tensor Rt 
)

element-wise divide

◆ Mul() [1/6]

cytnx::UniTensor cytnx::linalg::Mul ( const cytnx::UniTensor Lt,
const cytnx::UniTensor Rt 
)

element-wise subtract

◆ Mul() [2/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Mul ( const cytnx::UniTensor Lt,
const T &  rc 
)

◆ Mul() [3/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Mul ( const T &  lc,
const cytnx::UniTensor Rt 
)

◆ Mul() [4/6]

template<class T >
Tensor cytnx::linalg::Mul ( const T &  lc,
const Tensor Rt 
)

◆ Mul() [5/6]

template<class T >
Tensor cytnx::linalg::Mul ( const Tensor Lt,
const T &  rc 
)

◆ Mul() [6/6]

Tensor cytnx::linalg::Mul ( const Tensor Lt,
const Tensor Rt 
)

element-wise subtract

◆ Norm()

Tensor cytnx::linalg::Norm ( const Tensor Tl)

calculate the norm of a tensor.

Parameters
Tlinput Tensor
Returns
Tensor

[Note]

  1. if the input tensor is rank-1, the frobenius norm is calculated.
  2. if the input tensor is rank-N with N>=2, the tensor will be flatten to 1d first, and calculate the frobenius norm.

◆ Outer()

Tensor cytnx::linalg::Outer ( const Tensor Tl,
const Tensor Tr 
)

perform outer produces of two rank-1 Tensor.

Parameters
Tlrank-1 Tensor #1
Trrank-1 Tensor #2
Returns
[Tensor]

description: if the Tensor #1 has [shape_1], and Tensor #2 has [shape_2]; then the return Tensor will have shape: concate(shape_1,shape_2)

[Note] two tensor should on same device.

◆ Pow() [1/2]

Tensor cytnx::linalg::Pow ( const Tensor Tin,
const double &  p 
)

take power p on all the elements in Tensor.

Parameters
p,thepower
Returns
[Tensor]

◆ Pow() [2/2]

UniTensor cytnx::linalg::Pow ( const UniTensor Tin,
const double &  p 
)

take power p on all the elements in UniTensor.

Parameters
p,thepower
Returns
[UniTensor]

◆ Pow_() [1/2]

void cytnx::linalg::Pow_ ( Tensor Tin,
const double &  p 
)

inplace perform power on all the elements in Tensor.

Parameters
Tin,theinput Tensor.
p,thepower.

description: on return, the elements in Tin will be modified to it's exponetial value.

◆ Pow_() [2/2]

void cytnx::linalg::Pow_ ( UniTensor Tin,
const double &  p 
)

inplace perform power on all the elements in UniTensor.

Parameters
Tin,theinput UniTensor.
p,thepower.

description: on return, the elements in Tin will be modified to it's exponetial value.

◆ Qdr() [1/2]

std::vector< cytnx::UniTensor > cytnx::linalg::Qdr ( const cytnx::UniTensor Tin,
const bool &  is_tau = false 
)

◆ Qdr() [2/2]

std::vector< Tensor > cytnx::linalg::Qdr ( const Tensor Tin,
const bool &  is_tau = false 
)

Perform QDR decomposition on a rank-2 Tensor.

Parameters
Tina Tensor , it should be a rank-2 tensor (matrix)
is_tauif return the tau that contains the Householder reflectors that generate q along with r. The tau array contains scaling factors for the reflectors
Returns
[std::vector<Tensors>]
1. the first tensor is the orthomormal matrix [Q], a 2-d tensor (matrix)
2. the second tensor is the diagonal matrix [D], a 1-d tensor (matrix). 
3. the third tensor is the right-upper triangular matrix [R], a 2-d tensor (matrix). 
4. the forth tensor is the Householder reflectors [H], a 1-d tensor (matrix). It only return when is_tau=true.

◆ Qr() [1/2]

std::vector< cytnx::UniTensor > cytnx::linalg::Qr ( const cytnx::UniTensor Tin,
const bool &  is_tau = false 
)

◆ Qr() [2/2]

std::vector< Tensor > cytnx::linalg::Qr ( const Tensor Tin,
const bool &  is_tau = false 
)

Perform QR decomposition on a rank-2 Tensor.

Parameters
Tina Tensor , it should be a rank-2 tensor (matrix)
is_tauif return the tau that contains the Householder reflectors that generate q along with r. The tau array contains scaling factors for the reflectors
Returns
[std::vector<Tensors>]
1. the first tensor is the orthomormal matrix [Q], a 2-d tensor (matrix)
2. the second tensor is the right-upper triangular matrix [R], a 2-d tensor (matrix). 
3. the third tensor is the Householder reflectors [H], a 1-d tensor (matrix). It only return when is_tau=true.

◆ Sub() [1/6]

cytnx::UniTensor cytnx::linalg::Sub ( const cytnx::UniTensor Lt,
const cytnx::UniTensor Rt 
)

element-wise subtract

◆ Sub() [2/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Sub ( const cytnx::UniTensor Lt,
const T &  rc 
)

◆ Sub() [3/6]

template<class T >
cytnx::UniTensor cytnx::linalg::Sub ( const T &  lc,
const cytnx::UniTensor Rt 
)

◆ Sub() [4/6]

template<class T >
Tensor cytnx::linalg::Sub ( const T &  lc,
const Tensor Rt 
)

◆ Sub() [5/6]

template<class T >
Tensor cytnx::linalg::Sub ( const Tensor Lt,
const T &  rc 
)

◆ Sub() [6/6]

Tensor cytnx::linalg::Sub ( const Tensor Lt,
const Tensor Rt 
)

element-wise subtract

◆ Sum()

Tensor cytnx::linalg::Sum ( const Tensor Tn)

get the sum of all the elements.

◆ Svd() [1/2]

std::vector< cytnx::UniTensor > cytnx::linalg::Svd ( const cytnx::UniTensor Tin,
const bool &  is_U = true,
const bool &  is_vT = true 
)

◆ Svd() [2/2]

std::vector< Tensor > cytnx::linalg::Svd ( const Tensor Tin,
const bool &  is_U = true,
const bool &  is_vT = true 
)

Perform Singular-Value decomposition on a rank-2 Tensor.

Parameters
Tina Tensor , it should be a rank-2 tensor (matrix)
is_Uif return a left uniform matrix.
is_vTif return a right uniform matrix.
Returns
[std::vector<Tensors>]
1. the first tensor is a 1-d tensor contanin the singular values
2. the second tensor is the left uniform matrix [U], a 2-d tensor (matrix). It only return when is_U=true.
3. the third tensor is the right uniform matrix [vT], a 2-d tensor (matrix). It only return when is_vT=true.

◆ Svd_truncate() [1/2]

std::vector< cytnx::UniTensor > cytnx::linalg::Svd_truncate ( const cytnx::UniTensor Tin,
const cytnx_uint64 keepdim,
const double &  err = 0,
const bool &  is_U = true,
const bool &  is_vT = true,
const bool &  return_err = false 
)

◆ Svd_truncate() [2/2]

std::vector< Tensor > cytnx::linalg::Svd_truncate ( const Tensor Tin,
const cytnx_uint64 keepdim,
const double &  err = 0,
const bool &  is_U = true,
const bool &  is_vT = true,
const bool &  return_err = false 
)

◆ Tensordot()

Tensor cytnx::linalg::Tensordot ( const Tensor Tl,
const Tensor Tr,
const std::vector< cytnx_uint64 > &  idxl,
const std::vector< cytnx_uint64 > &  idxr,
const bool &  cacheL = false,
const bool &  cacheR = false 
)

perform tensor dot by sum out the indices assigned of two Tensors.

Parameters
TlTensor #1
TrTensor #2
idxlthe indices of rank of Tensor #1 that is going to sum with Tensor #2
idxrthe indices of rank of Tensor #2 that is going to sum with Tensor #1
cacheLcache Tensor #1 (See user-guide for details)
cacheRcache Tensor #2 (See user-guide for details)
Returns
[Tensor]

[Note]

  1. the elements in idxl and idxr have one to one correspondence.
  2. two tensors should on same device.

◆ Tensordot_dg()

Tensor cytnx::linalg::Tensordot_dg ( const Tensor Tl,
const Tensor Tr,
const std::vector< cytnx_uint64 > &  idxl,
const std::vector< cytnx_uint64 > &  idxr,
const bool &  diag_L 
)

perform tensor dot by sum out the indices assigned of two Tensors, with either one of them to be a rank-2 diagonal tensor represented by a rank-2 tensor.

Parameters
TlTensor #1
TrTensor #2
idxlthe indices of rank of Tensor #1 that is going to sum with Tensor #2
idxrthe indices of rank of Tensor #2 that is going to sum with Tensor #1
diag_Lif Tl(true)/Tr(false) is a diagnal matrix, represented by a rank-1 tensor.
Returns
[Tensor]

[Note]

  1. the elements in idxl and idxr have one to one correspondence.
  2. two tensors should on same device.
  3. if diag_L=true, Tl should be a rank-1 tensor as the diagonal elements of a diagonal matrix. if false, Tr should be a rank-1 tensor

◆ Trace() [1/2]

cytnx::UniTensor cytnx::linalg::Trace ( const cytnx::UniTensor Tin,
const cytnx_int64 a = 0,
const cytnx_int64 b = 1,
const bool &  by_label = false 
)

◆ Trace() [2/2]

Tensor cytnx::linalg::Trace ( const Tensor Tn,
const cytnx_uint64 axisA = 0,
const cytnx_uint64 axisB = 1 
)

perform trace over index.

[Note] the Tn should be at-least rank-2 Tensor.

◆ Tridiag()

std::vector< Tensor > cytnx::linalg::Tridiag ( const Tensor Diag,
const Tensor Sub_diag,
const bool &  is_V = true,
const bool &  is_row = false 
)

perform diagonalization of symmetric tri-diagnoal matrix.

Parameters
DiagTensor #1
Sub_diagTensor #2
is_Vif calculate the eigen value.
kReturn k lowest eigen vector if is_V=True
Returns
[vector<Tensor>] if is_V = True, the first tensor is the eigen value, and second tensor is eigenvector of shape [k,L].

description: two Tensors must be Rank-1, with length of Diag = L and Sub_diag length = L-1.

[Note] performance tune: This function have better performance when two vectors with same types, and are one of following type: cytnx_double, cytnx_float. In general all real type can be use as input, which will be promote to floating point type for calculation.

◆ Vectordot()

Tensor cytnx::linalg::Vectordot ( const Tensor Tl,
const Tensor Tr,
const bool &  is_conj = false 
)

perform inner product of vectors

Parameters
TlTensor #1
TrTensor #2
ifthe Tl should be conjugated (only work for complex. For real Tensor, no function), default: false
Returns
[Tensor] Rank-0

description: two Tensors must be Rank-1, with same length.

[Note] performance tune: This function have better performance when two vectors with same types, and are one of following type: cytnx_double, cytnx_float, cytnx_complex64 or cytnx_complex128.