Expression Templates Library (ETL)
strictly_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 strictly_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  strictly_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(0)) {
54  value = rhs;
55  } else {
57  }
58 
59  return *this;
60  }
61 
68  if (i < j || rhs == value_type(0)) {
69  value += rhs;
70  } else {
72  }
73 
74  return *this;
75  }
76 
83  if (i < j || rhs == value_type(0)) {
84  value -= rhs;
85  } else {
87  }
88 
89  return *this;
90  }
91 
98  if (i < j || rhs == value_type(1)) {
99  value *= rhs;
100  } else {
101  throw strictly_upper_exception();
102  }
103 
104  return *this;
105  }
106 
113  if (i < j || rhs == value_type(1)) {
114  value /= rhs;
115  } else {
116  throw strictly_upper_exception();
117  }
118 
119  return *this;
120  }
121 
128  if (i < j || (value % rhs) == value_type(0)) {
129  value %= rhs;
130  } else {
131  throw strictly_upper_exception();
132  }
133 
134  return *this;
135  }
136 
141  operator const_raw_reference_type&() const {
142  return value;
143  }
144 };
145 
146 } // namespace strictly_upper_detail
147 
148 } //end of namespace etl
matrix_type & matrix
Reference to the matrix.
Definition: strictly_upper_reference.hpp:32
strictly_upper_reference(matrix_type &matrix, size_t i, size_t j)
Constructs a new strictly_upper_reference.
Definition: strictly_upper_reference.hpp:43
strictly_upper_reference & operator-=(value_type rhs)
Subtract a new value from the proxy reference.
Definition: strictly_upper_reference.hpp:82
value_t< sub_type > value_type
The value contained in the expression.
Definition: dyn_matrix_view.hpp:31
M matrix_type
The matrix type.
Definition: strictly_upper_reference.hpp:25
typename matrix_type::value_type value_type
The value type.
Definition: strictly_upper_reference.hpp:26
Exception that is thrown when an operation is made to a strictly upper triangular matrix that would r...
Definition: strictly_upper_exception.hpp:24
value_type * raw_pointer_type
A raw pointer type.
Definition: strictly_upper_reference.hpp:27
value_type & raw_reference_type
A raw reference type.
Definition: strictly_upper_reference.hpp:28
strictly_upper_reference & operator%=(value_type rhs)
Modulo by a new value the proxy reference.
Definition: strictly_upper_reference.hpp:127
Root namespace for the ETL library.
Definition: adapter.hpp:15
size_t j
The second index.
Definition: strictly_upper_reference.hpp:34
M expr_t
The upper triangular matrix.
Definition: strictly_upper_reference.hpp:30
strictly_upper_reference & operator/=(value_type rhs)
Divide by a new value the proxy reference.
Definition: strictly_upper_reference.hpp:112
value_type & value
Reference to the value.
Definition: strictly_upper_reference.hpp:35
A proxy representing a reference to a mutable element of a strictly upper triangular matrix...
Definition: strictly_upper_reference.hpp:24
std::add_const_t< value_type > & const_raw_reference_type
A raw reference type.
Definition: strictly_upper_reference.hpp:29
strictly_upper_reference & operator+=(value_type rhs)
Adds a new value to the proxy reference.
Definition: strictly_upper_reference.hpp:67
strictly_upper_reference & operator*=(value_type rhs)
Multiply by a new value the proxy reference.
Definition: strictly_upper_reference.hpp:97
size_t i
The first index.
Definition: strictly_upper_reference.hpp:33
strictly_upper_reference & operator=(const value_type &rhs)
Sets a new value to the proxy reference.
Definition: strictly_upper_reference.hpp:52