Expression Templates Library (ETL)
one_if.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 #pragma once
9 
10 namespace etl {
11 
15 template <typename T, typename E>
17  static constexpr bool linear = true;
18  static constexpr bool thread_safe = true;
19  static constexpr bool desc_func = true;
20 
26  template <vector_mode_t V>
27  static constexpr bool vectorizable = false;
28 
32  template <typename L, typename R>
33  static constexpr bool gpu_computable = false;
34 
39  static constexpr int complexity() {
40  return 1;
41  }
42 
49  static constexpr T apply(const T& x, E value) noexcept {
50  return x == value ? 1.0 : 0.0;
51  }
52 
57  static std::string desc() noexcept {
58  return "one_if";
59  }
60 };
61 
62 } //end of namespace etl
Binary operator to get 1.0 if x equals to rhs value, 0 otherwise.
Definition: one_if.hpp:16
static constexpr int complexity()
Estimate the complexity of operator.
Definition: one_if.hpp:39
static constexpr bool gpu_computable
Indicates if the operator can be computed on GPU.
Definition: one_if.hpp:33
static constexpr bool linear
Indicates if the operator is linear or not.
Definition: one_if.hpp:17
static constexpr bool vectorizable
Indicates if the expression is vectorizable using the given vector mode.
Definition: one_if.hpp:27
static constexpr bool desc_func
Indicates if the description must be printed as function.
Definition: one_if.hpp:19
Root namespace for the ETL library.
Definition: adapter.hpp:15
static constexpr T apply(const T &x, E value) noexcept
Apply the unary operator on lhs and rhs.
Definition: one_if.hpp:49
static std::string desc() noexcept
Returns a textual representation of the operator.
Definition: one_if.hpp:57
static constexpr bool thread_safe
Indicates if the operator is thread safe or not.
Definition: one_if.hpp:18