-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
[BUG] The and
and or
operators produce incorrect results with SIMD inputs
#2374
Comments
leandrolcampos
added
bug
Something isn't working
mojo
Issues that are related to mojo
labels
Apr 22, 2024
leandrolcampos
changed the title
[BUG] The operators
[BUG] The Apr 22, 2024
and
and or
produces wrong results with SIMD inputsand
and or
operators produces wrong results with SIMD inputs
leandrolcampos
changed the title
[BUG] The
[BUG] The Apr 22, 2024
and
and or
operators produces wrong results with SIMD inputsand
and or
operators produce wrong results with SIMD inputs
leandrolcampos
changed the title
[BUG] The
[BUG] The Apr 22, 2024
and
and or
operators produce wrong results with SIMD inputsand
and or
operators produce incorrect results with SIMD inputs
I can reproduce. Mojo 24.2.1 |
|
linear
bot
changed the title
[BUG] The
[BUG] The Apr 29, 2024
and
and or
operators produce incorrect results with SIMD inputsand
and or
operators produce incorrect results with SIMD inputs
JoeLoser
pushed a commit
to JoeLoser/mojo
that referenced
this issue
May 3, 2024
…lmost_equal` (#38991) [External] [stdlib] Enhance Handling of Infinity and NaN in `assert_almost_equal` This PR enhances the `assert_almost_equal` function to correctly handle cases involving infinity and NaN. According to `test_assert_almost_equal` added to `/test/testing/test_assertion.mojo`, the current implementation of `assert_almost_equal` results in errors in the following cases: ```mojo alias float_type = DType.float32 alias _inf = inf[float_type]() alias _nan = nan[float_type]() ... _should_succeed( SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf) ) ... _should_fail( SIMD[float_type, 2](-_inf, 0.0), SIMD[float_type, 2](_inf, 0.0), rtol=0.1, ) _should_fail( SIMD[float_type, 2](_inf, 0.0), SIMD[float_type, 2](0.0, 0.0), rtol=0.1, ) ... _should_fail( SIMD[float_type, 2](_nan, 0.0), SIMD[float_type, 2](0.0, 0.0), equal_nan=True, ) ``` This PR also: - Eliminates the use of `and` and `or` in the `_isclose` function due to the issue outlined in modularml#2374. - Explicitly reduces boolean vectors to boolean scalar values instead of counting on implicit conversions for clarity. - Avoids arithmetic operations in `_isclose` and `assert_almost_equal` when the type is boolean, as these operations are not supported in this case. - Clarifies the behavior of `assert_almost_equal` in the docstring, highlighting differences from similar functions such as `numpy.testing.assert_allclose`. - Adds the `inf` function to `utils/_numerics` along with corresponding tests in `test/utils/test_numerics.mojo`. ORIGINAL_AUTHOR=Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> PUBLIC_PR_LINK=modularml#2375 Co-authored-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> Closes modularml#2375 MODULAR_ORIG_COMMIT_REV_ID: 2e8b24461dd3279bc841877cc0167acaa104f273
JoeLoser
pushed a commit
that referenced
this issue
May 3, 2024
…lmost_equal` (#38991) [External] [stdlib] Enhance Handling of Infinity and NaN in `assert_almost_equal` This PR enhances the `assert_almost_equal` function to correctly handle cases involving infinity and NaN. According to `test_assert_almost_equal` added to `/test/testing/test_assertion.mojo`, the current implementation of `assert_almost_equal` results in errors in the following cases: ```mojo alias float_type = DType.float32 alias _inf = inf[float_type]() alias _nan = nan[float_type]() ... _should_succeed( SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf) ) ... _should_fail( SIMD[float_type, 2](-_inf, 0.0), SIMD[float_type, 2](_inf, 0.0), rtol=0.1, ) _should_fail( SIMD[float_type, 2](_inf, 0.0), SIMD[float_type, 2](0.0, 0.0), rtol=0.1, ) ... _should_fail( SIMD[float_type, 2](_nan, 0.0), SIMD[float_type, 2](0.0, 0.0), equal_nan=True, ) ``` This PR also: - Eliminates the use of `and` and `or` in the `_isclose` function due to the issue outlined in #2374. - Explicitly reduces boolean vectors to boolean scalar values instead of counting on implicit conversions for clarity. - Avoids arithmetic operations in `_isclose` and `assert_almost_equal` when the type is boolean, as these operations are not supported in this case. - Clarifies the behavior of `assert_almost_equal` in the docstring, highlighting differences from similar functions such as `numpy.testing.assert_allclose`. - Adds the `inf` function to `utils/_numerics` along with corresponding tests in `test/utils/test_numerics.mojo`. ORIGINAL_AUTHOR=Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> PUBLIC_PR_LINK=#2375 Co-authored-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> Closes #2375 MODULAR_ORIG_COMMIT_REV_ID: 2e8b24461dd3279bc841877cc0167acaa104f273
JoeLoser
pushed a commit
to JoeLoser/mojo
that referenced
this issue
May 8, 2024
…lmost_equal` (#39452) [External] [stdlib] Enhance Handling of Infinity and NaN in `assert_almost_equal` This PR enhances the `assert_almost_equal` function to correctly handle cases involving infinity and NaN. According to `test_assert_almost_equal` added to `/test/testing/test_assertion.mojo`, the current implementation of `assert_almost_equal` results in errors in the following cases: ```mojo alias float_type = DType.float32 alias _inf = inf[float_type]() alias _nan = nan[float_type]() ... _should_succeed( SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf) ) ... _should_fail( SIMD[float_type, 2](-_inf, 0.0), SIMD[float_type, 2](_inf, 0.0), rtol=0.1, ) _should_fail( SIMD[float_type, 2](_inf, 0.0), SIMD[float_type, 2](0.0, 0.0), rtol=0.1, ) ... _should_fail( SIMD[float_type, 2](_nan, 0.0), SIMD[float_type, 2](0.0, 0.0), equal_nan=True, ) ``` This PR also: - Eliminates the use of `and` and `or` in the `_isclose` function due to the issue outlined in modularml#2374. - Explicitly reduces boolean vectors to boolean scalar values instead of counting on implicit conversions for clarity. - Avoids arithmetic operations in `_isclose` and `assert_almost_equal` when the type is boolean, as these operations are not supported in this case. - Clarifies the behavior of `assert_almost_equal` in the docstring, highlighting differences from similar functions such as `numpy.testing.assert_allclose`. - Adds the `inf` function to `utils/_numerics` along with corresponding tests in `test/utils/test_numerics.mojo`. ORIGINAL_AUTHOR=Leandro Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> PUBLIC_PR_LINK=modularml#2375 Co-authored-by: Leandro Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> Closes modularml#2375 MODULAR_ORIG_COMMIT_REV_ID: 8e0c2394d01d12015816f242e98d6f457af9cdfd
JoeLoser
pushed a commit
that referenced
this issue
May 8, 2024
…lmost_equal` (#39452) [External] [stdlib] Enhance Handling of Infinity and NaN in `assert_almost_equal` This PR enhances the `assert_almost_equal` function to correctly handle cases involving infinity and NaN. According to `test_assert_almost_equal` added to `/test/testing/test_assertion.mojo`, the current implementation of `assert_almost_equal` results in errors in the following cases: ```mojo alias float_type = DType.float32 alias _inf = inf[float_type]() alias _nan = nan[float_type]() ... _should_succeed( SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf) ) ... _should_fail( SIMD[float_type, 2](-_inf, 0.0), SIMD[float_type, 2](_inf, 0.0), rtol=0.1, ) _should_fail( SIMD[float_type, 2](_inf, 0.0), SIMD[float_type, 2](0.0, 0.0), rtol=0.1, ) ... _should_fail( SIMD[float_type, 2](_nan, 0.0), SIMD[float_type, 2](0.0, 0.0), equal_nan=True, ) ``` This PR also: - Eliminates the use of `and` and `or` in the `_isclose` function due to the issue outlined in #2374. - Explicitly reduces boolean vectors to boolean scalar values instead of counting on implicit conversions for clarity. - Avoids arithmetic operations in `_isclose` and `assert_almost_equal` when the type is boolean, as these operations are not supported in this case. - Clarifies the behavior of `assert_almost_equal` in the docstring, highlighting differences from similar functions such as `numpy.testing.assert_allclose`. - Adds the `inf` function to `utils/_numerics` along with corresponding tests in `test/utils/test_numerics.mojo`. ORIGINAL_AUTHOR=Leandro Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> PUBLIC_PR_LINK=#2375 Co-authored-by: Leandro Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> Closes #2375 MODULAR_ORIG_COMMIT_REV_ID: 8e0c2394d01d12015816f242e98d6f457af9cdfd
lsh
pushed a commit
to lsh/mojo
that referenced
this issue
May 17, 2024
…lmost_equal` (#38991) [External] [stdlib] Enhance Handling of Infinity and NaN in `assert_almost_equal` This PR enhances the `assert_almost_equal` function to correctly handle cases involving infinity and NaN. According to `test_assert_almost_equal` added to `/test/testing/test_assertion.mojo`, the current implementation of `assert_almost_equal` results in errors in the following cases: ```mojo alias float_type = DType.float32 alias _inf = inf[float_type]() alias _nan = nan[float_type]() ... _should_succeed( SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf) ) ... _should_fail( SIMD[float_type, 2](-_inf, 0.0), SIMD[float_type, 2](_inf, 0.0), rtol=0.1, ) _should_fail( SIMD[float_type, 2](_inf, 0.0), SIMD[float_type, 2](0.0, 0.0), rtol=0.1, ) ... _should_fail( SIMD[float_type, 2](_nan, 0.0), SIMD[float_type, 2](0.0, 0.0), equal_nan=True, ) ``` This PR also: - Eliminates the use of `and` and `or` in the `_isclose` function due to the issue outlined in modularml#2374. - Explicitly reduces boolean vectors to boolean scalar values instead of counting on implicit conversions for clarity. - Avoids arithmetic operations in `_isclose` and `assert_almost_equal` when the type is boolean, as these operations are not supported in this case. - Clarifies the behavior of `assert_almost_equal` in the docstring, highlighting differences from similar functions such as `numpy.testing.assert_allclose`. - Adds the `inf` function to `utils/_numerics` along with corresponding tests in `test/utils/test_numerics.mojo`. ORIGINAL_AUTHOR=Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> PUBLIC_PR_LINK=modularml#2375 Co-authored-by: Leandro Augusto Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> Closes modularml#2375 MODULAR_ORIG_COMMIT_REV_ID: 2e8b24461dd3279bc841877cc0167acaa104f273 Signed-off-by: Lukas Hermann <lukashermann28@gmail.com>
lsh
pushed a commit
to lsh/mojo
that referenced
this issue
May 17, 2024
…lmost_equal` (#39452) [External] [stdlib] Enhance Handling of Infinity and NaN in `assert_almost_equal` This PR enhances the `assert_almost_equal` function to correctly handle cases involving infinity and NaN. According to `test_assert_almost_equal` added to `/test/testing/test_assertion.mojo`, the current implementation of `assert_almost_equal` results in errors in the following cases: ```mojo alias float_type = DType.float32 alias _inf = inf[float_type]() alias _nan = nan[float_type]() ... _should_succeed( SIMD[float_type, 2](-_inf, _inf), SIMD[float_type, 2](-_inf, _inf) ) ... _should_fail( SIMD[float_type, 2](-_inf, 0.0), SIMD[float_type, 2](_inf, 0.0), rtol=0.1, ) _should_fail( SIMD[float_type, 2](_inf, 0.0), SIMD[float_type, 2](0.0, 0.0), rtol=0.1, ) ... _should_fail( SIMD[float_type, 2](_nan, 0.0), SIMD[float_type, 2](0.0, 0.0), equal_nan=True, ) ``` This PR also: - Eliminates the use of `and` and `or` in the `_isclose` function due to the issue outlined in modularml#2374. - Explicitly reduces boolean vectors to boolean scalar values instead of counting on implicit conversions for clarity. - Avoids arithmetic operations in `_isclose` and `assert_almost_equal` when the type is boolean, as these operations are not supported in this case. - Clarifies the behavior of `assert_almost_equal` in the docstring, highlighting differences from similar functions such as `numpy.testing.assert_allclose`. - Adds the `inf` function to `utils/_numerics` along with corresponding tests in `test/utils/test_numerics.mojo`. ORIGINAL_AUTHOR=Leandro Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> PUBLIC_PR_LINK=modularml#2375 Co-authored-by: Leandro Lacerda Campos <15185896+leandrolcampos@users.noreply.github.com> Closes modularml#2375 MODULAR_ORIG_COMMIT_REV_ID: 8e0c2394d01d12015816f242e98d6f457af9cdfd Signed-off-by: Lukas Hermann <lukashermann28@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug description
The
and
andor
operators produce incorrect results when they are applied to SIMD inputs.Steps to reproduce
Run the following program:
The program prints:
The outputs of
&
and|
are correct.System information
The text was updated successfully, but these errors were encountered: