Cytnx v1.0.0
Loading...
Searching...
No Matches
linalg.hpp
Go to the documentation of this file.
1#ifndef CYTNX_LINALG_H_
2#define CYTNX_LINALG_H_
3
4#include "LinOp.hpp"
5#include "Tensor.hpp"
6#include "Type.hpp"
7#include "UniTensor.hpp"
8#include "cytnx_error.hpp"
9#include "random.hpp"
10
11#ifdef BACKEND_TORCH
12#else
13
14 #include <functional>
15
16 #include "backend/Scalar.hpp"
17 #include "backend/Storage.hpp"
18
19namespace cytnx {
20
32
42 template <class T>
44
54 template <class T>
56
68
78 template <class T>
80
90 template <class T>
92
104
114 template <class T>
116
126 template <class T>
128
140
150 template <class T>
152
162 template <class T>
164
176
186 template <class T>
188
198 template <class T>
200
211 namespace linalg {
212
213 // Add:
214 //==================================================
237
270 template <class T>
271 cytnx::UniTensor Add(const T &lc, const cytnx::UniTensor &Rt);
272
306 template <class T>
307 cytnx::UniTensor Add(const cytnx::UniTensor &Lt, const T &rc);
308
309 // Sub:
310 //==================================================
334
367 template <class T>
368 cytnx::UniTensor Sub(const T &lc, const cytnx::UniTensor &Rt);
369
402 template <class T>
403 cytnx::UniTensor Sub(const cytnx::UniTensor &Lt, const T &rc);
404
405 // Mul:
406 //==================================================
430
463 template <class T>
464 cytnx::UniTensor Mul(const T &lc, const cytnx::UniTensor &Rt);
465
498 template <class T>
499 cytnx::UniTensor Mul(const cytnx::UniTensor &Lt, const T &rc);
500
501 // Div:
502 //==================================================
526
560 template <class T>
561 cytnx::UniTensor Div(const T &lc, const cytnx::UniTensor &Rt);
562
596 template <class T>
597 cytnx::UniTensor Div(const cytnx::UniTensor &Lt, const T &rc);
598
599 // Mod:
600 //==================================================
626
657 template <class T>
658 cytnx::UniTensor Mod(const T &lc, const cytnx::UniTensor &Rt);
659
690 template <class T>
691 cytnx::UniTensor Mod(const cytnx::UniTensor &Lt, const T &rc);
692
700 std::vector<cytnx::UniTensor> Svd(const cytnx::UniTensor &Tin, const bool &is_UvT = true);
701
711 std::vector<cytnx::UniTensor> Gesvd(const cytnx::UniTensor &Tin, const bool &is_U = true,
712 const bool &is_vT = true);
713
725 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
726 const cytnx_uint64 &keepdim, const double &err = 0.,
727 const bool &is_UvT = true,
728 const unsigned int &return_err = 0,
729 const cytnx_uint64 &mindim = 1);
730
778 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
779 const cytnx_uint64 &keepdim,
780 std::vector<cytnx_uint64> min_blockdim,
781 const double &err = 0., const bool &is_UvT = true,
782 const unsigned int &return_err = 0,
783 const cytnx_uint64 &mindim = 1);
784
796 std::vector<cytnx::UniTensor> Gesvd_truncate(const cytnx::UniTensor &Tin,
797 const cytnx_uint64 &keepdim,
798 const double &err = 0., const bool &is_U = true,
799 const bool &is_vT = true,
800 const unsigned int &return_err = 0,
801 const cytnx_uint64 &mindim = 1);
802
814 std::vector<cytnx::UniTensor> Gesvd_truncate(
815 const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim,
816 std::vector<cytnx_uint64> min_blockdim, const double &err = 0., const bool &is_U = true,
817 const bool &is_vT = true, const unsigned int &return_err = 0, const cytnx_uint64 &mindim = 1);
818
819 // Rsvd:
820 //==================================================
870 std::vector<cytnx::UniTensor> Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim,
871 double err = 0., bool is_U = true, bool is_vT = true,
872 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
873 cytnx_uint64 oversampling_summand = 10,
874 double oversampling_factor = 1.,
875 cytnx_uint64 power_iteration = 0,
876 unsigned int seed = random::__static_random_device());
877
904 std::vector<cytnx::UniTensor> Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim,
905 const std::vector<cytnx_uint64> min_blockdim,
906 double err = 0., bool is_U = true, bool is_vT = true,
907 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
908 cytnx_uint64 oversampling_summand = 10,
909 double oversampling_factor = 1.,
910 cytnx_uint64 power_iteration = 0,
911 unsigned int seed = random::__static_random_device());
912
913 std::vector<cytnx::UniTensor> Hosvd(
914 const cytnx::UniTensor &Tin, const std::vector<cytnx_uint64> &mode,
915 const bool &is_core = true, const bool &is_Ls = false,
916 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
917
926 template <typename T>
927 cytnx::UniTensor ExpH(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
928
936 template <typename T>
937 cytnx::UniTensor ExpM(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
938
948
957
966 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const cytnx_int64 &a = 0,
967 const cytnx_int64 &b = 1);
968
975 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const std::string &a, const std::string &b);
976
985 std::vector<cytnx::UniTensor> Qr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
986
995 std::vector<cytnx::UniTensor> Qdr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
996
997 // Pow:
998 //==================================================
1017 cytnx::UniTensor Pow(const cytnx::UniTensor &Tin, const double &p);
1018
1037 void Pow_(cytnx::UniTensor &Tin, const double &p);
1038
1039 // Inv:
1040 //==================================================
1067 cytnx::UniTensor Inv(const cytnx::UniTensor &Tin, double clip = -1.);
1068
1095 void Inv_(cytnx::UniTensor &Tin, double clip = -1.);
1096
1104
1111
1112 //====================================================================================
1113 // [Tensor]
1114 // ====================================================================================
1115 //====================================================================================
1116
1140 Tensor Add(const Tensor &Lt, const Tensor &Rt);
1141
1163 template <class T>
1164 Tensor Add(const T &lc, const Tensor &Rt);
1165
1187 template <class T>
1188 Tensor Add(const Tensor &Lt, const T &rc);
1189
1214 void iAdd(Tensor &Lt, const Tensor &Rt);
1215
1216 // Sub:
1217 //==================================================
1240 Tensor Sub(const Tensor &Lt, const Tensor &Rt);
1241
1263 template <class T>
1264 Tensor Sub(const T &lc, const Tensor &Rt);
1265
1287 template <class T>
1288 Tensor Sub(const Tensor &Lt, const T &rc);
1289
1314 void iSub(Tensor &Lt, const Tensor &Rt);
1315
1316 // Mul:
1317 //==================================================
1340 Tensor Mul(const Tensor &Lt, const Tensor &Rt);
1341
1363 template <class T>
1364 Tensor Mul(const T &lc, const Tensor &Rt);
1365
1387 template <class T>
1388 Tensor Mul(const Tensor &Lt, const T &rc);
1389
1414 void iMul(Tensor &Lt, const Tensor &Rt);
1415
1416 // Div:
1417 //==================================================
1441 Tensor Div(const Tensor &Lt, const Tensor &Rt);
1442
1465 template <class T>
1466 Tensor Div(const T &lc, const Tensor &Rt);
1467
1490 template <class T>
1491 Tensor Div(const Tensor &Lt, const T &rc);
1492
1517 void iDiv(Tensor &Lt, const Tensor &Rt);
1518
1519 // Mod:
1520 //==================================================
1521
1544 Tensor Mod(const Tensor &Lt, const Tensor &Rt);
1545
1566 template <class T>
1567 Tensor Mod(const T &lc, const Tensor &Rt);
1568
1589 template <class T>
1590 Tensor Mod(const Tensor &Lt, const T &rc);
1591
1592 // Cpr:
1593 //==================================================
1619 Tensor Cpr(const Tensor &Lt, const Tensor &Rt);
1620
1645 template <class T>
1646 Tensor Cpr(const T &lc, const Tensor &Rt);
1647
1672 template <class T>
1673 Tensor Cpr(const Tensor &Lt, const T &rc);
1674
1675 // Norm:
1676 //=================================================
1686 Tensor Norm(const Tensor &Tl);
1687
1688 // Norm:
1689 //=================================================
1700
1701 // Det:
1702 //=================================================
1711 Tensor Det(const Tensor &Tl);
1712
1713 // randomized isometries:
1714 //==================================================
1742 Tensor Rand_isometry(const Tensor &Tin, const cytnx_uint64 &keepdim,
1743 const cytnx_uint64 &power_iteration = 2,
1744 const unsigned int &seed = random::__static_random_device());
1745
1746 // Svd:
1747 //==================================================
1773 std::vector<Tensor> Svd(const Tensor &Tin, const bool &is_UvT = true);
1774
1775 // Gesvd:
1776 //==================================================
1804 std::vector<Tensor> Gesvd(const Tensor &Tin, const bool &is_U = true, const bool &is_vT = true);
1805
1806 // Svd_truncate:
1807 //==================================================
1852 std::vector<Tensor> Svd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1853 const double &err = 0., const bool &is_UvT = true,
1854 const unsigned int &return_err = 0,
1855 const cytnx_uint64 &mindim = 1);
1856
1857 // Rsvd:
1858 //==================================================
1905 std::vector<Tensor> Rsvd(const Tensor &Tin, cytnx_uint64 keepdim, double err = 0.,
1906 bool is_U = true, bool is_vT = true, unsigned int return_err = 0,
1907 cytnx_uint64 mindim = 1, cytnx_uint64 oversampling_summand = 10,
1908 double oversampling_factor = 1., cytnx_uint64 power_iteration = 0,
1909 unsigned int seed = random::__static_random_device());
1910 // Gesvd_truncate:
1911 //==================================================
1940 std::vector<Tensor> Gesvd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1941 const double &err = 0., const bool &is_U = true,
1942 const bool &is_vT = true, const unsigned int &return_err = 0,
1943 const cytnx_uint64 &mindim = 1);
1944
1945 // Hosvd:
1946 std::vector<Tensor> Hosvd(
1947 const Tensor &Tin, const std::vector<cytnx_uint64> &mode, const bool &is_core = true,
1948 const bool &is_Ls = false,
1949 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
1950
1951 // Qr:
1952 //==================================================
1978 std::vector<Tensor> Qr(const Tensor &Tin, const bool &is_tau = false);
1979
1980 // Qdr:
1981 //==================================================
2001 std::vector<Tensor> Qdr(const Tensor &Tin, const bool &is_tau = false);
2002
2003 // Eigh:
2004 //==================================================
2027 std::vector<Tensor> Eigh(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
2028
2029 std::vector<UniTensor> Eigh(const cytnx::UniTensor &Tin, const bool &is_V = true,
2030 const bool &row_v = false);
2031
2032 // Eig:
2033 //==================================================
2057 std::vector<Tensor> Eig(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
2058
2059 std::vector<UniTensor> Eig(const cytnx::UniTensor &Tin, const bool &is_V = true,
2060 const bool &row_v = false);
2061
2062 // Trace:
2063 //==================================================
2077 Tensor Trace(const Tensor &Tn, const cytnx_uint64 &axisA = 0, const cytnx_uint64 &axisB = 1);
2078
2079 // Min:
2080 //==================================================
2086 Tensor Min(const Tensor &Tn);
2087
2088 // Max:
2089 //==================================================
2095 Tensor Max(const Tensor &Tn);
2096
2097 // Sum:
2098 //==================================================
2103 Tensor Sum(const Tensor &Tn);
2104
2105 // Matmul:
2106 //==================================================
2118 Tensor Matmul(const Tensor &TL, const Tensor &TR);
2119
2120 // Matmul_dg:
2121 //==================================================
2128 Tensor Matmul_dg(const Tensor &Tl, const Tensor &Tr);
2129
2130 // InvM:
2131 //==================================================
2138 Tensor InvM(const Tensor &Tin);
2147 void InvM_(Tensor &Tin);
2148 void InvM_(UniTensor &Tin);
2149
2150 // Inv:
2151 //==================================================
2176 Tensor Inv(const Tensor &Tin, const double &clip = -1.);
2177
2202 void Inv_(Tensor &Tin, const double &clip = -1.);
2203
2204 // Conj:
2205 //==================================================
2220 Tensor Conj(const Tensor &Tin);
2221
2230 void Conj_(Tensor &Tin);
2231
2232 // Exp:
2233 //==================================================
2247 Tensor Exp(const Tensor &Tin);
2248
2262 Tensor Expf(const Tensor &Tin);
2263
2273 void Exp_(Tensor &Tin);
2274
2284 void Expf_(Tensor &Tin);
2285
2286 // Pow:
2287 //==================================================
2300 Tensor Pow(const Tensor &Tin, const double &p);
2301
2315 void Pow_(Tensor &Tin, const double &p);
2316
2317 // Abs:
2318 //==================================================
2326 Tensor Abs(const Tensor &Tin);
2327
2335 void Abs_(Tensor &Tin);
2336
2337 // Diag:
2338 //==================================================
2347 Tensor Diag(const Tensor &Tin);
2348
2349 // Tensordot:
2350 //==================================================
2366 Tensor Tensordot(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2367 const std::vector<cytnx_uint64> &idxr, const bool &cacheL = false,
2368 const bool &cacheR = false);
2369
2370 // Tensordot_dg:
2371 //==================================================
2389 Tensor Tensordot_dg(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2390 const std::vector<cytnx_uint64> &idxr, const bool &diag_L);
2391
2392 // Outer:
2393 //==================================================
2404 Tensor Outer(const Tensor &Tl, const Tensor &Tr);
2405
2406 // Kron:
2407 //==================================================
2424 Tensor Kron(const Tensor &Tl, const Tensor &Tr, const bool &Tl_pad_left = false,
2425 const bool &Tr_pad_left = false);
2426
2427 // Directsum:
2428 //==================================================
2443 Tensor Directsum(const Tensor &T1, const Tensor &T2,
2444 const std::vector<cytnx_uint64> &shared_axes);
2445
2446 // VectorDot:
2447 //=================================================
2459 Tensor Vectordot(const Tensor &Tl, const Tensor &Tr, const bool &is_conj = false);
2460
2461 // Dot:
2462 //=================================================
2482 Tensor Dot(const Tensor &Tl, const Tensor &Tr);
2483
2484 // Tridiag:
2485 //===========================================
2506 std::vector<Tensor> Tridiag(const Tensor &Diag, const Tensor &Sub_diag, const bool &is_V = true,
2507 const bool &is_row = false, bool throw_excp = false);
2508
2509 // ExpH:
2510 //===========================================
2528 template <typename T>
2529 Tensor ExpH(const Tensor &in, const T &a, const T &b = 0);
2542 Tensor ExpH(const Tensor &in);
2543
2544 // ExpM:
2545 //===========================================
2558 template <typename T>
2559 Tensor ExpM(const Tensor &in, const T &a, const T &b = 0);
2560
2571 Tensor ExpM(const Tensor &in);
2572
2573 // Arnoldi:
2574 //===========================================
2620 std::vector<Tensor> Arnoldi(LinOp *Hop, const Tensor &Tin = Tensor(),
2621 const std::string which = "LM", const cytnx_uint64 &maxiter = 10000,
2622 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2623 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2624 const bool &verbose = false);
2625
2626 // Arnoldi:
2627 //===========================================
2681 std::vector<UniTensor> Arnoldi(LinOp *Hop, const cytnx::UniTensor &Tin,
2682 const std::string which = "LM",
2683 const cytnx_uint64 &maxiter = 10000,
2684 const cytnx_double &cvg_crit = 1.0e-9, const cytnx_uint64 &k = 1,
2685 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2686 const bool &verbose = false);
2687
2688 // Lanczos:
2689 //===========================================
2720 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2721 const std::string method = "Gnd", const double &CvgCrit = 1.0e-14,
2722 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2723 const bool &is_V = true, const bool &is_row = false,
2724 const cytnx_uint32 &max_krydim = 0, const bool &verbose = false);
2765 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2766 const std::string which = "SA", const cytnx_uint64 &maxiter = 10000,
2767 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2768 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2769 const bool &verbose = false);
2817 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin,
2818 const std::string which = "SA",
2819 const cytnx_uint64 &maxiter = 10000,
2820 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2821 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2822 const bool &verbose = false);
2823
2824 // Lanczos:
2825 //===========================================
2859 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin = UniTensor(),
2860 const std::string method = "Gnd",
2861 const double &CvgCrit = 1.0e-14,
2862 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2863 const bool &is_V = true, const bool &is_row = false,
2864 const cytnx_uint32 &max_krydim = 4, const bool &verbose = false);
2865
2866 // Lanczos:
2867 //===========================================
2889 std::vector<Tensor> Lanczos_ER(LinOp *Hop, const cytnx_uint64 &k = 1, const bool &is_V = true,
2890 const cytnx_uint64 &maxiter = 10000,
2891 const double &CvgCrit = 1.0e-14, const bool &is_row = false,
2892 const Tensor &Tin = Tensor(), const cytnx_uint32 &max_krydim = 4,
2893 const bool &verbose = false);
2894
2895 // Lanczos:
2896 //===========================================
2915 std::vector<Tensor> Lanczos_Gnd(LinOp *Hop, const double &CvgCrit = 1.0e-14,
2916 const bool &is_V = true, const Tensor &Tin = Tensor(),
2917 const bool &verbose = false,
2918 const unsigned int &Maxiter = 100000);
2919
2920 // Lanczos:
2921 //===============================================
2940 std::vector<UniTensor> Lanczos_Gnd_Ut(LinOp *Hop, const cytnx::UniTensor &Tin,
2941 const double &CvgCrit = 1.0e-14, const bool &is_V = true,
2942 const bool &verbose = false,
2943 const unsigned int &Maxiter = 100000);
2944
2945 // Lanczos_Exp:
2946 //===============================================
2977 UniTensor Lanczos_Exp(LinOp *Hop, const cytnx::UniTensor &v, const Scalar &tau,
2978 const double &CvgCrit = 1.0e-10, const unsigned int &Maxiter = 100000,
2979 const bool &verbose = false);
2980
2981 // Lstsq:
2982 //===========================================
3008 std::vector<Tensor> Lstsq(const Tensor &A, const Tensor &b, const float &rcond = -1);
3009
3027 Tensor Axpy(const Scalar &a, const Tensor &x, const Tensor &y = Tensor());
3028
3047 void Axpy_(const Scalar &a, const Tensor &x, Tensor &y);
3048
3063 Tensor Ger(const Tensor &x, const Tensor &y, const Scalar &a = Scalar());
3064
3082 void Gemm_(const Scalar &a, const Tensor &x, const Tensor &y, const Scalar &b, Tensor &c);
3083
3099 Tensor Gemm(const Scalar &a, const Tensor &x, const Tensor &y);
3100
3126 void Gemm_Batch(const std::vector<Scalar> &alpha_array, const std::vector<Tensor> &a_tensors,
3127 const std::vector<Tensor> &b_tensors, const std::vector<Scalar> &beta_array,
3128 std::vector<Tensor> &c_tensors, const std::vector<cytnx_int64> &group_size);
3129
3130 } // namespace linalg
3131
3132 // operators:
3143 Tensor operator+(const Tensor &Lt, const Tensor &Rt);
3144
3154 template <class T>
3155 Tensor operator+(const T &lc, const Tensor &Rt);
3156
3166 template <class T>
3167 Tensor operator+(const Tensor &Lt, const T &rc);
3168
3169 //------------------------------------
3180 Tensor operator-(const Tensor &Lt, const Tensor &Rt);
3181
3191 template <class T>
3192 Tensor operator-(const T &lc, const Tensor &Rt);
3193
3203 template <class T>
3204 Tensor operator-(const Tensor &Lt, const T &rc);
3205
3206 //-----------------------------------
3217 Tensor operator*(const Tensor &Lt, const Tensor &Rt);
3218
3228 template <class T>
3229 Tensor operator*(const T &lc, const Tensor &Rt);
3230
3240 template <class T>
3241 Tensor operator*(const Tensor &Lt, const T &rc);
3242
3243 //----------------------------------
3256 Tensor operator/(const Tensor &Lt, const Tensor &Rt);
3257
3268 template <class T>
3269 Tensor operator/(const T &lc, const Tensor &Rt);
3270
3281 template <class T>
3282 Tensor operator/(const Tensor &Lt, const T &rc);
3283
3284 //----------------------------------
3295 Tensor operator%(const Tensor &Lt, const Tensor &Rt);
3296
3306 template <class T>
3307 Tensor operator%(const T &lc, const Tensor &Rt);
3308
3318 template <class T>
3319 Tensor operator%(const Tensor &Lt, const T &rc);
3320
3321 //----------------------------------
3331 Tensor operator==(const Tensor &Lt, const Tensor &Rt);
3332
3342 template <class T>
3343 Tensor operator==(const T &lc, const Tensor &Rt);
3344
3354 template <class T>
3355 Tensor operator==(const Tensor &Lt, const T &rc);
3356
3357} // namespace cytnx
3358
3359#endif // BACKEND_TORCH
3360
3361#endif // CYTNX_LINALG_H_
Definition LinOp.hpp:20
an tensor (multi-dimensional array)
Definition Tensor.hpp:41
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:2679
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 iSub(Tensor &Lt, const Tensor &Rt)
The subtraction function for Tensot, inplscely.
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.
void Axpy_(const Scalar &a, const Tensor &x, Tensor &y)
Blas Axpy, performing , inplacely.
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.
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.
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 Axpy(const Scalar &a, const Tensor &x, const Tensor &y=Tensor())
Blas Axpy, performing , inplacely.
Tensor Vectordot(const Tensor &Tl, const Tensor &Tr, const bool &is_conj=false)
perform inner product of vectors
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.
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.
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.
void iDiv(Tensor &Lt, const Tensor &Rt)
The inplace division function for Tensor, inplacely.
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.
cytnx::UniTensor ExpM(const cytnx::UniTensor &Tin, const T &a, const T &b=0)
Perform the exponential function on a UniTensor.
void iAdd(Tensor &Lt, const Tensor &Rt)
The addition 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.
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.
void iMul(Tensor &Lt, const Tensor &Rt)
The multiplication function for Tensor, inplacely.
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:29
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.