#include <Eigen/Core>
#include <cmath>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | autopas |
This is the main namespace of AutoPas. | |
namespace | autopas::utils |
In this namespace some helper classes and functions can be found used inside of AutoPas. | |
Functions | |
template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true> | |
Int_t | autopas::utils::Math::safeAdd (const Int_t &a, const Int_t &b, const Int_t &valUnderflow=std::numeric_limits< Int_t >::min(), const Int_t &valOverflow=std::numeric_limits< Int_t >::max()) |
Addition function for integer types that is safe against over and underflow. | |
template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true> | |
Float_t | autopas::utils::Math::safeAdd (const Float_t &a, const Float_t &b, const Float_t &valUnderflow=-std::numeric_limits< Float_t >::max(), const Float_t &valOverflow=std::numeric_limits< Float_t >::max()) |
Addition function for floating point types that is safe against over and underflow. | |
template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true> | |
Int_t | autopas::utils::Math::safeSub (const Int_t &a, const Int_t &b, const Int_t &valUnderflow=std::numeric_limits< Int_t >::min(), const Int_t &valOverflow=std::numeric_limits< Int_t >::max()) |
Subtraction function for integer types that is safe against over and underflow. | |
template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true> | |
Float_t | autopas::utils::Math::safeSub (const Float_t &a, const Float_t &b, const Float_t &valUnderflow=-std::numeric_limits< Float_t >::max(), const Float_t &valOverflow=std::numeric_limits< Float_t >::max()) |
Addition function for floating point types that is safe against over and underflow. | |
template<class Int_t , std::enable_if_t< std::is_integral_v< Int_t >, bool > = true> | |
Int_t | autopas::utils::Math::safeMul (const Int_t &a, const Int_t &b, const Int_t &valUnderflow=std::numeric_limits< Int_t >::min(), const Int_t &valOverflow=std::numeric_limits< Int_t >::max()) |
Multiplication function for integer types that is safe against over and underflow. | |
template<class Float_t , std::enable_if_t< std::is_floating_point_v< Float_t >, bool > = true> | |
Float_t | autopas::utils::Math::safeMul (const Float_t &a, const Float_t &b, const Float_t &valUnderflow=-std::numeric_limits< Float_t >::max(), const Float_t &valOverflow=std::numeric_limits< Float_t >::max()) |
Multiplication function for floating point types that is safe against over and underflow. | |
template<size_t exponent, class T > | |
T | autopas::utils::Math::pow (const T &base) |
No-overhead power function with exponent known at compile time. | |
double | autopas::utils::Math::normalPDF (double x) |
Probability density function PDF of the standard normal distribution. | |
double | autopas::utils::Math::normalCDF (double x) |
Cumulative distribution function CDF of the standard normal distribution. | |
double | autopas::utils::Math::sigmoid (double x) |
Sigmoid logistic function. | |
bool | autopas::utils::Math::isNearRel (double a, double b, double maxRelativeDifference=1e-9) |
Determines if two doubles are near each other. | |
bool | autopas::utils::Math::isNearAbs (double a, double b, double maxAbsoluteDifference) |
Determines if two doubles are near each other. | |
double | autopas::utils::Math::roundFixed (double d, int fixedPrecision) |
Round a floating point number to a given number of decimal digits. | |
double | autopas::utils::Math::roundFloating (double d, int floatingPrecision) |
Round a floating point number to a given floating precision. | |
Eigen::VectorXd | autopas::utils::Math::makeVectorXd (const std::vector< double > &elements) |
Create a vector of doubles from given elements. | |
Eigen::VectorXi | autopas::utils::Math::makeVectorXi (const std::vector< int > &elements) |
Create a vector of ints from given elements. | |
Variables | |
const double | autopas::utils::Math::normalScale = 1. / std::sqrt(2 * M_PI) |
Factor of PDF of standard normal distribution. | |
bool autopas::utils::Math::isNearAbs | ( | double | a, |
double | b, | ||
double | maxAbsoluteDifference | ||
) |
Determines if two doubles are near each other.
This function should be preferred to comparing with ==.
a | |
b | |
maxAbsoluteDifference | inclusive |
bool autopas::utils::Math::isNearRel | ( | double | a, |
double | b, | ||
double | maxRelativeDifference = 1e-9 |
||
) |
Determines if two doubles are near each other.
This function should be preferred to comparing with ==.
a | |
b | |
maxRelativeDifference | inclusive, relative to max(|a|, |b|). |
Eigen::VectorXd autopas::utils::Math::makeVectorXd | ( | const std::vector< double > & | elements | ) |
Create a vector of doubles from given elements.
elements |
Eigen::VectorXi autopas::utils::Math::makeVectorXi | ( | const std::vector< int > & | elements | ) |
Create a vector of ints from given elements.
elements |
double autopas::utils::Math::normalCDF | ( | double | x | ) |
Cumulative distribution function CDF of the standard normal distribution.
x |
double autopas::utils::Math::normalPDF | ( | double | x | ) |
Probability density function PDF of the standard normal distribution.
x |
T autopas::utils::Math::pow | ( | const T & | base | ) |
No-overhead power function with exponent known at compile time.
exponent | |
T |
base |
double autopas::utils::Math::roundFixed | ( | double | d, |
int | fixedPrecision | ||
) |
Round a floating point number to a given number of decimal digits.
d | Number to round. |
fixedPrecision | Number of decimal digits. Negative values lead to rounding of digits left of the decimal. |
double autopas::utils::Math::roundFloating | ( | double | d, |
int | floatingPrecision | ||
) |
Round a floating point number to a given floating precision.
d | Number to round. |
floatingPrecision | Number of significant digits. Values <0 will return in 0. |
Float_t autopas::utils::Math::safeAdd | ( | const Float_t & | a, |
const Float_t & | b, | ||
const Float_t & | valUnderflow = -std::numeric_limits<Float_t>::max() , |
||
const Float_t & | valOverflow = std::numeric_limits<Float_t>::max() |
||
) |
Addition function for floating point types that is safe against over and underflow.
If over or underflow is detected, the function returns the specified values.
Float_t |
a | |
b | |
valUnderflow | Return value in case of underflow. |
valOverflow | Return value in case of overflow. |
Int_t autopas::utils::Math::safeAdd | ( | const Int_t & | a, |
const Int_t & | b, | ||
const Int_t & | valUnderflow = std::numeric_limits<Int_t>::min() , |
||
const Int_t & | valOverflow = std::numeric_limits<Int_t>::max() |
||
) |
Addition function for integer types that is safe against over and underflow.
If over or underflow is detected, the function returns the specified values.
Int_t |
a | |
b | |
valUnderflow | Return value in case of underflow. |
valOverflow | Return value in case of overflow. |
Float_t autopas::utils::Math::safeMul | ( | const Float_t & | a, |
const Float_t & | b, | ||
const Float_t & | valUnderflow = -std::numeric_limits<Float_t>::max() , |
||
const Float_t & | valOverflow = std::numeric_limits<Float_t>::max() |
||
) |
Multiplication function for floating point types that is safe against over and underflow.
If over or underflow is detected, the function returns the specified values.
Float_t |
a | |
b | |
valUnderflow | Return value in case of underflow. |
valOverflow | Return value in case of overflow. |
Int_t autopas::utils::Math::safeMul | ( | const Int_t & | a, |
const Int_t & | b, | ||
const Int_t & | valUnderflow = std::numeric_limits<Int_t>::min() , |
||
const Int_t & | valOverflow = std::numeric_limits<Int_t>::max() |
||
) |
Multiplication function for integer types that is safe against over and underflow.
If over or underflow is detected, the function returns the specified values.
Int_t |
a | |
b | |
valUnderflow | Return value in case of underflow. |
valOverflow | Return value in case of overflow. |
Float_t autopas::utils::Math::safeSub | ( | const Float_t & | a, |
const Float_t & | b, | ||
const Float_t & | valUnderflow = -std::numeric_limits<Float_t>::max() , |
||
const Float_t & | valOverflow = std::numeric_limits<Float_t>::max() |
||
) |
Addition function for floating point types that is safe against over and underflow.
If over or underflow is detected, the function returns the specified values.
Float_t |
a | |
b | |
valUnderflow | Return value in case of underflow. |
valOverflow | Return value in case of overflow. |
Int_t autopas::utils::Math::safeSub | ( | const Int_t & | a, |
const Int_t & | b, | ||
const Int_t & | valUnderflow = std::numeric_limits<Int_t>::min() , |
||
const Int_t & | valOverflow = std::numeric_limits<Int_t>::max() |
||
) |
Subtraction function for integer types that is safe against over and underflow.
If over or underflow is detected, the function returns the specified values.
Int_t |
a | |
b | |
valUnderflow | Return value in case of underflow. |
valOverflow | Return value in case of overflow. |
double autopas::utils::Math::sigmoid | ( | double | x | ) |
Sigmoid logistic function.
x |