Kacper-Pietkun opened a new pull request, #21096:
URL: https://github.com/apache/incubator-mxnet/pull/21096

   ## Description ##
   Incorrect rounding of a number.
   
   ```
   import numpy as onp
   import mxnet as mx
   
   
   onp_d1 = onp.array([0.941], dtype=onp.float16)
   onp_d2 = onp.array([0.1569], dtype=onp.float16)
   mx_d1 = mx.numpy.array(onp_d1, dtype=onp.float16)
   mx_d2 = mx.numpy.array(onp_d2, dtype=onp.float16)
   
   # 0.941 / 0.1569 = 5.997450605481198
   onp_out = onp.floor_divide(onp_d1, onp_d2)  # onp_out = [5.] <= GOOD
   mx_out = mx.np.floor_divide(mx_d1, mx_d2)  # mx_out = [6.] <= WRONG
   ```
   
   
   ## Cause ##
   Incorrect rounding was caused by unnecessary implicit conversion from float 
to float16 after division but before rounding (5.99745 was saved as 6 during 
conversion from float to float16, because of lack of precision).
   
   ## Solution #
   From now, before doing calculations float16 arguments are explicitly casted 
to float and they are converted back to float16 only after division and 
rounding has been made.
   
   ## Checklist ##
   ### Essentials ###
   - [x] PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], 
[FEATURE], [DOC], etc)
   - [x] Changes are complete (i.e. I finished coding on this PR)
   - [x] All changes have test coverage


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to