MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / get_nearest_linear_coord

Function get_nearest_linear_coord

dnn/src/arm_common/resize/helper.h:89–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87}
88
89static inline std::tuple<float, int, float, int> get_nearest_linear_coord(
90 InterpolationMode imode, float scale, int size, int idx) {
91 if (size == 1) {
92 return std::make_tuple(1.0f, 0, 0.0f, 0);
93 }
94
95 float alpha = (idx + 0.5f) / scale - 0.5f;
96 int origin_idx = static_cast<int>(floor(alpha));
97 alpha -= origin_idx;
98
99 if (imode == InterpolationMode::INTER_NEAREST) {
100 origin_idx = get_nearest_src(scale, size, idx);
101 alpha = 0;
102 }
103
104 if (origin_idx < 0) {
105 origin_idx = 0;
106 alpha = 0;
107 } else if (origin_idx + 1 >= size) {
108 origin_idx = size - 2;
109 alpha = 1;
110 }
111
112 return std::make_tuple(1 - alpha, origin_idx, alpha, origin_idx + 1);
113}
114}; // namespace resize
115}; // namespace arm_common
116}; // namespace megdnn

Callers 4

resize_direct_nchwxxFunction · 0.85
repFunction · 0.85
resize_direct_nchwxxFunction · 0.85
repFunction · 0.85

Calls 2

get_nearest_srcFunction · 0.70
floorFunction · 0.50

Tested by

no test coverage detected