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 08:32:19 UTC

[GitHub] [incubator-singa] nudles commented on a change in pull request #510: SINGA 475 - add min operator

nudles commented on a change in pull request #510: SINGA 475 - add min operator
URL: https://github.com/apache/incubator-singa/pull/510#discussion_r313761395
 
 

 ##########
 File path: python/singa/autograd.py
 ##########
 @@ -1945,3 +1945,29 @@ def backward(self, dy):
 
 def sub(a, b):
     return Sub()(a,b)[0]
+
+
+class Min(Operation):
+    def __init__(self):
+        super(Min, self).__init__()    
+    
+    def forward(self, a, b):
+        m = singa.__sub__(a,b)
+        mask0 = singa.LTFloat(m,0) 
+        mask00 = singa.__mul__(singa.LEFloat(m,0),a)
+        mask1 = singa.GTFloat(m,0)
+        mask11=singa.__mul__(mask1,b)
+        mask = singa.__add__(mask00,mask11)
+        
+        if training:
+            self.mask = mask
+            self.mask0 = mask0
+            self.mask1 = mask1
+        return mask
+
+    def backward(self, dy):
+        return (self.mask0,self.mask1)
 
 Review comment:
   dy is not multiplied in the backward?

----------------------------------------------------------------
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