Expression Templates Library (ETL)
hermitian_reference.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2014-2023 Baptiste Wicht
3 // Distributed under the terms of the MIT License.
4 // (See accompanying file LICENSE or copy at
5 // http://opensource.org/licenses/MIT)
6 //=======================================================================
7 
13 #pragma once
14 
15 namespace etl {
16 
17 namespace herm_detail {
22 template <typename M>
24  using matrix_type = M;
28  using const_raw_reference_type = std::add_const_t<value_type>&;
29  using expr_t = M;
30 
32  size_t i;
33  size_t j;
36 
43  hermitian_reference(matrix_type& matrix, size_t i, size_t j) : matrix(matrix), i(i), j(j), value(matrix(i, j)), sym_value(matrix(j, i)) {
44  //Nothing else to init
45  }
46 
53  value = rhs;
54  if (i != j) {
55  sym_value = get_conj(value);
56  }
57  return *this;
58  }
59 
66  value += rhs;
67  if (i != j) {
68  sym_value = get_conj(value);
69  }
70  return *this;
71  }
72 
79  value -= rhs;
80  if (i != j) {
81  sym_value = get_conj(value);
82  }
83  return *this;
84  }
85 
92  value *= rhs;
93  if (i != j) {
94  sym_value *= get_conj(value);
95  }
96  return *this;
97  }
98 
105  value /= rhs;
106  if (i != j) {
107  sym_value = get_conj(value);
108  }
109  return *this;
110  }
111 
118  value %= rhs;
119  if (i != j) {
120  sym_value = get_conj(value);
121  }
122  return *this;
123  }
124 
130  bool operator==(const hermitian_reference& rhs) const {
131  return value == rhs.value;
132  }
133 
139  bool operator!=(const hermitian_reference& rhs) const {
140  return value != rhs.value;
141  }
142 
148  bool operator==(const value_type& rhs) const {
149  return value == rhs;
150  }
151 
157  bool operator!=(const value_type& rhs) const {
158  return value != rhs;
159  }
160 
165  operator const_raw_reference_type&() const {
166  return value;
167  }
168 
175  friend std::ostream& operator<<(std::ostream& os, const hermitian_reference& ref) {
176  typename M::value_type c = ref;
177  return os << c;
178  }
179 };
180 
184 template <typename M>
185 inline typename M::value_type get_conj(const hermitian_reference<M>& ref) {
186  typename M::value_type c = ref;
187  using etl::get_conj;
188  return get_conj(c);
189 }
190 
191 } //end of namespace herm_detail
192 
193 } //end of namespace etl
value_type * raw_pointer_type
A raw pointer type.
Definition: hermitian_reference.hpp:26
bool operator!=(const hermitian_reference &rhs) const
Test if the hermitian reference value is not equals to the given value.
Definition: hermitian_reference.hpp:139
value_t< sub_type > value_type
The value contained in the expression.
Definition: dyn_matrix_view.hpp:31
value_type & sym_value
Reference to the symmetric value.
Definition: hermitian_reference.hpp:35
M expr_t
The hermitian matrix.
Definition: hermitian_reference.hpp:29
size_t j
The second index.
Definition: hermitian_reference.hpp:33
bool operator!=(const value_type &rhs) const
Test if the hermitian reference value is not equals to the given value.
Definition: hermitian_reference.hpp:157
hermitian_reference & operator/=(value_type rhs)
Divide by a new value the proxy reference.
Definition: hermitian_reference.hpp:104
hermitian_reference & operator=(const value_type &rhs)
Sets a new value to the proxy reference.
Definition: hermitian_reference.hpp:52
hermitian_reference & operator%=(value_type rhs)
Modulo by a new value the proxy reference.
Definition: hermitian_reference.hpp:117
Root namespace for the ETL library.
Definition: adapter.hpp:15
bool operator==(const hermitian_reference &rhs) const
Test if the hermitian reference value is equals to the given value.
Definition: hermitian_reference.hpp:130
M matrix_type
The matrix type.
Definition: hermitian_reference.hpp:24
value_type & raw_reference_type
A raw reference type.
Definition: hermitian_reference.hpp:27
A proxy representing a reference to a mutable element of an hermitian matrix.
Definition: hermitian_reference.hpp:23
typename matrix_type::value_type value_type
The value type.
Definition: hermitian_reference.hpp:25
std::complex< T > get_conj(const std::complex< T > &c)
Returns the conjugate of the given complex number.
Definition: complex.hpp:555
bool operator==(const value_type &rhs) const
Test if the hermitian reference value is equals to the given value.
Definition: hermitian_reference.hpp:148
value_type & value
Reference to the value.
Definition: hermitian_reference.hpp:34
hermitian_reference(matrix_type &matrix, size_t i, size_t j)
Constructs a new hermitian_reference.
Definition: hermitian_reference.hpp:43
matrix_type & matrix
Reference to the matrix.
Definition: hermitian_reference.hpp:31
hermitian_reference & operator+=(value_type rhs)
Adds a new value to the proxy reference.
Definition: hermitian_reference.hpp:65
friend std::ostream & operator<<(std::ostream &os, const hermitian_reference &ref)
Outputs an hermitian reference to the stream.
Definition: hermitian_reference.hpp:175
hermitian_reference & operator-=(value_type rhs)
Subtract a new value from the proxy reference.
Definition: hermitian_reference.hpp:78
hermitian_reference & operator*=(value_type rhs)
Multiply by a new value the proxy reference.
Definition: hermitian_reference.hpp:91
size_t i
The first index.
Definition: hermitian_reference.hpp:32
std::add_const_t< value_type > & const_raw_reference_type
A raw reference type.
Definition: hermitian_reference.hpp:28