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#include <functional>
12#include <type_traits>
13
14#include "backend/Scalar.hpp"
15#include "backend/Storage.hpp"
16
17namespace cytnx {
18
19 // The scalar-like operand concepts (cytnx_scalar_value, cytnx_scalar_like,
20 // cytnx_unitensor_scalar_like) are defined in Tensor.hpp, which this header includes. They must
21 // be declared there because cytnx_scalar_like names Tensor::Tproxy, and because Tensor.hpp
22 // forward-declares the constrained `Tensor <op> T` operators -- those forward declarations have
23 // to carry the identical constraint or they form a distinct, unconstrained overload set
24 // (#1003, operator hygiene -- Ian's note).
25
51
61 template <cytnx_unitensor_scalar_like T>
63
73 template <cytnx_unitensor_scalar_like T>
75
90
100 template <cytnx_unitensor_scalar_like T>
102
112 template <cytnx_unitensor_scalar_like T>
114
129
139 template <cytnx_unitensor_scalar_like T>
141
151 template <cytnx_unitensor_scalar_like T>
153
168
178 template <cytnx_unitensor_scalar_like T>
180
190 template <cytnx_unitensor_scalar_like T>
192
204
214 template <cytnx_scalar_value T>
216
226 template <cytnx_scalar_value T>
228
239 namespace linalg {
240
241 // Add:
242 //==================================================
265
298 template <class T>
299 cytnx::UniTensor Add(const T &lc, const cytnx::UniTensor &Rt);
300
334 template <class T>
335 cytnx::UniTensor Add(const cytnx::UniTensor &Lt, const T &rc);
336
337 // Sub:
338 //==================================================
362
395 template <class T>
396 cytnx::UniTensor Sub(const T &lc, const cytnx::UniTensor &Rt);
397
430 template <class T>
431 cytnx::UniTensor Sub(const cytnx::UniTensor &Lt, const T &rc);
432
433 // Mul:
434 //==================================================
458
491 template <class T>
492 cytnx::UniTensor Mul(const T &lc, const cytnx::UniTensor &Rt);
493
526 template <class T>
527 cytnx::UniTensor Mul(const cytnx::UniTensor &Lt, const T &rc);
528
529 // Div:
530 //==================================================
554
588 template <class T>
589 cytnx::UniTensor Div(const T &lc, const cytnx::UniTensor &Rt);
590
624 template <class T>
625 cytnx::UniTensor Div(const cytnx::UniTensor &Lt, const T &rc);
626
627 // Mod:
628 //==================================================
654
685 template <class T>
686 cytnx::UniTensor Mod(const T &lc, const cytnx::UniTensor &Rt);
687
718 template <class T>
719 cytnx::UniTensor Mod(const cytnx::UniTensor &Lt, const T &rc);
720
728 std::vector<cytnx::UniTensor> Svd(const cytnx::UniTensor &Tin, const bool &is_UvT = true);
729
739 std::vector<cytnx::UniTensor> Gesvd(const cytnx::UniTensor &Tin, const bool &is_U = true,
740 const bool &is_vT = true);
741
753 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
754 const cytnx_uint64 &keepdim, const double &err = 0.,
755 const bool &is_UvT = true,
756 const unsigned int &return_err = 0,
757 const cytnx_uint64 &mindim = 1);
758
806 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
807 const cytnx_uint64 &keepdim,
808 std::vector<cytnx_uint64> min_blockdim,
809 const double &err = 0., const bool &is_UvT = true,
810 const unsigned int &return_err = 0,
811 const cytnx_uint64 &mindim = 1);
812
824 std::vector<cytnx::UniTensor> Gesvd_truncate(const cytnx::UniTensor &Tin,
825 const cytnx_uint64 &keepdim,
826 const double &err = 0., const bool &is_U = true,
827 const bool &is_vT = true,
828 const unsigned int &return_err = 0,
829 const cytnx_uint64 &mindim = 1);
830
842 std::vector<cytnx::UniTensor> Gesvd_truncate(
843 const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim,
844 std::vector<cytnx_uint64> min_blockdim, const double &err = 0., const bool &is_U = true,
845 const bool &is_vT = true, const unsigned int &return_err = 0, const cytnx_uint64 &mindim = 1);
846
847 // Rsvd:
848 //==================================================
898 std::vector<cytnx::UniTensor> Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim,
899 double err = 0., bool is_U = true, bool is_vT = true,
900 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
901 cytnx_uint64 oversampling_summand = 10,
902 double oversampling_factor = 1.,
903 cytnx_uint64 power_iteration = 0,
904 unsigned int seed = random::__static_random_device());
905
932 std::vector<cytnx::UniTensor> Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim,
933 const std::vector<cytnx_uint64> min_blockdim,
934 double err = 0., bool is_U = true, bool is_vT = true,
935 unsigned int return_err = 0, cytnx_uint64 mindim = 1,
936 cytnx_uint64 oversampling_summand = 10,
937 double oversampling_factor = 1.,
938 cytnx_uint64 power_iteration = 0,
939 unsigned int seed = random::__static_random_device());
940
941 std::vector<cytnx::UniTensor> Hosvd(
942 const cytnx::UniTensor &Tin, const std::vector<cytnx_uint64> &mode,
943 const bool &is_core = true, const bool &is_Ls = false,
944 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
945
954 template <typename T>
955 cytnx::UniTensor ExpH(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
956
964 template <typename T>
965 cytnx::UniTensor ExpM(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
966
976
985
994 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const cytnx_int64 &a = 0,
995 const cytnx_int64 &b = 1);
996
1003 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const std::string &a, const std::string &b);
1004
1013 std::vector<cytnx::UniTensor> Qr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
1014
1023 std::vector<cytnx::UniTensor> Qdr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
1024
1025 // Pow:
1026 //==================================================
1045 cytnx::UniTensor Pow(const cytnx::UniTensor &Tin, const double &p);
1046
1065 void Pow_(cytnx::UniTensor &Tin, const double &p);
1066
1067 // Inv:
1068 //==================================================
1095 cytnx::UniTensor Inv(const cytnx::UniTensor &Tin, double clip = -1.);
1096
1123 void Inv_(cytnx::UniTensor &Tin, double clip = -1.);
1124
1132
1139
1140 //====================================================================================
1141 // [Tensor]
1142 // ====================================================================================
1143 //====================================================================================
1144
1168 Tensor Add(const Tensor &Lt, const Tensor &Rt);
1169
1191 template <class T>
1192 Tensor Add(const T &lc, const Tensor &Rt);
1193
1215 template <class T>
1216 Tensor Add(const Tensor &Lt, const T &rc);
1217
1246 void iAdd(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar = false);
1247
1248 // Sub:
1249 //==================================================
1272 Tensor Sub(const Tensor &Lt, const Tensor &Rt);
1273
1295 template <class T>
1296 Tensor Sub(const T &lc, const Tensor &Rt);
1297
1319 template <class T>
1320 Tensor Sub(const Tensor &Lt, const T &rc);
1321
1350 void iSub(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar = false);
1351
1352 // Mul:
1353 //==================================================
1376 Tensor Mul(const Tensor &Lt, const Tensor &Rt);
1377
1399 template <class T>
1400 Tensor Mul(const T &lc, const Tensor &Rt);
1401
1423 template <class T>
1424 Tensor Mul(const Tensor &Lt, const T &rc);
1425
1454 void iMul(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar = false);
1455
1456 // Div:
1457 //==================================================
1481 Tensor Div(const Tensor &Lt, const Tensor &Rt);
1482
1505 template <class T>
1506 Tensor Div(const T &lc, const Tensor &Rt);
1507
1530 template <class T>
1531 Tensor Div(const Tensor &Lt, const T &rc);
1532
1561 void iDiv(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar = false);
1562
1563 // Mod:
1564 //==================================================
1565
1588 Tensor Mod(const Tensor &Lt, const Tensor &Rt);
1589
1610 template <class T>
1611 Tensor Mod(const T &lc, const Tensor &Rt);
1612
1633 template <class T>
1634 Tensor Mod(const Tensor &Lt, const T &rc);
1635
1636 // Cpr:
1637 //==================================================
1663 Tensor Cpr(const Tensor &Lt, const Tensor &Rt);
1664
1689 template <class T>
1690 Tensor Cpr(const T &lc, const Tensor &Rt);
1691
1716 template <class T>
1717 Tensor Cpr(const Tensor &Lt, const T &rc);
1718
1719 // Norm:
1720 //=================================================
1731 [[deprecated("use norm() (returns Scalar) instead")]] Tensor Norm(const Tensor &Tl);
1732
1733 // norm:
1734 //=================================================
1744 Scalar norm(const Tensor &Tl);
1745
1746 // Norm:
1747 //=================================================
1758 [[deprecated("use norm() (returns Scalar) instead")]] Tensor Norm(const cytnx::UniTensor &uTl);
1759
1760 // norm:
1761 //=================================================
1771 Scalar norm(const cytnx::UniTensor &uTl);
1772
1773 // Det:
1774 //=================================================
1783 Tensor Det(const Tensor &Tl);
1784
1785 // randomized isometries:
1786 //==================================================
1814 Tensor Rand_isometry(const Tensor &Tin, const cytnx_uint64 &keepdim,
1815 const cytnx_uint64 &power_iteration = 2,
1816 const unsigned int &seed = random::__static_random_device());
1817
1818 // Svd:
1819 //==================================================
1845 std::vector<Tensor> Svd(const Tensor &Tin, const bool &is_UvT = true);
1846
1847 // Gesvd:
1848 //==================================================
1876 std::vector<Tensor> Gesvd(const Tensor &Tin, const bool &is_U = true, const bool &is_vT = true);
1877
1878 // Svd_truncate:
1879 //==================================================
1924 std::vector<Tensor> Svd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1925 const double &err = 0., const bool &is_UvT = true,
1926 const unsigned int &return_err = 0,
1927 const cytnx_uint64 &mindim = 1);
1928
1929 // Rsvd:
1930 //==================================================
1977 std::vector<Tensor> Rsvd(const Tensor &Tin, cytnx_uint64 keepdim, double err = 0.,
1978 bool is_U = true, bool is_vT = true, unsigned int return_err = 0,
1979 cytnx_uint64 mindim = 1, cytnx_uint64 oversampling_summand = 10,
1980 double oversampling_factor = 1., cytnx_uint64 power_iteration = 0,
1981 unsigned int seed = random::__static_random_device());
1982 // Gesvd_truncate:
1983 //==================================================
2012 std::vector<Tensor> Gesvd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
2013 const double &err = 0., const bool &is_U = true,
2014 const bool &is_vT = true, const unsigned int &return_err = 0,
2015 const cytnx_uint64 &mindim = 1);
2016
2017 // Hosvd:
2018 std::vector<Tensor> Hosvd(
2019 const Tensor &Tin, const std::vector<cytnx_uint64> &mode, const bool &is_core = true,
2020 const bool &is_Ls = false,
2021 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
2022
2023 // Qr:
2024 //==================================================
2050 std::vector<Tensor> Qr(const Tensor &Tin, const bool &is_tau = false);
2051
2052 // Qdr:
2053 //==================================================
2073 std::vector<Tensor> Qdr(const Tensor &Tin, const bool &is_tau = false);
2074
2075 // Eigh:
2076 //==================================================
2099 std::vector<Tensor> Eigh(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
2100
2101 std::vector<UniTensor> Eigh(const cytnx::UniTensor &Tin, const bool &is_V = true,
2102 const bool &row_v = false);
2103
2104 // Eig:
2105 //==================================================
2129 std::vector<Tensor> Eig(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
2130
2131 std::vector<UniTensor> Eig(const cytnx::UniTensor &Tin, const bool &is_V = true,
2132 const bool &row_v = false);
2133
2134 // Trace:
2135 //==================================================
2149 Tensor Trace(const Tensor &Tn, const cytnx_uint64 &axisA = 0, const cytnx_uint64 &axisB = 1);
2150
2151 // Min:
2152 //==================================================
2158 Tensor Min(const Tensor &Tn);
2159
2160 // Max:
2161 //==================================================
2167 Tensor Max(const Tensor &Tn);
2168
2169 // Sum:
2170 //==================================================
2175 Tensor Sum(const Tensor &Tn);
2176
2177 // Matmul:
2178 //==================================================
2190 Tensor Matmul(const Tensor &TL, const Tensor &TR);
2191
2192 // Matmul_dg:
2193 //==================================================
2200 Tensor Matmul_dg(const Tensor &Tl, const Tensor &Tr);
2201
2202 // InvM:
2203 //==================================================
2210 Tensor InvM(const Tensor &Tin);
2219 void InvM_(Tensor &Tin);
2220 void InvM_(UniTensor &Tin);
2221
2222 // Inv:
2223 //==================================================
2248 Tensor Inv(const Tensor &Tin, const double &clip = -1.);
2249
2274 void Inv_(Tensor &Tin, const double &clip = -1.);
2275
2276 // Conj:
2277 //==================================================
2292 Tensor Conj(const Tensor &Tin);
2293
2302 void Conj_(Tensor &Tin);
2303
2304 // Exp:
2305 //==================================================
2319 Tensor Exp(const Tensor &Tin);
2320
2331 [[deprecated("use Exp() (dtype-preserving) instead")]] Tensor Expf(const Tensor &Tin);
2332
2343 void Exp_(Tensor &Tin);
2344
2353 [[deprecated("use Exp_() (dtype-preserving) instead")]] void Expf_(Tensor &Tin);
2354
2355 // Pow:
2356 //==================================================
2369 Tensor Pow(const Tensor &Tin, const double &p);
2370
2384 void Pow_(Tensor &Tin, const double &p);
2385
2386 // Abs:
2387 //==================================================
2395 Tensor Abs(const Tensor &Tin);
2396
2404 void Abs_(Tensor &Tin);
2405
2406 // Diag:
2407 //==================================================
2416 Tensor Diag(const Tensor &Tin);
2417
2418 // Tensordot:
2419 //==================================================
2435 Tensor Tensordot(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2436 const std::vector<cytnx_uint64> &idxr, const bool &cacheL = false,
2437 const bool &cacheR = false);
2438
2439 // Tensordot_dg:
2440 //==================================================
2458 Tensor Tensordot_dg(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2459 const std::vector<cytnx_uint64> &idxr, const bool &diag_L);
2460
2461 // Outer:
2462 //==================================================
2473 Tensor Outer(const Tensor &Tl, const Tensor &Tr);
2474
2475 // Kron:
2476 //==================================================
2493 Tensor Kron(const Tensor &lhs, const Tensor &rhs, bool lhs_pad_left = false,
2494 bool rhs_pad_left = false);
2495
2496 // Directsum:
2497 //==================================================
2512 Tensor Directsum(const Tensor &T1, const Tensor &T2,
2513 const std::vector<cytnx_uint64> &shared_axes);
2514
2515 // VectorDot:
2516 //=================================================
2528 Tensor Vectordot(const Tensor &Tl, const Tensor &Tr, const bool &is_conj = false);
2529
2530 // Dot:
2531 //=================================================
2551 Tensor Dot(const Tensor &Tl, const Tensor &Tr);
2552
2553 // Tridiag:
2554 //===========================================
2575 std::vector<Tensor> Tridiag(const Tensor &Diag, const Tensor &Sub_diag, const bool &is_V = true,
2576 const bool &is_row = false, bool throw_excp = false);
2577
2578 // ExpH:
2579 //===========================================
2597 template <typename T>
2598 Tensor ExpH(const Tensor &in, const T &a, const T &b = 0);
2611 Tensor ExpH(const Tensor &in);
2612
2613 // ExpM:
2614 //===========================================
2627 template <typename T>
2628 Tensor ExpM(const Tensor &in, const T &a, const T &b = 0);
2629
2640 Tensor ExpM(const Tensor &in);
2641
2642 // Arnoldi:
2643 //===========================================
2689 std::vector<Tensor> Arnoldi(LinOp *Hop, const Tensor &Tin = Tensor(),
2690 const std::string which = "LM", const cytnx_uint64 &maxiter = 10000,
2691 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2692 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2693 const bool &verbose = false);
2694
2695 // Arnoldi:
2696 //===========================================
2750 std::vector<UniTensor> Arnoldi(LinOp *Hop, const cytnx::UniTensor &Tin,
2751 const std::string which = "LM",
2752 const cytnx_uint64 &maxiter = 10000,
2753 const cytnx_double &cvg_crit = 1.0e-9, const cytnx_uint64 &k = 1,
2754 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2755 const bool &verbose = false);
2756
2757 // Lanczos:
2758 //===========================================
2789 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2790 const std::string method = "Gnd", const double &CvgCrit = 1.0e-14,
2791 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2792 const bool &is_V = true, const bool &is_row = false,
2793 const cytnx_uint32 &max_krydim = 0, const bool &verbose = false);
2834 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2835 const std::string which = "SA", const cytnx_uint64 &maxiter = 10000,
2836 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2837 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2838 const bool &verbose = false);
2886 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin,
2887 const std::string which = "SA",
2888 const cytnx_uint64 &maxiter = 10000,
2889 const cytnx_double &cvg_crit = 0, const cytnx_uint64 &k = 1,
2890 const bool &is_V = true, const cytnx_int32 &ncv = 0,
2891 const bool &verbose = false);
2892
2893 // Lanczos:
2894 //===========================================
2928 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin = UniTensor(),
2929 const std::string method = "Gnd",
2930 const double &CvgCrit = 1.0e-14,
2931 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2932 const bool &is_V = true, const bool &is_row = false,
2933 const cytnx_uint32 &max_krydim = 4, const bool &verbose = false);
2934
2935 // Lanczos:
2936 //===========================================
2958 std::vector<Tensor> Lanczos_ER(LinOp *Hop, const cytnx_uint64 &k = 1, const bool &is_V = true,
2959 const cytnx_uint64 &maxiter = 10000,
2960 const double &CvgCrit = 1.0e-14, const bool &is_row = false,
2961 const Tensor &Tin = Tensor(), const cytnx_uint32 &max_krydim = 4,
2962 const bool &verbose = false);
2963
2964 // Lanczos:
2965 //===========================================
2984 std::vector<Tensor> Lanczos_Gnd(LinOp *Hop, const double &CvgCrit = 1.0e-14,
2985 const bool &is_V = true, const Tensor &Tin = Tensor(),
2986 const bool &verbose = false,
2987 const unsigned int &Maxiter = 100000);
2988
2989 // Lanczos:
2990 //===============================================
3009 std::vector<UniTensor> Lanczos_Gnd_Ut(LinOp *Hop, const cytnx::UniTensor &Tin,
3010 const double &CvgCrit = 1.0e-14, const bool &is_V = true,
3011 const bool &verbose = false,
3012 const unsigned int &Maxiter = 100000);
3013
3014 // Lanczos_Exp:
3015 //===============================================
3046 UniTensor Lanczos_Exp(LinOp *Hop, const cytnx::UniTensor &v, const Scalar &tau,
3047 const double &CvgCrit = 1.0e-10, const unsigned int &Maxiter = 100000,
3048 const bool &verbose = false);
3049
3050 // Lstsq:
3051 //===========================================
3077 std::vector<Tensor> Lstsq(const Tensor &A, const Tensor &b, const float &rcond = -1);
3078
3093 Tensor Ger(const Tensor &x, const Tensor &y, const Scalar &a = Scalar());
3094
3112 void Gemm_(const Scalar &a, const Tensor &x, const Tensor &y, const Scalar &b, Tensor &c);
3113
3129 Tensor Gemm(const Scalar &a, const Tensor &x, const Tensor &y);
3130
3156 void Gemm_Batch(const std::vector<Scalar> &alpha_array, const std::vector<Tensor> &a_tensors,
3157 const std::vector<Tensor> &b_tensors, const std::vector<Scalar> &beta_array,
3158 std::vector<Tensor> &c_tensors, const std::vector<cytnx_int64> &group_size);
3159
3160 } // namespace linalg
3161
3162 // operators:
3173 Tensor operator+(const Tensor &Lt, const Tensor &Rt);
3174
3184 template <cytnx_scalar_like T>
3185 Tensor operator+(const T &lc, const Tensor &Rt);
3186
3196 template <cytnx_scalar_like T>
3197 Tensor operator+(const Tensor &Lt, const T &rc);
3198
3199 //------------------------------------
3210 Tensor operator-(const Tensor &Lt, const Tensor &Rt);
3211
3221 template <cytnx_scalar_like T>
3222 Tensor operator-(const T &lc, const Tensor &Rt);
3223
3233 template <cytnx_scalar_like T>
3234 Tensor operator-(const Tensor &Lt, const T &rc);
3235
3236 //-----------------------------------
3247 Tensor operator*(const Tensor &Lt, const Tensor &Rt);
3248
3258 template <cytnx_scalar_like T>
3259 Tensor operator*(const T &lc, const Tensor &Rt);
3260
3270 template <cytnx_scalar_like T>
3271 Tensor operator*(const Tensor &Lt, const T &rc);
3272
3273 //----------------------------------
3286 Tensor operator/(const Tensor &Lt, const Tensor &Rt);
3287
3298 template <cytnx_scalar_like T>
3299 Tensor operator/(const T &lc, const Tensor &Rt);
3300
3311 template <cytnx_scalar_like T>
3312 Tensor operator/(const Tensor &Lt, const T &rc);
3313
3314 //----------------------------------
3325 Tensor operator%(const Tensor &Lt, const Tensor &Rt);
3326
3336 template <cytnx_scalar_value T>
3337 Tensor operator%(const T &lc, const Tensor &Rt);
3338
3348 template <cytnx_scalar_value T>
3349 Tensor operator%(const Tensor &Lt, const T &rc);
3350
3351 //----------------------------------
3361 Tensor operator==(const Tensor &Lt, const Tensor &Rt);
3362
3372 template <cytnx_scalar_value T>
3373 Tensor operator==(const T &lc, const Tensor &Rt);
3374
3384 template <cytnx_scalar_value T>
3385 Tensor operator==(const Tensor &Lt, const T &rc);
3386
3387} // namespace cytnx
3388
3389#endif // CYTNX_LINALG_H_
Definition LinOp.hpp:18
an tensor (multi-dimensional array)
Definition Tensor.hpp:33
An Enhanced tensor specifically designed for physical Tensor network simulation.
Definition UniTensor.hpp:2773
cytnx::UniTensor Conj(const cytnx::UniTensor &UT)
Elementwise conjugate of the UniTensor.
cytnx::UniTensor Inv(const cytnx::UniTensor &Tin, double clip=-1.)
Element-wise (pseudo-)inverse.
std::vector< cytnx::UniTensor > Qr(const cytnx::UniTensor &Tin, const bool &is_tau=false)
Perform the QR decomposition on a UniTensor.
Tensor Dot(const Tensor &Tl, const Tensor &Tr)
dot product of two arrays.
cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const cytnx_int64 &a=0, const cytnx_int64 &b=1)
Perform the trace over two legs of a UniTensor.
Tensor Tensordot(const Tensor &Tl, const Tensor &Tr, const std::vector< cytnx_uint64 > &idxl, const std::vector< cytnx_uint64 > &idxr, const bool &cacheL=false, const bool &cacheR=false)
perform tensor dot by sum out the indices assigned of two Tensors.
std::vector< Tensor > Eig(const Tensor &Tin, const bool &is_V=true, const bool &row_v=false)
eigen-value decomposition for generic square matrix
Tensor Sum(const Tensor &Tn)
get the sum of all the elements.
Tensor Min(const Tensor &Tn)
get the minimum element.
void Gemm_(const Scalar &a, const Tensor &x, const Tensor &y, const Scalar &b, Tensor &c)
Blas Gemm, performing , inplacely.
void Abs_(Tensor &Tin)
inplace perform elementwiase absolute value. @This is just a inplace version of Abs....
Tensor Abs(const Tensor &Tin)
Elementwise absolute value.
Tensor Outer(const Tensor &Tl, const Tensor &Tr)
perform outer produces of two rank-1 Tensor.
std::vector< cytnx::UniTensor > Svd(const cytnx::UniTensor &Tin, const bool &is_UvT=true)
Perform Singular-Value decomposition on a UniTensor using divide-and-conquer method.
Tensor Matmul(const Tensor &TL, const Tensor &TR)
perform matrix multiplication on two tensors.
cytnx::UniTensor Mod(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
element-wise modulo
Tensor Expf(const Tensor &Tin)
Exponential all the element in Tensor (deprecated).
Tensor Diag(const Tensor &Tin)
return a diagonal tensor with diagonal elements provided as Tin.
std::vector< Tensor > Lstsq(const Tensor &A, const Tensor &b, const float &rcond=-1)
Return the least-squares solution to a linear matrix equation.
std::vector< Tensor > Tridiag(const Tensor &Diag, const Tensor &Sub_diag, const bool &is_V=true, const bool &is_row=false, bool throw_excp=false)
perform diagonalization of symmetric tri-diagnoal matrix.
void Expf_(Tensor &Tin)
inplace perform Exponential on all the element in Tensor (deprecated).
Tensor Det(const Tensor &Tl)
Calculate the determinant of a tensor.
std::vector< Tensor > Eigh(const Tensor &Tin, const bool &is_V=true, const bool &row_v=false)
eigen-value decomposition for Hermitian matrix
std::vector< cytnx::UniTensor > Gesvd_truncate(const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim, const double &err=0., const bool &is_U=true, const bool &is_vT=true, const unsigned int &return_err=0, const cytnx_uint64 &mindim=1)
Perform Singular-Value decomposition on a UniTensor with truncation.
void Gemm_Batch(const std::vector< Scalar > &alpha_array, const std::vector< Tensor > &a_tensors, const std::vector< Tensor > &b_tensors, const std::vector< Scalar > &beta_array, std::vector< Tensor > &c_tensors, const std::vector< cytnx_int64 > &group_size)
Blas Gemm_Batch, performing many(batch) , inplacely. You do not need to consider the row-major or col...
UniTensor Lanczos_Exp(LinOp *Hop, const cytnx::UniTensor &v, const Scalar &tau, const double &CvgCrit=1.0e-10, const unsigned int &Maxiter=100000, const bool &verbose=false)
Perform the Lanczos algorithm for hermitian operator to approximate .
void Conj_(cytnx::UniTensor &UT)
Inplace elementwise conjugate of the UniTensor.
std::vector< cytnx::UniTensor > Gesvd(const cytnx::UniTensor &Tin, const bool &is_U=true, const bool &is_vT=true)
Perform Singular-Value decomposition on a UniTensor using ?gesvd method.
cytnx::UniTensor Pow(const cytnx::UniTensor &Tin, const double &p)
Take the power p of all elements in a UniTensor.
cytnx::UniTensor Mul(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The multiplication function between two UniTensor.
std::vector< Tensor > Lanczos(LinOp *Hop, const Tensor &Tin=Tensor(), const std::string method="Gnd", const double &CvgCrit=1.0e-14, const unsigned int &Maxiter=10000, const cytnx_uint64 &k=1, const bool &is_V=true, const bool &is_row=false, const cytnx_uint32 &max_krydim=0, const bool &verbose=false)
perform Lanczos for hermitian/symmetric matrices or linear function.
Tensor Max(const Tensor &Tn)
get the maximum element.
cytnx::UniTensor Sub(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The subtraction function between two UniTensor.
Tensor Norm(const Tensor &Tl)
Calculate the norm of a tensor.
Tensor Rand_isometry(const Tensor &Tin, const cytnx_uint64 &keepdim, const cytnx_uint64 &power_iteration=2, const unsigned int &seed=random::__static_random_device())
Generate an isometrized left isometry for a rank-2 Tensor (a matrix), such that Q * Qdag * Tin approx...
std::vector< cytnx::UniTensor > Hosvd(const cytnx::UniTensor &Tin, const std::vector< cytnx_uint64 > &mode, const bool &is_core=true, const bool &is_Ls=false, const std::vector< cytnx_int64 > &trucate_dim=std::vector< cytnx_int64 >())
Tensor Vectordot(const Tensor &Tl, const Tensor &Tr, const bool &is_conj=false)
perform inner product of vectors
void iDiv(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar=false)
The inplace division function for Tensor, inplacely.
void Exp_(Tensor &Tin)
inplace perform Exponential on all the element in Tensor.
std::vector< cytnx::UniTensor > Svd_truncate(const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim, const double &err=0., const bool &is_UvT=true, const unsigned int &return_err=0, const cytnx_uint64 &mindim=1)
Perform Singular-Value decomposition on a UniTensor with truncation.
Tensor Exp(const Tensor &Tin)
Exponential all the element in Tensor.
Tensor Ger(const Tensor &x, const Tensor &y, const Scalar &a=Scalar())
Blas Ger, performing return = a*vec(x)*vec(y)^T.
void Pow_(cytnx::UniTensor &Tin, const double &p)
Take the power p of all elements in a UniTensor, inplacely.
Tensor Gemm(const Scalar &a, const Tensor &x, const Tensor &y)
Blas Gemm, performing return.
Scalar norm(const Tensor &Tl)
Calculate the norm of a tensor.
void iAdd(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar=false)
The addition function for Tensor, inplacely.
std::vector< Tensor > Lanczos_ER(LinOp *Hop, const cytnx_uint64 &k=1, const bool &is_V=true, const cytnx_uint64 &maxiter=10000, const double &CvgCrit=1.0e-14, const bool &is_row=false, const Tensor &Tin=Tensor(), const cytnx_uint32 &max_krydim=4, const bool &verbose=false)
perform Lanczos for hermitian/symmetric matrices or linear function.
std::vector< UniTensor > Lanczos_Gnd_Ut(LinOp *Hop, const cytnx::UniTensor &Tin, const double &CvgCrit=1.0e-14, const bool &is_V=true, const bool &verbose=false, const unsigned int &Maxiter=100000)
perform Lanczos for hermitian/symmetric matrices or linear function to get ground state and lowest ei...
std::vector< cytnx::UniTensor > Qdr(const cytnx::UniTensor &Tin, const bool &is_tau=false)
Perform the QDR decomposition on a UniTensor.
void InvM_(Tensor &Tin)
inplace matrix inverse.
cytnx::UniTensor Add(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The addition function between two UniTensor.
Tensor Tensordot_dg(const Tensor &Tl, const Tensor &Tr, const std::vector< cytnx_uint64 > &idxl, const std::vector< cytnx_uint64 > &idxr, const bool &diag_L)
perform tensor dot by sum out the indices assigned of two Tensors, with either one of them to be a ra...
Tensor Directsum(const Tensor &T1, const Tensor &T2, const std::vector< cytnx_uint64 > &shared_axes)
perform directsum of two Tensor.
void iSub(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar=false)
The subtraction function for Tensot, inplscely.
cytnx::UniTensor ExpM(const cytnx::UniTensor &Tin, const T &a, const T &b=0)
Perform the exponential function on a UniTensor.
void iMul(Tensor &Lt, const Tensor &Rt, bool rhs_is_weak_scalar=false)
The multiplication function for Tensor, inplacely.
std::vector< Tensor > Arnoldi(LinOp *Hop, const Tensor &Tin=Tensor(), const std::string which="LM", const cytnx_uint64 &maxiter=10000, const cytnx_double &cvg_crit=0, const cytnx_uint64 &k=1, const bool &is_V=true, const cytnx_int32 &ncv=0, const bool &verbose=false)
Performs Arnoldi iteration for matrices or linear functions.
std::vector< Tensor > Lanczos_Gnd(LinOp *Hop, const double &CvgCrit=1.0e-14, const bool &is_V=true, const Tensor &Tin=Tensor(), const bool &verbose=false, const unsigned int &Maxiter=100000)
perform Lanczos for hermitian/symmetric matrices or linear function to get ground state and lowest ei...
cytnx::UniTensor ExpH(const cytnx::UniTensor &Tin, const T &a, const T &b=0)
Perform the exponential function on a UniTensor, which the blocks are Hermitian matrix.
std::vector< cytnx::UniTensor > Rsvd(const cytnx::UniTensor &Tin, cytnx_uint64 keepdim, double err=0., bool is_U=true, bool is_vT=true, unsigned int return_err=0, cytnx_uint64 mindim=1, cytnx_uint64 oversampling_summand=10, double oversampling_factor=1., cytnx_uint64 power_iteration=0, unsigned int seed=random::__static_random_device())
Perform a randomized truncated Singular-Value decomposition of a UniTensor.
Tensor Cpr(const Tensor &Lt, const Tensor &Rt)
The comparison function for Tensor.
Tensor Kron(const Tensor &lhs, const Tensor &rhs, bool lhs_pad_left=false, bool rhs_pad_left=false)
perform kronecker produces of two Tensor.
void Inv_(cytnx::UniTensor &Tin, double clip=-1.)
Element-wise (pseudo-)inverse, inplacely.
Tensor Matmul_dg(const Tensor &Tl, const Tensor &Tr)
perform matrix multiplication on two Tensors with one rank-1 and the other rank-2 where the rank-1 re...
Tensor InvM(const Tensor &Tin)
Matrix inverse.
cytnx::UniTensor Div(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The division function between two UniTensor.
std::random_device __static_random_device
Definition UniTensor.hpp:27
Definition Accessor.hpp:12
cytnx::UniTensor operator*(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The multiplication operator between two UniTensor.
cytnx::UniTensor operator-(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The subtraction operator between two UniTensor.
Tensor operator==(const Tensor &Lt, const Tensor &Rt)
The comparison operator for Tensor.
cytnx::UniTensor operator%(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The modulo operator between two UniTensor.
cytnx::UniTensor operator+(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The addition operator between two UniTensor.
cytnx::UniTensor operator/(const cytnx::UniTensor &Lt, const cytnx::UniTensor &Rt)
The division operator between two UniTensor.