From dev-return-3206-archive-asf-public=cust-asf.ponee.io@singa.incubator.apache.org Thu Aug 8 09:46:31 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 463E6180642 for ; Thu, 8 Aug 2019 11:46:31 +0200 (CEST) Received: (qmail 10399 invoked by uid 500); 8 Aug 2019 09:46:30 -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 10389 invoked by uid 99); 8 Aug 2019 09:46:30 -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; Thu, 08 Aug 2019 09:46:30 +0000 From: GitBox To: dev@singa.apache.org Subject: [GitHub] [incubator-singa] chrishkchris opened a new pull request #500: SINGA-478 (Python 3 uses __itruediv__ instead of __idiv__) Message-ID: <156525759052.23615.16884239318598379913.gitbox@gitbox.apache.org> Date: Thu, 08 Aug 2019 09:46:30 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit chrishkchris opened a new pull request #500: SINGA-478 (Python 3 uses __itruediv__ instead of __idiv__) URL: https://github.com/apache/incubator-singa/pull/500 We need to add `__itruediv__` for python 3 in tensor.py because the original `__idiv__` is not supported by python 3 anymore. To understand the problem, let's study the following code first: ``` from singa import tensor from singa import device import numpy as np Y = np.ones(shape=[10],dtype=np.float32) * 10.0 y = tensor.from_numpy(Y) y.to_device(device.get_default_device()) def divide(y): y /= 10 divide(y) print(tensor.to_numpy(y)) ``` Without adding the `__itruediv__` function, the result is as follows, which means that the /= operation is not in place operation: `[10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]` After adding the _itruediv_ function, the result is as follows, which means that the /= operation is in place operation: `[1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]` This is because the `__idiv__` operation is for python 2, while `__itruediv__` is for python 3. Therefore, if we do not add the `__itruediv__` operator in tensor.py, it just uses a default operation which is not in place operation. Meanwhile, I am not sure if I also need to add `__truediv__` for python 3 to acts as `__div__` for python 2. ---------------------------------------------------------------- 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