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

Function PadGrad

tensorflow/cc/gradients/array_grad.cc:305–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303
304template <bool IsPadV2>
305Status PadGrad(const Scope& scope, const Operation& op,
306 const std::vector<Output>& grad_inputs,
307 std::vector<Output>* grad_outputs) {
308 auto x = op.input(0);
309 auto a = op.input(1); // [Rank(x), 2]
310 // Takes a slice of a. The 1st column. [Rank(x), 1].
311 auto size = Stack(scope, {Rank(scope, x), 1});
312 auto pad_before = Slice(scope, a, {0, 0}, size);
313 // Make it a 1-D tensor.
314 auto begin = Reshape(scope, pad_before, {-1});
315 grad_outputs->push_back(Slice(scope, grad_inputs[0], begin, Shape(scope, x)));
316 grad_outputs->push_back(NoGradient());
317 // PadV2 adds a "constant_values" input.
318 if (IsPadV2) {
319 grad_outputs->push_back(NoGradient());
320 }
321 return scope.status();
322}
323REGISTER_GRADIENT_OP("Pad", PadGrad<false>);
324REGISTER_GRADIENT_OP("PadV2", PadGrad<true>);
325

Callers

nothing calls this directly

Calls 9

StackClass · 0.85
NoGradientFunction · 0.85
RankFunction · 0.50
SliceClass · 0.50
ReshapeFunction · 0.50
ShapeClass · 0.50
inputMethod · 0.45
push_backMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected