MaximumMinimumGradCommon adds shared ops to calculate gradients for the binary Maximum and Minimum ops.
| 543 | // MaximumMinimumGradCommon adds shared ops to calculate gradients for |
| 544 | // the binary Maximum and Minimum ops. |
| 545 | Status MaximumMinimumGradCommon(const Scope& scope, const Operation& op, |
| 546 | const std::vector<Output>& grad_inputs, |
| 547 | std::vector<Output>* grad_outputs, |
| 548 | const Output& comparator) { |
| 549 | // comparator is a boolean tensor, with |
| 550 | // y = x_1 at points where comparator is true, and x_2 otherwise |
| 551 | // Therefore |
| 552 | // dy/dx_1 = 1 where comparator is true, and 0 otherwise. |
| 553 | // dy/dx_2 = 0 where comparator is true, and 1 otherwise. |
| 554 | auto grad = grad_inputs[0]; |
| 555 | auto zeros = ZerosLike(scope, grad); |
| 556 | auto gx_1 = Where3(scope, comparator, grad, zeros); |
| 557 | auto gx_2 = Where3(scope, comparator, zeros, grad); |
| 558 | return BinaryGradCommon(scope, op, grad_outputs, gx_1, gx_2); |
| 559 | } |
| 560 | |
| 561 | Status MaximumGrad(const Scope& scope, const Operation& op, |
| 562 | const std::vector<Output>& grad_inputs, |
no test coverage detected