23namespace vctr::expressions
26template <
size_t extent,
class SrcType, is::constantWithType<
bool> ClampLow, is::constantWithType<
bool> ClampHigh>
32 VCTR_COMMON_UNARY_EXPRESSION_MEMBERS (
Clamp, src)
34 static constexpr bool clampLow = ClampLow::value;
35 static constexpr bool clampHigh = ClampHigh::value;
37 void applyRuntimeArgs (value_type newLowerBound, value_type newUpperBound)
39 lowerBound = newLowerBound;
40 upperBound = newUpperBound;
43 VCTR_FORCEDINLINE
constexpr value_type operator[] (
size_t i)
const
48 return std::clamp (src[i], lowerBound, upperBound);
51 return std::max (src[i], lowerBound);
54 return std::min (src[i], upperBound);
59 VCTR_FORCEDINLINE
const value_type* evalNextVectorOpInExpressionChain (value_type* dst)
const
65 Expression::Accelerate::clampLow (src.evalNextVectorOpInExpressionChain (dst), lowerBound, dst, size());
69 auto l =
clampLow ? lowerBound : std::numeric_limits<value_type>::lowest();
70 Expression::Accelerate::clamp (src.evalNextVectorOpInExpressionChain (dst), l, upperBound, dst, size());
76 VCTR_FORCEDINLINE
const value_type* evalNextVectorOpInExpressionChain (value_type* dst)
const
80 const auto* s = src.evalNextVectorOpInExpressionChain (dst);
84 Expression::IPP::clampLow (s, lowerBound, dst,
sizeToInt (size()));
91 Expression::IPP::clampHigh (s, upperBound, dst,
sizeToInt (size()));
97 void assertBoundsAreSet()
const
102 VCTR_ASSERT (lowerBound != std::numeric_limits<value_type>::max());
105 VCTR_ASSERT (upperBound != std::numeric_limits<value_type>::max());
108 value_type lowerBound = std::numeric_limits<value_type>::max();
109 value_type upperBound = std::numeric_limits<value_type>::max();
112template <
size_t extent,
class SrcType>
115template <
size_t extent,
class SrcType>
118template <
size_t extent,
class SrcType>
121template <
size_t extent,
class SrcType, is::constant LowerBound, is::constant UpperBound>
127 static constexpr value_type lowerBound = LowerBound::value;
128 static constexpr value_type upperBound = UpperBound::value;
135 VCTR_FORCEDINLINE
constexpr value_type operator[] (
size_t i)
const
138 return std::clamp (src[i], lowerBound, upperBound);
141 return std::max (src[i], lowerBound);
144 return std::min (src[i], upperBound);
146 return std::max (lowerBound, src[i]);
151 VCTR_FORCEDINLINE
const value_type* evalNextVectorOpInExpressionChain (value_type* dst)
const
155 Expression::Accelerate::clampLow (src.evalNextVectorOpInExpressionChain (dst), lowerBound, dst, size());
159 auto l =
clampLow ? lowerBound : std::numeric_limits<value_type>::lowest();
160 Expression::Accelerate::clamp (src.evalNextVectorOpInExpressionChain (dst), l, upperBound, dst, size());
166 VCTR_FORCEDINLINE
const value_type* evalNextVectorOpInExpressionChain (value_type* dst)
const
169 const auto* s = src.evalNextVectorOpInExpressionChain (dst);
173 Expression::IPP::clampLow (s, lowerBound, dst,
sizeToInt (size()));
180 Expression::IPP::clampHigh (s, upperBound, dst,
sizeToInt (size()));
201 return makeExpressionChainBuilderWithRuntimeArgs<expressions::ClampLow> (lowerBound, std::numeric_limits<T>::max());
214 return makeExpressionChainBuilderWithRuntimeArgs<expressions::ClampHigh> (std::numeric_limits<T>::max(), upperBound);
225constexpr auto clamp (T lowerBound, T upperBound)
227 return makeExpressionChainBuilderWithRuntimeArgs<expressions::ClampLowHigh> (lowerBound, upperBound);
240template <auto lowerBound>
251template <auto upperBound>
262template <auto lowerBound, auto upperBound>
Constrains a type to be of the type DisabledConstant.
Definition: NumericTypeConcepts.h:91
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:242
A combined concept to check if Intel IPP is a suitable option for a real valued floating point vector...
Definition: ContainerAndExpressionConcepts.h:266
constexpr ExpressionChainBuilder< expressions::ClampByConstant, DisabledConstant, Constant< upperBound > > clampHighByConstant
Ensures that the elements are not higher than upperBound.
Definition: Clamp.h:252
constexpr auto clampLow(T lowerBound)
Ensures that the elements are not lower than lowerBound.
Definition: Clamp.h:199
constexpr ExpressionChainBuilder< expressions::ClampByConstant, Constant< lowerBound >, Constant< upperBound > > clampByConstant
Ensures that the elements are not lower than lowerBound and not higher than upperBound.
Definition: Clamp.h:263
constexpr auto clampHigh(T upperBound)
Ensures that the elements are not greater than upperBound.
Definition: Clamp.h:212
constexpr ExpressionChainBuilder< expressions::ClampByConstant, Constant< lowerBound >, DisabledConstant > clampLowByConstant
Ensures that the elements are not lower than lowerBound.
Definition: Clamp.h:241
constexpr auto clamp(T lowerBound, T upperBound)
Ensures that the elements are not lower than lowerBound and not higher than upperBound.
Definition: Clamp.h:225
The main namespace of the VCTR project.
Definition: Array.h:24
typename detail::ValueType< std::remove_cvref_t< T > >::Type ValueType
If T is an expression template, it equals its return type, if it's a type that defines value_type as ...
Definition: Traits.h:201
int sizeToInt(size_t size)
Casts the size_t argument to an int.
Definition: PlatformVectorOpsHelpers.h:27
A simple helper struct to pass a constant as argument wrapped in a struct with a single public static...
Definition: ExpressionChainBuilder.h:104
A helper struct to indicate that a constant template should be considered disabled.
Definition: ExpressionChainBuilder.h:110
An expression chain builder is an object which supplies various operator<< overloads which build chai...
Definition: ExpressionChainBuilder.h:136
The base class to every expression template.
Definition: ExpressionTemplate.h:37