27 #ifndef MAQUIS_DMRG_MODELS_TAG_DETAIL_H
28 #define MAQUIS_DMRG_MODELS_TAG_DETAIL_H
30 #include <alps/numeric/isnan.hpp>
31 #include <alps/numeric/isinf.hpp>
32 #include <alps/numeric/is_nonzero.hpp>
34 namespace tag_detail {
43 std::pair<tag_type, tag_type>
const & j)
const
45 if (i.first < j.first)
47 else if (i.first > j.first)
50 return i.second < j.second;
54 template <
class Matrix,
class SymmGroup>
57 for (
typename Matrix::size_type b=0; b < op.
n_blocks(); ++b)
59 bool only_zero =
true;
60 const Matrix& m = op[b];
61 for (
int i = 0; i <
num_rows(m); i++)
64 if (alps::numeric::is_nonzero(m(i,j))) {
76 template <
class Matrix,
class SymmGroup>
82 typename Matrix::value_type invscale;
85 const Matrix& m = op[0];
86 for (
int i = 0; i <
num_rows(m); i++)
88 if (std::abs(m(i,j)) > 1.e-20) {
93 for (
typename Matrix::size_type b=0; b < op.
n_blocks(); ++b)
95 const Matrix& m = op[b];
96 for (
int i = 0; i <
num_rows(m); i++)
101 if (std::abs(normalized-1.0) > 1e-15 && normalized > 1e-15)
111 if (alps::numeric::isnan(x) || alps::numeric::isinf(x))
112 throw std::runtime_error(
"NaN / INF numeric Error occured while comparing operator scales\n");
116 inline bool num_check(std::complex<double> x) {
return true; }
118 template <
class Matrix,
class SymmGroup>
119 std::pair<bool, typename Matrix::value_type>
124 return std::make_pair(
false, 0.);
127 return std::make_pair(
true, 1.0);
129 typename Matrix::value_type invscale1, invscale2;
132 const Matrix& m1 = reference[0];
133 for (
int i = 0; i <
num_rows(m1); i++)
134 for(
int j = 0; j <
num_cols(m1); j++)
136 if (std::abs(m1(i,j)) > 1.e-50) {
137 invscale1 = 1./m1(i,j);
140 if(i == (
num_rows(m1)-1) && j == (
num_cols(m1)-1)){
return std::make_pair(
false, 0.); }
143 const Matrix& m2 = sample[0];
144 for (
int i = 0; i <
num_rows(m2); i++)
145 for(
int j = 0; j <
num_cols(m2); j++)
147 if (std::abs(m2(i,j)) > 1.e-50) {
148 invscale2 = 1./m2(i,j);
151 if(i == (
num_rows(m2)-1) && j == (
num_cols(m2)-1)){
return std::make_pair(
false, 0.); }
155 for (
typename Matrix::size_type b=0; b < reference.
n_blocks(); ++b)
157 const Matrix& mb1 = reference[b];
158 const Matrix& mb2 = sample[b];
159 for (
int i = 0; i <
num_rows(mb1); i++)
160 for(
int j = 0; j <
num_cols(mb1); j++)
162 typename Matrix::value_type t1 = mb1(i,j) * invscale1, t2 = mb2(i,j) * invscale2;
163 if (std::abs(t1 - t2) > 1e-12)
164 return std::make_pair(
false, 0.);
168 typename Matrix::value_type scale = invscale1 / invscale2;
172 catch (std::exception e) { maquis::cout <<
"invscale1 numcheck failed\n"; exit(1);}
174 catch (std::exception e) { maquis::cout <<
"invscale2 numcheck failed\n"; exit(1);}
176 catch (std::exception e) { maquis::cout <<
"scale numcheck failed\n"; exit(1);}
179 return std::make_pair(
true, scale);
size_type n_blocks() const
void remove_empty_blocks(block_matrix< Matrix, SymmGroup > &op)
std::size_t num_rows(maquis::dmrg::one_matrix< T > const &m)
bool operator()(std::pair< tag_type, tag_type > const &i, std::pair< tag_type, tag_type > const &j) const
bool is_uniform(block_matrix< Matrix, SymmGroup > const &op)
real_type< typename T::value_type >::type type
std::size_t num_cols(maquis::dmrg::one_matrix< T > const &m)
Index< SymmGroup > const & right_basis() const
void remove_block(charge r, charge c)
std::pair< bool, typename Matrix::value_type > equal(block_matrix< Matrix, SymmGroup > const &reference, block_matrix< Matrix, SymmGroup > const &sample)
Index< SymmGroup > const & left_basis() const