ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Typedefs | Enumerations | Functions
tag_detail Namespace Reference

Classes

struct  pair_cmp
 

Typedefs

typedef unsigned tag_type
 

Enumerations

enum  operator_kind { bosonic, fermionic }
 

Functions

template<class Matrix , class SymmGroup >
void remove_empty_blocks (block_matrix< Matrix, SymmGroup > &op)
 
template<class Matrix , class SymmGroup >
bool is_uniform (block_matrix< Matrix, SymmGroup > const &op)
 
template<class T >
bool num_check (T x)
 
bool num_check (std::complex< double > x)
 
template<class Matrix , class SymmGroup >
std::pair< bool, typename
Matrix::value_type > 
equal (block_matrix< Matrix, SymmGroup > const &reference, block_matrix< Matrix, SymmGroup > const &sample)
 

Typedef Documentation

typedef unsigned tag_detail::tag_type

Definition at line 36 of file tag_detail.h.

Enumeration Type Documentation

Enumerator
bosonic 
fermionic 

Definition at line 38 of file tag_detail.h.

Function Documentation

template<class Matrix , class SymmGroup >
std::pair<bool, typename Matrix::value_type> tag_detail::equal ( block_matrix< Matrix, SymmGroup > const &  reference,
block_matrix< Matrix, SymmGroup > const &  sample 
)

Definition at line 120 of file tag_detail.h.

122  {
123  if (reference.left_basis() != sample.left_basis() || reference.right_basis() != sample.right_basis())
124  return std::make_pair(false, 0.);
125 
126  if (sample.n_blocks() == 0)
127  return std::make_pair(true, 1.0);
128 
129  typename Matrix::value_type invscale1, invscale2;
130 
131  // determine scale of matrices
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++)
135  {
136  if (std::abs(m1(i,j)) > 1.e-50) {
137  invscale1 = 1./m1(i,j);
138  break;
139  }
140  if(i == (num_rows(m1)-1) && j == (num_cols(m1)-1)){ return std::make_pair(false, 0.); }
141  }
142 
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++)
146  {
147  if (std::abs(m2(i,j)) > 1.e-50) {
148  invscale2 = 1./m2(i,j);
149  break;
150  }
151  if(i == (num_rows(m2)-1) && j == (num_cols(m2)-1)){ return std::make_pair(false, 0.); }
152  }
153 
154  // Check all blocks for equality modulo scale factor
155  for (typename Matrix::size_type b=0; b < reference.n_blocks(); ++b)
156  {
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++)
161  {
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.);
165  }
166  }
167 
168  typename Matrix::value_type scale = invscale1 / invscale2;
169 
170 #ifndef NDEBUG
171  try { num_check(invscale1); }
172  catch (std::exception e) { maquis::cout << "invscale1 numcheck failed\n"; exit(1);}
173  try { num_check(invscale2); }
174  catch (std::exception e) { maquis::cout << "invscale2 numcheck failed\n"; exit(1);}
175  try { num_check(scale); }
176  catch (std::exception e) { maquis::cout << "scale numcheck failed\n"; exit(1);}
177 #endif
178 
179  return std::make_pair(true, scale);
180  }
size_type n_blocks() const
std::size_t num_rows(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:99
std::size_t num_cols(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:102
Index< SymmGroup > const & right_basis() const
Index< SymmGroup > const & left_basis() const
bool num_check(std::complex< double > x)
Definition: tag_detail.h:116
template<class Matrix , class SymmGroup >
bool tag_detail::is_uniform ( block_matrix< Matrix, SymmGroup > const &  op)

Definition at line 77 of file tag_detail.h.

78  {
79  if (op.n_blocks() == 0)
80  return true;
81 
82  typename Matrix::value_type invscale;
83 
84  // determine scale of matrices
85  const Matrix& m = op[0];
86  for (int i = 0; i < num_rows(m); i++)
87  for(int j = 0; j < num_cols(m); j++)
88  if (std::abs(m(i,j)) > 1.e-20) {
89  invscale = 1./m(i,j);
90  break;
91  }
92 
93  for (typename Matrix::size_type b=0; b < op.n_blocks(); ++b)
94  {
95  const Matrix& m = op[b];
96  for (int i = 0; i < num_rows(m); i++)
97  for(int j = 0; j < num_cols(m); j++)
98  {
99  typename maquis::traits::real_type<typename Matrix::value_type>::type normalized = std::abs(m(i,j) * invscale);
100  // if not 1 and not 0
101  if (std::abs(normalized-1.0) > 1e-15 && normalized > 1e-15)
102  return false;
103  }
104  }
105 
106  return true;
107  }
size_type n_blocks() const
std::size_t num_rows(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:99
real_type< typename T::value_type >::type type
Definition: traits.hpp:9
std::size_t num_cols(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:102
template<class T >
bool tag_detail::num_check ( x)

Definition at line 110 of file tag_detail.h.

110  {
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");
113  return true;
114  }
bool tag_detail::num_check ( std::complex< double >  x)
inline

Definition at line 116 of file tag_detail.h.

116 { return true; }
template<class Matrix , class SymmGroup >
void tag_detail::remove_empty_blocks ( block_matrix< Matrix, SymmGroup > &  op)

Definition at line 55 of file tag_detail.h.

56  {
57  for (typename Matrix::size_type b=0; b < op.n_blocks(); ++b)
58  {
59  bool only_zero = true;
60  const Matrix& m = op[b];
61  for (int i = 0; i < num_rows(m); i++)
62  for(int j = 0; j < num_cols(m); j++)
63  {
64  if (alps::numeric::is_nonzero(m(i,j))) {
65  only_zero = false;
66  break;
67  }
68  }
69  if (only_zero) {
70  op.remove_block(b);
71  --b;
72  }
73  }
74  }
size_type n_blocks() const
std::size_t num_rows(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:99
std::size_t num_cols(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:102
void remove_block(charge r, charge c)