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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to