algorithm

module aare

Functions

template<typename T> size_t last_smaller (const T *first, const T *last, T val)

Index of the last element that is smaller than val. Requires a sorted array. Uses >= for ordering. If all elements are smaller it returns the last element and if all elements are larger it returns the first element.

Parameters:
  • first – iterator to the first element

  • last – iterator to the last element

  • val – value to compare

Returns:

index of the last element that is smaller than val

template<typename T> size_t last_smaller (const NDArray< T, 1 > &arr, T val)
template<typename T> size_t last_smaller (const std::vector< T > &vec, T val)
template<typename T> size_t first_larger (const T *first, const T *last, T val)

Index of the first element that is larger than val. Requires a sorted array. Uses > for ordering. If all elements are larger it returns the first element and if all elements are smaller it returns the last element.

Parameters:
  • first – iterator to the first element

  • last – iterator to the last element

  • val – value to compare

Returns:

index of the first element that is larger than val

template<typename T> size_t first_larger (const NDArray< T, 1 > &arr, T val)
template<typename T> size_t first_larger (const std::vector< T > &vec, T val)
template<typename T> size_t nearest_index (const T *first, const T *last, T val)

Index of the nearest element to val. Requires a sorted array. If there is no difference it takes the first element.

Parameters:
  • first – iterator to the first element

  • last – iterator to the last element

  • val – value to compare

Returns:

index of the nearest element

template<typename T> size_t nearest_index (const NDArray< T, 1 > &arr, T val)
template<typename T> size_t nearest_index (const std::vector< T > &vec, T val)
template<typename T, size_t N> size_t nearest_index (const std::array< T, N > &arr, T val)
template<typename T> std::vector< T > cumsum (const std::vector< T > &vec)