Args: dy (CTensor): the gradient tensor from upper operations Returns: a tuple for (*dx), dx is data for dL / dx.
(self, dy)
| 3442 | return res |
| 3443 | |
| 3444 | def backward(self, dy): |
| 3445 | """ |
| 3446 | Args: |
| 3447 | dy (CTensor): the gradient tensor from upper operations |
| 3448 | Returns: |
| 3449 | a tuple for (*dx), dx is data for dL / dx. |
| 3450 | """ |
| 3451 | if self.l == 1: |
| 3452 | return self.masks[0][0] |
| 3453 | else: |
| 3454 | ret = [] |
| 3455 | cumulation = None |
| 3456 | for mask0, mask1 in self.masks[::-1]: |
| 3457 | if not cumulation: |
| 3458 | ret.insert(0, mask1) |
| 3459 | cumulation = mask0 |
| 3460 | else: |
| 3461 | ret.insert(0, singa.__mul__(cumulation, mask1)) |
| 3462 | cumulation = singa.__mul__(cumulation, mask0) |
| 3463 | ret.insert(0, cumulation) |
| 3464 | return tuple(ret) |
| 3465 | |
| 3466 | |
| 3467 | def max(*l): |