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
46
56 template <class T>
58
68 template <class T>
70
85
95 template <class T>
97
107 template <class T>
109
124
134 template <class T>
136
146 template <class T>
148
163
173 template <class T>
175
185 template <class T>
187
199
209 template <class T>
211
221 template <class T>
223
234 namespace linalg {
235
236 // Add:
237 //==================================================
260
293 template <class T>
294 cytnx::UniTensor Add(const T &lc, const cytnx::UniTensor &Rt);
295
329 template <class T>
330 cytnx::UniTensor Add(const cytnx::UniTensor &Lt, const T &rc);
331
332 // Sub:
333 //==================================================
357
390 template <class T>
391 cytnx::UniTensor Sub(const T &lc, const cytnx::UniTensor &Rt);
392
425 template <class T>
426 cytnx::UniTensor Sub(const cytnx::UniTensor &Lt, const T &rc);
427
428 // Mul:
429 //==================================================
453
486 template <class T>
487 cytnx::UniTensor Mul(const T &lc, const cytnx::UniTensor &Rt);
488
521 template <class T>
522 cytnx::UniTensor Mul(const cytnx::UniTensor &Lt, const T &rc);
523
524 // Div:
525 //==================================================
549
583 template <class T>
584 cytnx::UniTensor Div(const T &lc, const cytnx::UniTensor &Rt);
585
619 template <class T>
620 cytnx::UniTensor Div(const cytnx::UniTensor &Lt, const T &rc);
621
622 // Mod:
623 //==================================================
649
680 template <class T>
681 cytnx::UniTensor Mod(const T &lc, const cytnx::UniTensor &Rt);
682
713 template <class T>
714 cytnx::UniTensor Mod(const cytnx::UniTensor &Lt, const T &rc);
715
723 std::vector<cytnx::UniTensor> Svd(const cytnx::UniTensor &Tin, const bool &is_UvT = true);
724
734 std::vector<cytnx::UniTensor> Gesvd(const cytnx::UniTensor &Tin, const bool &is_U = true,
735 const bool &is_vT = true);
736
748 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
749 const cytnx_uint64 &keepdim, const double &err = 0.,
750 const bool &is_UvT = true,
751 const unsigned int &return_err = 0,
752 const cytnx_uint64 &mindim = 1);
753
801 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
802 const cytnx_uint64 &keepdim,
803 std::vector<cytnx_uint64> min_blockdim,
804 const double &err = 0., const bool &is_UvT = true,
805 const unsigned int &return_err = 0,
806 const cytnx_uint64 &mindim = 1);
807
819 std::vector<cytnx::UniTensor> Gesvd_truncate(const cytnx::UniTensor &Tin,
820 const cytnx_uint64 &keepdim,
821 const double &err = 0., const bool &is_U = true,
822 const bool &is_vT = true,
823 const unsigned int &return_err = 0,
824 const cytnx_uint64 &mindim = 1);
825
837 std::vector<cytnx::UniTensor> Gesvd_truncate(
838 const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim,
839 std::vector<cytnx_uint64> min_blockdim, const double &err = 0., const bool &is_U = true,
840 const bool &is_vT = true, const unsigned int &return_err = 0, const cytnx_uint64 &mindim = 1);
841
842 // Rsvd:
843 //==================================================
893 std::vector<cytnx::UniTensor> Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim,
894 double err = 0., bool is_U = true, bool is_vT = true,
895 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
896 cytnx_uint64 oversampling_summand = 10,
897 double oversampling_factor = 1.,
898 cytnx_uint64 power_iteration = 0,
899 unsigned int seed = random::__static_random_device());
900
927 std::vector<cytnx::UniTensor> Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim,
928 const std::vector<cytnx_uint64> min_blockdim,
929 double err = 0., bool is_U = true, bool is_vT = true,
930 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
931 cytnx_uint64 oversampling_summand = 10,
932 double oversampling_factor = 1.,
933 cytnx_uint64 power_iteration = 0,
934 unsigned int seed = random::__static_random_device());
935
936 std::vector<cytnx::UniTensor> Hosvd(
937 const cytnx::UniTensor &Tin, const std::vector<cytnx_uint64> &mode,
938 const bool &is_core = true, const bool &is_Ls = false,
939 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
940
949 template <typename T>
950 cytnx::UniTensor ExpH(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
951
959 template <typename T>
960 cytnx::UniTensor ExpM(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
961
971
980
989 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const cytnx_int64 &a = 0,
990 const cytnx_int64 &b = 1);
991
998 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const std::string &a, const std::string &b);
999
1008 std::vector<cytnx::UniTensor> Qr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
1009
1018 std::vector<cytnx::UniTensor> Qdr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
1019
1020 // Pow:
1021 //==================================================
1040 cytnx::UniTensor Pow(const cytnx::UniTensor &Tin, const double &p);
1041
1060 void Pow_(cytnx::UniTensor &Tin, const double &p);
1061
1062 // Inv:
1063 //==================================================
1090 cytnx::UniTensor Inv(const cytnx::UniTensor &Tin, double clip = -1.);
1091
1118 void Inv_(cytnx::UniTensor &Tin, double clip = -1.);
1119
1127
1134
1135 //====================================================================================
1136 // [Tensor]
1137 // ====================================================================================
1138 //====================================================================================
1139
1163 Tensor Add(const Tensor &Lt, const Tensor &Rt);
1164
1186 template <class T>
1187 Tensor Add(const T &lc, const Tensor &Rt);
1188
1210 template <class T>
1211 Tensor Add(const Tensor &Lt, const T &rc);
1212
1237 void iAdd(Tensor &Lt, const Tensor &Rt);
1238
1239 // Sub:
1240 //==================================================
1263 Tensor Sub(const Tensor &Lt, const Tensor &Rt);
1264
1286 template <class T>
1287 Tensor Sub(const T &lc, const Tensor &Rt);
1288
1310 template <class T>
1311 Tensor Sub(const Tensor &Lt, const T &rc);
1312
1337 void iSub(Tensor &Lt, const Tensor &Rt);
1338
1339 // Mul:
1340 //==================================================
1363 Tensor Mul(const Tensor &Lt, const Tensor &Rt);
1364
1386 template <class T>
1387 Tensor Mul(const T &lc, const Tensor &Rt);
1388
1410 template <class T>
1411 Tensor Mul(const Tensor &Lt, const T &rc);
1412
1437 void iMul(Tensor &Lt, const Tensor &Rt);
1438
1439 // Div:
1440 //==================================================
1464 Tensor Div(const Tensor &Lt, const Tensor &Rt);
1465
1488 template <class T>
1489 Tensor Div(const T &lc, const Tensor &Rt);
1490
1513 template <class T>
1514 Tensor Div(const Tensor &Lt, const T &rc);
1515
1540 void iDiv(Tensor &Lt, const Tensor &Rt);
1541
1542 // Mod:
1543 //==================================================
1544
1567 Tensor Mod(const Tensor &Lt, const Tensor &Rt);
1568
1589 template <class T>
1590 Tensor Mod(const T &lc, const Tensor &Rt);
1591
1612 template <class T>
1613 Tensor Mod(const Tensor &Lt, const T &rc);
1614
1615 // Cpr:
1616 //==================================================
1642 Tensor Cpr(const Tensor &Lt, const Tensor &Rt);
1643
1668 template <class T>
1669 Tensor Cpr(const T &lc, const Tensor &Rt);
1670
1695 template <class T>
1696 Tensor Cpr(const Tensor &Lt, const T &rc);
1697
1698 // Norm:
1699 //=================================================
1710 [[deprecated("use norm() (returns Scalar) instead")]] Tensor Norm(const Tensor &Tl);
1711
1712 // norm:
1713 //=================================================
1723 Scalar norm(const Tensor &Tl);
1724
1725 // Norm:
1726 //=================================================
1737 [[deprecated("use norm() (returns Scalar) instead")]] Tensor Norm(const cytnx::UniTensor &uTl);
1738
1739 // norm:
1740 //=================================================
1750 Scalar norm(const cytnx::UniTensor &uTl);
1751
1752 // Det:
1753 //=================================================
1762 Tensor Det(const Tensor &Tl);
1763
1764 // randomized isometries:
1765 //==================================================
1793 Tensor Rand_isometry(const Tensor &Tin, const cytnx_uint64 &keepdim,
1794 const cytnx_uint64 &power_iteration = 2,
1795 const unsigned int &seed = random::__static_random_device());
1796
1797 // Svd:
1798 //==================================================
1824 std::vector<Tensor> Svd(const Tensor &Tin, const bool &is_UvT = true);
1825
1826 // Gesvd:
1827 //==================================================
1855 std::vector<Tensor> Gesvd(const Tensor &Tin, const bool &is_U = true, const bool &is_vT = true);
1856
1857 // Svd_truncate:
1858 //==================================================
1903 std::vector<Tensor> Svd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1904 const double &err = 0., const bool &is_UvT = true,
1905 const unsigned int &return_err = 0,
1906 const cytnx_uint64 &mindim = 1);
1907
1908 // Rsvd:
1909 //==================================================
1956 std::vector<Tensor> Rsvd(const Tensor &Tin, cytnx_uint64 keepdim, double err = 0.,
1957 bool is_U = true, bool is_vT = true, unsigned int return_err = 0,
1958 cytnx_uint64 mindim = 1, cytnx_uint64 oversampling_summand = 10,
1959 double oversampling_factor = 1., cytnx_uint64 power_iteration = 0,
1960 unsigned int seed = random::__static_random_device());
1961 // Gesvd_truncate:
1962 //==================================================
1991 std::vector<Tensor> Gesvd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1992 const double &err = 0., const bool &is_U = true,
1993 const bool &is_vT = true, const unsigned int &return_err = 0,
1994 const cytnx_uint64 &mindim = 1);
1995
1996 // Hosvd:
1997 std::vector<Tensor> Hosvd(
1998 const Tensor &Tin, const std::vector<cytnx_uint64> &mode, const bool &is_core = true,
1999 const bool &is_Ls = false,
2000 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
2001
2002 // Qr:
2003 //==================================================
2029 std::vector<Tensor> Qr(const Tensor &Tin, const bool &is_tau = false);
2030
2031 // Qdr:
2032 //==================================================
2052 std::vector<Tensor> Qdr(const Tensor &Tin, const bool &is_tau = false);
2053
2054 // Eigh:
2055 //==================================================
2078 std::vector<Tensor> Eigh(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
2079
2080 std::vector<UniTensor> Eigh(const cytnx::UniTensor &Tin, const bool &is_V = true,
2081 const bool &row_v = false);
2082
2083 // Eig:
2084 //==================================================
2108 std::vector<Tensor> Eig(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
2109
2110 std::vector<UniTensor> Eig(const cytnx::UniTensor &Tin, const bool &is_V = true,
2111 const bool &row_v = false);
2112
2113 // Trace:
2114 //==================================================
2128 Tensor Trace(const Tensor &Tn, const cytnx_uint64 &axisA = 0, const cytnx_uint64 &axisB = 1);
2129
2130 // Min:
2131 //==================================================
2137 Tensor Min(const Tensor &Tn);
2138
2139 // Max:
2140 //==================================================
2146 Tensor Max(const Tensor &Tn);
2147
2148 // Sum:
2149 //==================================================
2154 Tensor Sum(const Tensor &Tn);
2155
2156 // Matmul:
2157 //==================================================
2169 Tensor Matmul(const Tensor &TL, const Tensor &TR);
2170
2171 // Matmul_dg:
2172 //==================================================
2179 Tensor Matmul_dg(const Tensor &Tl, const Tensor &Tr);
2180
2181 // InvM:
2182 //==================================================
2189 Tensor InvM(const Tensor &Tin);
2198 void InvM_(Tensor &Tin);
2199 void InvM_(UniTensor &Tin);
2200
2201 // Inv:
2202 //==================================================
2227 Tensor Inv(const Tensor &Tin, const double &clip = -1.);
2228
2253 void Inv_(Tensor &Tin, const double &clip = -1.);
2254
2255 // Conj:
2256 //==================================================
2271 Tensor Conj(const Tensor &Tin);
2272
2281 void Conj_(Tensor &Tin);
2282
2283 // Exp:
2284 //==================================================
2298 Tensor Exp(const Tensor &Tin);
2299
2310 [[deprecated("use Exp() (dtype-preserving) instead")]] Tensor Expf(const Tensor &Tin);
2311
2322 void Exp_(Tensor &Tin);
2323
2332 [[deprecated("use Exp_() (dtype-preserving) instead")]] void Expf_(Tensor &Tin);
2333
2334 // Pow:
2335 //==================================================
2348 Tensor Pow(const Tensor &Tin, const double &p);
2349
2363 void Pow_(Tensor &Tin, const double &p);
2364
2365 // Abs:
2366 //==================================================
2374 Tensor Abs(const Tensor &Tin);
2375
2383 void Abs_(Tensor &Tin);
2384
2385 // Diag:
2386 //==================================================
2395 Tensor Diag(const Tensor &Tin);
2396
2397 // Tensordot:
2398 //==================================================
2414 Tensor Tensordot(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2415 const std::vector<cytnx_uint64> &idxr, const bool &cacheL = false,
2416 const bool &cacheR = false);
2417
2418 // Tensordot_dg:
2419 //==================================================
2437 Tensor Tensordot_dg(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2438 const std::vector<cytnx_uint64> &idxr, const bool &diag_L);
2439
2440 // Outer:
2441 //==================================================
2452 Tensor Outer(const Tensor &Tl, const Tensor &Tr);
2453
2454 // Kron:
2455 //==================================================
2472 Tensor Kron(const Tensor &lhs, const Tensor &rhs, bool lhs_pad_left = false,
2473 bool rhs_pad_left = false);
2474
2475 // Directsum:
2476 //==================================================
2491 Tensor Directsum(const Tensor &T1, const Tensor &T2,
2492 const std::vector<cytnx_uint64> &shared_axes);
2493
2494 // VectorDot:
2495 //=================================================
2507 Tensor Vectordot(const Tensor &Tl, const Tensor &Tr, const bool &is_conj = false);
2508
2509 // Dot:
2510 //=================================================
2530 Tensor Dot(const Tensor &Tl, const Tensor &Tr);
2531
2532 // Tridiag:
2533 //===========================================
2554 std::vector<Tensor> Tridiag(const Tensor &Diag, const Tensor &Sub_diag, const bool &is_V = true,
2555 const bool &is_row = false, bool throw_excp = false);
2556
2557 // ExpH:
2558 //===========================================
2576 template <typename T>
2577 Tensor ExpH(const Tensor &in, const T &a, const T &b = 0);
2590 Tensor ExpH(const Tensor &in);
2591
2592 // ExpM:
2593 //===========================================
2606 template <typename T>
2607 Tensor ExpM(const Tensor &in, const T &a, const T &b = 0);
2608
2619 Tensor ExpM(const Tensor &in);
2620
2621 // Arnoldi:
2622 //===========================================
2668 std::vector<Tensor> Arnoldi(LinOp *Hop, const Tensor &Tin = Tensor(),
2669 const std::string which = "LM", const cytnx_uint64 &maxiter = 10000,
2670 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2671 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2672 const bool &verbose = false);
2673
2674 // Arnoldi:
2675 //===========================================
2729 std::vector<UniTensor> Arnoldi(LinOp *Hop, const cytnx::UniTensor &Tin,
2730 const std::string which = "LM",
2731 const cytnx_uint64 &maxiter = 10000,
2732 const cytnx_double &cvg_crit = 1.0e-9, const cytnx_uint64 &k = 1,
2733 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2734 const bool &verbose = false);
2735
2736 // Lanczos:
2737 //===========================================
2768 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2769 const std::string method = "Gnd", const double &CvgCrit = 1.0e-14,
2770 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2771 const bool &is_V = true, const bool &is_row = false,
2772 const cytnx_uint32 &max_krydim = 0, const bool &verbose = false);
2813 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2814 const std::string which = "SA", const cytnx_uint64 &maxiter = 10000,
2815 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2816 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2817 const bool &verbose = false);
2865 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin,
2866 const std::string which = "SA",
2867 const cytnx_uint64 &maxiter = 10000,
2868 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2869 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2870 const bool &verbose = false);
2871
2872 // Lanczos:
2873 //===========================================
2907 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin = UniTensor(),
2908 const std::string method = "Gnd",
2909 const double &CvgCrit = 1.0e-14,
2910 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2911 const bool &is_V = true, const bool &is_row = false,
2912 const cytnx_uint32 &max_krydim = 4, const bool &verbose = false);
2913
2914 // Lanczos:
2915 //===========================================
2937 std::vector<Tensor> Lanczos_ER(LinOp *Hop, const cytnx_uint64 &k = 1, const bool &is_V = true,
2938 const cytnx_uint64 &maxiter = 10000,
2939 const double &CvgCrit = 1.0e-14, const bool &is_row = false,
2940 const Tensor &Tin = Tensor(), const cytnx_uint32 &max_krydim = 4,
2941 const bool &verbose = false);
2942
2943 // Lanczos:
2944 //===========================================
2963 std::vector<Tensor> Lanczos_Gnd(LinOp *Hop, const double &CvgCrit = 1.0e-14,
2964 const bool &is_V = true, const Tensor &Tin = Tensor(),
2965 const bool &verbose = false,
2966 const unsigned int &Maxiter = 100000);
2967
2968 // Lanczos:
2969 //===============================================
2988 std::vector<UniTensor> Lanczos_Gnd_Ut(LinOp *Hop, const cytnx::UniTensor &Tin,
2989 const double &CvgCrit = 1.0e-14, const bool &is_V = true,
2990 const bool &verbose = false,
2991 const unsigned int &Maxiter = 100000);
2992
2993 // Lanczos_Exp:
2994 //===============================================
3025 UniTensor Lanczos_Exp(LinOp *Hop, const cytnx::UniTensor &v, const Scalar &tau,
3026 const double &CvgCrit = 1.0e-10, const unsigned int &Maxiter = 100000,
3027 const bool &verbose = false);
3028
3029 // Lstsq:
3030 //===========================================
3056 std::vector<Tensor> Lstsq(const Tensor &A, const Tensor &b, const float &rcond = -1);
3057
3072 Tensor Ger(const Tensor &x, const Tensor &y, const Scalar &a = Scalar());
3073
3091 void Gemm_(const Scalar &a, const Tensor &x, const Tensor &y, const Scalar &b, Tensor &c);
3092
3108 Tensor Gemm(const Scalar &a, const Tensor &x, const Tensor &y);
3109
3135 void Gemm_Batch(const std::vector<Scalar> &alpha_array, const std::vector<Tensor> &a_tensors,
3136 const std::vector<Tensor> &b_tensors, const std::vector<Scalar> &beta_array,
3137 std::vector<Tensor> &c_tensors, const std::vector<cytnx_int64> &group_size);
3138
3139 } // namespace linalg
3140
3141 // operators:
3152 Tensor operator+(const Tensor &Lt, const Tensor &Rt);
3153
3163 template <class T>
3164 Tensor operator+(const T &lc, const Tensor &Rt);
3165
3175 template <class T>
3176 Tensor operator+(const Tensor &Lt, const T &rc);
3177
3178 //------------------------------------
3189 Tensor operator-(const Tensor &Lt, const Tensor &Rt);
3190
3200 template <class T>
3201 Tensor operator-(const T &lc, const Tensor &Rt);
3202
3212 template <class T>
3213 Tensor operator-(const Tensor &Lt, const T &rc);
3214
3215 //-----------------------------------
3226 Tensor operator*(const Tensor &Lt, const Tensor &Rt);
3227
3237 template <class T>
3238 Tensor operator*(const T &lc, const Tensor &Rt);
3239
3249 template <class T>
3250 Tensor operator*(const Tensor &Lt, const T &rc);
3251
3252 //----------------------------------
3265 Tensor operator/(const Tensor &Lt, const Tensor &Rt);
3266
3277 template <class T>
3278 Tensor operator/(const T &lc, const Tensor &Rt);
3279
3290 template <class T>
3291 Tensor operator/(const Tensor &Lt, const T &rc);
3292
3293 //----------------------------------
3304 Tensor operator%(const Tensor &Lt, const Tensor &Rt);
3305
3315 template <class T>
3316 Tensor operator%(const T &lc, const Tensor &Rt);
3317
3327 template <class T>
3328 Tensor operator%(const Tensor &Lt, const T &rc);
3329
3330 //----------------------------------
3340 Tensor operator==(const Tensor &Lt, const Tensor &Rt);
3341
3351 template <class T>
3352 Tensor operator==(const T &lc, const Tensor &Rt);
3353
3363 template <class T>
3364 Tensor operator==(const Tensor &Lt, const T &rc);
3365
3366} // namespace cytnx
3367
3368#endif // BACKEND_TORCH
3369
3370#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:2775
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.
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 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.
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.
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.
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.