joddiy commented on a change in pull request #528: SINGA 475 - add logical operator: and, or, xor, not & negative, reciprocal URL: https://github.com/apache/incubator-singa/pull/528#discussion_r325462186
########## File path: python/singa/autograd.py ########## @@ -2522,3 +2523,144 @@ def backward(self, dy): def max(a,b): return Max()(a,b)[0] + +class And(Operation): + def __init__(self): + super(And, self).__init__() + + def forward(self, a, b): + m = singa.__div__(a,b) + + mask0 = singa.GEFloat(m,1) + mask1 = singa.LEFloat(m,1) + cur = singa.__mul__(mask0,mask1) + + return cur + + def backward(self, dy): + assert 0,('no gradient') + return None + +def _and(a,b): + return And()(a,b)[0] + + +class Or(Operation): + def __init__(self): + super(Or, self).__init__() + + def forward(self, a, b): + #find equal element-wise + m = singa.__sub__(a,b) Review comment: if a = -b, the Signs of them are, 1, and -1, and then, you take a square on it, the result will be 1 and 1, and you add them together, is 2, take the Sign again, you get a 1 finally. ---------------------------------------------------------------- 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