Args: x (CTensor): matrix. Return: the result CTensor
(self, x, slope)
| 802 | super(PRelu, self).__init__() |
| 803 | |
| 804 | def forward(self, x, slope): |
| 805 | """ |
| 806 | Args: |
| 807 | x (CTensor): matrix. |
| 808 | Return: |
| 809 | the result CTensor |
| 810 | """ |
| 811 | mask0 = singa.LTFloat(x, 0.0) |
| 812 | res = singa.__mul__(x, mask0) |
| 813 | res = singa.__mul__(res, slope) |
| 814 | res += singa.ReLU(x) |
| 815 | if training: |
| 816 | self.input = x |
| 817 | self.slope = slope |
| 818 | self.mask0 = mask0 |
| 819 | self.shape0 = list(x.shape()) |
| 820 | self.shape1 = list(slope.shape()) |
| 821 | self.shape3 = list(res.shape()) |
| 822 | return res |
| 823 | |
| 824 | def backward(self, dy): |
| 825 | """ |