You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@singa.apache.org by GitBox <gi...@apache.org> on 2019/08/14 09:08:40 UTC

[GitHub] [incubator-singa] nudles commented on a change in pull request #496: SINGA-474 Mean operator

nudles commented on a change in pull request #496: SINGA-474 Mean operator
URL: https://github.com/apache/incubator-singa/pull/496#discussion_r313776385
 
 

 ##########
 File path: python/singa/autograd.py
 ##########
 @@ -354,6 +354,41 @@ def backward(self, dy):
         return singa.__mul__(dy, dx)
 
 
+def relu(x):
+    return ReLU()(x)[0]
+
+class Mean(Operation):
+    def __init__(self):
+        super(Mean, self).__init__()
+
+    def forward(self, *l):
+        """
+        Args:
+            l: a list of CTensor
+            element-wise mean operator
+        Returns:
+            a new CTensor
+        """
+        if training:
+            self.l = len(l)
+        assert(len(l)>0);
+        x = l[0]
+        for i in range(1,len(l)):
+            x = singa.__add__(x,l[i])
 
 Review comment:
   this is not efficient. you can create an empty tensor and then accumulate each of l into it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services