MCL
A C++ library mirroring some of the most common Matlab functions.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
basicop.h
Go to the documentation of this file.
1 /*
2  MCL
3  Copyright (c) 2012-18, Enzo De Sena
4  All rights reserved.
5 
6  Authors: Enzo De Sena, enzodesena@gmail.com
7  */
8 
9 #ifndef MCL_BASICINFORMATION_H
10 #define MCL_BASICINFORMATION_H
11 
12 
13 #include "mcltypes.h"
14 #include "pointwiseop.h"
15 #include <vector>
16 #include <limits>
17 
18 using std::vector;
19 
20 namespace mcl {
21 
27 template<class T>
28 Int MinIndex(const std::vector<T>& input) noexcept {
29  T min_value = std::numeric_limits<T>::max();
30  Int min_index = 0;
31  for (Int i=0; i<(Int)input.size(); ++i) {
32  if (input[i] < min_value) {
33  min_value = input[i];
34  min_index = i;
35  }
36  }
37  return min_index;
38 }
39 
41 template<class T>
42 T Min(const std::vector<T>& input) {
43  return input[MinIndex(input)];
44 }
45 
46 
52 template<class T>
53 Int MaxIndex(const std::vector<T>& input) noexcept {
54  return MinIndex(Opposite(input));
55 }
56 
57 template<>
58 Int MaxIndex<UInt>(const std::vector<UInt>& input) noexcept;
59 
60 
62 template<class T>
63 T Max(const std::vector<T>& input) noexcept {
64  return input[MaxIndex(input)];
65 }
66 
67 
68 
69 
74 std::vector<UInt>
75 FindPeaksIndexes(const std::vector<Real>& vector,
76  const Real min_peak_height = std::numeric_limits<Real>::min());
77 
82 std::vector<Real>
83 FindPeaks(const std::vector<Real>& vector,
84  const Real min_peak_height = std::numeric_limits<Real>::min());
85 
86 
87 bool BasicOpTest();
88 
89 }
91 #endif