All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fastMath.hpp
Go to the documentation of this file.
#ifndef OPENPOSE_UTILITIES_MATH_HPP
#define OPENPOSE_UTILITIES_MATH_HPP
namespace op
{
// Use op::round/max/min for basic types (int, char, long, float, double, etc). Never with classes!
// `std::` alternatives uses 'const T&' instead of 'const T' as argument.
// E.g., std::round is really slow (~300 ms vs ~10 ms when I individually apply it to each element of a whole
// image array
// Round functions
// Signed
template<typename T>
inline char charRound(const T a)
{
return char(a+0.5f);
}
template<typename T>
inline signed char sCharRound(const T a)
{
return (signed char)(a+0.5f);
}
template<typename T>
inline int intRound(const T a)
{
return int(a+0.5f);
}
template<typename T>
inline long longRound(const T a)
{
return long(a+0.5f);
}
template<typename T>
inline long long longLongRound(const T a)
{
return (long long)(a+0.5f);
}
// Unsigned
template<typename T>
inline unsigned char uCharRound(const T a)
{
return (unsigned char)(a+0.5f);
}
template<typename T>
inline unsigned int uIntRound(const T a)
{
return (unsigned int)(a+0.5f);
}
template<typename T>
inline unsigned long ulongRound(const T a)
{
return (unsigned long)(a+0.5f);
}
template<typename T>
inline unsigned long long uLongLongRound(const T a)
{
return (unsigned long long)(a+0.5f);
}
// Max/min functions
template<typename T>
inline T fastMax(const T a, const T b)
{
return (a > b ? a : b);
}
template<typename T>
inline T fastMin(const T a, const T b)
{
return (a < b ? a : b);
}
template<class T>
inline T fastTruncate(T value, T min = 0, T max = 1)
{
return fastMin(max, fastMax(min, value));
}
}
#endif // OPENPOSE_UTILITIES_MATH_HPP
op::uIntRound
unsigned int uIntRound(const T a)
Definition: fastMath.hpp:51
op::fastMax
T fastMax(const T a, const T b)
Definition: fastMath.hpp:70
op::fastTruncate
T fastTruncate(T value, T min=0, T max=1)
Definition: fastMath.hpp:82
op::charRound
char charRound(const T a)
Definition: fastMath.hpp:14
op::longRound
long longRound(const T a)
Definition: fastMath.hpp:32
op::ulongRound
unsigned long ulongRound(const T a)
Definition: fastMath.hpp:57
op::sCharRound
signed char sCharRound(const T a)
Definition: fastMath.hpp:20
op::uCharRound
unsigned char uCharRound(const T a)
Definition: fastMath.hpp:45
op::fastMin
T fastMin(const T a, const T b)
Definition: fastMath.hpp:76
op::intRound
int intRound(const T a)
Definition: fastMath.hpp:26
op::uLongLongRound
unsigned long long uLongLongRound(const T a)
Definition: fastMath.hpp:63
op::longLongRound
long long longLongRound(const T a)
Definition: fastMath.hpp:38