MCPcopy Create free account
hub / github.com/apache/singa / Sum

Class Sum

python/singa/autograd.py:1110–1141  ·  view source on GitHub ↗

Element-wise sum of each of the input tensors

Source from the content-addressed store, hash-verified

1108
1109
1110class Sum(Operator):
1111 """
1112 Element-wise sum of each of the input tensors
1113 """
1114
1115 def __init__(self):
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 """
1136 Args:
1137 dy (CTensor): dL / dy
1138 Returns:
1139 dx (CTensor): dL / dx
1140 """
1141 return [dy] * self.l
1142
1143
1144def sum(*l):

Callers 4

sumFunction · 0.70
TEST_FFunction · 0.50
TEST_FFunction · 0.50
TestOneEpochFunction · 0.50

Calls

no outgoing calls

Tested by 3

TEST_FFunction · 0.40
TEST_FFunction · 0.40
TestOneEpochFunction · 0.40