-
Couldn't load subscription status.
- Fork 19
[fix][math] Fix error in Division of Array and a Scalar #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[fix][math] Fix error in Division of Array and a Scalar #244
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I somehow got confused about the backends and how arithmetic operations are finally down to the backend functions in _math_funcs.mojo. Perhaps we need to write a small API guidance for this part.
|
@forfudan you are right, I also kinda got confused when I was fixing this. |
f80cc95
into
Mojo-Numerics-and-Algorithms-group:pre-0.7
Error description
The above code produces an array filled with 2.0 which is wrong since the expected result is an array filled with 0.5. This error occurred due to the symmetric implementation of all arithmetic operators i.e
array +-*/ scalar, but this results in wrong value for division since it always calculatesarray / scalareven when the user input is (scalar / array).Solution
This PR fixes this error by adding a new function to the backends that calculate the array and scalar arithmetic operations so that array / scalar and scalar / array result in the correct values.