MCPcopy Create free account
hub / github.com/Xilinx/CHaiDNN / Trim2FixedPoint

Function Trim2FixedPoint

software/interface/xi_readwrite_util.cpp:70–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70void Trim2FixedPoint(float &data, const int bw, const int fl, int round_floor_flag)
71{
72 float pow_bw_minus_1 = pow(2, bw-1);
73 float pow_minus_fl = pow(2, -fl);
74 float pow_plus_fl = pow(2, fl);
75 float max_data = (pow_bw_minus_1 - 1) * pow_minus_fl;
76 float min_data = -pow_bw_minus_1 * pow_minus_fl;
77
78 // Saturate data
79 data = std::max(std::min(data, max_data), min_data);
80 if(round_floor_flag == 1) //if floor
81 {
82 //Floor data
83 data = (floor(data*pow_plus_fl))/pow_plus_fl;
84 }
85 else
86 {
87 // Round data
88 data /= pow_minus_fl;
89 data = round(data);
90
91 data *= pow_minus_fl;
92
93 }
94
95}
96
97int loadPixelMeanSubtractedDatatoBuffptr(const char *img_path, IO_DATA_TYPE *buff_ptr, int height, int width, int img_channel, int resize_h, int resize_w, int fbits_input, char *mean_path)
98{

Callers 1

Calls 2

maxFunction · 0.50
minFunction · 0.50

Tested by

no test coverage detected