ALPS MPS Codes
Reference documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
one_matrix.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  * 2013-2013 by Sebastian Keller <sebkelle@phys.ethz.ch>
7  *
8  *
9  * This software is part of the ALPS Applications, published under the ALPS
10  * Application License; you can use, redistribute it and/or modify it under
11  * the terms of the license, either version 1 or (at your option) any later
12  * version.
13  *
14  * You should have received a copy of the ALPS Application License along with
15  * the ALPS Applications; see the file LICENSE.txt. If not, the license is also
16  * available from http://alps.comp-phys.org/.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
21  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
22  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  * DEALINGS IN THE SOFTWARE.
25  *
26  *****************************************************************************/
27 
28 #ifndef MAQUIS_ONE_MATRIX_HPP
29 #define MAQUIS_ONE_MATRIX_HPP
30 
31 namespace maquis {
32  namespace dmrg {
33 
34  // Dummy Matrix of constant size 1 for MPO construction and compression
35  template <typename T>
36  class one_matrix {
37  public:
38  typedef T value_type;
39  typedef T& reference;
40  typedef T const& const_reference;
41  typedef std::size_t size_type;
42  typedef std::ptrdiff_t difference_type;
43  // TODO: Introduce iterator classes that support *, !=, ++, ...
46 
47  explicit one_matrix(size_type rows = 1, size_type cols = 1, T init_value = T()) {
48  assert(cols==1 && rows==1);
49  val_ = init_value;
50  }
51 
52  void swap(one_matrix & r) { std::swap((*this)(0,0), r(0,0)); }
53 
54  friend void swap(one_matrix & x, one_matrix & y)
55  {
56  x.swap(y);
57  }
58 
59  inline value_type& operator()(const size_type i, const size_type j) {
60  assert(i==0 && j==0);
61  return val_;
62  }
63  inline value_type const& operator()(const size_type i, const size_type j) const {
64  assert(i==0 && j==0);
65  return val_;
66  }
67 
68  inline bool operator == (one_matrix const& rhs) const { return this->val_ == rhs(0,0); }
69 
70  inline one_matrix<T>& operator += (one_matrix const& rhs) { this->val_ += rhs(0,0); return *this; }
71  inline one_matrix<T>& operator -= (one_matrix const& rhs) { this->val_ -= rhs(0,0); return *this; }
72 
73  template <typename T2>
74  inline one_matrix<T>& operator *= (T2 const& t) { this->val_ *= t; return *this; }
75 
76  template <typename T2>
77  inline one_matrix<T>& operator /= (T2 const& t) { this->val_ /= t; return *this; }
78 
79  inline bool empty() const { return false; }
80 
81  inline size_type num_rows() const { return 1; }
82  inline size_type num_cols() const { return 1; }
83 
84  std::pair<element_iterator, element_iterator> elements() { return std::make_pair(val_, NULL); }
85  std::pair<const_element_iterator, const_element_iterator> elements() const { return std::make_pair(val_, NULL); }
86 
87  //MemoryBlock const& get_values() const;
88  //MemoryBlock & get_values();
89 
90  private:
91 
92  T val_;
93  };
94 
95  }
96 }
97 
98 template <typename T>
99 inline std::size_t num_rows(maquis::dmrg::one_matrix<T> const & m) { return 1; }
100 
101 template <typename T>
102 inline std::size_t num_cols(maquis::dmrg::one_matrix<T> const & m) { return 1; }
103 
104 template <typename T>
106 {
107  c(0,0) = a(0,0) * b(0,0);
108 }
109 
110 namespace maquis {
111  namespace dmrg {
112 
113  template <typename T>
115  { return one_matrix<T>(1,1, m1(0,0) + m2(0,0)); }
116 
117  template <typename T>
119  { return one_matrix<T>(1,1, m1(0,0) - m2(0,0)); }
120 
121  template <typename T>
123  { return one_matrix<T>(1,1, -a(0,0)); }
124 
125  template<typename T>
127  { return one_matrix<T>(1,1, m1(0,0) * m2(0,0)); }
128 
129  template<typename T>
130  std::size_t size_of(one_matrix<T> const & m) { return 1; }
131 
132  template <typename T>
133  std::ostream& operator << (std::ostream& o, one_matrix<T> const& m) { o << m(0,0); return o; }
134 
135  }
136 }
137 
138 #endif //MAQUIS_ONE_MATRIX_HPP
std::ptrdiff_t difference_type
Definition: one_matrix.hpp:42
bool operator==(one_matrix const &rhs) const
Definition: one_matrix.hpp:68
size_type num_cols() const
Definition: one_matrix.hpp:82
const one_matrix< T > operator*(one_matrix< T > const &m1, one_matrix< T > const &m2)
Definition: one_matrix.hpp:126
one_matrix< T > & operator-=(one_matrix const &rhs)
Definition: one_matrix.hpp:71
void swap(MPSTensor< Matrix, SymmGroup > &x, MPSTensor< Matrix, SymmGroup > &y)
const_reference const_element_iterator
Definition: one_matrix.hpp:45
one_matrix(size_type rows=1, size_type cols=1, T init_value=T())
Definition: one_matrix.hpp:47
std::size_t num_rows(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:99
std::pair< const_element_iterator, const_element_iterator > elements() const
Definition: one_matrix.hpp:85
std::pair< element_iterator, element_iterator > elements()
Definition: one_matrix.hpp:84
value_type const & operator()(const size_type i, const size_type j) const
Definition: one_matrix.hpp:63
const one_matrix< T > operator+(one_matrix< T > m1, one_matrix< T > const &m2)
Definition: one_matrix.hpp:114
one_matrix< T > & operator/=(T2 const &t)
Definition: one_matrix.hpp:77
friend void swap(one_matrix &x, one_matrix &y)
Definition: one_matrix.hpp:54
std::size_t num_cols(maquis::dmrg::one_matrix< T > const &m)
Definition: one_matrix.hpp:102
std::size_t size_of(one_matrix< T > const &m)
Definition: one_matrix.hpp:130
size_type num_rows() const
Definition: one_matrix.hpp:81
const one_matrix< T > operator-(one_matrix< T > m1, one_matrix< T > const &m2)
Definition: one_matrix.hpp:118
one_matrix< T > & operator*=(T2 const &t)
Definition: one_matrix.hpp:74
void gemm(maquis::dmrg::one_matrix< T > const &a, maquis::dmrg::one_matrix< T > const &b, maquis::dmrg::one_matrix< T > &c)
Definition: one_matrix.hpp:105
one_matrix< T > & operator+=(one_matrix const &rhs)
Definition: one_matrix.hpp:70
void swap(one_matrix &r)
Definition: one_matrix.hpp:52
value_type & operator()(const size_type i, const size_type j)
Definition: one_matrix.hpp:59