etl/docs/maths/threshold.md
2026-04-16 12:40:36 +02:00

972 B

title
threshold

{{< callout type="info">}} Header: threshold.h
Since: 20.9.0
{{< /callout >}}

template <typename TInput, typename TCompare = etl::less<TInput> >
class threshold : public etl::unary_function<TInput, TInput>

TInput The input data type.
TCompare The functor type used to compare values to the threshold. The default is etl::less.


threshold(TInput   threshold_value, 
          TInput   true_value, 
          TInput   false_value, 
          TCompare compare = TCompare())

Description
Constructor.


TInput operator()(TInput value) const

Threshold a value.

Example

std::array<int, 10> input
{
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9
};

std::array<int, 10> output;

etl::threshold<int> threshold(4, 0, 9); // Compares each value to 4 and output 0 or 9.

std::transform(input.begin(), input.end(), output.begin(), threshold);

// output == 0, 0, 0, 0, 9, 9, 9, 9, 9, 9