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

Function rep

dnn/src/naive/resize/opr_impl.cpp:106–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104 rounding::RoundingConverter<ctype> output_converter;
105
106 rep(n, N) {
107 rep(oh, OH) rep(ow, OW) {
108 switch (imode) {
109 case InterpolationMode::NEAREST: {
110 auto ih = get_nearest_src(scale_h, IH, oh);
111 auto iw = get_nearest_src(scale_w, IW, ow);
112
113 rep(c, static_cast<int>(C)) {
114 dptr[c * OH * OW + oh * OW + ow] =
115 sptr[c * S_IC + ih * S_IH + iw * S_IW];
116 }
117 break;
118 }
119 case InterpolationMode::INTER_LINEAR: {
120 int ih0, ih1, iw0, iw1;
121 float ah0, ah1, aw0, aw1;
122
123 std::tie(ah0, ih0, ah1, ih1) =
124 get_nearest_linear_coord(kern_param.imode, scale_h, IH, oh);
125 std::tie(aw0, iw0, aw1, iw1) =
126 get_nearest_linear_coord(kern_param.imode, scale_w, IW, ow);
127
128 rep(c, static_cast<int>(C)) {
129 dptr[c * OH * OW + oh * OW + ow] = output_converter(
130 sptr[c * S_IC + ih0 * S_IH + iw0 * S_IW] * ah0 * aw0 +
131 sptr[c * S_IC + ih0 * S_IH + iw1 * S_IW] * ah0 * aw1 +
132 sptr[c * S_IC + ih1 * S_IH + iw0 * S_IW] * ah1 * aw0 +
133 sptr[c * S_IC + ih1 * S_IH + iw1 * S_IW] * ah1 * aw1);
134 }
135 break;
136 }
137 case InterpolationMode::INTER_CUBIC: {
138 auto coord_h = get_cubic_coord(scale_h, oh);
139 auto coord_w = get_cubic_coord(scale_w, ow);
140
141 float alphah = coord_h.first;
142 float alphaw = coord_w.first;
143
144 int ih0 = coord_h.second - 1;
145 int iw0 = coord_w.second - 1;
146 float h_coeff[4], w_coeff[4];
147 interpolate_cubic(alphah, h_coeff);
148 interpolate_cubic(alphaw, w_coeff);
149
150 rep(c, static_cast<int>(C)) {
151 constexpr int ksize = 4;
152 float ret = 0;
153 rep(kh, ksize) {
154 int h = saturate<int, int>(ih0 + kh, 0, IH - 1);
155 rep(kw, ksize) {
156 int w = saturate<int, int>(iw0 + kw, 0, IW - 1);
157 ret += sptr[c * S_IC + h * S_IH + w * S_IW] *
158 h_coeff[kh] * w_coeff[kw];
159 }
160 }
161 dptr[c * OH * OW + oh * OW + ow] = output_converter(ret);
162 }
163 break;

Callers 1

exec_internalMethod · 0.50

Calls 3

get_nearest_linear_coordFunction · 0.85
get_nearest_srcFunction · 0.50
interpolate_cubicFunction · 0.50

Tested by

no test coverage detected