MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / MaximumMinimumGradCommon

Function MaximumMinimumGradCommon

tensorflow/cc/gradients/math_grad.cc:545–559  ·  view source on GitHub ↗

MaximumMinimumGradCommon adds shared ops to calculate gradients for the binary Maximum and Minimum ops.

Source from the content-addressed store, hash-verified

543// MaximumMinimumGradCommon adds shared ops to calculate gradients for
544// the binary Maximum and Minimum ops.
545Status 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
561Status MaximumGrad(const Scope& scope, const Operation& op,
562 const std::vector<Output>& grad_inputs,

Callers 2

MaximumGradFunction · 0.85
MinimumGradFunction · 0.85

Calls 2

BinaryGradCommonFunction · 0.85
ZerosLikeFunction · 0.50

Tested by

no test coverage detected