/* MCL Copyright (c) 2012-18, Enzo De Sena All rights reserved. Authors: Enzo De Sena, enzodesena@gmail.com */ #ifndef MCL_BASICINFORMATION_H #define MCL_BASICINFORMATION_H #include "mcltypes.h" #include "pointwiseop.h" #include #include using std::vector; namespace mcl { /** Returns the index associated to the maximum value in the vector. The index counts starting from 0. If there are two maxima, the index of the first one is returned. */ template Int MinIndex(const std::vector& input) noexcept { T min_value = std::numeric_limits::max(); Int min_index = 0; for (Int i=0; i<(Int)input.size(); ++i) { if (input[i] < min_value) { min_value = input[i]; min_index = i; } } return min_index; } /** Returns the maximum value of the vector. */ template T Min(const std::vector& input) { return input[MinIndex(input)]; } /** Returns the index associated to the maximum value in the vector. The index counts starting from 0. If there are two maxima, the index of the first one is returned. */ template Int MaxIndex(const std::vector& input) noexcept { return MinIndex(Opposite(input)); } template<> Int MaxIndex(const std::vector& input) noexcept; /** Returns the maximum value of the vector. */ template T Max(const std::vector& input) noexcept { return input[MaxIndex(input)]; } /** Returns the indexes of the local peaks in the vector. Equivalent to Matlab's findpeaks. */ std::vector FindPeaksIndexes(const std::vector& vector, const Real min_peak_height = std::numeric_limits::min()); /** Returns the values local peaks in the vector. Equivalent to Matlab's findpeaks. */ std::vector FindPeaks(const std::vector& vector, const Real min_peak_height = std::numeric_limits::min()); bool BasicOpTest(); } /**< namespace mcl */ #endif