ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
function_objects.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * MAQUIS MATRICES Project
4  *
5  * 2011-2011 by Bela Bauer <bauerb@phys.ethz.ch>
6  *
7  * This software is part of the ALPS Applications, published under the ALPS
8  * Application License; you can use, redistribute it and/or modify it under
9  * the terms of the license, either version 1 or (at your option) any later
10  * version.
11  *
12  * You should have received a copy of the ALPS Application License along with
13  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
14  * available from http://alps.comp-phys.org/.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
19  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
20  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  *****************************************************************************/
25 
26 #ifndef MAQUIS_FUNCTION_OBJECTS_H
27 #define MAQUIS_FUNCTION_OBJECTS_H
28 
29 #include <alps/numeric/conj.hpp>
30 
31 namespace utils {
32  using alps::numeric::conj;
33 
34 #define DEFINE_FUNCTION_OBJECT(name, return_type, arg_type) \
35 struct functor_##name { template<class T> return_type operator() (arg_type t) { return name(t); } };
36 
37 #define DEFINE_VOID_FUNCTION_OBJECT(name, arg_type) \
38 struct functor_##name { template<class T> void operator() (arg_type t) { name(t); } };
39 
41  DEFINE_FUNCTION_OBJECT(norm_square, typename maquis::traits::real_type<T>::type, T const &)
42  DEFINE_FUNCTION_OBJECT(transpose, T, T const &)
43  DEFINE_VOID_FUNCTION_OBJECT(transpose_inplace, T &)
44  DEFINE_FUNCTION_OBJECT(conj, T, T)
45  DEFINE_VOID_FUNCTION_OBJECT(conj_inplace, T&)
46  DEFINE_FUNCTION_OBJECT(conjugate, T, T const &)
47  DEFINE_FUNCTION_OBJECT(adjoint, T, T const &)
48  DEFINE_VOID_FUNCTION_OBJECT(adjoint_inplace, T &)
49  DEFINE_FUNCTION_OBJECT(sqrt, T, T const &)
50  DEFINE_VOID_FUNCTION_OBJECT(sqrt_inplace, T &)
51  DEFINE_FUNCTION_OBJECT(exp, T, T const &)
52  DEFINE_FUNCTION_OBJECT(size_of, std::size_t, T const &)
53 
54 #undef DEFINE_FUNCTION_OBJECT
55 #undef DEFINE_VOID_FUNCTION_OBJECT
56 
57  template<class T>
58  struct constant
59  {
60  T val;
61  constant(T v) : val(v) { }
62  T operator()() const { return val; }
63  };
64 
65  struct get_first
66  {
67  template<class T1, class T2>
68  T1 operator()(std::pair<T1, T2> const & p) { return p.first; }
69  };
70 
71  struct get_second
72  {
73  template<class T1, class T2>
74  T2 operator()(std::pair<T1, T2> const & p) { return p.second; }
75  };
76 
77 } /* namespace */
78 
79 #endif
T2 operator()(std::pair< T1, T2 > const &p)
T1 operator()(std::pair< T1, T2 > const &p)
T operator()() const
T::value_type type
Definition: traits.hpp:8
#define DEFINE_FUNCTION_OBJECT(name, return_type, arg_type)
std::size_t size_of(Iterator i1, Iterator i2)
Definition: sizeof.h:32
block_matrix< Matrix, SymmGroup > adjoint(block_matrix< Matrix, SymmGroup > m)
block_matrix< Matrix, SymmGroup > sqrt(block_matrix< Matrix, SymmGroup > m)
block_matrix< Matrix, SymmGroup >::scalar_type trace(block_matrix< Matrix, SymmGroup > const &m)
block_matrix< Matrix, SymmGroup > conjugate(block_matrix< Matrix, SymmGroup > m)
#define DEFINE_VOID_FUNCTION_OBJECT(name, arg_type)
block_matrix< typename maquis::traits::transpose_view< Matrix >::type, SymmGroup > transpose(block_matrix< Matrix, SymmGroup > const &m)