Skip to content

Fixes #2508 and #2519: Fixes uint scalar handling and overhauls mod/fmod for floats - #2520

Merged
Ethan-DeBandi99 merged 2 commits into
Bears-R-Us:masterfrom
stress-tess:2508_incorrect_uint_scalars
Jun 29, 2023
Merged

Ethan-DeBandi99 merged 2 commits into
Bears-R-Us:masterfrom
stress-tess:2508_incorrect_uint_scalars

Conversation

@stress-tess

@stress-tess stress-tess commented Jun 21, 2023 •

Copy link
Copy Markdown
Member

This PR (fixes #2508 and closes #2519)

  • resolves two bugs with our handling of uint scalars
  • overhauls our mod and adds fmod
    • adds testing to verify these match their numpy equivalents
  • fixes the divmod test

The two bugs involving uint scalars are:

Picking more representative examples for uint scalars and uint arrays in testAllOperators revealed this incorrect handling.
i.e.

uint scalar: np.uint64(2**63 + 1)
uint array: np.arange(2**64 - SIZE, 2**64, 1, dtype=np.uint64)

run_tests on master before updating the test:

# ops not implemented by numpy or arkouda: 114
# ops implemented by numpy but not arkouda: 135
# ops implemented by arkouda but not numpy: 4
# ops implemented by both: 611
  Matching results:         611 / 611
  Arkouda execution errors: 0 / 611

  Dtype mismatches:         0 / 611

  Value mismatches:         0 / 611

run_tests on master after updating the test:

# ops not implemented by numpy or arkouda: 122
# ops implemented by numpy but not arkouda: 147
# ops implemented by arkouda but not numpy: 6
# ops implemented by both: 589
  Matching results:         584 / 589
  Arkouda execution errors: 0 / 589

  Dtype mismatches:         2 / 589
int64(array) + uint64(scalar): float64(np) vs. int64(ak)
int64(array) - uint64(scalar): float64(np) vs. int64(ak)
  Value mismatches:         3 / 589
uint64(array) % float64(array): np: [           nan 5.68434189e-14 5.68434189e-14 5.68434189e-14
 5.68434189e-14 1.33333333e-01 5.68434189e-14 1.46031746e+00
 5.68434189e-14 0.00000000e+00]
ak: [nan  0.  0.  0.  0.  0.  0.  0.  0.  0.]
uint64(array) % float64(scalar): np: [1.19112358 1.19112358 1.19112358 1.19112358 1.19112358 1.19112358
 1.19112358 1.19112358 1.19112358 1.19112358]
ak: [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
uint64(scalar) % float64(array): np: [           nan 2.84217094e-14 2.84217094e-14 2.84217094e-14
 2.84217094e-14 6.22222222e-01 2.84217094e-14 7.30158730e-01
 2.84217094e-14 0.00000000e+00]
ak: [nan  0.  0.  0.  0.  0.  0.  0.  0.  0.]

run_tests on this PR after updating the tests:

# ops not implemented by numpy or arkouda: 122
# ops implemented by numpy but not arkouda: 145
# ops implemented by arkouda but not numpy: 6
# ops implemented by both: 591
  Matching results:         591 / 591
  Arkouda execution errors: 0 / 591

  Dtype mismatches:         0 / 591

  Value mismatches:         0 / 591

The biggest difference between the results from master before updating the tests and this PR after updating the tests is ops implemented by numpy but not arkouda. We see that this number has increased by 10. I hunted down the ones that it appeared like we supported before. They're all combinations of ops between uint scalar and int array. For all these operations the uint array and int array version is also not supported. So I think if we decide to add this support to arkouda we should do it a future issue and add the vector-vector, vector-scalar, and scalar-vector

int64(array) / uint64(scalar)
int64(array) // uint64(scalar)
int64(array) * uint64(scalar)
int64(array) % uint64(scalar)
int64(array) ** uint64(scalar)

uint64(scalar) / int64(array)
uint64(scalar) // int64(array)
uint64(scalar) * int64(array)
uint64(scalar) % int64(array)
uint64(scalar) ** int64(array)

Comment thread src/BinOp.chpl Resolved
Pierce Hayes added 2 commits June 23, 2023 13:19
This PR (fixes Bears-R-Us#2508) resolves two bugs with our handling of uint scalars.

- dtype mismatch:
  - `int arr +/- uint scalar` and vice versa resulted in an int array. It should be a real array to match numpy
- value mismatch:
  - `large reals scalars (i.e. > 2 ** 63) % real arrays` were giving incorrect values. Since we cast `uint` scalars before doing operations with real arrays, this issue popped
  - Attempted to resolve by switching to `fmod`, see chapel-lang/chapel#22584

Picking more representative examples for uint scalars and uint arrays in `testAllOperators` revealed this incorrect handling.
Adds `mod` and `fmod` functions to arkouda which match the numpy equivalents. Fixes value mismatch for float mods
@stress-tess
stress-tess force-pushed the 2508_incorrect_uint_scalars branch from 39405b8 to ae92d29 Compare June 23, 2023 21:14
@stress-tess stress-tess changed the title Fixes #2508: Fixes uint scalar handling Fixes #2508 and #2519: Fixes uint scalar handling and overhauls mod/fmod for floats Jun 23, 2023
@stress-tess
stress-tess requested a review from jaketrookman June 23, 2023 21:22

@Ethan-DeBandi99 Ethan-DeBandi99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question to clarify. Otherwise, everything looks good.

Comment thread arkouda/numeric.py Resolved
Comment thread arkouda/pdarrayclass.py Resolved

@jaketrookman jaketrookman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Great work

@Ethan-DeBandi99 Ethan-DeBandi99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The one component that we will be researching further has been captured in an to look into.

@Ethan-DeBandi99
Ethan-DeBandi99 added this pull request to the merge queue Jun 29, 2023
Merged via the queue into Bears-R-Us:master with commit 49763d5 Jun 29, 2023
@stress-tess
stress-tess deleted the 2508_incorrect_uint_scalars branch June 29, 2023 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

overhaul our mod functionality incorrect results with uint scalars

4 participants