| 18 | mType = SEMI_LINEAR; |
| 19 | } |
| 20 | virtual std::vector<Express::VARP> onGrad(Express::EXPRP expr, |
| 21 | const std::vector<Express::VARP>& backwardOutput) override { |
| 22 | auto inputs = expr->inputs(); |
| 23 | auto type = inputs[1]->getInfo()->type; |
| 24 | std::vector<VARP> result(inputs.size(), nullptr); |
| 25 | if (type.code != halide_type_float) { |
| 26 | return result; |
| 27 | } |
| 28 | auto outputDiff = backwardOutput[0]; |
| 29 | // d (select(x, a, b)) = da * (x>0) + db * (x < 0) |
| 30 | { |
| 31 | auto zero = MNN::Express::_ZerosLike(expr->inputs()[1]); |
| 32 | result[1] = MNN::Express::_Select(inputs[0], outputDiff, zero); |
| 33 | result[2] = MNN::Express::_Select(inputs[0], zero, outputDiff); |
| 34 | } |
| 35 | return result; |
| 36 | } |
| 37 | }; |
| 38 | |
| 39 | static void _create() { |
nothing calls this directly
no test coverage detected