Skip to content
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: Fix for npyv__trunc_s32_f32 (VXE) #23147

Merged
merged 2 commits into from Feb 2, 2023

Conversation

charris
Copy link
Member

@charris charris commented Feb 2, 2023

Backport of #23077.

np.sin(), np.cos() are giving erroneous result for float32 (VXE).
This PR is fixing npyv__trunc_s32_f32(npyv_f32 a) to resolve the issue.

np.sin() reproduce (without fix)

>>> c = np.array( [-25.091976, 90.14286], dtype=np.float32)
>>> np.sin(c)
array([0.04075377, 0.5707917 ], dtype=float32)
>>> 

>>> c = np.array( [90.14286], dtype=np.float32)
>>> np.sin(c)
array([0.8210949], dtype=float32)
>>>

>>> c = np.array( [-25.091976,  90.14286,   46.39879], dtype=np.float32)
>>> np.sin(c)
array([ 0.04075377, -0.5707917 ,  0.6632113 ], dtype=float32)  

After the fix:

>>> import numpy as np
>>> c = np.array( [-25.091976, 90.14286], dtype=np.float32)
>>> np.sin(c)
array([0.04075377, 0.8210949 ], dtype=float32)

>>> c = np.array( [90.14286], dtype=np.float32)
>>> np.sin(c)
array([0.8210949], dtype=float32)

>>> c = np.array( [-25.091976,  90.14286,   46.39879], dtype=np.float32)
>>> np.sin(c)
array([0.04075377, 0.8210949 , 0.6632113 ], dtype=float32)
>>>

Test failure without fix -

FAILED ../../core/tests/test_umath.py::TestAVXFloat32Transcendental::test_sincos_float32 - AssertionError: Arrays are not almost equal up to 2 ULP (max difference is 2.13071e+09 ULP)
FAILED ../../core/tests/test_umath.py::TestAVXFloat32Transcendental::test_strided_float32 - AssertionError: X and Y are not equal to 2 ULP (max is 6.79208e+06)
FAILED ../../core/tests/test_umath_accuracy.py::TestAccuracy::test_validate_fp16_transcendentals[cos] - AssertionError: Arrays are not almost equal up to 1 ULP (max difference is 30720 ULP)
FAILED ../../core/tests/test_umath_accuracy.py::TestAccuracy::test_validate_fp16_transcendentals[sin] - AssertionE

np.sin(), np.cos() are giving erroneous result for float32 (VXE)
This PR is fixing `npyv_s32 npyv__trunc_s32_f32(npyv_f32 a)`
to resolve the issue.
@charris charris added 00 - Bug 06 - Regression 08 - Backport Used to tag backport PRs component: SIMD Issues in SIMD (fast instruction sets) code or machinery labels Feb 2, 2023
@charris charris added this to the 1.24.2 release milestone Feb 2, 2023
@charris charris merged commit 62af62a into numpy:maintenance/1.24.x Feb 2, 2023
@charris charris deleted the backport-23077 branch February 2, 2023 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug 06 - Regression 08 - Backport Used to tag backport PRs component: SIMD Issues in SIMD (fast instruction sets) code or machinery
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants