33 #include <alps/numeric/isnan.hpp>
34 #include <alps/numeric/isinf.hpp>
42 template<
class Matrix,
class SymmGroup>
47 typename Matrix::value_type val)
52 , cur_normalization(
Unorm)
78 template<
class Matrix,
class SymmGroup>
89 , cur_normalization(
Unorm)
112 template<
class Matrix,
class SymmGroup>
123 swap(right_i, new_right_i);
124 swap(left_i, old_left_i);
127 cur_normalization = normalization;
130 template<
class Matrix,
class SymmGroup>
141 swap(left_i, new_left_i);
142 swap(right_i, old_right_i);
145 cur_normalization = normalization;
148 template<
class Matrix,
class SymmGroup>
154 template<
class Matrix,
class SymmGroup>
160 template<
class Matrix,
class SymmGroup>
166 template<
class Matrix,
class SymmGroup>
172 template<
class Matrix,
class SymmGroup>
179 reshape_right_to_left_new<Matrix>(phys_i, left_i, right_i,
187 template<
class Matrix,
class SymmGroup>
194 reshape_left_to_right_new<Matrix>(phys_i, left_i, right_i,
202 template<
class Matrix,
class SymmGroup>
209 if (cur_normalization ==
Unorm || cur_normalization ==
Rnorm) {
217 right_i =
data().right_basis();
220 cur_normalization =
Lnorm;
236 cur_normalization =
Lnorm;
240 return identity_matrix<Matrix>(
data().right_basis());
243 template<
class Matrix,
class SymmGroup>
250 if (cur_normalization ==
Unorm || cur_normalization ==
Lnorm) {
258 left_i =
data().left_basis();
261 cur_normalization =
Rnorm;
277 cur_normalization =
Rnorm;
281 return identity_matrix<Matrix>(
data().left_basis());
284 template<
class Matrix,
class SymmGroup>
289 data().shift_basis(diff);
292 template<
class Matrix,
class SymmGroup>
296 cur_normalization =
Unorm;
300 replace_left_paired(tmp);
303 template<
class Matrix,
class SymmGroup>
307 cur_normalization =
Unorm;
311 replace_right_paired(tmp);
314 template<
class Matrix,
class SymmGroup>
318 cur_normalization =
Unorm;
322 template<
class Matrix,
class SymmGroup>
326 cur_normalization =
Unorm;
330 template<
class Matrix,
class SymmGroup>
334 data() =
data().inplace_conjugate();
337 template<
class Matrix,
class SymmGroup>
341 return data().norm();
348 maquis::cout <<
"a: " << a << std::endl;
349 maquis::cout <<
"b: " << b << std::endl;
354 template<
class Matrix,
class SymmGroup>
373 std::vector<scalar_type> vt; vt.reserve(i1.
size());
376 typename SymmGroup::charge c = i1[b].first;
377 assert(
data().has_block(c,c) && rhs.
data().has_block(c,c) );
384 template<
class Matrix,
class SymmGroup>
385 std::ostream& operator<<(std::ostream& os, MPSTensor<Matrix, SymmGroup>
const & mps)
387 os <<
"Physical space: " << mps.phys_i << std::endl;
388 os <<
"Left space: " << mps.left_i << std::endl;
389 os <<
"Right space: " << mps.right_i << std::endl;
394 template<
class Matrix,
class SymmGroup>
398 throw std::runtime_error(
"Not implemented!");
400 return cur_normalization ==
Lnorm;
403 template<
class Matrix,
class SymmGroup>
407 throw std::runtime_error(
"Not implemented!");
409 return cur_normalization ==
Rnorm;
412 template<
class Matrix,
class SymmGroup>
415 if (isleftnormalized(test) || isrightnormalized(test))
421 template<
class Matrix,
class SymmGroup>
425 cur_normalization =
Unorm;
429 template<
class Matrix,
class SymmGroup>
436 template<
class Matrix,
class SymmGroup>
444 template<
class Matrix,
class SymmGroup>
452 template<
class Matrix,
class SymmGroup>
460 template<
class Matrix,
class SymmGroup>
466 assert( phys_i == rhs.
phys_i );
472 cur_normalization =
Unorm;
474 for (std::size_t i = 0; i <
data().n_blocks(); ++i)
476 typename SymmGroup::charge lc =
data().left_basis()[i].first, rc =
data().right_basis()[i].first;
477 std::size_t matched_block = rhs.
data().find_block(lc,rc);
478 if (matched_block < rhs.
data().n_blocks()) {
479 data()[i] += rhs.
data()[matched_block];
486 template<
class Matrix,
class SymmGroup>
492 assert( phys_i == rhs.
phys_i );
497 cur_normalization =
Unorm;
499 for (std::size_t i = 0; i <
data().n_blocks(); ++i)
501 typename SymmGroup::charge lc =
data().left_basis()[i].first, rc =
data().right_basis()[i].first;
502 if (rhs.
data().has_block(lc,rc)) {
510 template<
class Matrix,
class SymmGroup>
517 swap(this->data_, b.data_);
518 swap(this->cur_storage, b.cur_storage);
519 swap(this->cur_normalization, b.cur_normalization);
522 template<
class Matrix,
class SymmGroup>
523 template<
class Archive>
528 ar[
"phys_i"] >> phys_i;
529 ar[
"left_i"] >> left_i;
530 ar[
"right_i"] >> right_i;
531 ar[
"data_"] >>
data();
532 cur_normalization =
Unorm;
535 template<
class Matrix,
class SymmGroup>
536 template<
class Archive>
540 ar[
"phys_i"] << phys_i;
541 ar[
"left_i"] << left_i;
542 ar[
"right_i"] << right_i;
543 ar[
"data_"] <<
data();
546 template<
class Matrix,
class SymmGroup>
552 throw std::runtime_error(
"right basis is wrong");
560 throw std::runtime_error(
"left basis is wrong");
569 for (std::size_t i = 0; i <
data().n_blocks(); ++i)
571 if (
data().left_basis()[i].first !=
data().right_basis()[i].first)
572 throw std::runtime_error(
"particle number is wrong");
578 template<
class Matrix,
class SymmGroup>
581 for (std::size_t k = 0; k <
data().n_blocks(); ++k)
586 if ( alps::numeric::isnan(
data()[k](i,j)) )
587 throw std::runtime_error(
"NaN found!");
588 if ( alps::numeric::isinf(
data()[k](i,j)) )
589 throw std::runtime_error(
"INF found!");
595 template <
class Matrix,
class SymmGroup>
603 }
catch (std::exception & e) {
604 error +=
"I'm unreasonable. " + std::string(e.what());
608 }
catch (std::exception & e) {
609 error +=
"He's unreasonable. " + std::string(e.what());
620 if (
data().n_blocks() != rhs.
data().n_blocks())
621 error +=
"n_blocks doesn't match. ";
623 for (
int b=0; b <
data().n_blocks(); ++b) {
624 if (
data()[b].num_cols() != rhs.
data()[b].num_cols() ||
data()[b].num_rows() != rhs.
data()[b].num_rows())
625 error +=
"Size of block doesn't match. ";
626 for (
int i=0; i <
data()[b].num_rows() && error.empty(); ++i)
627 for (
int j=0; j <
data()[b].num_cols() && error.empty(); ++j)
628 if (
data()[b](i,j) != rhs.
data()[b](i,j))
629 error +=
"Data doesn't match. ";
634 throw std::runtime_error(error);
638 template<
class Matrix,
class SymmGroup>
641 return data().num_elements();
block_matrix< Matrix, SymmGroup > normalize_right(DecompMethod method=DefaultSolver(), bool multiplied=true, double truncation=0, Index< SymmGroup > bond_dim=Index< SymmGroup >())
void multiply_by_scalar(const scalar_type &)
real_type scalar_norm() const
void make_left_paired() const
bool isrightnormalized(bool test=false) const
Index< SymmGroup > const & col_dim() const
bool isobccompatible(Indicator) const
MPSTensor const & operator/=(const scalar_type &)
maquis::traits::scalar_type< Matrix >::type scalar_type
void make_right_paired() const
void check_equal(MPSTensor< Matrix, SymmGroup > const &) const
scalar_type scalar_overlap(MPSTensor const &) const
void swap(MPSTensor< Matrix, SymmGroup > &x, MPSTensor< Matrix, SymmGroup > &y)
void verbose_assert(T const &a, T const &b)
Index< SymmGroup > const & row_dim() const
void save(Archive &ar) const
std::size_t num_rows(maquis::dmrg::one_matrix< T > const &m)
#define semi_parallel_for(constraint,...)
void multiply_from_left(block_matrix< Matrix, SymmGroup > const &)
functions for joining two MPS : |psi1> + |psi2>
block_matrix< Matrix, SymmGroup > normalize_left(DecompMethod method=DefaultSolver(), bool multiplied=true, double truncation=0, Index< SymmGroup > bond_dim=Index< SymmGroup >())
block_matrix< Matrix, SymmGroup > adjoin(block_matrix< Matrix, SymmGroup > const &m)
static value_type uniform()
bool isnormalized(bool test=false) const
Index< SymmGroup > phys_i
MPS< Matrix, SymmGroup >::scalar_type overlap(MPS< Matrix, SymmGroup > const &mps1, MPS< Matrix, SymmGroup > const &mps2)
void replace_left_paired(block_matrix< Matrix, SymmGroup > const &, Indicator=Unorm)
bool weak_equal(Index< SymmGroup > const &a, Index< SymmGroup > const &b)
declaration of the MPSTensor class
MPSTensor(Index< SymmGroup > const &sd=Index< SymmGroup >(), Index< SymmGroup > const &ld=Index< SymmGroup >(), Index< SymmGroup > const &rd=Index< SymmGroup >(), bool fillrand=true, value_type val=0)
void svd(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &U, block_matrix< Matrix, SymmGroup > &V, block_matrix< DiagMatrix, SymmGroup > &S)
std::size_t num_cols(maquis::dmrg::one_matrix< T > const &m)
void shift_aux_charges(typename SymmGroup::charge)
block_matrix< Matrix, SymmGroup > const & const_data() const
Index< SymmGroup > const & right_basis() const
bool isleftnormalized(bool test=false) const
void multiply_from_right(block_matrix< Matrix, SymmGroup > const &)
algorithms for block_matrix (gemm, svd, etc.)
std::size_t num_elements() const
Index< SymmGroup > const & site_dim() const
void lq(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &L, block_matrix< Matrix, SymmGroup > &Q)
Index< SymmGroup > left_i
friend void swap(MPSTensor &a, MPSTensor &b)
MPSTensor const & operator+=(MPSTensor const &)
void swap_with(MPSTensor &b)
functions to reshape the representation of data in MPSTensor
void gemm(block_matrix< Matrix1, SymmGroup > const &A, block_matrix< Matrix2, SymmGroup > const &B, block_matrix< Matrix3, SymmGroup > &C)
Index< SymmGroup > right_i
_Tp accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
Index< SymmGroup > const & left_basis() const
block_matrix< Matrix, SymmGroup > & data()
void replace_right_paired(block_matrix< Matrix, SymmGroup > const &, Indicator=Unorm)
void qr(block_matrix< Matrix, SymmGroup > const &M, block_matrix< Matrix, SymmGroup > &Q, block_matrix< Matrix, SymmGroup > &R)
Index< SymmGroup > common_subset(Index< SymmGroup > &a, Index< SymmGroup > &b)
MPSTensor const & operator*=(const scalar_type &)
maquis::traits::real_type< Matrix >::type real_type
void divide_by_scalar(const scalar_type &)
MPSTensor const & operator-=(MPSTensor const &)