Args: l (a list of CTensor): element-wise sum operator Returns: a CTensor for the result
(self, *l)
| 1116 | super(Sum, self).__init__() |
| 1117 | |
| 1118 | def forward(self, *l): |
| 1119 | """ |
| 1120 | Args: |
| 1121 | l (a list of CTensor): element-wise sum operator |
| 1122 | Returns: |
| 1123 | a CTensor for the result |
| 1124 | """ |
| 1125 | if training: |
| 1126 | self.l = len(l) |
| 1127 | assert (len(l) > 0) |
| 1128 | x = singa.Tensor(list(l[0].shape()), l[0].device()) |
| 1129 | x.SetFloatValue(0.0) |
| 1130 | for i in range(len(l)): |
| 1131 | x += l[i] |
| 1132 | return x |
| 1133 | |
| 1134 | def backward(self, dy): |
| 1135 | """ |