You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/01/09 09:30:53 UTC
[GitHub] [incubator-mxnet] haojin2 edited a comment on issue #17255: [DO NOT
REVIEW]Set np default dtype( float32 <-> float64)
haojin2 edited a comment on issue #17255: [DO NOT REVIEW]Set np default dtype( float32 <-> float64)
URL: https://github.com/apache/incubator-mxnet/pull/17255#issuecomment-572472159
@marcoabreu
Let's probably take a look at this example to help you understand:
```python
import numpy as np
a = np.ones((4096, 1024)) / 1000000
# original code, a is of type float64
```
```python
from mxnet import np, npx
npx.set_np()
# transitioning to NP on MXNet, swapping the library
a = np.ones((4096, 1024)) / 1000000
# a is of type float32, which might not be able to accurately represent very small numbers,
# could possibly cause some precision errors in later computations
a = np.ones((4096, 1024), dtype=np.float64) / 1000000
# to recover the same precision, need to touch the original code to explicitly specify the dtype,
# number of lines changed is the same as number of array creation functions used with in the whole file.
```
```python
from mxnet import np, npx
npx.set_np()
# transitioning to NP on MXNet, swapping the library
npx.set_np_default_type()
# switch the default type, this function call could be further merged to be part of set_np function
a = np.ones((4096, 1024)) / 1000000
# now a is of type float64, not interfering with the original assumption of precisions without any changes to the original code.
# only one more line is added, not the same as the total # of array creations in the script.
```
----------------------------------------------------------------
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