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
10#ifdef BACKEND_TORCH
11#else
12
13 #include <functional>
14
15 #include "backend/Scalar.hpp"
16 #include "backend/Storage.hpp"
17
18namespace cytnx {
21
33
43 template <class T>
45
55 template <class T>
57
69
79 template <class T>
81
91 template <class T>
93
105
115 template <class T>
117
127 template <class T>
129
141
151 template <class T>
153
163 template <class T>
165
177
187 template <class T>
189
199 template <class T>
201
212 namespace linalg {
213
214 // Add:
215 //==================================================
238
271 template <class T>
272 cytnx::UniTensor Add(const T &lc, const cytnx::UniTensor &Rt);
273
307 template <class T>
308 cytnx::UniTensor Add(const cytnx::UniTensor &Lt, const T &rc);
309
310 // Sub:
311 //==================================================
335
368 template <class T>
369 cytnx::UniTensor Sub(const T &lc, const cytnx::UniTensor &Rt);
370
403 template <class T>
404 cytnx::UniTensor Sub(const cytnx::UniTensor &Lt, const T &rc);
405
406 // Mul:
407 //==================================================
431
464 template <class T>
465 cytnx::UniTensor Mul(const T &lc, const cytnx::UniTensor &Rt);
466
499 template <class T>
500 cytnx::UniTensor Mul(const cytnx::UniTensor &Lt, const T &rc);
501
502 // Div:
503 //==================================================
527
561 template <class T>
562 cytnx::UniTensor Div(const T &lc, const cytnx::UniTensor &Rt);
563
597 template <class T>
598 cytnx::UniTensor Div(const cytnx::UniTensor &Lt, const T &rc);
599
600 // Mod:
601 //==================================================
627
658 template <class T>
659 cytnx::UniTensor Mod(const T &lc, const cytnx::UniTensor &Rt);
660
691 template <class T>
692 cytnx::UniTensor Mod(const cytnx::UniTensor &Lt, const T &rc);
693
701 std::vector<cytnx::UniTensor> Svd(const cytnx::UniTensor &Tin, const bool &is_UvT = true);
702
712 std::vector<cytnx::UniTensor> Gesvd(const cytnx::UniTensor &Tin, const bool &is_U = true,
713 const bool &is_vT = true);
714
726 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
727 const cytnx_uint64 &keepdim, const double &err = 0.,
728 const bool &is_UvT = true,
729 const unsigned int &return_err = 0,
730 const cytnx_uint64 &mindim = 1);
731
779 std::vector<cytnx::UniTensor> Svd_truncate(const cytnx::UniTensor &Tin,
780 const cytnx_uint64 &keepdim,
781 std::vector<cytnx_uint64> min_blockdim,
782 const double &err = 0., const bool &is_UvT = true,
783 const unsigned int &return_err = 0,
784 const cytnx_uint64 &mindim = 1);
785
797 std::vector<cytnx::UniTensor> Gesvd_truncate(const cytnx::UniTensor &Tin,
798 const cytnx_uint64 &keepdim,
799 const double &err = 0., const bool &is_U = true,
800 const bool &is_vT = true,
801 const unsigned int &return_err = 0,
802 const cytnx_uint64 &mindim = 1);
803
815 std::vector<cytnx::UniTensor> Gesvd_truncate(
816 const cytnx::UniTensor &Tin, const cytnx_uint64 &keepdim,
817 std::vector<cytnx_uint64> min_blockdim, const double &err = 0., const bool &is_U = true,
818 const bool &is_vT = true, const unsigned int &return_err = 0, const cytnx_uint64 &mindim = 1);
819
820 std::vector<cytnx::UniTensor> Hosvd(
821 const cytnx::UniTensor &Tin, const std::vector<cytnx_uint64> &mode,
822 const bool &is_core = true, const bool &is_Ls = false,
823 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
824
833 template <typename T>
834 cytnx::UniTensor ExpH(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
835
843 template <typename T>
844 cytnx::UniTensor ExpM(const cytnx::UniTensor &Tin, const T &a, const T &b = 0);
845
855
864
869 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const cytnx_int64 &a = 0,
870 const cytnx_int64 &b = 1);
871
879 cytnx::UniTensor Trace(const cytnx::UniTensor &Tin, const std::string &a, const std::string &b);
880
889 std::vector<cytnx::UniTensor> Qr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
890
899 std::vector<cytnx::UniTensor> Qdr(const cytnx::UniTensor &Tin, const bool &is_tau = false);
900
901 // Pow:
902 //==================================================
915 UniTensor Pow(const cytnx::UniTensor &Tin, const double &p);
916
928 void Pow_(UniTensor &Tin, const double &p);
929
937
944
945 //====================================================================================
946 // [Tensor]
947 // ====================================================================================
948 //====================================================================================
949
973 Tensor Add(const Tensor &Lt, const Tensor &Rt);
974
996 template <class T>
997 Tensor Add(const T &lc, const Tensor &Rt);
998
1020 template <class T>
1021 Tensor Add(const Tensor &Lt, const T &rc);
1022
1047 void iAdd(Tensor &Lt, const Tensor &Rt);
1048
1049 // Sub:
1050 //==================================================
1073 Tensor Sub(const Tensor &Lt, const Tensor &Rt);
1074
1096 template <class T>
1097 Tensor Sub(const T &lc, const Tensor &Rt);
1098
1120 template <class T>
1121 Tensor Sub(const Tensor &Lt, const T &rc);
1122
1147 void iSub(Tensor &Lt, const Tensor &Rt);
1148
1149 // Mul:
1150 //==================================================
1173 Tensor Mul(const Tensor &Lt, const Tensor &Rt);
1174
1196 template <class T>
1197 Tensor Mul(const T &lc, const Tensor &Rt);
1198
1220 template <class T>
1221 Tensor Mul(const Tensor &Lt, const T &rc);
1222
1247 void iMul(Tensor &Lt, const Tensor &Rt);
1248
1249 // Div:
1250 //==================================================
1274 Tensor Div(const Tensor &Lt, const Tensor &Rt);
1275
1298 template <class T>
1299 Tensor Div(const T &lc, const Tensor &Rt);
1300
1323 template <class T>
1324 Tensor Div(const Tensor &Lt, const T &rc);
1325
1350 void iDiv(Tensor &Lt, const Tensor &Rt);
1351
1352 // Mod:
1353 //==================================================
1354
1377 Tensor Mod(const Tensor &Lt, const Tensor &Rt);
1378
1399 template <class T>
1400 Tensor Mod(const T &lc, const Tensor &Rt);
1401
1422 template <class T>
1423 Tensor Mod(const Tensor &Lt, const T &rc);
1424
1425 // Cpr:
1426 //==================================================
1452 Tensor Cpr(const Tensor &Lt, const Tensor &Rt);
1453
1478 template <class T>
1479 Tensor Cpr(const T &lc, const Tensor &Rt);
1480
1505 template <class T>
1506 Tensor Cpr(const Tensor &Lt, const T &rc);
1507
1508 // Norm:
1509 //=================================================
1519 Tensor Norm(const Tensor &Tl);
1520
1521 // Norm:
1522 //=================================================
1533
1534 // Det:
1535 //=================================================
1544 Tensor Det(const Tensor &Tl);
1545
1546 // Svd:
1547 //==================================================
1573 std::vector<Tensor> Svd(const Tensor &Tin, const bool &is_UvT = true);
1574
1575 // Gesvd:
1576 //==================================================
1604 std::vector<Tensor> Gesvd(const Tensor &Tin, const bool &is_U = true, const bool &is_vT = true);
1605
1606 // Svd_truncate:
1607 //==================================================
1652 std::vector<Tensor> Svd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1653 const double &err = 0., const bool &is_UvT = true,
1654 const unsigned int &return_err = 0,
1655 const cytnx_uint64 &mindim = 1);
1656
1657 // Gesvd_truncate:
1658 //==================================================
1700 std::vector<Tensor> Gesvd_truncate(const Tensor &Tin, const cytnx_uint64 &keepdim,
1701 const double &err = 0., const bool &is_U = true,
1702 const bool &is_vT = true, const unsigned int &return_err = 0,
1703 const cytnx_uint64 &mindim = 1);
1704
1705 // Hosvd:
1706 std::vector<Tensor> Hosvd(
1707 const Tensor &Tin, const std::vector<cytnx_uint64> &mode, const bool &is_core = true,
1708 const bool &is_Ls = false,
1709 const std::vector<cytnx_int64> &trucate_dim = std::vector<cytnx_int64>());
1710
1711 // Qr:
1712 //==================================================
1738 std::vector<Tensor> Qr(const Tensor &Tin, const bool &is_tau = false);
1739
1740 // Qdr:
1741 //==================================================
1761 std::vector<Tensor> Qdr(const Tensor &Tin, const bool &is_tau = false);
1762
1763 // Eigh:
1764 //==================================================
1787 std::vector<Tensor> Eigh(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
1788
1789 std::vector<UniTensor> Eigh(const cytnx::UniTensor &Tin, const bool &is_V = true,
1790 const bool &row_v = false);
1791
1792 // Eig:
1793 //==================================================
1813 std::vector<Tensor> Eig(const Tensor &Tin, const bool &is_V = true, const bool &row_v = false);
1814
1815 std::vector<UniTensor> Eig(const cytnx::UniTensor &Tin, const bool &is_V = true,
1816 const bool &row_v = false);
1817
1818 // Trace:
1819 //==================================================
1833 Tensor Trace(const Tensor &Tn, const cytnx_uint64 &axisA = 0, const cytnx_uint64 &axisB = 1);
1834
1835 // Min:
1836 //==================================================
1842 Tensor Min(const Tensor &Tn);
1843
1844 // Max:
1845 //==================================================
1851 Tensor Max(const Tensor &Tn);
1852
1853 // Sum:
1854 //==================================================
1859 Tensor Sum(const Tensor &Tn);
1860
1861 // Matmul:
1862 //==================================================
1874 Tensor Matmul(const Tensor &TL, const Tensor &TR);
1875
1876 // Matmul_dg:
1877 //==================================================
1884 Tensor Matmul_dg(const Tensor &Tl, const Tensor &Tr);
1885
1886 // InvM:
1887 //==================================================
1894 Tensor InvM(const Tensor &Tin);
1903 void InvM_(Tensor &Tin);
1904 void InvM_(UniTensor &Tin);
1905 // Inv:
1906 //==================================================
1925 Tensor Inv(const Tensor &Tin, const double &clip);
1926
1939 void Inv_(Tensor &Tin, const double &clip);
1940
1941 // Conj:
1942 //==================================================
1957 Tensor Conj(const Tensor &Tin);
1958
1967 void Conj_(Tensor &Tin);
1968
1969 // Exp:
1970 //==================================================
1984 Tensor Exp(const Tensor &Tin);
1985
1999 Tensor Expf(const Tensor &Tin);
2000
2010 void Exp_(Tensor &Tin);
2011
2021 void Expf_(Tensor &Tin);
2022
2023 // Pow:
2024 //==================================================
2036 Tensor Pow(const Tensor &Tin, const double &p);
2037
2044 void Pow_(Tensor &Tin, const double &p);
2045
2046 // Abs:
2047 //==================================================
2055 Tensor Abs(const Tensor &Tin);
2056
2064 void Abs_(Tensor &Tin);
2065
2066 // Diag:
2067 //==================================================
2076 Tensor Diag(const Tensor &Tin);
2077
2078 // Tensordot:
2079 //==================================================
2095 Tensor Tensordot(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2096 const std::vector<cytnx_uint64> &idxr, const bool &cacheL = false,
2097 const bool &cacheR = false);
2098
2099 // Tensordot_dg:
2100 //==================================================
2118 Tensor Tensordot_dg(const Tensor &Tl, const Tensor &Tr, const std::vector<cytnx_uint64> &idxl,
2119 const std::vector<cytnx_uint64> &idxr, const bool &diag_L);
2120
2121 // Outer:
2122 //==================================================
2133 Tensor Outer(const Tensor &Tl, const Tensor &Tr);
2134
2135 // Kron:
2136 //==================================================
2153 Tensor Kron(const Tensor &Tl, const Tensor &Tr, const bool &Tl_pad_left = false,
2154 const bool &Tr_pad_left = false);
2155
2156 // Directsum:
2157 //==================================================
2172 Tensor Directsum(const Tensor &T1, const Tensor &T2,
2173 const std::vector<cytnx_uint64> &shared_axes);
2174
2175 // VectorDot:
2176 //=================================================
2188 Tensor Vectordot(const Tensor &Tl, const Tensor &Tr, const bool &is_conj = false);
2189
2190 // Dot:
2191 //=================================================
2211 Tensor Dot(const Tensor &Tl, const Tensor &Tr);
2212
2213 // Tridiag:
2214 //===========================================
2235 std::vector<Tensor> Tridiag(const Tensor &Diag, const Tensor &Sub_diag, const bool &is_V = true,
2236 const bool &is_row = false, bool throw_excp = false);
2237
2238 // ExpH:
2239 //===========================================
2257 template <typename T>
2258 Tensor ExpH(const Tensor &in, const T &a, const T &b = 0);
2271 Tensor ExpH(const Tensor &in);
2272
2273 // ExpM:
2274 //===========================================
2287 template <typename T>
2288 Tensor ExpM(const Tensor &in, const T &a, const T &b = 0);
2289
2300 Tensor ExpM(const Tensor &in);
2301
2302 // Arnoldi:
2303 //===========================================
2333 std::vector<Tensor> Arnoldi(LinOp *Hop, const Tensor &Tin = Tensor(),
2334 const std::string which = "LM", const cytnx_uint64 &maxiter = 10000,
2335 const cytnx_double &cvg_crit = 1.0e-9, const cytnx_uint64 &k = 1,
2336 const bool &is_V = true, const bool &verbose = false);
2337
2338 // Arnoldi:
2339 //===========================================
2373 std::vector<UniTensor> Arnoldi(LinOp *Hop, const cytnx::UniTensor &Tin,
2374 const std::string which = "LM",
2375 const cytnx_uint64 &maxiter = 10000,
2376 const cytnx_double &cvg_crit = 1.0e-9, const cytnx_uint64 &k = 1,
2377 const bool &is_V = true, const bool &verbose = false);
2378
2379 // Lanczos:
2380 //===========================================
2411 std::vector<Tensor> Lanczos(LinOp *Hop, const Tensor &Tin = Tensor(),
2412 const std::string method = "Gnd", const double &CvgCrit = 1.0e-14,
2413 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2414 const bool &is_V = true, const bool &is_row = false,
2415 const cytnx_uint32 &max_krydim = 0, const bool &verbose = false);
2416
2417 // Lanczos:
2418 //===========================================
2449 std::vector<UniTensor> Lanczos(LinOp *Hop, const cytnx::UniTensor &Tin = UniTensor(),
2450 const std::string method = "Gnd",
2451 const double &CvgCrit = 1.0e-14,
2452 const unsigned int &Maxiter = 10000, const cytnx_uint64 &k = 1,
2453 const bool &is_V = true, const bool &is_row = false,
2454 const cytnx_uint32 &max_krydim = 4, const bool &verbose = false);
2455
2456 // Lanczos:
2457 //===========================================
2479 std::vector<Tensor> Lanczos_ER(LinOp *Hop, const cytnx_uint64 &k = 1, const bool &is_V = true,
2480 const cytnx_uint64 &maxiter = 10000,
2481 const double &CvgCrit = 1.0e-14, const bool &is_row = false,
2482 const Tensor &Tin = Tensor(), const cytnx_uint32 &max_krydim = 4,
2483 const bool &verbose = false);
2484
2485 // Lanczos:
2486 //===========================================
2505 std::vector<Tensor> Lanczos_Gnd(LinOp *Hop, const double &CvgCrit = 1.0e-14,
2506 const bool &is_V = true, const Tensor &Tin = Tensor(),
2507 const bool &verbose = false,
2508 const unsigned int &Maxiter = 100000);
2509
2510 // Lanczos:
2511 //===============================================
2530 std::vector<UniTensor> Lanczos_Gnd_Ut(LinOp *Hop, const cytnx::UniTensor &Tin,
2531 const double &CvgCrit = 1.0e-14, const bool &is_V = true,
2532 const bool &verbose = false,
2533 const unsigned int &Maxiter = 100000);
2534
2535 // Lanczos_Exp:
2536 //===============================================
2567 UniTensor Lanczos_Exp(LinOp *Hop, const cytnx::UniTensor &v, const Scalar &tau,
2568 const double &CvgCrit = 1.0e-10, const unsigned int &Maxiter = 100000,
2569 const bool &verbose = false);
2570
2571 // Lstsq:
2572 //===========================================
2598 std::vector<Tensor> Lstsq(const Tensor &A, const Tensor &b, const float &rcond = -1);
2599
2617 Tensor Axpy(const Scalar &a, const Tensor &x, const Tensor &y = Tensor());
2618
2637 void Axpy_(const Scalar &a, const Tensor &x, Tensor &y);
2638
2653 Tensor Ger(const Tensor &x, const Tensor &y, const Scalar &a = Scalar());
2654
2672 void Gemm_(const Scalar &a, const Tensor &x, const Tensor &y, const Scalar &b, Tensor &c);
2673
2689 Tensor Gemm(const Scalar &a, const Tensor &x, const Tensor &y);
2690
2718 void Gemm_Batch(const std::vector<cytnx_int64> &m_array,
2719 const std::vector<cytnx_int64> &n_array,
2720 const std::vector<cytnx_int64> &k_array, const std::vector<Scalar> &alpha_array,
2721 const std::vector<Tensor> &a_tensors, const std::vector<Tensor> &b_tensors,
2722 const std::vector<Scalar> &beta_array, std::vector<Tensor> &c_tensors,
2723 const cytnx_int64 group_count, const std::vector<cytnx_int64> &group_size);
2724
2726 void __Gemm_Batch(const std::vector<char> &transa_array, const std::vector<char> &transb_array,
2727 const std::vector<blas_int> &m_array, const std::vector<blas_int> &n_array,
2728 const std::vector<blas_int> &k_array, const std::vector<Scalar> &alpha_array,
2729 const void **a_array, const void **b_array,
2730 const std::vector<Scalar> &beta_array, void **c_array,
2731 const blas_int group_count, const std::vector<blas_int> &group_size,
2732 const unsigned int dtype, const int device);
2733
2735
2736 } // namespace linalg
2737
2738 // operators:
2749 Tensor operator+(const Tensor &Lt, const Tensor &Rt);
2750
2760 template <class T>
2761 Tensor operator+(const T &lc, const Tensor &Rt);
2762
2772 template <class T>
2773 Tensor operator+(const Tensor &Lt, const T &rc);
2774
2775 //------------------------------------
2786 Tensor operator-(const Tensor &Lt, const Tensor &Rt);
2787
2797 template <class T>
2798 Tensor operator-(const T &lc, const Tensor &Rt);
2799
2809 template <class T>
2810 Tensor operator-(const Tensor &Lt, const T &rc);
2811
2812 //-----------------------------------
2823 Tensor operator*(const Tensor &Lt, const Tensor &Rt);
2824
2834 template <class T>
2835 Tensor operator*(const T &lc, const Tensor &Rt);
2836
2846 template <class T>
2847 Tensor operator*(const Tensor &Lt, const T &rc);
2848
2849 //----------------------------------
2862 Tensor operator/(const Tensor &Lt, const Tensor &Rt);
2863
2874 template <class T>
2875 Tensor operator/(const T &lc, const Tensor &Rt);
2876
2887 template <class T>
2888 Tensor operator/(const Tensor &Lt, const T &rc);
2889
2890 //----------------------------------
2901 Tensor operator%(const Tensor &Lt, const Tensor &Rt);
2902
2912 template <class T>
2913 Tensor operator%(const T &lc, const Tensor &Rt);
2914
2924 template <class T>
2925 Tensor operator%(const Tensor &Lt, const T &rc);
2926
2927 //----------------------------------
2937 Tensor operator==(const Tensor &Lt, const Tensor &Rt);
2938
2948 template <class T>
2949 Tensor operator==(const T &lc, const Tensor &Rt);
2950
2960 template <class T>
2961 Tensor operator==(const Tensor &Lt, const T &rc);
2962
2963} // namespace cytnx
2964
2965#endif // BACKEND_TORCH
2966
2967#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:1794
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.
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.
void iAdd(Tensor &Lt, const Tensor &Rt)
The addition function for Tensor, inplacely.
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...
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=1.0e-9, const cytnx_uint64 &k=1, const bool &is_V=true, const bool &verbose=false)
perform Arnoldi for matrices or linear function.
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.
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.
int get_mkl_code()
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.
int set_mkl_ilp64()