ivutils
Loading...
Searching...
No Matches
math_utils.h File Reference

Some useful math functions. More...

#include <functional>
#include <complex>
#include <limits>
#include <cmath>
#include "refobj.h"
Include dependency graph for math_utils.h:
This graph shows which files directly or indirectly include this file:

Classes

class  accomp_pred< T >
 Compare predicate based on accomp to use in STL. More...
 
class  comp_function< arg_t, result_t, comp_t >
 used to construct max_function and min_function More...
 
class  max_function< arg_t, result_t >
 maximal value of given functions More...
 
class  min_function< arg_t, result_t >
 minimal value of given functions More...
 
class  ptr_stor_t< T >
 Pointer storage class for a vector followinfg storage_prototype. More...
 
class  base_iterator< value_t >
 base class for virtual iterators More...
 
class  virtual_iterator< iterator_t, value_t >
 virtualizator for iterators More...
 
class  comb_range_t< iT >
 Iterates over all combinations of numbers from 0 to count[i] in each direction. More...
 

Functions

template<class T >
int test_NaN (T x)
 tests if x is NaN
 
template<class T >
ceil2 (const T val)
 round given value up to the near number of the type 2^N
 
template<class T >
bool accomp (const T x, const T y, const T val=T(1), int mult_epsilon=1024)
 compare x and y within some accuracy which depends on parameter val.
 
template<class T >
acfloor (const T x, T val=T(1), int mult_epsilon=1024)
 return floor(x) or ceil(x) [if x is equal to ceil(x) within some accuracy which depends on parameter val]
 
template<class T >
acdiv (T x, T y, int mult_epsilon=1024)
 calculates ratio between x and y.
 
template<class T >
log_reduce (const T &x)
 Logarithmically reduces the argument: log_reduce(x) = log(x), x>e log_reduce(x) -> -log(-x), x<e linear between [-e,e], first derivative continuous.
 
template<class T >
align_to_grid (const T &x, const T &x0, const T &dx)
 Alignes x to the neares node of dx, starting from x0.
 
template<class T >
int step_fun (const T &t1, const T &t2)
 returns -1 if t1<t2; 1 if t2>t1; 0 if t1==t2 can be used in implementation of operators < or > for some classes
 
template<int N, class arr_t >
std::size_t find_diagonal (const arr_t &sizes, int sum, std::vector< arr_t > &inds)
 Finds all possible integer tuples of dimension N>0, where the sum of integer elements in a tuple equals sum and the elements are between [0, sizes[i]) in each dimension i.
 

Detailed Description

Some useful math functions.

Function Documentation

◆ acdiv()

template<class T >
T acdiv ( x,
y,
int  mult_epsilon = 1024 
)

calculates ratio between x and y.

if this ratio is close to some integer number with some accuracy, then returns this integer number.

◆ align_to_grid()

template<class T >
T align_to_grid ( const T &  x,
const T &  x0,
const T &  dx 
)

Alignes x to the neares node of dx, starting from x0.

Returns
the aligned value

◆ find_diagonal()

template<int N, class arr_t >
std::size_t find_diagonal ( const arr_t &  sizes,
int  sum,
std::vector< arr_t > &  inds 
)

Finds all possible integer tuples of dimension N>0, where the sum of integer elements in a tuple equals sum and the elements are between [0, sizes[i]) in each dimension i.

The tuples are constructed as instances of arr_t and pushed back to vector inds.

Returns
the number of tuples found.