14#include "backend/Scalar.hpp"
15#include "backend/Storage.hpp"
61 template <cytnx_unitensor_scalar_like T>
73 template <cytnx_unitensor_scalar_like T>
100 template <cytnx_unitensor_scalar_like T>
112 template <cytnx_unitensor_scalar_like T>
139 template <cytnx_unitensor_scalar_like T>
151 template <cytnx_unitensor_scalar_like T>
178 template <cytnx_unitensor_scalar_like T>
190 template <cytnx_unitensor_scalar_like T>
214 template <cytnx_scalar_value T>
226 template <cytnx_scalar_value T>
740 const bool &is_vT =
true);
754 const cytnx_uint64 &keepdim,
const double &err = 0.,
755 const bool &is_UvT =
true,
756 const unsigned int &return_err = 0,
757 const cytnx_uint64 &mindim = 1);
807 const cytnx_uint64 &keepdim,
808 std::vector<cytnx_uint64> min_blockdim,
809 const double &err = 0.,
const bool &is_UvT =
true,
810 const unsigned int &return_err = 0,
811 const cytnx_uint64 &mindim = 1);
825 const cytnx_uint64 &keepdim,
826 const double &err = 0.,
const bool &is_U =
true,
827 const bool &is_vT =
true,
828 const unsigned int &return_err = 0,
829 const cytnx_uint64 &mindim = 1);
844 std::vector<cytnx_uint64> min_blockdim,
const double &err = 0.,
const bool &is_U =
true,
845 const bool &is_vT =
true,
const unsigned int &return_err = 0,
const cytnx_uint64 &mindim = 1);
899 double err = 0.,
bool is_U =
true,
bool is_vT =
true,
900 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
901 cytnx_uint64 oversampling_summand = 10,
902 double oversampling_factor = 1.,
903 cytnx_uint64 power_iteration = 0,
933 const std::vector<cytnx_uint64> min_blockdim,
934 double err = 0.,
bool is_U =
true,
bool is_vT =
true,
935 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
936 cytnx_uint64 oversampling_summand = 10,
937 double oversampling_factor = 1.,
938 cytnx_uint64 power_iteration = 0,
941 std::vector<cytnx::UniTensor>
Hosvd(
943 const bool &is_core =
true,
const bool &is_Ls =
false,
944 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
954 template <
typename T>
964 template <
typename T>
995 const cytnx_int64 &b = 1);
1815 const cytnx_uint64 &power_iteration = 2,
1845 std::vector<Tensor>
Svd(
const Tensor &Tin,
const bool &is_UvT =
true);
1876 std::vector<Tensor>
Gesvd(
const Tensor &Tin,
const bool &is_U =
true,
const bool &is_vT =
true);
1925 const double &err = 0.,
const bool &is_UvT =
true,
1926 const unsigned int &return_err = 0,
1927 const cytnx_uint64 &mindim = 1);
1977 std::vector<Tensor>
Rsvd(
const Tensor &Tin, cytnx_uint64 keepdim,
double err = 0.,
1978 bool is_U =
true,
bool is_vT =
true,
unsigned int return_err = 0,
1979 cytnx_uint64 mindim = 1, cytnx_uint64 oversampling_summand = 10,
1980 double oversampling_factor = 1., cytnx_uint64 power_iteration = 0,
2013 const double &err = 0.,
const bool &is_U =
true,
2014 const bool &is_vT =
true,
const unsigned int &return_err = 0,
2015 const cytnx_uint64 &mindim = 1);
2019 const Tensor &Tin,
const std::vector<cytnx_uint64> &mode,
const bool &is_core =
true,
2020 const bool &is_Ls =
false,
2021 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
2050 std::vector<Tensor>
Qr(
const Tensor &Tin,
const bool &is_tau =
false);
2073 std::vector<Tensor>
Qdr(
const Tensor &Tin,
const bool &is_tau =
false);
2099 std::vector<Tensor>
Eigh(
const Tensor &Tin,
const bool &is_V =
true,
const bool &row_v =
false);
2102 const bool &row_v =
false);
2129 std::vector<Tensor>
Eig(
const Tensor &Tin,
const bool &is_V =
true,
const bool &row_v =
false);
2132 const bool &row_v =
false);
2353 [[deprecated(
"use Exp_() (dtype-preserving) instead")]]
void Expf_(
Tensor &Tin);
2436 const std::vector<cytnx_uint64> &idxr,
const bool &cacheL =
false,
2437 const bool &cacheR =
false);
2459 const std::vector<cytnx_uint64> &idxr,
const bool &diag_L);
2494 bool rhs_pad_left =
false);
2513 const std::vector<cytnx_uint64> &shared_axes);
2576 const bool &is_row =
false,
bool throw_excp =
false);
2597 template <
typename T>
2627 template <
typename T>
2690 const std::string which =
"LM",
const cytnx_uint64 &maxiter = 10000,
2691 const cytnx_double &cvg_crit = 0,
const cytnx_uint64 &k = 1,
2692 const bool &is_V =
true,
const cytnx_int32 &ncv = 0,
2693 const bool &verbose =
false);
2751 const std::string which =
"LM",
2752 const cytnx_uint64 &maxiter = 10000,
2753 const cytnx_double &cvg_crit = 1.0e-9,
const cytnx_uint64 &k = 1,
2754 const bool &is_V =
true,
const cytnx_int32 &ncv = 0,
2755 const bool &verbose =
false);
2790 const std::string method =
"Gnd",
const double &CvgCrit = 1.0e-14,
2791 const unsigned int &Maxiter = 10000,
const cytnx_uint64 &k = 1,
2792 const bool &is_V =
true,
const bool &is_row =
false,
2793 const cytnx_uint32 &max_krydim = 0,
const bool &verbose =
false);
2835 const std::string which =
"SA",
const cytnx_uint64 &maxiter = 10000,
2836 const cytnx_double &cvg_crit = 0,
const cytnx_uint64 &k = 1,
2837 const bool &is_V =
true,
const cytnx_int32 &ncv = 0,
2838 const bool &verbose =
false);
2887 const std::string which =
"SA",
2888 const cytnx_uint64 &maxiter = 10000,
2889 const cytnx_double &cvg_crit = 0,
const cytnx_uint64 &k = 1,
2890 const bool &is_V =
true,
const cytnx_int32 &ncv = 0,
2891 const bool &verbose =
false);
2929 const std::string method =
"Gnd",
2930 const double &CvgCrit = 1.0e-14,
2931 const unsigned int &Maxiter = 10000,
const cytnx_uint64 &k = 1,
2932 const bool &is_V =
true,
const bool &is_row =
false,
2933 const cytnx_uint32 &max_krydim = 4,
const bool &verbose =
false);
2958 std::vector<Tensor>
Lanczos_ER(
LinOp *Hop,
const cytnx_uint64 &k = 1,
const bool &is_V =
true,
2959 const cytnx_uint64 &maxiter = 10000,
2960 const double &CvgCrit = 1.0e-14,
const bool &is_row =
false,
2961 const Tensor &Tin =
Tensor(),
const cytnx_uint32 &max_krydim = 4,
2962 const bool &verbose =
false);
2986 const bool &verbose =
false,
2987 const unsigned int &Maxiter = 100000);
3010 const double &CvgCrit = 1.0e-14,
const bool &is_V =
true,
3011 const bool &verbose =
false,
3012 const unsigned int &Maxiter = 100000);
3047 const double &CvgCrit = 1.0e-10,
const unsigned int &Maxiter = 100000,
3048 const bool &verbose =
false);
3156 void Gemm_Batch(
const std::vector<Scalar> &alpha_array,
const std::vector<Tensor> &a_tensors,
3157 const std::vector<Tensor> &b_tensors,
const std::vector<Scalar> &beta_array,
3158 std::vector<Tensor> &c_tensors,
const std::vector<cytnx_int64> &group_size);
3184 template <cytnx_scalar_like T>
3196 template <cytnx_scalar_like T>
3221 template <cytnx_scalar_like T>
3233 template <cytnx_scalar_like T>
3258 template <cytnx_scalar_like T>
3270 template <cytnx_scalar_like T>
3298 template <cytnx_scalar_like T>
3311 template <cytnx_scalar_like T>
3336 template <cytnx_scalar_value T>
3348 template <cytnx_scalar_value T>
3372 template <cytnx_scalar_value T>
3384 template <cytnx_scalar_value T>
an tensor (multi-dimensional array)
Definition Tensor.hpp:33
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:2773
cytnx::UniTensor Conj(const cytnx::UniTensor &UT)
Elementwise conjugate of the UniTensor.
cytnx::UniTensor Inv(const cytnx::UniTensor &Tin, double clip=-1.)
Element-wise (pseudo-)inverse.
std::vector< cytnx::UniTensor > Qr(const cytnx::UniTensor &Tin, const bool &is_tau=false)
Perform the QR decomposition on a UniTensor.
Tensor Dot(const Tensor &Tl, const Tensor &Tr)
dot product of two arrays.
cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const cytnx_int64 &a=0, const cytnx_int64 &b=1)
Perform the trace over two legs of a UniTensor.
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.
std::vector< Tensor > Eig(const Tensor &Tin, const bool &is_V=true, const bool &row_v=false)
eigen-value decomposition for generic square matrix
Tensor Sum(const Tensor &Tn)
get the sum of all the elements.
Tensor Min(const Tensor &Tn)
get the minimum element.
void Gemm_(const Scalar &a, const Tensor &x, const Tensor &y, const Scalar &b, Tensor &c)
Blas Gemm, performing , inplacely.
void Abs_(Tensor &Tin)
inplace perform elementwiase absolute value. @This is just a inplace version of Abs....
Tensor Abs(const Tensor &Tin)
Elementwise absolute value.
Tensor Outer(const Tensor &Tl, const Tensor &Tr)
perform outer produces of two rank-1 Tensor.
std::vector< cytnx::UniTensor > Svd(const cytnx::UniTensor &Tin, const bool &is_UvT=true)
Perform Singular-Value decomposition on a UniTensor using divide-and-conquer method.
Tensor Matmul(const Tensor &TL, const Tensor &TR)
perform matrix multiplication on two tensors.
cytnx::UniTensor Mod(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
element-wise modulo
Tensor Expf(const Tensor &Tin)
Exponential all the element in Tensor (deprecated).
Tensor Diag(const Tensor &Tin)
return a diagonal tensor with diagonal elements provided as Tin.
std::vector< Tensor > Lstsq(const Tensor &A, const Tensor &b, const float &rcond=-1)
Return the least-squares solution to a linear matrix equation.
std::vector< Tensor > Tridiag(const Tensor &Diag, const Tensor &Sub_diag, const bool &is_V=true, const bool &is_row=false, bool throw_excp=false)
perform diagonalization of symmetric tri-diagnoal matrix.
void Expf_(Tensor &Tin)
inplace perform Exponential on all the element in Tensor (deprecated).
Tensor Det(const Tensor &Tl)
Calculate the determinant of a tensor.
std::vector< Tensor > Eigh(const Tensor &Tin, const bool &is_V=true, const bool &row_v=false)
eigen-value decomposition for Hermitian matrix
std::vector< cytnx::UniTensor > Gesvd_truncate(const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim, const double &err=0., const bool &is_U=true, const bool &is_vT=true, const unsigned int &return_err=0, const cytnx_uint64 &mindim=1)
Perform Singular-Value decomposition on a UniTensor with truncation.
void Gemm_Batch(const std::vector< Scalar > &alpha_array, const std::vector< Tensor > &a_tensors, const std::vector< Tensor > &b_tensors, const std::vector< Scalar > &beta_array, std::vector< Tensor > &c_tensors, const std::vector< cytnx_int64 > &group_size)
Blas Gemm_Batch, performing many(batch) , inplacely. You do not need to consider the row-major or col...
UniTensor Lanczos_Exp(LinOp *Hop, const cytnx::UniTensor &v, const Scalar &tau, const double &CvgCrit=1.0e-10, const unsigned int &Maxiter=100000, const bool &verbose=false)
Perform the Lanczos algorithm for hermitian operator to approximate .
void Conj_(cytnx::UniTensor &UT)
Inplace elementwise conjugate of the UniTensor.
std::vector< cytnx::UniTensor > Gesvd(const cytnx::UniTensor &Tin, const bool &is_U=true, const bool &is_vT=true)
Perform Singular-Value decomposition on a UniTensor using ?gesvd method.
cytnx::UniTensor Pow(const cytnx::UniTensor &Tin, const double &p)
Take the power p of all elements in a UniTensor.
cytnx::UniTensor Mul(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The multiplication function between two UniTensor.
std::vector< Tensor > Lanczos(LinOp *Hop, const Tensor &Tin=Tensor(), const std::string method="Gnd", const double &CvgCrit=1.0e-14, const unsigned int &Maxiter=10000, const cytnx_uint64 &k=1, const bool &is_V=true, const bool &is_row=false, const cytnx_uint32 &max_krydim=0, const bool &verbose=false)
perform Lanczos for hermitian/symmetric matrices or linear function.
Tensor Max(const Tensor &Tn)
get the maximum element.
cytnx::UniTensor Sub(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The subtraction function between two UniTensor.
Tensor Norm(const Tensor &Tl)
Calculate the norm of a tensor.
Tensor Rand_isometry(const Tensor &Tin, const cytnx_uint64 &keepdim, const cytnx_uint64 &power_iteration=2, const unsigned int &seed=random::__static_random_device())
Generate an isometrized left isometry for a rank-2 Tensor (a matrix), such that Q * Qdag * Tin approx...
std::vector< cytnx::UniTensor > 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 >())
Tensor Vectordot(const Tensor &Tl, const Tensor &Tr, const bool &is_conj=false)
perform inner product of vectors
void iDiv(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar=false)
The inplace division function for Tensor, inplacely.
void Exp_(Tensor &Tin)
inplace perform Exponential on all the element in Tensor.
std::vector< cytnx::UniTensor > Svd_truncate(const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim, const double &err=0., const bool &is_UvT=true, const unsigned int &return_err=0, const cytnx_uint64 &mindim=1)
Perform Singular-Value decomposition on a UniTensor with truncation.
Tensor Exp(const Tensor &Tin)
Exponential all the element in Tensor.
Tensor Ger(const Tensor &x, const Tensor &y, const Scalar &a=Scalar())
Blas Ger, performing return = a*vec(x)*vec(y)^T.
void Pow_(cytnx::UniTensor &Tin, const double &p)
Take the power p of all elements in a UniTensor, inplacely.
Tensor Gemm(const Scalar &a, const Tensor &x, const Tensor &y)
Blas Gemm, performing return.
Scalar norm(const Tensor &Tl)
Calculate the norm of a tensor.
void iAdd(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar=false)
The addition function for Tensor, inplacely.
std::vector< Tensor > 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.
std::vector< UniTensor > Lanczos_Gnd_Ut(LinOp *Hop, const cytnx::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 ei...
std::vector< cytnx::UniTensor > Qdr(const cytnx::UniTensor &Tin, const bool &is_tau=false)
Perform the QDR decomposition on a UniTensor.
void InvM_(Tensor &Tin)
inplace matrix inverse.
cytnx::UniTensor Add(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The addition function between two UniTensor.
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 ra...
Tensor Directsum(const Tensor &T1, const Tensor &T2, const std::vector< cytnx_uint64 > &shared_axes)
perform directsum of two Tensor.
void iSub(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar=false)
The subtraction function for Tensot, inplscely.
cytnx::UniTensor ExpM(const cytnx::UniTensor &Tin, const T &a, const T &b=0)
Perform the exponential function on a UniTensor.
void iMul(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar=false)
The multiplication function for Tensor, inplacely.
std::vector< Tensor > Arnoldi(LinOp *Hop, const Tensor &Tin=Tensor(), const std::string which="LM", const cytnx_uint64 &maxiter=10000, const cytnx_double &cvg_crit=0, const cytnx_uint64 &k=1, const bool &is_V=true, const cytnx_int32 &ncv=0, const bool &verbose=false)
Performs Arnoldi iteration for matrices or linear functions.
std::vector< Tensor > 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 ei...
cytnx::UniTensor ExpH(const cytnx::UniTensor &Tin, const T &a, const T &b=0)
Perform the exponential function on a UniTensor, which the blocks are Hermitian matrix.
std::vector< cytnx::UniTensor > Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim, double err=0., bool is_U=true, bool is_vT=true, unsigned int return_err=0, cytnx_uint64 mindim=1, cytnx_uint64 oversampling_summand=10, double oversampling_factor=1., cytnx_uint64 power_iteration=0, unsigned int seed=random::__static_random_device())
Perform a randomized truncated Singular-Value decomposition of a UniTensor.
Tensor Cpr(const Tensor &Lt, const Tensor &Rt)
The comparison function for Tensor.
Tensor Kron(const Tensor &lhs, const Tensor &rhs, bool lhs_pad_left=false, bool rhs_pad_left=false)
perform kronecker produces of two Tensor.
void Inv_(cytnx::UniTensor &Tin, double clip=-1.)
Element-wise (pseudo-)inverse, inplacely.
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 re...
Tensor InvM(const Tensor &Tin)
Matrix inverse.
cytnx::UniTensor Div(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The division function between two UniTensor.
std::random_device __static_random_device
Definition UniTensor.hpp:27
Definition Accessor.hpp:12
cytnx::UniTensor operator*(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The multiplication operator between two UniTensor.
cytnx::UniTensor operator-(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The subtraction operator between two UniTensor.
Tensor operator==(const Tensor &Lt, const Tensor &Rt)
The comparison operator for Tensor.
cytnx::UniTensor operator%(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The modulo operator between two UniTensor.
cytnx::UniTensor operator+(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The addition operator between two UniTensor.
cytnx::UniTensor operator/(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The division operator between two UniTensor.