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
718 std::vector<cytnx::UniTensor> Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim,
719 bool is_U = true, bool is_vT = true,
720 cytnx_uint64 power_iteration = 2,
721 unsigned int seed = random::__static_random_device());
722
732 std::vector<cytnx::UniTensor> Gesvd(const cytnx::UniTensor &Tin, const bool &is_U = true,
733 const bool &is_vT = true);
734
746 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
747 const cytnx_uint64 &keepdim, const double &err = 0.,
748 const bool &is_UvT = true,
749 const unsigned int &return_err = 0,
750 const cytnx_uint64 &mindim = 1);
751
799 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
800 const cytnx_uint64 &keepdim,
801 std::vector<cytnx_uint64> min_blockdim,
802 const double &err = 0., const bool &is_UvT = true,
803 const unsigned int &return_err = 0,
804 const cytnx_uint64 &mindim = 1);
805
817 std::vector<cytnx::UniTensor> Gesvd_truncate(const cytnx::UniTensor &Tin,
818 const cytnx_uint64 &keepdim,
819 const double &err = 0., const bool &is_U = true,
820 const bool &is_vT = true,
821 const unsigned int &return_err = 0,
822 const cytnx_uint64 &mindim = 1);
823
835 std::vector<cytnx::UniTensor> Gesvd_truncate(
836 const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim,
837 std::vector<cytnx_uint64> min_blockdim, const double &err = 0., const bool &is_U = true,
838 const bool &is_vT = true, const unsigned int &return_err = 0, const cytnx_uint64 &mindim = 1);
839
840 // Rsvd_truncate:
841 //==================================================
890 std::vector<cytnx::UniTensor> Rsvd_truncate(
891 const cytnx::UniTensor &Tin, cytnx_uint64 keepdim, double err = 0., bool is_U = true,
892 bool is_vT = true, unsigned int return_err = 0, cytnx_uint64 mindim = 1,
893 cytnx_uint64 oversampling_summand = 10, double oversampling_factor = 1.,
894 cytnx_uint64 power_iteration = 0, unsigned int seed = random::__static_random_device());
895
896 std::vector<cytnx::UniTensor> Hosvd(
897 const cytnx::UniTensor &Tin, const std::vector<cytnx_uint64> &mode,
898 const bool &is_core = true, const bool &is_Ls = false,
899 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
900
909 template <typename T>
910 cytnx::UniTensor ExpH(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
911
919 template <typename T>
920 cytnx::UniTensor ExpM(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
921
931
940
945 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const cytnx_int64 &a = 0,
946 const cytnx_int64 &b = 1);
947
955 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const std::string &a, const std::string &b);
956
965 std::vector<cytnx::UniTensor> Qr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
966
975 std::vector<cytnx::UniTensor> Qdr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
976
977 // Pow:
978 //==================================================
991 UniTensor Pow(const cytnx::UniTensor &Tin, const double &p);
992
1004 void Pow_(UniTensor &Tin, const double &p);
1005
1013
1020
1021 //====================================================================================
1022 // [Tensor]
1023 // ====================================================================================
1024 //====================================================================================
1025
1049 Tensor Add(const Tensor &Lt, const Tensor &Rt);
1050
1072 template <class T>
1073 Tensor Add(const T &lc, const Tensor &Rt);
1074
1096 template <class T>
1097 Tensor Add(const Tensor &Lt, const T &rc);
1098
1123 void iAdd(Tensor &Lt, const Tensor &Rt);
1124
1125 // Sub:
1126 //==================================================
1149 Tensor Sub(const Tensor &Lt, const Tensor &Rt);
1150
1172 template <class T>
1173 Tensor Sub(const T &lc, const Tensor &Rt);
1174
1196 template <class T>
1197 Tensor Sub(const Tensor &Lt, const T &rc);
1198
1223 void iSub(Tensor &Lt, const Tensor &Rt);
1224
1225 // Mul:
1226 //==================================================
1249 Tensor Mul(const Tensor &Lt, const Tensor &Rt);
1250
1272 template <class T>
1273 Tensor Mul(const T &lc, const Tensor &Rt);
1274
1296 template <class T>
1297 Tensor Mul(const Tensor &Lt, const T &rc);
1298
1323 void iMul(Tensor &Lt, const Tensor &Rt);
1324
1325 // Div:
1326 //==================================================
1350 Tensor Div(const Tensor &Lt, const Tensor &Rt);
1351
1374 template <class T>
1375 Tensor Div(const T &lc, const Tensor &Rt);
1376
1399 template <class T>
1400 Tensor Div(const Tensor &Lt, const T &rc);
1401
1426 void iDiv(Tensor &Lt, const Tensor &Rt);
1427
1428 // Mod:
1429 //==================================================
1430
1453 Tensor Mod(const Tensor &Lt, const Tensor &Rt);
1454
1475 template <class T>
1476 Tensor Mod(const T &lc, const Tensor &Rt);
1477
1498 template <class T>
1499 Tensor Mod(const Tensor &Lt, const T &rc);
1500
1501 // Cpr:
1502 //==================================================
1528 Tensor Cpr(const Tensor &Lt, const Tensor &Rt);
1529
1554 template <class T>
1555 Tensor Cpr(const T &lc, const Tensor &Rt);
1556
1581 template <class T>
1582 Tensor Cpr(const Tensor &Lt, const T &rc);
1583
1584 // Norm:
1585 //=================================================
1595 Tensor Norm(const Tensor &Tl);
1596
1597 // Norm:
1598 //=================================================
1609
1610 // Det:
1611 //=================================================
1620 Tensor Det(const Tensor &Tl);
1621
1622 // randomized isometries:
1623 //==================================================
1651 Tensor Rand_isometry(const Tensor &Tin, const cytnx_uint64 &keepdim,
1652 const cytnx_uint64 &power_iteration = 2,
1653 const unsigned int &seed = random::__static_random_device());
1654
1655 // Svd:
1656 //==================================================
1682 std::vector<Tensor> Svd(const Tensor &Tin, const bool &is_UvT = true);
1683
1684 // Gesvd:
1685 //==================================================
1713 std::vector<Tensor> Gesvd(const Tensor &Tin, const bool &is_U = true, const bool &is_vT = true);
1714
1715 // Rsvd:
1716 //==================================================
1734 std::vector<Tensor> Rsvd(const Tensor &Tin, cytnx_uint64 keepdim, bool is_U = true,
1735 bool is_vT = true, cytnx_uint64 power_iteration = 2,
1736 unsigned int seed = random::__static_random_device());
1737
1738 // Svd_truncate:
1739 //==================================================
1784 std::vector<Tensor> Svd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1785 const double &err = 0., const bool &is_UvT = true,
1786 const unsigned int &return_err = 0,
1787 const cytnx_uint64 &mindim = 1);
1788
1789 // Rsvd_truncate:
1790 //==================================================
1838 std::vector<Tensor> Rsvd_truncate(const Tensor &Tin, cytnx_uint64 keepdim, double err = 0.,
1839 bool is_U = true, bool is_vT = true,
1840 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
1841 cytnx_uint64 oversampling_summand = 10,
1842 double oversampling_factor = 1.,
1843 cytnx_uint64 power_iteration = 0,
1844 unsigned int seed = random::__static_random_device());
1845 // Gesvd_truncate:
1846 //==================================================
1875 std::vector<Tensor> Gesvd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1876 const double &err = 0., const bool &is_U = true,
1877 const bool &is_vT = true, const unsigned int &return_err = 0,
1878 const cytnx_uint64 &mindim = 1);
1879
1880 // Hosvd:
1881 std::vector<Tensor> Hosvd(
1882 const Tensor &Tin, const std::vector<cytnx_uint64> &mode, const bool &is_core = true,
1883 const bool &is_Ls = false,
1884 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
1885
1886 // Qr:
1887 //==================================================
1913 std::vector<Tensor> Qr(const Tensor &Tin, const bool &is_tau = false);
1914
1915 // Qdr:
1916 //==================================================
1936 std::vector<Tensor> Qdr(const Tensor &Tin, const bool &is_tau = false);
1937
1938 // Eigh:
1939 //==================================================
1962 std::vector<Tensor> Eigh(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
1963
1964 std::vector<UniTensor> Eigh(const cytnx::UniTensor &Tin, const bool &is_V = true,
1965 const bool &row_v = false);
1966
1967 // Eig:
1968 //==================================================
1988 std::vector<Tensor> Eig(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
1989
1990 std::vector<UniTensor> Eig(const cytnx::UniTensor &Tin, const bool &is_V = true,
1991 const bool &row_v = false);
1992
1993 // Trace:
1994 //==================================================
2008 Tensor Trace(const Tensor &Tn, const cytnx_uint64 &axisA = 0, const cytnx_uint64 &axisB = 1);
2009
2010 // Min:
2011 //==================================================
2017 Tensor Min(const Tensor &Tn);
2018
2019 // Max:
2020 //==================================================
2026 Tensor Max(const Tensor &Tn);
2027
2028 // Sum:
2029 //==================================================
2034 Tensor Sum(const Tensor &Tn);
2035
2036 // Matmul:
2037 //==================================================
2049 Tensor Matmul(const Tensor &TL, const Tensor &TR);
2050
2051 // Matmul_dg:
2052 //==================================================
2059 Tensor Matmul_dg(const Tensor &Tl, const Tensor &Tr);
2060
2061 // InvM:
2062 //==================================================
2069 Tensor InvM(const Tensor &Tin);
2078 void InvM_(Tensor &Tin);
2079 void InvM_(UniTensor &Tin);
2080 // Inv:
2081 //==================================================
2100 Tensor Inv(const Tensor &Tin, const double &clip);
2101
2114 void Inv_(Tensor &Tin, const double &clip);
2115
2116 // Conj:
2117 //==================================================
2132 Tensor Conj(const Tensor &Tin);
2133
2142 void Conj_(Tensor &Tin);
2143
2144 // Exp:
2145 //==================================================
2159 Tensor Exp(const Tensor &Tin);
2160
2174 Tensor Expf(const Tensor &Tin);
2175
2185 void Exp_(Tensor &Tin);
2186
2196 void Expf_(Tensor &Tin);
2197
2198 // Pow:
2199 //==================================================
2211 Tensor Pow(const Tensor &Tin, const double &p);
2212
2219 void Pow_(Tensor &Tin, const double &p);
2220
2221 // Abs:
2222 //==================================================
2230 Tensor Abs(const Tensor &Tin);
2231
2239 void Abs_(Tensor &Tin);
2240
2241 // Diag:
2242 //==================================================
2251 Tensor Diag(const Tensor &Tin);
2252
2253 // Tensordot:
2254 //==================================================
2270 Tensor Tensordot(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2271 const std::vector<cytnx_uint64> &idxr, const bool &cacheL = false,
2272 const bool &cacheR = false);
2273
2274 // Tensordot_dg:
2275 //==================================================
2293 Tensor Tensordot_dg(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2294 const std::vector<cytnx_uint64> &idxr, const bool &diag_L);
2295
2296 // Outer:
2297 //==================================================
2308 Tensor Outer(const Tensor &Tl, const Tensor &Tr);
2309
2310 // Kron:
2311 //==================================================
2328 Tensor Kron(const Tensor &Tl, const Tensor &Tr, const bool &Tl_pad_left = false,
2329 const bool &Tr_pad_left = false);
2330
2331 // Directsum:
2332 //==================================================
2347 Tensor Directsum(const Tensor &T1, const Tensor &T2,
2348 const std::vector<cytnx_uint64> &shared_axes);
2349
2350 // VectorDot:
2351 //=================================================
2363 Tensor Vectordot(const Tensor &Tl, const Tensor &Tr, const bool &is_conj = false);
2364
2365 // Dot:
2366 //=================================================
2386 Tensor Dot(const Tensor &Tl, const Tensor &Tr);
2387
2388 // Tridiag:
2389 //===========================================
2410 std::vector<Tensor> Tridiag(const Tensor &Diag, const Tensor &Sub_diag, const bool &is_V = true,
2411 const bool &is_row = false, bool throw_excp = false);
2412
2413 // ExpH:
2414 //===========================================
2432 template <typename T>
2433 Tensor ExpH(const Tensor &in, const T &a, const T &b = 0);
2446 Tensor ExpH(const Tensor &in);
2447
2448 // ExpM:
2449 //===========================================
2462 template <typename T>
2463 Tensor ExpM(const Tensor &in, const T &a, const T &b = 0);
2464
2475 Tensor ExpM(const Tensor &in);
2476
2477 // Arnoldi:
2478 //===========================================
2524 std::vector<Tensor> Arnoldi(LinOp *Hop, const Tensor &Tin = Tensor(),
2525 const std::string which = "LM", const cytnx_uint64 &maxiter = 10000,
2526 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2527 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2528 const bool &verbose = false);
2529
2530 // Arnoldi:
2531 //===========================================
2580 std::vector<UniTensor> Arnoldi(LinOp *Hop, const cytnx::UniTensor &Tin,
2581 const std::string which = "LM",
2582 const cytnx_uint64 &maxiter = 10000,
2583 const cytnx_double &cvg_crit = 1.0e-9, const cytnx_uint64 &k = 1,
2584 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2585 const bool &verbose = false);
2586
2587 // Lanczos:
2588 //===========================================
2619 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2620 const std::string method = "Gnd", const double &CvgCrit = 1.0e-14,
2621 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2622 const bool &is_V = true, const bool &is_row = false,
2623 const cytnx_uint32 &max_krydim = 0, const bool &verbose = false);
2664 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2665 const std::string which = "SA", const cytnx_uint64 &maxiter = 10000,
2666 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2667 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2668 const bool &verbose = false);
2711 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin,
2712 const std::string which = "SA",
2713 const cytnx_uint64 &maxiter = 10000,
2714 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2715 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2716 const bool &verbose = false);
2717
2718 // Lanczos:
2719 //===========================================
2753 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin = UniTensor(),
2754 const std::string method = "Gnd",
2755 const double &CvgCrit = 1.0e-14,
2756 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2757 const bool &is_V = true, const bool &is_row = false,
2758 const cytnx_uint32 &max_krydim = 4, const bool &verbose = false);
2759
2760 // Lanczos:
2761 //===========================================
2783 std::vector<Tensor> Lanczos_ER(LinOp *Hop, const cytnx_uint64 &k = 1, const bool &is_V = true,
2784 const cytnx_uint64 &maxiter = 10000,
2785 const double &CvgCrit = 1.0e-14, const bool &is_row = false,
2786 const Tensor &Tin = Tensor(), const cytnx_uint32 &max_krydim = 4,
2787 const bool &verbose = false);
2788
2789 // Lanczos:
2790 //===========================================
2809 std::vector<Tensor> Lanczos_Gnd(LinOp *Hop, const double &CvgCrit = 1.0e-14,
2810 const bool &is_V = true, const Tensor &Tin = Tensor(),
2811 const bool &verbose = false,
2812 const unsigned int &Maxiter = 100000);
2813
2814 // Lanczos:
2815 //===============================================
2834 std::vector<UniTensor> Lanczos_Gnd_Ut(LinOp *Hop, const cytnx::UniTensor &Tin,
2835 const double &CvgCrit = 1.0e-14, const bool &is_V = true,
2836 const bool &verbose = false,
2837 const unsigned int &Maxiter = 100000);
2838
2839 // Lanczos_Exp:
2840 //===============================================
2871 UniTensor Lanczos_Exp(LinOp *Hop, const cytnx::UniTensor &v, const Scalar &tau,
2872 const double &CvgCrit = 1.0e-10, const unsigned int &Maxiter = 100000,
2873 const bool &verbose = false);
2874
2875 // Lstsq:
2876 //===========================================
2902 std::vector<Tensor> Lstsq(const Tensor &A, const Tensor &b, const float &rcond = -1);
2903
2921 Tensor Axpy(const Scalar &a, const Tensor &x, const Tensor &y = Tensor());
2922
2941 void Axpy_(const Scalar &a, const Tensor &x, Tensor &y);
2942
2957 Tensor Ger(const Tensor &x, const Tensor &y, const Scalar &a = Scalar());
2958
2976 void Gemm_(const Scalar &a, const Tensor &x, const Tensor &y, const Scalar &b, Tensor &c);
2977
2993 Tensor Gemm(const Scalar &a, const Tensor &x, const Tensor &y);
2994
3022 void Gemm_Batch(const std::vector<cytnx_int64> &m_array,
3023 const std::vector<cytnx_int64> &n_array,
3024 const std::vector<cytnx_int64> &k_array, const std::vector<Scalar> &alpha_array,
3025 const std::vector<Tensor> &a_tensors, const std::vector<Tensor> &b_tensors,
3026 const std::vector<Scalar> &beta_array, std::vector<Tensor> &c_tensors,
3027 const cytnx_int64 group_count, const std::vector<cytnx_int64> &group_size);
3028
3030 void __Gemm_Batch(const std::vector<char> &transa_array, const std::vector<char> &transb_array,
3031 const std::vector<blas_int> &m_array, const std::vector<blas_int> &n_array,
3032 const std::vector<blas_int> &k_array, const std::vector<Scalar> &alpha_array,
3033 const void **a_array, const void **b_array,
3034 const std::vector<Scalar> &beta_array, void **c_array,
3035 const blas_int group_count, const std::vector<blas_int> &group_size,
3036 const unsigned int dtype, const int device);
3037
3039
3040 } // namespace linalg
3041
3042 // operators:
3053 Tensor operator+(const Tensor &Lt, const Tensor &Rt);
3054
3064 template <class T>
3065 Tensor operator+(const T &lc, const Tensor &Rt);
3066
3076 template <class T>
3077 Tensor operator+(const Tensor &Lt, const T &rc);
3078
3079 //------------------------------------
3090 Tensor operator-(const Tensor &Lt, const Tensor &Rt);
3091
3101 template <class T>
3102 Tensor operator-(const T &lc, const Tensor &Rt);
3103
3113 template <class T>
3114 Tensor operator-(const Tensor &Lt, const T &rc);
3115
3116 //-----------------------------------
3127 Tensor operator*(const Tensor &Lt, const Tensor &Rt);
3128
3138 template <class T>
3139 Tensor operator*(const T &lc, const Tensor &Rt);
3140
3150 template <class T>
3151 Tensor operator*(const Tensor &Lt, const T &rc);
3152
3153 //----------------------------------
3166 Tensor operator/(const Tensor &Lt, const Tensor &Rt);
3167
3178 template <class T>
3179 Tensor operator/(const T &lc, const Tensor &Rt);
3180
3191 template <class T>
3192 Tensor operator/(const Tensor &Lt, const T &rc);
3193
3194 //----------------------------------
3205 Tensor operator%(const Tensor &Lt, const Tensor &Rt);
3206
3216 template <class T>
3217 Tensor operator%(const T &lc, const Tensor &Rt);
3218
3228 template <class T>
3229 Tensor operator%(const Tensor &Lt, const T &rc);
3230
3231 //----------------------------------
3241 Tensor operator==(const Tensor &Lt, const Tensor &Rt);
3242
3252 template <class T>
3253 Tensor operator==(const T &lc, const Tensor &Rt);
3254
3264 template <class T>
3265 Tensor operator==(const Tensor &Lt, const T &rc);
3266
3267} // namespace cytnx
3268
3269#endif // BACKEND_TORCH
3270
3271#endif // CYTNX_LINALG_H_
int32_t blas_int
Definition Type.hpp:27
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:2599
void Gemm_Batch(const std::vector< cytnx_int64 > &m_array, const std::vector< cytnx_int64 > &n_array, const std::vector< cytnx_int64 > &k_array, 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 cytnx_int64 group_count, 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...
cytnx::UniTensor Conj(const cytnx::UniTensor &UT)
Elementwise conjugate of the UniTensor.
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)
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....
void Pow_(UniTensor &Tin, const double &p)
Take power p on all the elements in UniTensor, inplacely.
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.
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.
Tensor Inv(const Tensor &Tin, const double &clip)
Element-wise inverse with clip.
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.
void Inv_(Tensor &Tin, const double &clip)
inplace perform Element-wise inverse with clip.
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.
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...
UniTensor Pow(const cytnx::UniTensor &Tin, const double &p)
take power p on all the elements in UniTensor.
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.
std::vector< cytnx::UniTensor > Rsvd_truncate(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 truncated Singular-Value decomposition of a UniTensor.
std::vector< cytnx::UniTensor > Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim, bool is_U=true, bool is_vT=true, cytnx_uint64 power_iteration=2, unsigned int seed=random::__static_random_device())
Perform randomized Singular-Value decomposition on a UniTensor using the ?gesvd method.
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.
Tensor Cpr(const Tensor &Lt, const Tensor &Rt)
The comparison function for Tensor.
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.