Args: dy (CTensor): the gradient tensor from upper operations Returns: CTensor, the gradient over input
(self, dy)
| 2758 | return x1 |
| 2759 | |
| 2760 | def backward(self, dy): |
| 2761 | """ |
| 2762 | Args: |
| 2763 | dy (CTensor): the gradient tensor from upper operations |
| 2764 | Returns: |
| 2765 | CTensor, the gradient over input |
| 2766 | """ |
| 2767 | # TODO(wangwei) check the correctness |
| 2768 | dx1 = singa.GTFloat(self.input, 0.0) |
| 2769 | dx2 = singa.LTFloat(self.input, 0.0) |
| 2770 | dx2 = singa.MultFloat(dx2, self.a) |
| 2771 | dx = singa.__add__(dx1, dx2) |
| 2772 | dx *= dy |
| 2773 | return dx |
| 2774 | |
| 2775 | |
| 2776 | def leakyrelu(x, a=0.01): |