-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmin_max.cpp
More file actions
33 lines (24 loc) · 758 Bytes
/
min_max.cpp
File metadata and controls
33 lines (24 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "min_max.hpp"
using namespace std;
namespace data_analysis {
MinMax::MinMax(int window_size) :
queue(Queue(window_size)){
min = std::numeric_limits<double>::infinity();
max = -std::numeric_limits<double>::infinity();
}
void MinMax::update(const base::VectorXd &input_data, double& _min, double &_max){
if(queue.queueSize() == numeric_limits<int>::max()){
min = std::min(input_data.minCoeff(), min);
max = std::max(input_data.maxCoeff(), max);
}
else{
queue.pushShift(input_data);
for(size_t i = 0; i < queue.size(); i++){
min = std::min(queue[i].minCoeff(), min);
max = std::max(queue[i].maxCoeff(), max);
}
}
_min = min;
_max = max;
}
}