| 740 | REGISTER_GRADIENT_OP("Sum", SumGrad); |
| 741 | |
| 742 | Status MeanGrad(const Scope& scope, const Operation& op, |
| 743 | const std::vector<Output>& grad_inputs, |
| 744 | std::vector<Output>* grad_outputs) { |
| 745 | // The Mean gradient is just like the Sum gradient, except that |
| 746 | // all gradients are also divided by the size of reduced groups. |
| 747 | auto sum_grad = SumGradHelper(scope, op, grad_inputs); |
| 748 | |
| 749 | // The product of all entries in a tensor's shape is the total |
| 750 | // number of entries in the tensor. This step calculates |
| 751 | // n_input_entries/n_output_entries |
| 752 | // = group_size |
| 753 | auto input_shape = Shape(scope, op.input(0)); |
| 754 | auto output_shape = Shape(scope, op.output(0)); |
| 755 | auto zero = Const(scope, 0); |
| 756 | auto group_size = SafeDivHelper(scope, Prod(scope, input_shape, zero), |
| 757 | Prod(scope, output_shape, zero)); |
| 758 | |
| 759 | // propagate sum_grad/group_size |
| 760 | grad_outputs->push_back( |
| 761 | Div(scope, sum_grad, Cast(scope, group_size, sum_grad.type()))); |
| 762 | |
| 763 | // Stop propagation along reduction_indices |
| 764 | grad_outputs->push_back(NoGradient()); |
| 765 | return scope.status(); |
| 766 | } |
| 767 | REGISTER_GRADIENT_OP("Mean", MeanGrad); |
| 768 | |
| 769 | Status ErfGrad(const Scope& scope, const Operation& op, |
nothing calls this directly
no test coverage detected