ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * ALPS MPS DMRG Project
4  *
5  * Copyright (C) 2013 Institute for Theoretical Physics, ETH Zurich
6  * 2011-2013 by Michele Dolfi <dolfim@phys.ethz.ch>
7  *
8  * This software is part of the ALPS Applications, published under the ALPS
9  * Application License; you can use, redistribute it and/or modify it under
10  * the terms of the license, either version 1 or (at your option) any later
11  * version.
12  *
13  * You should have received a copy of the ALPS Application License along with
14  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
15  * available from http://alps.comp-phys.org/.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23  * DEALINGS IN THE SOFTWARE.
24  *
25  *****************************************************************************/
26 
27 #ifndef UTILS_HPP_
28 #define UTILS_HPP_
29 
30 #include <cstddef>
31 #include <complex>
32 
34  static double prefactor;
35  bool operator() (std::size_t i, std::size_t j) {
36  bool ret = (i < j);
37  if (ret) prefactor *= -1.;
38  return ret;
39  }
40 };
41 
42 template<class T>
43 bool check_real(T x) { return true; }
44 
45 template<class T>
46 bool check_real(std::complex<T> x)
47 {
48  return std::imag(x)/std::real(x) < 1e-14 || std::imag(x) < 1e-14;
49 }
50 
51 
52 template <class InputIterator, class Predicate>
53 bool all_true (InputIterator first, InputIterator last, Predicate pred)
54 {
55  bool allTrue = true;
56  while (allTrue && first != last)
57  allTrue = pred(*first++);
58  return allTrue;
59 }
60 
61 #endif /* UTILS_HPP_ */
bool all_true(InputIterator first, InputIterator last, Predicate pred)
Definition: utils.hpp:53
bool check_real(T x)
Definition: utils.hpp:43
bool operator()(std::size_t i, std::size_t j)
Definition: utils.hpp:35
static double prefactor
Definition: utils.hpp:34
alps::numeric::real_type< T >::type real(T f)
Definition: bindings.hpp:38