Args: x (CTensor): matrix Returns: a CTensor for the result
(self, x)
| 3180 | self.gamma = gamma |
| 3181 | |
| 3182 | def forward(self, x): |
| 3183 | """ |
| 3184 | Args: |
| 3185 | x (CTensor): matrix |
| 3186 | Returns: |
| 3187 | a CTensor for the result |
| 3188 | """ |
| 3189 | x = singa.AddFloat(singa.MultFloat(x, self.alpha), self.gamma) |
| 3190 | if training: |
| 3191 | self.cache = x |
| 3192 | |
| 3193 | x = singa.ReLU(x) |
| 3194 | mask1 = singa.LTFloat(x, 1.0) |
| 3195 | mask2 = singa.GEFloat(x, 1.0) |
| 3196 | |
| 3197 | ans = singa.__add__(singa.__mul__(x, mask1), mask2) |
| 3198 | return singa.ReLU(ans) |
| 3199 | |
| 3200 | def backward(self, dy): |
| 3201 | """ |