From dev-return-3672-archive-asf-public=cust-asf.ponee.io@singa.incubator.apache.org Tue Sep 17 11:52:10 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id B9FD0180652 for ; Tue, 17 Sep 2019 13:52:09 +0200 (CEST) Received: (qmail 47035 invoked by uid 500); 17 Sep 2019 11:52:09 -0000 Mailing-List: contact dev-help@singa.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@singa.incubator.apache.org Delivered-To: mailing list dev@singa.incubator.apache.org Received: (qmail 47008 invoked by uid 99); 17 Sep 2019 11:52:09 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Sep 2019 11:52:09 +0000 From: GitBox To: dev@singa.apache.org Subject: [GitHub] [incubator-singa] joddiy commented on a change in pull request #528: SINGA 475 - add logical operator: and, or, xor, not & negative, reciprocal Message-ID: <156872112898.7265.10175136670320782391.gitbox@gitbox.apache.org> Date: Tue, 17 Sep 2019 11:52:08 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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_r325108637 ########## 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: not clear, plz use this: ``` m = singa.__add__(singa.PowFloat(singa.Sign(a), 2.0), singa.PowFloat(singa.Sign(b), 2.0)) cur = singa.Sign(m) ``` ---------------------------------------------------------------- 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