Reference documentation for deal.II version 9.6.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
FloatingPointComparator< Number > Struct Template Reference

#include <deal.II/base/floating_point_comparator.h>

Public Types

enum class  ComparisonResult { less , equal , greater }
 
using ScalarNumber
 

Public Member Functions

 FloatingPointComparator (const ScalarNumber tolerance, const bool use_absolute_tolerance=true, const std::bitset< width > &mask=std::bitset< width >().flip())
 
 FloatingPointComparator (const FloatingPointComparator &rhs)=default
 
 FloatingPointComparator (FloatingPointComparator &&rhs) noexcept=default
 
template<typename T >
bool operator() (const T &object1, const T &object2) const
 
template<typename T >
ComparisonResult compare (const std::vector< T > &v1, const std::vector< T > &v2) const
 
template<std::size_t dim, typename T >
ComparisonResult compare (const std::array< T, dim > &t1, const std::array< T, dim > &t2) const
 
template<int rank, int dim, typename T >
ComparisonResult compare (const Tensor< rank, dim, T > &t1, const Tensor< rank, dim, T > &t2) const
 
template<int rank, int dim, int spacedim, typename T >
ComparisonResult compare (const DerivativeForm< rank, dim, spacedim, T > &t1, const DerivativeForm< rank, dim, spacedim, T > &t2) const
 
template<typename T >
ComparisonResult compare (const Table< 2, T > &t1, const Table< 2, T > &t2) const
 
ComparisonResult compare (const ScalarNumber s1, const ScalarNumber s2) const
 
ComparisonResult compare (const VectorizedArray< ScalarNumber, width > &v1, const VectorizedArray< ScalarNumber, width > &v2) const
 

Static Public Attributes

static constexpr std::size_t width
 

Private Attributes

const ScalarNumber tolerance
 
const bool use_absolute_tolerance
 
const std::bitset< widthmask
 

Detailed Description

template<typename Number>
struct FloatingPointComparator< Number >

A class that is used to compare floating point arrays (e.g. std::vector, Tensor<1,dim>, etc.). The most common use case of this comparator is for detecting arrays with the same content for the sake of compression. The idea of this class is to consider two arrays as equal if they are the same within a given tolerance. We use this comparator class within a std::map<> of the given arrays. Note that this comparison operator does not satisfy all the mathematical properties one usually wants to have (consider e.g. the numbers a=0, b=0.1, c=0.2 with tolerance 0.15; the operator gives a<c, but neither a<b? nor b<c? is satisfied). This is not a problem in the use cases for this class, but be careful when using it in other contexts.

Definition at line 44 of file floating_point_comparator.h.

Member Typedef Documentation

◆ ScalarNumber

template<typename Number >
using FloatingPointComparator< Number >::ScalarNumber
Initial value:
typename ::internal::VectorizedArrayTrait<Number>::value_type

Definition at line 46 of file floating_point_comparator.h.

Member Enumeration Documentation

◆ ComparisonResult

template<typename Number >
enum class FloatingPointComparator::ComparisonResult
strong

An enum to decode whether a particular comparison returns less, larger, or equal. This is needed beyond the regular operator() because of efficiency reasons in nested checks as supported by this class.

Enumerator
less 
equal 
greater 

Definition at line 56 of file floating_point_comparator.h.

Constructor & Destructor Documentation

◆ FloatingPointComparator() [1/3]

template<typename Number >
FloatingPointComparator< Number >::FloatingPointComparator ( const ScalarNumber tolerance,
const bool use_absolute_tolerance = true,
const std::bitset< width > & mask = std::bitset<width>().flip() )

Constructor.

Definition at line 147 of file floating_point_comparator.h.

◆ FloatingPointComparator() [2/3]

template<typename Number >
FloatingPointComparator< Number >::FloatingPointComparator ( const FloatingPointComparator< Number > & rhs)
default

◆ FloatingPointComparator() [3/3]

template<typename Number >
FloatingPointComparator< Number >::FloatingPointComparator ( FloatingPointComparator< Number > && rhs)
defaultnoexcept

Member Function Documentation

◆ operator()()

template<typename Number >
template<typename T >
bool FloatingPointComparator< Number >::operator() ( const T & object1,
const T & object2 ) const

Compare two objects of the same type and return true in case the first object is less than the second one. This function calls the compare() functions below, so only types supported by compare() will work with this function.

Definition at line 163 of file floating_point_comparator.h.

◆ compare() [1/7]

template<typename Number >
template<typename T >
FloatingPointComparator< Number >::ComparisonResult FloatingPointComparator< Number >::compare ( const std::vector< T > & v1,
const std::vector< T > & v2 ) const

Compare two vectors of numbers (not necessarily of the same length), where vectors of different lengths are first sorted by their length and then by the entries.

Definition at line 174 of file floating_point_comparator.h.

◆ compare() [2/7]

template<typename Number >
template<std::size_t dim, typename T >
FloatingPointComparator< Number >::ComparisonResult FloatingPointComparator< Number >::compare ( const std::array< T, dim > & t1,
const std::array< T, dim > & t2 ) const

Compare two arrays.

Definition at line 197 of file floating_point_comparator.h.

◆ compare() [3/7]

template<typename Number >
template<int rank, int dim, typename T >
FloatingPointComparator< Number >::ComparisonResult FloatingPointComparator< Number >::compare ( const Tensor< rank, dim, T > & t1,
const Tensor< rank, dim, T > & t2 ) const

Compare two tensors.

Definition at line 214 of file floating_point_comparator.h.

◆ compare() [4/7]

template<typename Number >
template<int rank, int dim, int spacedim, typename T >
FloatingPointComparator< Number >::ComparisonResult FloatingPointComparator< Number >::compare ( const DerivativeForm< rank, dim, spacedim, T > & t1,
const DerivativeForm< rank, dim, spacedim, T > & t2 ) const

Compare two derivative forms.

Definition at line 231 of file floating_point_comparator.h.

◆ compare() [5/7]

template<typename Number >
template<typename T >
FloatingPointComparator< Number >::ComparisonResult FloatingPointComparator< Number >::compare ( const Table< 2, T > & t1,
const Table< 2, T > & t2 ) const

Compare two tables.

Definition at line 249 of file floating_point_comparator.h.

◆ compare() [6/7]

template<typename Number >
FloatingPointComparator< Number >::ComparisonResult FloatingPointComparator< Number >::compare ( const ScalarNumber s1,
const ScalarNumber s2 ) const

Compare two scalar numbers.

Definition at line 269 of file floating_point_comparator.h.

◆ compare() [7/7]

template<typename Number >
FloatingPointComparator< Number >::ComparisonResult FloatingPointComparator< Number >::compare ( const VectorizedArray< ScalarNumber, width > & v1,
const VectorizedArray< ScalarNumber, width > & v2 ) const

Compare two VectorizedArray instances.

Definition at line 290 of file floating_point_comparator.h.

Member Data Documentation

◆ width

template<typename Number >
std::size_t FloatingPointComparator< Number >::width
staticconstexpr
Initial value:

Definition at line 48 of file floating_point_comparator.h.

◆ tolerance

template<typename Number >
const ScalarNumber FloatingPointComparator< Number >::tolerance
private

Definition at line 137 of file floating_point_comparator.h.

◆ use_absolute_tolerance

template<typename Number >
const bool FloatingPointComparator< Number >::use_absolute_tolerance
private

Definition at line 138 of file floating_point_comparator.h.

◆ mask

template<typename Number >
const std::bitset<width> FloatingPointComparator< Number >::mask
private

Definition at line 139 of file floating_point_comparator.h.


The documentation for this struct was generated from the following file: