[
https://issues.apache.org/jira/browse/SINGA-478?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16903748#comment-16903748
]
ASF subversion and git services commented on SINGA-478:
-------------------------------------------------------
Commit 744a979cc95791401dd625664ab34b7988677fb3 in incubator-singa's branch
refs/heads/master from chrishkchris
[ https://gitbox.apache.org/repos/asf?p=incubator-singa.git;h=744a979 ]
SINGA-478 Add the __itruediv__ for python 3
We need to add _itruediv_ 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:
[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:
[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.
> Python 3 uses __itruediv__ instead of __idiv__
> ----------------------------------------------
>
> Key: SINGA-478
> URL: https://issues.apache.org/jira/browse/SINGA-478
> Project: Singa
> Issue Type: Improvement
> Components: Core
> Reporter: YEUNG SAI HO
> Priority: Major
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> We need to add __itruediv__ 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:
> {code:java}
> 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))
> {code}
> Without adding the {color:#333333}__itruediv__{color} function, the result
> is as follows, which means that the /= operation is not in place:
> {code:java}
> [10. 10. 10. 10. 10. 10. 10. 10. 10. 10.]
> {code}
> After adding the __itruediv__ function, the result is as follows, which means
> that the /= operation is in place:
> {code:java}
> [1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
> {code}
> This is because the {color:#333333}__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.{color}
>
>
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)