Expression Templates Library (ETL)
uni_upper_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 uni_upper_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;
36 
43  uni_upper_reference(matrix_type& matrix, size_t i, size_t j) : matrix(matrix), i(i), j(j), value(matrix(i, j)) {
44  //Nothing else to init
45  }
46 
53  if (i == j && rhs == value_type(1)) {
54  value = rhs;
55  } else if (i < j || rhs == value_type(0)) {
56  value = rhs;
57  } else {
58  throw uni_upper_exception();
59  }
60 
61  return *this;
62  }
63 
70  if (i == j && rhs == value_type(0)) {
71  value += rhs;
72  } else if (i < j || rhs == value_type(0)) {
73  value += rhs;
74  } else {
75  throw uni_upper_exception();
76  }
77 
78  return *this;
79  }
80 
87  if (i == j && rhs == value_type(0)) {
88  value -= rhs;
89  } else if (i < j || rhs == value_type(0)) {
90  value -= rhs;
91  } else {
92  throw uni_upper_exception();
93  }
94 
95  return *this;
96  }
97 
104  if (i == j && rhs == value_type(1)) {
105  value *= rhs;
106  } else if (i < j || rhs == value_type(1)) {
107  value *= rhs;
108  } else {
109  throw uni_upper_exception();
110  }
111 
112  return *this;
113  }
114 
121  if (i == j && rhs == value_type(1)) {
122  value /= rhs;
123  } else if (i < j || rhs == value_type(1)) {
124  value /= rhs;
125  } else {
126  throw uni_upper_exception();
127  }
128 
129  return *this;
130  }
131 
138  if (i == j && rhs == value_type(0)) {
139  value %= rhs;
140  } else if (i < j || (value % rhs) == value_type(0)) {
141  value %= rhs;
142  } else {
143  throw uni_upper_exception();
144  }
145 
146  return *this;
147  }
148 
153  operator const_raw_reference_type&() const {
154  return value;
155  }
156 };
157 
158 } //end of namespace uni_upper_detail
159 
160 } //end of namespace etl
std::add_const_t< value_type > & const_raw_reference_type
A raw reference type.
Definition: uni_upper_reference.hpp:29
matrix_type & matrix
Reference to the matrix.
Definition: uni_upper_reference.hpp:32
value_t< sub_type > value_type
The value contained in the expression.
Definition: dyn_matrix_view.hpp:31
M expr_t
The uni upper triangular matrix.
Definition: uni_upper_reference.hpp:30
uni_upper_reference & operator+=(value_type rhs)
Adds a new value to the proxy reference.
Definition: uni_upper_reference.hpp:69
value_type & value
Reference to the value.
Definition: uni_upper_reference.hpp:35
A proxy representing a reference to a mutable element of a uni upper triangular matrix.
Definition: uni_upper_reference.hpp:24
size_t i
The first index.
Definition: uni_upper_reference.hpp:33
Root namespace for the ETL library.
Definition: adapter.hpp:15
size_t j
The second index.
Definition: uni_upper_reference.hpp:34
value_type & raw_reference_type
A raw reference type.
Definition: uni_upper_reference.hpp:28
uni_upper_reference & operator=(const value_type &rhs)
Sets a new value to the proxy reference.
Definition: uni_upper_reference.hpp:52
uni_upper_reference(matrix_type &matrix, size_t i, size_t j)
Constructs a new uni_upper_reference.
Definition: uni_upper_reference.hpp:43
uni_upper_reference & operator*=(value_type rhs)
Multiply by a new value the proxy reference.
Definition: uni_upper_reference.hpp:103
uni_upper_reference & operator-=(value_type rhs)
Subtract a new value from the proxy reference.
Definition: uni_upper_reference.hpp:86
value_type * raw_pointer_type
A raw pointer type.
Definition: uni_upper_reference.hpp:27
uni_upper_reference & operator/=(value_type rhs)
Divide by a new value the proxy reference.
Definition: uni_upper_reference.hpp:120
M matrix_type
The matrix type.
Definition: uni_upper_reference.hpp:25
typename matrix_type::value_type value_type
The value type.
Definition: uni_upper_reference.hpp:26
Exception that is thrown when an operation is made to a uni upper triangular matrix that would render...
Definition: uni_upper_exception.hpp:24
uni_upper_reference & operator%=(value_type rhs)
Modulo by a new value the proxy reference.
Definition: uni_upper_reference.hpp:137