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

Function rep

dnn/src/naive/warp_affine/opr_impl.cpp:37–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 sptr += n * C * IH * IW;
36
37 rep(ow, OW) {
38 float alphaw = mptr[0] * ow + mptr[1] * oh + mptr[2];
39 float alphah = mptr[3] * ow + mptr[4] * oh + mptr[5];
40
41 int iw0 = get_real_coord(std::floor(alphaw) + 0, IW);
42 int iw1 = get_real_coord(std::floor(alphaw) + 1, IW);
43 int ih0 = get_real_coord(std::floor(alphah) + 0, IH);
44 int ih1 = get_real_coord(std::floor(alphah) + 1, IH);
45
46 alphaw -= floor(alphaw);
47 alphah -= floor(alphah);
48 if (bmode != BorderMode::CONSTANT) {
49 rep(c, C) {
50 dptr[c * OH * OW + oh * OW + ow] = output_converter(
51 sptr[c * IH * IW + ih0 * IW + iw0] * (1.0f - alphaw) *
52 (1.0f - alphah) +
53 sptr[c * IH * IW + ih0 * IW + iw1] * alphaw * (1.0f - alphah) +
54 sptr[c * IH * IW + ih1 * IW + iw0] * (1.0f - alphaw) * alphah +
55 sptr[c * IH * IW + ih1 * IW + iw1] * alphaw * alphah);
56 }
57 } else {
58 rep(c, C) {
59 const float b = border_val;
60 auto val = (ih0 != -1 && iw0 != -1 ? sptr[c * IH * IW + ih0 * IW + iw0]
61 : b) *
62 (1.0f - alphaw) * (1.0f - alphah) +
63 (ih0 != -1 && iw1 != -1 ? sptr[c * IH * IW + ih0 * IW + iw1]
64 : b) *
65 alphaw * (1.0f - alphah) +
66 (ih1 != -1 && iw0 != -1 ? sptr[c * IH * IW + ih1 * IW + iw0]
67 : b) *
68 (1.0f - alphaw) * alphah +
69 (ih1 != -1 && iw1 != -1 ? sptr[c * IH * IW + ih1 * IW + iw1]
70 : b) *
71 alphaw * alphah;
72 dptr[c * OH * OW + oh * OW + ow] =
73 output_converter(std::isfinite(val) ? val : b);
74 }
75 }
76 }
77}
78
79template <typename ctype, typename mtype>

Callers 1

warp_affine_cvFunction · 0.70

Calls 2

floorFunction · 0.50
isfiniteFunction · 0.50

Tested by

no test coverage detected