No-data policies#
No-data values are used to signal the absence of a valid value to use in a computation. Various conventions exist to do this. To support these conventions, algorithms can make use of input and output no-data policies. Depending on the policies used when instantiating an algorithm, it will use a specific concrete convention. A single application can support multiple conventions.
Often a special value is used to mark no-data. This special value is then dependent on the element type. In
case of floating point values, NaN
is a popular option to represent no-data. In case of signed integral
values, std::numeric_limits<Element>::min
is an option, and in case of unsigned integral values,
std::numeric_limits<Element>::max
. But other conventions exist as well.
Conventions for how to represent no-data values differ per software package. By making this decision configurable at compile-time, LUE can support most of them, without sacrificing performance.
Input no-data#
An input no-data policy is any class that provides an interface similar to the following class:
template<typename Element>
class InputNoDataPolicy
{
public:
auto is_no_data(Element const& value) -> bool;
template<typename Data, typename... Idxs>
auto is_no_data(Data const& data, Idxs const... idx) -> bool;
};
The policy is used to check whether input element values contain no-data. Often, algorithms will want to treat such elements differently. For example, in case of a focal operation, no-data values within the focal window may have to be skipped from the computation of the result value.
The lue::policy::SkipNoData
policy is special in that it does not perform any check at all. This
policy can be used when it is guaranteed that none of the input elements will contain a no-data value. An
optimizing compiler will completely remove the “check” from the code.
-
template<typename Element>
class SkipNoData# Input no-data policy that does nothing.
Use this policy if you do not want to check for no-data values in the input.
See also
DontMarkNoData
Subclassed by lue::policy::DontMarkNoData< Element >
Public Static Functions
-
static inline constexpr auto is_no_data([[maybe_unused]] Element const &value) -> bool#
Return whether element contains no-data.
This function always returns
false
.
-
template<typename Data, typename ...Idxs>
static inline constexpr auto is_no_data([[maybe_unused]] Data const &data, [[maybe_unused]] Idxs const... idx) -> bool# Return whether the element at index idx in data contains no-data.
This function always returns
false
.- Template Parameters:
Data – Collection of elements
-
static inline constexpr auto is_no_data([[maybe_unused]] Element const &value) -> bool#
-
template<typename Element>
class DetectNoDataByValue# Input no-data policy.
Policy suitable for those cases where no-data is represented by some “special” value, like a minimum value, maximum value, or a very small value.
See also
MarkNoDataByValue, DetectNoDataByNaN
Warning
Don’t use this policy when Element is a floating point type and when the no-data value must be represented by a NaN
Subclassed by lue::policy::MarkNoDataByValue< Element >
Public Functions
-
inline DetectNoDataByValue()#
Construct an instance, using the default DetectNoDataByValue::no_data_value as the no-data value in tests.
-
inline DetectNoDataByValue(Element const value)#
Construct an instance, using value as the no-data value in tests.
Warning
If Element is a floating point type, value must not by NaN
Public Static Attributes
- static constexpr Element no_data_value {[](){static_assert(std::is_floating_point_v<Element> || std::is_integral_v<Element>);if constexpr (std::is_integral_v<Element> && std::is_signed_v<Element>){return std::numeric_limits<Element>::min();}else if constexpr (std::is_integral_v<Element> && std::is_unsigned_v<Element>){return std::numeric_limits<Element>::max();}else if constexpr (std::is_floating_point_v<Element>){return std::numeric_limits<Element>::lowest();}}()}
The default no-data value to use in tests.
These values are used, depending on Element:
Type
value
signed integral
std::numeric_limits<Element>::min()
unsigned integral
std::numeric_limits<Element>::max()
floating point
std::numeric_limits<Element>::lowest()
-
inline DetectNoDataByValue()#
-
template<typename Element>
class DetectNoDataByNaN# Input no-data policy.
Policy to use when Element is a floating point type and NaN is used to represent no-data values.
See also
MarkNoDataByNaN, DetectNoDataByValue
Subclassed by lue::policy::MarkNoDataByNaN< Element >
Output no-data#
An output no-data policy is any class that provides an interface similar to the following class:
template<typename Element>
class OutputNoDataPolicy
{
public:
void mark_no_data(Element& value)
template<typename Data, typename... Idxs>
void mark_no_data(Data& data, Idxs const... idx);
};
The policy is used to mark a result element of an algorithm as no-data. For example, in case of the sqrt
algorithm, when the domain policy detected that an input element
value is not within the domain of valid input values (is negative in this case), then mark_no_data
should
mark the result element as no-data.
The lue::policy::DontMarkNoData
policy is special in that it does not mark any result element as
no-data. This policy can be used when it is guaranteed that marking no-data is never needed. An optimizing
compiler will completely remove the “marking” from the code.
-
template<typename Element>
class DontMarkNoData : public lue::policy::SkipNoData<Element># Output no-data policy that does nothing.
Use this policy if you do not want to mark no-data values in the output.
See also
SkipNoData
-
template<typename Element>
class MarkNoDataByValue : public lue::policy::DetectNoDataByValue<Element># Output no-data policy.
Policy suitable for those cases where no-data is represented by some “special” value, like a minimum value, maximum value, or a very small value.
See also
DetectNoDataByValue, MarkNoDataByNaN
Public Functions
-
inline MarkNoDataByValue()#
Construct an instance, using the default DetectNoDataByValue::no_data_value as the no-data value.
-
inline MarkNoDataByValue(Element const value)#
Construct an instance, using value as the no-data value.
-
inline MarkNoDataByValue()#
-
template<typename Element>
class MarkNoDataByNaN : public lue::policy::DetectNoDataByNaN<Element># Output no-data policy.
Policy to use when Element is a floating point type and NaN is used to represent no-data values.
See also
DetectNoDataByNaN, MarkNoDataByValue