Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

MXNet Python numerical scalar is truncated when we set the locale #18079

Closed
stu1130 opened this issue Apr 16, 2020 · 2 comments
Closed

MXNet Python numerical scalar is truncated when we set the locale #18079

stu1130 opened this issue Apr 16, 2020 · 2 comments

Comments

@stu1130
Copy link
Contributor

stu1130 commented Apr 16, 2020

Description

deepjavalibrary/djl#49 indicates that MXNet backend didn't handle the locale right. When we use the operator that can input the scalar, we use string as medium to pass the scalar to backend. In C++ engine, we use std::stod to convert the string back to double https://github.com/apache/incubator-mxnet/blob/7a59239a260920dfde7c6bac410679c57a868cc0/src/operator/tensor/elemwise_binary_scalar_op.h#L365
The std::stod converts the string based on locale, but it doesn't get the locale from environment variable. So it is still use us by default. This is not the case in Java, you can see scalar was truncated which leads to wrong result.

You can reproduce the issue with the following command:

# install the de_DE.UTF-8 locale on the system
# 0.7 in de_DE.UTF-8 is represented as 0,7
# start the python
>>> import mxnet as mx
>>> from mxnet import npx
>>> import locale
>>> a = mx.np.array(1.3)
>>> a + 0.7
2.0 # right result as expected
>>> locale.setlocale(locale.LC_NUMERIC, 'de_DE.UTF-8')
>>>  a + 0.7
1.3 # wrong result because 0.7 was truncated to 0.0
@stu1130 stu1130 added the Bug label Apr 16, 2020
@stu1130 stu1130 changed the title MXNet Python numerical scalar broken when we set the locale MXNet Python numerical scalar is truncated when we set the locale Apr 16, 2020
@nickguletskii
Copy link
Contributor

Related: #17177

@stu1130
Copy link
Contributor Author

stu1130 commented Apr 24, 2020

I can confirm the issue is fixed by #17177 Thanks @nickguletskii

@stu1130 stu1130 closed this as completed Apr 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants