10#ifndef MATH_ALGO_HEADER
11#define MATH_ALGO_HEADER
29template <
typename FwdIter>
34 throw std::invalid_argument(
"Invalid range");
36 FwdIter lowest =
first;
37 std::size_t lowest_id = 0;
39 for (std::size_t cnt = 1; ++
first != last; ++cnt)
55template <
typename FwdIter>
60 throw std::invalid_argument(
"Invalid range");
62 FwdIter largest =
first;
63 std::size_t largest_id = 0;
65 for (std::size_t cnt = 1; ++
first != last; ++cnt)
67 if (*largest < *
first)
81template <
typename Key,
typename Value>
85 std::size_t range1 = 0;
86 std::size_t range2 = vec.size();
87 while (range1 != range2)
89 std::size_t pos = (range1 + range2) / 2;
90 if (key < vec[pos].
first)
92 else if (vec[pos].
first < key)
95 return &vec[pos].second;
112 {
return this->state++; }
122 return init + next * next;
130 return init + std::abs(next);
139 bool operator() (T
const& v1, T
const& v2)
140 {
return (v1 - eps <= v2 && v2 <= v1 + eps); }
144template <
typename T,
int S>
150 T
const& operator* (
void)
const {
return *pos; }
152 {
return pos == other.
pos; }
154 {
return pos != other.
pos; }
166vector_clean (std::vector<bool>
const& delete_list, std::vector<T>* vector)
168 typename std::vector<T>::iterator vr = vector->begin();
169 typename std::vector<T>::iterator vw = vector->begin();
170 typename std::vector<bool>::const_iterator dr = delete_list.begin();
172 while (vr != vector->end() && dr != delete_list.end())
184 vector->erase(vw, vector->end());
198 T
const& width, T
const& height, T* x1, T* x2, T* y1, T* y2)
200 *x1 = (cx > ks ? cx - ks : T(0));
201 *x2 = (cx + ks > width - T(1) ? width - T(1) : cx + ks);
202 *y1 = (cy > ks ? cy - ks : T(0));
203 *y2 = (cy + ks > height - T(1) ? height - T(1) : cy + ks);
226 void operator() (T& val) { val *= value; }
235 void operator() (T& val) { val /= div; }
244 void operator() (T& val) { val += value; }
253 void operator() (T& val) { val -= value; }
262 void operator() (T& val) { val = std::pow(val, value); }
266template <
typename M,
typename V>
271 void operator() (V& vec) { vec = mat * vec; }
303 val = std::floor(val);
311 val = std::ceil(val);
#define MATH_NAMESPACE_BEGIN
#define MATH_NAMESPACE_END
#define MATH_ALGO_NAMESPACE_BEGIN
#define MATH_ALGO_NAMESPACE_END
void foreach_ceil(T &val)
for-each functor: applies ceil operation to the operand.
void foreach_floor(T &val)
for-each functor: applies floor operation to the operand.
std::size_t max_element_id(FwdIter first, FwdIter last)
Algorithm that returns the ID (starting from zero at element 'first') of the largest element in range...
T accum_squared_sum(T const &init, T const &next)
Squared sum accumulator.
void vector_clean(std::vector< bool > const &delete_list, std::vector< T > *vector)
Erases all elements from 'vector' that are marked with 'true' in 'delete_list'.
void foreach_negate_value(T &val)
for-each functor: negates the operand.
void foreach_round(T &val)
for-each functor: applies rounding to the operand.
Value const * binary_search(std::vector< std::pair< Key, Value > > const &vec, Key const &key)
Algorithm that finds the value corresponding to a key in sorted vector of key-value pairs.
std::size_t min_element_id(FwdIter first, FwdIter last)
Algorithm that returns the ID (starting from zero at element 'first') of the smallest element in rang...
void sort_values(T *a, T *b, T *c)
void foreach_absolute_value(T &val)
for-each functor: applies absolute value to operand.
T accum_absolute_sum(T const &init, T const &next)
Absolute sum accumulator.
void foreach_invert_value(T &val)
for-each functor: inverts floating point values with 1/value.
void kernel_region(T const &cx, T const &cy, T const &ks, T const &width, T const &height, T *x1, T *x2, T *y1, T *y2)
Returns the kernel region (x1,y1) to (x2,y2) for a kernel of size ks for image of size (width,...
T round(T const &x)
Removes the fractional part of the value to the closest integer.
void swap(mve::Image< T > &a, mve::Image< T > &b)
Specialization of std::swap for efficient image swapping.
IncrementGenerator(T const &init=T(0))
Iterator that advances 'S' elements of type T.
InterleavedIter(T const *pos)
for-each functor: adds a constant value to operand.
foreach_addition_with_const(T const &value)
for-each functor: raises each operand to the power of constant value.
foreach_constant_power(T const &value)
for-each functor: divides operand by constant divisor.
foreach_divide_by_const(T const &div)
for-each functor: matrix-vector multiplication.
foreach_matrix_mult(M const &matrix)
for-each functor: multiplies operand with constant factor.
foreach_multiply_with_const(T const &value)
for-each functor: substracts a constant value to operand.
foreach_substraction_with_const(T const &value)
Epsilon comparator predicate.
predicate_epsilon_equal(T const &eps)