backward of ReduceMean Args: dy (CTensor): gradient tensor. Returns: the gradient tensor over input tensor.
(self, dy)
| 4123 | return _x |
| 4124 | |
| 4125 | def backward(self, dy): |
| 4126 | """ |
| 4127 | backward of ReduceMean |
| 4128 | Args: |
| 4129 | dy (CTensor): gradient tensor. |
| 4130 | Returns: |
| 4131 | the gradient tensor over input tensor. |
| 4132 | """ |
| 4133 | x_shape, x = self.cache |
| 4134 | dy = singa.Reshape(dy, x_shape) |
| 4135 | mask = singa.Tensor(list(x.shape()), x.device()) |
| 4136 | mask.SetFloatValue(1.0) |
| 4137 | dy = singa.__mul__(mask, dy) |
| 4138 | dy = singa.MultFloat(dy, self.scale) |
| 4139 | return dy |
| 4140 | |
| 4141 | |
| 4142 | def reduce_mean(x, axes=None, keepdims=1): |