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

Function dispatch_powc

src/jit/impl/halide/ast_hl.cpp:195–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195Halide::Expr dispatch_powc(Halide::FuncRef inp, float exp) {
196 if (almost_equal(exp, .0f)) {
197 return Halide::cast(inp.function().output_types()[0], 1);
198 }
199 auto int_neg = [exp](Halide::Expr x) {
200 if (exp < 0) {
201 return Halide::cast(x.type(), 1) / x;
202 }
203 return x;
204 };
205 if (almost_equal(std::abs(exp), 1.f)) {
206 return int_neg(inp);
207 }
208 if (almost_equal(std::abs(exp), 2.f)) {
209 return int_neg(inp * inp);
210 }
211 if (almost_equal(std::abs(exp), 3.f)) {
212 return int_neg(inp * inp * inp);
213 }
214 if (almost_equal(std::abs(exp), 4.f)) {
215 auto x = inp * inp;
216 return int_neg(x * x);
217 }
218
219 if (almost_equal(exp, .5f)) {
220 return Halide::sqrt(inp);
221 }
222
223 int exp_i = std::round(exp);
224 if (almost_equal(static_cast<float>(exp_i), exp)) {
225 auto yabs = Halide::pow(Halide::abs(inp), exp);
226 if (exp_i & 1) {
227 return Halide::select(inp < 0, -yabs, yabs);
228 } else {
229 return yabs;
230 }
231 }
232
233 return Halide::pow(inp, exp);
234}
235
236} // anonymous namespace
237

Callers 1

initMethod · 0.85

Calls 8

almost_equalFunction · 0.85
castFunction · 0.85
functionMethod · 0.80
absFunction · 0.50
sqrtFunction · 0.50
roundFunction · 0.50
powFunction · 0.50
typeMethod · 0.45

Tested by

no test coverage detected