Skip to content

Commit a9ecd68

Browse files
committed
added Rsvd_notruncate for symmetric and fermionic UniTensors
1 parent a40726f commit a9ecd68

5 files changed

Lines changed: 1145 additions & 147 deletions

File tree

include/linalg.hpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -708,19 +708,30 @@ namespace cytnx {
708708
subspace, and the smallest singular values are less reliable. Use truncation with oversampling.
709709
@param[in] is_U if \em true, the left-unitary UniTensor U (isometry) is returned.
710710
@param[in] is_vT if \em true, the right-unitary UniTensor vT (isometry) is returned.
711+
@param[in] mindim at least this amount of singular values are kept in each block.
712+
@param[in] oversampling_summand the randomized SVD computes [(1 + oversampling_factor) *
713+
keepdim*d/D + oversampling_summand] singular values in each block before further truncating,
714+
where d is the block dimension and D the full tensor dimension (each being the minimum of row
715+
and column dimension of the block or tensor respectively).
716+
@param[in] oversampling_factor see oversampling_summand
711717
@param[in] power_iteration number of iterations for the power method: Y = (A *
712718
Adag)^power_iteration * A * Tin
713719
@param[in] seed the seed for the random generator. [Default] Using device entropy.
714720
@see Rand_isometry(const Tensor &Tin, const cytnx_uint64 &keepdim, const cytnx_uint64
715721
&power_iteration, const unsigned int &seed)
716722
@see Rsvd()
717723
@see Gesvd()
724+
@note At least one singular value per symmetry sector is always kept.
725+
@note More than keepdim singular values might be returned (depending on mindim,
726+
oversampling_summand, oversampling_factor, and symmetry sector sizes).
718727
@warning No truncation of the singular values is performed, and the smaller ones will be
719728
inaccurate. Use Rsvd() for a truncated version that drops small singular values.
720729
*/
721730
std::vector<cytnx::UniTensor> Rsvd_notruncate(
722731
const cytnx::UniTensor &Tin, cytnx_uint64 keepdim, bool is_U = true, bool is_vT = true,
723-
cytnx_uint64 power_iteration = 2, unsigned int seed = random::__static_random_device());
732+
cytnx_uint64 mindim = 1, cytnx_uint64 oversampling_summand = 0,
733+
double oversampling_factor = 0., cytnx_uint64 power_iteration = 2,
734+
unsigned int seed = random::__static_random_device());
724735

725736
/**
726737
@brief Perform Singular-Value decomposition on a UniTensor using ?gesvd method.
@@ -865,10 +876,12 @@ namespace cytnx {
865876
the largest error will be pushed back to the vector (The smallest singular value in the return
866877
singular values matrix \f$ S \f$.) If \p return_err is > 1, then the full list of truncated
867878
singular values will be returned.
868-
@param[in] oversampling_summand the randomized SVD computes (1 + oversampling_fact) * keepdim +
869-
oversampling_summand before further truncating to keepdim
870-
@param[in] oversampling_fact the randomized SVD computes (1 + oversampling_fact) * keepdim +
871-
oversampling_summand before further truncating to keepdim
879+
@param[in] mindim at least this amount of singular values are kept in each block.
880+
@param[in] oversampling_summand the randomized SVD computes [(1 + oversampling_factor) *
881+
keepdim*d/D + oversampling_summand] singular values in each block before further truncating,
882+
where d is the block dimension and D the full tensor dimension (each being the minimum of row
883+
and column dimension of the block or tensor respectively).
884+
@param[in] oversampling_factor see oversampling_summand
872885
@param[in] power_iteration number of iterations for the power method: Y = (A *
873886
Adag)^power_iteration * A * Tin
874887
@param[in] seed the seed for the random generator. [Default] Using device entropy.
@@ -1887,10 +1900,12 @@ namespace cytnx {
18871900
the largest error will be pushed back to the vector (The smallest singular value in the return
18881901
singular values matrix \f$ S \f$.) If \p return_err is a \em positive int, then the
18891902
full list of truncated singular values will be returned.
1890-
@param[in] oversampling_summand the randomized SVD computes (1 + oversampling_fact) * keepdim +
1891-
oversampling_summand before further truncating to keepdim
1892-
@param[in] oversampling_fact the randomized SVD computes (1 + oversampling_fact) * keepdim +
1893-
oversampling_summand before further truncating to keepdim
1903+
@param[in] mindim at least this amount of singular values are kept in each block.
1904+
@param[in] oversampling_summand the randomized SVD computes [(1 + oversampling_factor) *
1905+
keepdim*d/D + oversampling_summand] singular values in each block before further truncating,
1906+
where d is the block dimension and D the full tensor dimension (each being the minimum of row
1907+
and column dimension of the block or tensor respectively).
1908+
@param[in] oversampling_factor see oversampling_summand
18941909
@param[in] power_iteration number of iterations for the power method: Y = (A *
18951910
Adag)^power_iteration * A * Tin
18961911
@param[in] seed the seed for the random generator. [Default] Using device entropy.

pybind/linalg_py.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,17 @@ void linalg_binding(py::module &m) {
7373
m_linalg.def(
7474
"Rsvd_notruncate",
7575
[](const cytnx::UniTensor &Tin, cytnx_uint64 keepdim, bool is_U, bool is_vT,
76+
cytnx_uint64 mindim, cytnx_uint64 oversampling_summand, double oversampling_factor,
7677
cytnx_uint64 power_iteration, int64_t seed) {
7778
if (seed == -1) {
7879
// If user doesn't specify seed argument
7980
seed = cytnx::random::__static_random_device();
8081
}
81-
return cytnx::linalg::Rsvd_notruncate(Tin, keepdim, is_U, is_vT, power_iteration, seed);
82+
return cytnx::linalg::Rsvd_notruncate(Tin, keepdim, is_U, is_vT, mindim, oversampling_summand,
83+
oversampling_factor, power_iteration, seed);
8284
},
8385
py::arg("Tin"), py::arg("keepdim"), py::arg("is_U") = true, py::arg("is_vT") = true,
86+
py::arg("mindim") = 1, py::arg("oversampling_summand") = 0, py::arg("oversampling_factor") = 0.,
8487
py::arg("power_iteration") = 2, py::arg("seed") = -1);
8588

8689
m_linalg.def(

src/algo/Vstack.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace cytnx {
1616
typedef Accessor ac;
1717

1818
Tensor Vstack(const std::vector<Tensor> &In_tensors) {
19-
Tensor out;
20-
2119
std::vector<Tensor> _Ins;
2220

2321
// check:
@@ -82,7 +80,7 @@ namespace cytnx {
8280
}
8381

8482
// allocate out!
85-
out = zeros({Dcomb, Dshare}, dtype_id, device_id);
83+
Tensor out = zeros({Dcomb, Dshare}, dtype_id, device_id);
8684

8785
std::vector<void *> rawPtr(In_tensors.size());
8886
for (int i = 0; i < _Ins.size(); i++) {

0 commit comments

Comments
 (0)