Expression Templates Library (ETL)
dim_testable.hpp
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 
8 /*
9  * \file dim_testable.hpp
10  * \brief Use CRTP technique to inject functions that test the dimensions.
11  */
12 
13 #pragma once
14 
15 namespace etl {
16 
17 template <typename E>
18 bool is_symmetric(E&& expr);
19 
20 template <typename E>
21 bool is_triangular(E&& expr);
22 
23 template <typename E>
24 bool is_lower_triangular(E&& expr);
25 
26 template <typename E>
27 bool is_upper_triangular(E&& expr);
28 
29 template <typename E>
30 bool is_strictly_lower_triangular(E&& expr);
31 
32 template <typename E>
33 bool is_strictly_upper_triangular(E&& expr);
34 
35 template <typename E>
36 bool is_uni_lower_triangular(E&& expr);
37 
38 template <typename E>
39 bool is_uni_upper_triangular(E&& expr);
40 
44 template <typename D>
45 struct dim_testable {
46  using derived_t = D;
47 
52  derived_t& as_derived() noexcept {
53  return *static_cast<derived_t*>(this);
54  }
55 
60  const derived_t& as_derived() const noexcept {
61  return *static_cast<const derived_t*>(this);
62  }
63 
68  bool is_square() const noexcept {
69  return etl::is_square(as_derived());
70  }
71 
76  bool is_rectangular() const noexcept {
78  }
79 
84  bool is_sub_square() const noexcept {
86  }
87 
92  bool is_sub_rectangular() const noexcept {
94  }
95 
100  bool is_symmetric() const noexcept {
101  return etl::is_symmetric(as_derived());
102  }
103 
108  bool is_lower_triangular() const noexcept {
110  }
111 
116  bool is_uni_lower_triangular() const noexcept {
118  }
119 
124  bool is_strictly_lower_triangular() const noexcept {
126  }
127 
132  bool is_upper_triangular() const noexcept {
134  }
135 
140  bool is_uni_upper_triangular() const noexcept {
142  }
143 
148  bool is_strictly_upper_triangular() const noexcept {
150  }
151 
156  bool is_triangular() const noexcept {
157  return etl::is_triangular(as_derived());
158  }
159 };
160 
161 } //end of namespace etl
bool is_triangular(E &&expr)
Indicates if the given expression is a triangular matrix or not.
Definition: adapters.hpp:308
bool is_sub_square(E &&expr)
Indicates if the given expression contains sub matrices that are square.
Definition: globals.hpp:70
bool is_rectangular() const noexcept
Indicates if the expressions is of rectangular dimensions (only for 2d expression) ...
Definition: dim_testable.hpp:76
bool is_upper_triangular() const noexcept
Indicates if the given expression is a upper triangular matrix or not.
Definition: dim_testable.hpp:132
D D
The number of dimensions.
Definition: dyn_matrix_view.hpp:24
bool is_symmetric() const noexcept
Indicates if the given expression is a symmetric matrix or not.
Definition: dim_testable.hpp:100
bool is_triangular() const noexcept
Indicates if the given expression is a triangular matrix or not.
Definition: dim_testable.hpp:156
bool is_lower_triangular(E &&expr)
Indicates if the given expression is a lower triangular matrix or not.
Definition: adapters.hpp:114
An unary expression.
Definition: unary_expr.hpp:126
Root namespace for the ETL library.
Definition: adapter.hpp:15
bool is_uni_upper_triangular() const noexcept
Indicates if the given expression is a uni upper triangular matrix or not.
Definition: dim_testable.hpp:140
bool is_sub_rectangular() const noexcept
Indicates if the expressions is of rectangular dimensions, ignoring the first dimension (only for 3d ...
Definition: dim_testable.hpp:92
bool is_sub_square() const noexcept
Indicates if the expressions is of square dimensions, ignoring the first dimension (only for 3d expre...
Definition: dim_testable.hpp:84
bool is_uni_lower_triangular(E &&expr)
Indicates if the given expression is a uni lower triangular matrix or not.
Definition: adapters.hpp:153
bool is_symmetric(E &&expr)
Indicates if the given expression is a symmetric matrix or not.
Definition: adapters.hpp:87
bool is_strictly_upper_triangular() const noexcept
Indicates if the given expression is a strictly upper triangular matrix or not.
Definition: dim_testable.hpp:148
bool is_square(E &&expr)
Indicates if the given expression is a square matrix or not.
Definition: globals.hpp:30
bool is_upper_triangular(E &&expr)
Indicates if the given expression is a upper triangular matrix or not.
Definition: adapters.hpp:211
bool is_strictly_lower_triangular() const noexcept
Indicates if the given expression is a strictly lower triangular matrix or not.
Definition: dim_testable.hpp:124
bool is_sub_rectangular(E &&expr)
Indicates if the given expression contains sub matrices that are rectangular.
Definition: globals.hpp:80
bool is_uni_lower_triangular() const noexcept
Indicates if the given expression is a uni lower triangular matrix or not.
Definition: dim_testable.hpp:116
bool is_rectangular(E &&expr)
Indicates if the given expression is a rectangular matrix or not.
Definition: globals.hpp:60
bool is_square() const noexcept
Indicates if the expressions is of square dimensions (only for 2d expression)
Definition: dim_testable.hpp:68
bool is_uni_upper_triangular(E &&expr)
Indicates if the given expression is a strictly upper triangular matrix or not.
Definition: adapters.hpp:250
derived_t & as_derived() noexcept
Returns a reference to the derived object, i.e. the object using the CRTP injector.
Definition: dim_testable.hpp:52
bool is_lower_triangular() const noexcept
Indicates if the given expression is a lower triangular matrix or not.
Definition: dim_testable.hpp:108
const derived_t & as_derived() const noexcept
Returns a reference to the derived object, i.e. the object using the CRTP injector.
Definition: dim_testable.hpp:60
bool is_strictly_lower_triangular(E &&expr)
Indicates if the given expression is a strictly lower triangular matrix or not.
Definition: adapters.hpp:184
CRTP class to inject functions testing the dimensions.
Definition: dim_testable.hpp:45
bool is_strictly_upper_triangular(E &&expr)
Indicates if the given expression is a strictly upper triangular matrix or not.
Definition: adapters.hpp:281