Free-standing operators for UncertainValue

CPP API: Free-standing operators for UncertainValue
Free-standing operators for UncertainValue

These operators enable seamless arithmetic between UncertainValue objects and scalar or AD (Automatic Differentiation) types. More...

Typedefs

using mio::UncertainValue< FP >::Type = FP
 

Functions

template<class IOContext >
static IOResult< UncertainValuemio::UncertainValue< FP >::deserialize (IOContext &io)
 deserialize an object of this class. More...
 
FP mio::UncertainValue< FP >::draw_sample ()
 Sets the value by sampling from the distribution and returns the new value. More...
 
observer_ptr< ParameterDistributionmio::UncertainValue< FP >::get_distribution ()
 Returns the parameter distribution. More...
 
observer_ptr< const ParameterDistributionmio::UncertainValue< FP >::get_distribution () const
 Returns the parameter distribution. More...
 
 mio::UncertainValue< FP >::operator const FP & () const
 
 mio::UncertainValue< FP >::operator FP & ()
 Conversion to scalar reference by returning the scalar contained in UncertainValue. More...
 
UncertainValuemio::UncertainValue< FP >::operator= (const UncertainValue &other)
 Set an UncertainValue from another UncertainValue containing a scalar and a distribution. More...
 
UncertainValuemio::UncertainValue< FP >::operator= (FP v)
 Set an UncertainValue from a scalar, distribution remains unchanged. More...
 
template<typename T >
requires std::is_convertible_v< T, FP > UncertainValue< FP > & mio::UncertainValue< FP >::operator= (T v)
 Assign a scalar of any type convertible to FP to this UncertainValue. More...
 
template<class IOContext >
void mio::UncertainValue< FP >::serialize (IOContext &io) const
 serialize this. More...
 
void mio::UncertainValue< FP >::set_distribution (const ParameterDistribution &dist)
 Sets the distribution of the value. More...
 
 mio::UncertainValue< FP >::UncertainValue (const UncertainValue &other)
 Create an UncertainValue by cloning scalar value and distribution of another UncertainValue. More...
 
 mio::UncertainValue< FP >::UncertainValue (FP v, const ParameterDistribution &dist)
 
 mio::UncertainValue< FP >::UncertainValue (FP v=static_cast< FP >(0.0))
 
template<typename T >
requires std::is_convertible_v< T, FP > mio::UncertainValue< FP >::UncertainValue (T v)
 Create an UncertainValue from a scalar of any type convertible to FP. More...
 
 mio::UncertainValue< FP >::UncertainValue (UncertainValue &&other)=default
 
FP mio::UncertainValue< FP >::value () const
 Conversion to scalar by returning the scalar contained in UncertainValue. More...
 

Variables

std::unique_ptr< ParameterDistributionmio::UncertainValue< FP >::m_dist
 
FP mio::UncertainValue< FP >::m_value
 

Comparison operators with scalar or AD type on right (UncertainValue <op> T)

template<typename FP , typename T >
bool mio::operator> (const UncertainValue< FP > &lhs, const T &rhs)
 
template<typename FP , typename T >
bool mio::operator< (const UncertainValue< FP > &lhs, const T &rhs)
 
template<typename FP , typename T >
bool mio::operator>= (const UncertainValue< FP > &lhs, const T &rhs)
 
template<typename FP , typename T >
bool mio::operator<= (const UncertainValue< FP > &lhs, const T &rhs)
 
template<typename FP , typename T >
bool mio::operator== (const UncertainValue< FP > &lhs, const T &rhs)
 
template<typename FP , typename T >
bool mio::operator!= (const UncertainValue< FP > &lhs, const T &rhs)
 

Comparison operators with scalar or AD type on left (T <op> UncertainValue)

