File tree Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Expand file tree Collapse file tree 3 files changed +22
-2
lines changed Original file line number Diff line number Diff line change 1
1
#include < map>
2
+ #include < algorithm>
2
3
3
4
#include " vtr_assert.h"
4
5
#include " vtr_error.h"
@@ -20,6 +21,19 @@ int ipow(int base, int exp) {
20
21
return result;
21
22
}
22
23
24
+ float median (std::vector<float > vector) {
25
+ VTR_ASSERT (vector.size () > 0 );
26
+
27
+ std::sort (vector.begin (), vector.end ());
28
+
29
+ auto size = vector.size ();
30
+ if (size % 2 == 0 ) {
31
+ return (float )(vector[size / 2 - 1 ] + vector[size / 2 ]) / 2 ;
32
+ }
33
+
34
+ return (float )vector[size / 2 ];
35
+ }
36
+
23
37
/* Performs linear interpolation or extrapolation on the set of (x,y) values specified by the xy_map.
24
38
* A requested x value is passed in, and we return the interpolated/extrapolated y value at this requested value of x.
25
39
* Meant for maps where both key and element are numbers.
Original file line number Diff line number Diff line change 2
2
#define VTR_MATH_H
3
3
4
4
#include < map>
5
+ #include < vector>
5
6
#include < cmath>
6
7
7
8
#include " vtr_assert.h"
@@ -10,6 +11,9 @@ namespace vtr {
10
11
/* ********************** Math operations *************************************/
11
12
int ipow (int base, int exp);
12
13
14
+ // Returns the median of an input vector.
15
+ float median (std::vector<float > vector);
16
+
13
17
template <typename X, typename Y>
14
18
Y linear_interpolate_or_extrapolate (const std::map<X, Y>* xy_map, X requested_x);
15
19
Original file line number Diff line number Diff line change 5
5
#include " vtr_assert.h"
6
6
#include " vtr_log.h"
7
7
#include " vtr_memory.h"
8
+ #include " vtr_math.h"
8
9
9
10
#include " vpr_types.h"
10
11
#include " vpr_error.h"
@@ -390,8 +391,9 @@ static void load_rr_indexed_data_T_values() {
390
391
auto switch_T_total_histogram = build_histogram (switch_T_total[cost_index], 10 );
391
392
auto switch_Cinternal_total_histogram = build_histogram (switch_Cinternal_total[cost_index], 10 );
392
393
393
- float Rnode = get_histogram_mode (R_total_histogram);
394
- float Cnode = get_histogram_mode (C_total_histogram);
394
+ // Sort Rnode and Cnode
395
+ float Cnode = vtr::median (C_total[cost_index]);
396
+ float Rnode = vtr::median (R_total[cost_index]);
395
397
float Rsw = get_histogram_mode (switch_R_total_histogram);
396
398
float Tsw = get_histogram_mode (switch_T_total_histogram);
397
399
float Cinternalsw = get_histogram_mode (switch_Cinternal_total_histogram);
You can’t perform that action at this time.
0 commit comments