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

Function SquaredDifferenceGrad

tensorflow/cc/gradients/math_grad.cc:475–487  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

473REGISTER_GRADIENT_OP("DivNoNan", DivNoNanGrad);
474
475Status SquaredDifferenceGrad(const Scope& scope, const Operation& op,
476 const std::vector<Output>& grad_inputs,
477 std::vector<Output>* grad_outputs) {
478 auto x_1 = ConjugateHelper(scope, op.input(0));
479 auto x_2 = ConjugateHelper(scope, op.input(1));
480 // y = (x_1 - x_2)^2
481 // dy/dx_1 = 2 * (x_1 - x_2)
482 // dy/dx_2 = -2 * (x_1 - x_2)
483 auto two = Cast(scope, Const(scope, 2), grad_inputs[0].type());
484 auto gx_1 = Mul(scope, grad_inputs[0], Mul(scope, two, Sub(scope, x_1, x_2)));
485 auto gx_2 = Neg(scope, gx_1);
486 return BinaryGradCommon(scope, op, grad_outputs, gx_1, gx_2);
487}
488REGISTER_GRADIENT_OP("SquaredDifference", SquaredDifferenceGrad);
489
490Status AddNGrad(const Scope& scope, const Operation& op,

Callers

nothing calls this directly

Calls 9

ConjugateHelperFunction · 0.85
BinaryGradCommonFunction · 0.85
typeMethod · 0.65
CastFunction · 0.50
ConstFunction · 0.50
MulFunction · 0.50
SubFunction · 0.50
NegFunction · 0.50
inputMethod · 0.45

Tested by

no test coverage detected