math/include/utils_math

namespace feasst

Functions

int round(double x)

Return rounded double to nearest integer. This rounding is implemented as floor(x+0.5), such that feasstRound(-0.5) == 0. The cplusplus library round(-0.5) from math.h results in round(-0.5) == -1, such that rounding at the halfway point is away from zero. This breaks the first bin on histograms.

template<class T>
double average(const std::vector<T> &x)

Return the average of a vector.

template<class T>
T product(const std::vector<T> &vec)

Return product of all elements of a vector.

template<class T>
T minimum(const std::vector<T> &vec)

Return the minimum element of a vector.

template<class T>
T minimum(const std::vector<std::vector<T>> &vec)

Return the minimum element of a 2D vector.

template<class T>
T minimum(const std::vector<std::vector<std::vector<T>>> &vec)

Return the minimum element of a 3D vector.

template<class T>
T minimum(const std::vector<std::vector<std::vector<std::vector<T>>>> &vec)

Return the minimum element of a 4D vector.

template<class T>
T maximum(const std::vector<T> &vec)

Return the maximum element of a vector.

template<class T>
T maximum(const std::vector<std::vector<T>> &vec)

Return the maximum element of a 2D vector.

template<class T>
T maximum(const std::vector<std::vector<std::vector<T>>> &vec)

Return the maximum element of a 3D vector.

template<class T>
T maximum(const std::vector<std::vector<std::vector<std::vector<T>>>> &vec)

Return the maximum element of a 4D vector.

template<class T>
T sum(const std::vector<T> &vec)

Return the sum of all elements in a vector.

template<class T>
T sum(const T &data)

Terminate recursive template for multidimensional sums.

template<class T>
T sum(const std::deque<T> &vec)

Return the sum of all elements in a deque.

template<class T>
std::vector<int> local_minimum_indices(const std::vector<T> &vec, const int num_smooth)

Return the minimum element of a 2D vector with smoothing. The returned indices must be global minimum between +/- num_smooth.

template<typename T>
std::vector<T> feasst_union(const std::vector<T> &vec1, const std::vector<T> &vec2)

Compute the union of two vectors.

template<typename T>
std::vector<T> feasst_difference(const std::vector<T> &vec1, const std::vector<T> &vec2)

Compute the difference of two vectors.

template<typename T>
int sgn(T val)

Return the sign of the value. Thanks to https://stackoverflow.com/questions/1903954/ is-there-a-standard-sign-function-signum-sgn-in-c-c

double radians_to_degrees(const double radians)

Convert radians to degrees.

double degrees_to_radians(const double degrees)

Convert degrees to radians.

template<typename T>
void swap(T *val1, T *val2)

Swap the values.

template<typename T>
void sort(T *min, T *max)

Sort the values in order of increasing size.

bool is_in_interval(const double value, double bound1, double bound2)

Return true if value is between bounds 1 and 2, inclusive.

std::vector<double> cumulative_probability(const std::vector<double> &weights)

Return the cumulative probability from a weighted series.

double spherical_shell_volume(const double lower, const double upper, const int dimension)

Return the volume in a spherical shell.

template<typename T>
void add(const std::vector<T> &vec1, std::vector<T> *vec2)

Add vec1 to vec2.

template<typename T>
void add(const std::vector<std::vector<T>> &vec1, std::vector<std::vector<T>> *vec2)

Add vec1 to vec2.

template<typename T>
void add(const std::vector<std::vector<std::vector<T>>> &vec1, std::vector<std::vector<std::vector<T>>> *vec2)

Add vec1 to vec2.

template<typename T>
void add(const std::vector<std::vector<std::vector<std::vector<T>>>> &vec1, std::vector<std::vector<std::vector<std::vector<T>>>> *vec2)

Add vec1 to vec2.