Expression Templates Library (ETL)
symmetric_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 sym_detail {
18 
23 template <typename M>
25  using matrix_type = M;
29  using const_raw_reference_type = std::add_const_t<value_type>&;
30  using expr_t = M;
31 
33  size_t i;
34  size_t j;
37 
44  symmetric_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)) {
45  //Nothing else to init
46  }
47 
54  value = rhs;
55  if (i != j) {
56  sym_value = rhs;
57  }
58  return *this;
59  }
60 
67  value += rhs;
68  if (i != j) {
69  sym_value += rhs;
70  }
71  return *this;
72  }
73 
80  value -= rhs;
81  if (i != j) {
82  sym_value -= rhs;
83  }
84  return *this;
85  }
86 
93  value *= rhs;
94  if (i != j) {
95  sym_value *= rhs;
96  }
97  return *this;
98  }
99 
106  value /= rhs;
107  if (i != j) {
108  sym_value /= rhs;
109  }
110  return *this;
111  }
112 
119  value %= rhs;
120  if (i != j) {
121  sym_value %= rhs;
122  }
123  return *this;
124  }
125 
130  operator const_raw_reference_type&() const {
131  return value;
132  }
133 };
134 
135 } //end of namespace sym_detail
136 
137 } //end of namespace etl
value_type & sym_value
Reference to the symmetric value.
Definition: symmetric_reference.hpp:36
symmetric_reference(matrix_type &matrix, size_t i, size_t j)
Constructs a new symmetric_reference.
Definition: symmetric_reference.hpp:44
value_t< sub_type > value_type
The value contained in the expression.
Definition: dyn_matrix_view.hpp:31
symmetric_reference & operator+=(value_type rhs)
Adds a new value to the proxy reference.
Definition: symmetric_reference.hpp:66
M matrix_type
The matrix type.
Definition: symmetric_reference.hpp:25
symmetric_reference & operator*=(value_type rhs)
Multiply by a new value the proxy reference.
Definition: symmetric_reference.hpp:92
symmetric_reference & operator%=(value_type rhs)
Modulo by a new value the proxy reference.
Definition: symmetric_reference.hpp:118
size_t i
The first index.
Definition: symmetric_reference.hpp:33
Root namespace for the ETL library.
Definition: adapter.hpp:15
symmetric_reference & operator=(const value_type &rhs)
Sets a new value to the proxy reference.
Definition: symmetric_reference.hpp:53
value_type & value
Reference to the value.
Definition: symmetric_reference.hpp:35
matrix_type & matrix
Reference to the matrix.
Definition: symmetric_reference.hpp:32
A proxy representing a reference to a mutable element of a symmetric matrix.
Definition: symmetric_reference.hpp:24
typename matrix_type::value_type value_type
The value type.
Definition: symmetric_reference.hpp:26
std::add_const_t< value_type > & const_raw_reference_type
A raw reference type.
Definition: symmetric_reference.hpp:29
symmetric_reference & operator-=(value_type rhs)
Subtract a new value from the proxy reference.
Definition: symmetric_reference.hpp:79
size_t j
The second index.
Definition: symmetric_reference.hpp:34
value_type * raw_pointer_type
A raw pointer type.
Definition: symmetric_reference.hpp:27
M expr_t
The symmetric matrix.
Definition: symmetric_reference.hpp:30
symmetric_reference & operator/=(value_type rhs)
Divide by a new value the proxy reference.
Definition: symmetric_reference.hpp:105
value_type & raw_reference_type
A raw reference type.
Definition: symmetric_reference.hpp:28