Expression Templates Library (ETL)
value_testable.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 template <typename E>
18 bool is_diagonal(E&& expr);
19 
25 template <typename D>
27  using derived_t = D;
28 
33  derived_t& as_derived() noexcept {
34  return *static_cast<derived_t*>(this);
35  }
36 
41  const derived_t& as_derived() const noexcept {
42  return *static_cast<const derived_t*>(this);
43  }
44 
49  bool is_finite() const noexcept {
50  return std::all_of(as_derived().begin(), as_derived().end(), static_cast<bool (*)(value_t<derived_t>)>(std::isfinite));
51  }
52 
57  bool is_zero() const noexcept {
58  return std::all_of(as_derived().begin(), as_derived().end(), [](value_t<derived_t> v) { return v == value_t<derived_t>(0); });
59  }
60 
65  bool is_diagonal() const noexcept {
66  return etl::is_diagonal(as_derived());
67  }
68 
73  bool is_uniform() const noexcept {
74  return etl::is_uniform(as_derived());
75  }
76 };
77 
78 } //end of namespace etl
const derived_t & as_derived() const noexcept
Returns a reference to the derived object, i.e. the object using the CRTP injector.
Definition: value_testable.hpp:41
bool is_finite() const noexcept
Indicates if the expression contains only finite values.
Definition: value_testable.hpp:49
bool is_uniform(E &&expr)
Indicates if the given expression is uniform (all elements of the same value)
Definition: globals.hpp:90
bool is_diagonal() const noexcept
Indicates if the expression is diagonal.
Definition: value_testable.hpp:65
bool is_zero() const noexcept
Indicates if the expression contains only zero values.
Definition: value_testable.hpp:57
D D
The number of dimensions.
Definition: dyn_matrix_view.hpp:24
An unary expression.
Definition: unary_expr.hpp:126
CRTP class to inject functions testing values of the expressions.
Definition: value_testable.hpp:26
Root namespace for the ETL library.
Definition: adapter.hpp:15
bool is_diagonal(E &&expr)
Indicates if the given expression is a diagonal matrix or not.
Definition: adapters.hpp:318
bool is_uniform() const noexcept
Indicates if the expression is uniform, i.e. all elements are of the same value.
Definition: value_testable.hpp:73
derived_t & as_derived() noexcept
Returns a reference to the derived object, i.e. the object using the CRTP injector.
Definition: value_testable.hpp:33
typename decay_traits< E >::value_type value_t
Traits to extract the value type out of an ETL type.
Definition: tmp.hpp:81