Args: dy (CTensor): the gradient tensor from upper operations Returns: a tuple for (da, db), da is data for dL / da, db is data for dL / db.
(self, dy)
| 3023 | return res |
| 3024 | |
| 3025 | def backward(self, dy): |
| 3026 | """ |
| 3027 | Args: |
| 3028 | dy (CTensor): the gradient tensor from upper operations |
| 3029 | Returns: |
| 3030 | a tuple for (da, db), da is data for dL / da, db is data |
| 3031 | for dL / db. |
| 3032 | """ |
| 3033 | dx0 = dy |
| 3034 | dx1 = singa.MultFloat(dy, -1.0) |
| 3035 | if (type(dy) == float) or self.shape0 == self.shape1: |
| 3036 | assert self.shape0 == self.shape1, ('should have same shape') |
| 3037 | return dx0, dx1 |
| 3038 | # handle broadcast |
| 3039 | dx0 = back_broadcast(self.shape3, self.shape0, dx0) |
| 3040 | dx1 = back_broadcast(self.shape3, self.shape1, dx1) |
| 3041 | return dx0, dx1 |
| 3042 | |
| 3043 | |
| 3044 | def sub(a, b): |
nothing calls this directly
no test coverage detected