Args: dy (CTensor): dL / dy Returns: dx (CTensor): dL / dx
(self, dy)
| 822 | return res |
| 823 | |
| 824 | def backward(self, dy): |
| 825 | """ |
| 826 | Args: |
| 827 | dy (CTensor): dL / dy |
| 828 | Returns: |
| 829 | dx (CTensor): dL / dx |
| 830 | """ |
| 831 | dx1mask = singa.GEFloat(self.input, 0.0) |
| 832 | dx2 = singa.__mul__(self.mask0, self.slope) |
| 833 | dx = singa.__add__(dx1mask, dx2) |
| 834 | dx = singa.__mul__(dy, dx) |
| 835 | dslope = singa.__mul__(dy, singa.__mul__(self.mask0, self.input)) |
| 836 | if (type(dy) == float) or self.shape0 == self.shape1: |
| 837 | assert self.shape0 == self.shape1, ('should have same shape') |
| 838 | return dx, dslope |
| 839 | # handle broadcast |
| 840 | dx = back_broadcast(self.shape3, self.shape0, dx) |
| 841 | dslope = back_broadcast(self.shape3, self.shape1, dslope) |
| 842 | return dx, dslope |
| 843 | |
| 844 | |
| 845 | def prelu(x, slope): |
nothing calls this directly
no test coverage detected