| 135 | REGISTER_GRADIENT_OP("SplitV", SplitVGrad); |
| 136 | |
| 137 | Status FillGrad(const Scope& scope, const Operation& op, |
| 138 | const std::vector<Output>& grad_inputs, |
| 139 | std::vector<Output>* grad_outputs) { |
| 140 | // y = fill(fill_shape, x) |
| 141 | // No gradient returned for the fill_shape argument. |
| 142 | grad_outputs->push_back(NoGradient()); |
| 143 | // The gradient for x (which must be a scalar) is just the sum of |
| 144 | // all the gradients from the shape it fills. |
| 145 | // We use ReduceSum to implement this, which needs an argument providing |
| 146 | // the indices of all the dimensions of the incoming gradient. |
| 147 | // grad(x) = reduce_sum(grad(y), [0..rank(grad(y))]) |
| 148 | auto all_dims = Range(scope, Const(scope, 0), Rank(scope, grad_inputs[0]), |
| 149 | Const(scope, 1)); |
| 150 | grad_outputs->push_back(ReduceSum(scope, grad_inputs[0], all_dims)); |
| 151 | return scope.status(); |
| 152 | } |
| 153 | REGISTER_GRADIENT_OP("Fill", FillGrad); |
| 154 | |
| 155 | Status DiagGrad(const Scope& scope, const Operation& op, |