template<typename FP , typename T >
bool mio::operator> (const T &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP , typename T >
bool mio::operator< (const T &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP , typename T >
bool mio::operator>= (const T &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP , typename T >
bool mio::operator<= (const T &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP , typename T >
bool mio::operator== (const T &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP , typename T >
bool mio::operator!= (const T &lhs, const UncertainValue< FP > &rhs)
 

Comparison operators between two UncertainValue objects

template<typename FP >
bool mio::operator> (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP >
bool mio::operator< (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP >
bool mio::operator>= (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP >
bool mio::operator<= (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP >
bool mio::operator== (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP >
bool mio::operator!= (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 

Arithmetic operators between two UncertainValue objects (returns FP)

template<typename FP >
FP mio::operator* (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP >
FP mio::operator/ (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP >
FP mio::operator+ (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP >
FP mio::operator- (const UncertainValue< FP > &lhs, const UncertainValue< FP > &rhs)
 

Arithmetic operators with scalar or AD type on right (UncertainValue <op> T)

template<typename FP , typename T >
FP mio::operator* (const UncertainValue< FP > &lhs, const T &rhs)
 
template<typename FP , typename T >
FP mio::operator/ (const UncertainValue< FP > &lhs, const T &rhs)
 
template<typename FP , typename T >
FP mio::operator+ (const UncertainValue< FP > &lhs, const T &rhs)
 
template<typename FP , typename T >
FP mio::operator- (const UncertainValue< FP > &lhs, const T &rhs)
 

Arithmetic operators with scalar or AD type on left (T <op> UncertainValue)

template<typename FP , typename T >
FP mio::operator* (const T &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP , typename T >
FP mio::operator/ (const T &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP , typename T >
FP mio::operator+ (const T &lhs, const UncertainValue< FP > &rhs)
 
template<typename FP , typename T >
FP mio::operator- (const T &lhs, const UncertainValue< FP > &rhs)
 

Compound assignment operators for FP and UncertainValue<FP>

template<typename FP >
FP & mio::operator+= (FP &lhs, const UncertainValue< FP > &rhs)
 Print statement for UncertainValue<FP> (required for AD types) More...
 
template<typename FP >
FP & mio::operator-= (FP &lhs, const UncertainValue< FP > &rhs)
 Print statement for UncertainValue<FP> (required for AD types) More...
 
template<typename FP >
FP & mio::operator*= (FP &lhs, const UncertainValue< FP > &rhs)
 Print statement for UncertainValue<FP> (required for AD types) More...
 
template<typename FP >
FP & mio::operator/= (FP &lhs, const UncertainValue< FP > &rhs)
 Print statement for UncertainValue<FP> (required for AD types) More...
 
template<typename FP >
std::ostream & mio::operator<< (std::ostream &os, const UncertainValue< FP > &uv)
 Print statement for UncertainValue<FP> (required for AD types) More...
 

Detailed Description

These operators enable seamless arithmetic between UncertainValue objects and scalar or AD (Automatic Differentiation) types.

Template parameter T:

  • T is any type convertible to FP (the floating-point type of UncertainValue).
  • This includes scalars and AD types, as long as they can be cast to FP.

Why needed:

  • UncertainValue is often used with both plain scalars (e.g., double, float, int) and AD types (e.g., active_type, AD expression templates).
  • Without these operators and templated constructors, assigning or operating on UncertainValue with AD expressions or scalars would fail, as the compiler cannot automatically convert complex AD expressions to UncertainValue.

Typedef Documentation

◆ Type

template<typename FP = ScalarType>
using mio::UncertainValue< FP >::Type = FP

Function Documentation

◆ deserialize()

template<typename FP = ScalarType>
template<class IOContext >
static IOResult<UncertainValue> mio::UncertainValue< FP >::deserialize ( IOContext &  io)
inlinestatic

deserialize an object of this class.

See also
mio::deserialize

◆ draw_sample()

template<typename FP = ScalarType>
FP mio::UncertainValue< FP >::draw_sample ( )
inline

Sets the value by sampling from the distribution and returns the new value.

If no distribution is set, the value is not changed.

◆ get_distribution() [1/2]

template<typename FP = ScalarType>
observer_ptr<ParameterDistribution> mio::UncertainValue< FP >::get_distribution ( )
inline

Returns the parameter distribution.

If it is not set, a nullptr is returned.

◆ get_distribution() [2/2]

template<typename FP = ScalarType>
observer_ptr<const ParameterDistribution> mio::UncertainValue< FP >::get_distribution ( ) const
inline

Returns the parameter distribution.

If it is not set, a nullptr is returned.

◆ operator const FP &()

template<typename FP = ScalarType>
mio::UncertainValue< FP >::operator const FP & ( ) const
inline

◆ operator FP &()

template<typename FP = ScalarType>
mio::UncertainValue< FP >::operator FP & ( )
inline

Conversion to scalar reference by returning the scalar contained in UncertainValue.

◆ operator!=() [1/3]

template<typename FP , typename T >
bool mio::operator!= ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator!=() [2/3]

template<typename FP , typename T >
bool mio::operator!= ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator!=() [3/3]

template<typename FP >
bool mio::operator!= ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator*() [1/3]

template<typename FP , typename T >
FP mio::operator* ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator*() [2/3]

template<typename FP , typename T >
FP mio::operator* ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator*() [3/3]

template<typename FP >
FP mio::operator* ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator*=()

template<typename FP >
FP& mio::operator*= ( FP &  lhs,
const UncertainValue< FP > &  rhs 
)

Print statement for UncertainValue<FP> (required for AD types)

◆ operator+() [1/3]

template<typename FP , typename T >
FP mio::operator+ ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator+() [2/3]

template<typename FP , typename T >
FP mio::operator+ ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator+() [3/3]

template<typename FP >
FP mio::operator+ ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator+=()

template<typename FP >
FP& mio::operator+= ( FP &  lhs,
const UncertainValue< FP > &  rhs 
)

Print statement for UncertainValue<FP> (required for AD types)

◆ operator-() [1/3]

template<typename FP , typename T >
FP mio::operator- ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator-() [2/3]

template<typename FP , typename T >
FP mio::operator- ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator-() [3/3]

template<typename FP >
FP mio::operator- ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator-=()

template<typename FP >
FP& mio::operator-= ( FP &  lhs,
const UncertainValue< FP > &  rhs 
)

Print statement for UncertainValue<FP> (required for AD types)

◆ operator/() [1/3]

template<typename FP , typename T >
FP mio::operator/ ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator/() [2/3]

template<typename FP , typename T >
FP mio::operator/ ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator/() [3/3]

template<typename FP >
FP mio::operator/ ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator/=()

template<typename FP >
FP& mio::operator/= ( FP &  lhs,
const UncertainValue< FP > &  rhs 
)

Print statement for UncertainValue<FP> (required for AD types)

◆ operator<() [1/3]

template<typename FP , typename T >
bool mio::operator< ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator<() [2/3]

template<typename FP , typename T >
bool mio::operator< ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator<() [3/3]

template<typename FP >
bool mio::operator< ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator<<()

template<typename FP >
std::ostream& mio::operator<< ( std::ostream &  os,
const UncertainValue< FP > &  uv 
)
inline

Print statement for UncertainValue<FP> (required for AD types)

◆ operator<=() [1/3]

template<typename FP , typename T >
bool mio::operator<= ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator<=() [2/3]

template<typename FP , typename T >
bool mio::operator<= ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator<=() [3/3]

template<typename FP >
bool mio::operator<= ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator=() [1/3]

template<typename FP = ScalarType>
UncertainValue& mio::UncertainValue< FP >::operator= ( const UncertainValue< FP > &  other)
inline

Set an UncertainValue from another UncertainValue containing a scalar and a distribution.

◆ operator=() [2/3]

template<typename FP = ScalarType>
UncertainValue& mio::UncertainValue< FP >::operator= ( FP  v)
inline

Set an UncertainValue from a scalar, distribution remains unchanged.

◆ operator=() [3/3]

template<typename FP = ScalarType>
template<typename T >
requires std::is_convertible_v<T, FP> UncertainValue<FP>& mio::UncertainValue< FP >::operator= ( v)
inline

Assign a scalar of any type convertible to FP to this UncertainValue.

The contained scalar is updated, while the distribution remains unchanged. Supports scalars and AD (Automatic Differentiation) types that can be cast to FP.

◆ operator==() [1/3]

template<typename FP , typename T >
bool mio::operator== ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator==() [2/3]

template<typename FP , typename T >
bool mio::operator== ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator==() [3/3]

template<typename FP >
bool mio::operator== ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator>() [1/3]

template<typename FP , typename T >
bool mio::operator> ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator>() [2/3]

template<typename FP , typename T >
bool mio::operator> ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator>() [3/3]

template<typename FP >
bool mio::operator> ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator>=() [1/3]

template<typename FP , typename T >
bool mio::operator>= ( const T &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ operator>=() [2/3]

template<typename FP , typename T >
bool mio::operator>= ( const UncertainValue< FP > &  lhs,
const T &  rhs 
)
inline

◆ operator>=() [3/3]

template<typename FP >
bool mio::operator>= ( const UncertainValue< FP > &  lhs,
const UncertainValue< FP > &  rhs 
)
inline

◆ serialize()

template<typename FP = ScalarType>
template<class IOContext >
void mio::UncertainValue< FP >::serialize ( IOContext &  io) const
inline

serialize this.

See also
mio::serialize

◆ set_distribution()

template<typename FP = ScalarType>
void mio::UncertainValue< FP >::set_distribution ( const ParameterDistribution dist)
inline

Sets the distribution of the value.

The function uses copy semantics, i.e. it copies the distribution object.

◆ UncertainValue() [1/5]

template<typename FP = ScalarType>
mio::UncertainValue< FP >::UncertainValue ( const UncertainValue< FP > &  other)
inline

Create an UncertainValue by cloning scalar value and distribution of another UncertainValue.

◆ UncertainValue() [2/5]

template<typename FP = ScalarType>
mio::UncertainValue< FP >::UncertainValue ( FP  v,
const ParameterDistribution dist 
)
inline

◆ UncertainValue() [3/5]

template<typename FP = ScalarType>
mio::UncertainValue< FP >::UncertainValue ( FP  v = static_cast<FP>(0.0))
inline

◆ UncertainValue() [4/5]

template<typename FP = ScalarType>
template<typename T >
requires std::is_convertible_v<T, FP> mio::UncertainValue< FP >::UncertainValue ( v)
inline

Create an UncertainValue from a scalar of any type convertible to FP.

This constructor allows initializing UncertainValue with scalars or AD (Automatic Differentiation) types that can be cast to FP. The distribution remains unset.

◆ UncertainValue() [5/5]

template<typename FP = ScalarType>
mio::UncertainValue< FP >::UncertainValue ( UncertainValue< FP > &&  other)
default

◆ value()

template<typename FP = ScalarType>
FP mio::UncertainValue< FP >::value ( ) const
inline

Conversion to scalar by returning the scalar contained in UncertainValue.

Variable Documentation

◆ m_dist

template<typename FP = ScalarType>
std::unique_ptr<ParameterDistribution> mio::UncertainValue< FP >::m_dist
private

◆ m_value

template<typename FP = ScalarType>
FP mio::UncertainValue< FP >::m_value
private