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

Method get_nearest_linear_coord

dnn/src/common/resize.cpp:85–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

floorFunction · 0.50
get_nearest_srcFunction · 0.50

Tested by

no test coverage detected