Thanks to visit codestin.com
Credit goes to github.com

Skip to content

esp32: Workaround math.gamma(-inf) result. #15539

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

Merged

Conversation

projectgus
Copy link
Contributor

@projectgus projectgus commented Jul 25, 2024

Summary

Without this workaround, math.gamma(-float("inf")) returns inf instead of raising a math domain ValueError.

Found while testing #15523.

Upstream issue reported as espressif/esp-idf#14273

Testing

tests/float/math_domain_special.py fails on esp32 without this fix.

This work was funded through GitHub Sponsors.

Copy link

codecov bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.43%. Comparing base (ad3552a) to head (ce57eb3).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #15539   +/-   ##
=======================================
  Coverage   98.43%   98.43%           
=======================================
  Files         161      161           
  Lines       21281    21281           
=======================================
  Hits        20948    20948           
  Misses        333      333           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS

@dpgeorge
Copy link
Member

This is related to espressif/esp-idf#7282, where I reported that math.tgamma(-inf) was broken.

I guess it's fine to work around the math.gamma(-inf) issue with our custom config option (otherwise we could report it to IDF and hope for an eventual fix).

@projectgus
Copy link
Contributor Author

This is related to espressif/esp-idf#7282, where I reported that math.tgamma(-inf) was broken.

This is calling tgamma, so according to that issue it should be fixed... 🤔

@projectgus projectgus force-pushed the bugfix/esp32_math_gamma_neg_inf branch from ed8afe9 to 50f6881 Compare July 30, 2024 01:24
@projectgus
Copy link
Contributor Author

Looks like tgammaf() wasn't fixed when tgamma() was. Have opened another ESP-IDF issue and linked it from the PR description.

Suggest we merge this workaround until an upstream fix is available.

@projectgus projectgus changed the title esp32: Fix math.gamma(-inf) result. esp32: Workaround math.gamma(-inf) result. Jul 30, 2024
@projectgus projectgus force-pushed the bugfix/esp32_math_gamma_neg_inf branch from 50f6881 to 1f4019c Compare July 30, 2024 01:27
@projectgus projectgus force-pushed the bugfix/esp32_math_gamma_neg_inf branch from 1f4019c to a8838b7 Compare August 1, 2024 06:14
@projectgus
Copy link
Contributor Author

@dpgeorge Updated, verified the test still passes on ESP32.

@projectgus projectgus force-pushed the bugfix/esp32_math_gamma_neg_inf branch from a8838b7 to cdc3e4f Compare August 1, 2024 06:23
@dpgeorge
Copy link
Member

dpgeorge commented Aug 2, 2024

@projectgus for a change like this, ideally it would be split into two commits, one for the new option added to modmath.c, and a second for the esp32 port to enable this option to work around the bug; eg the first commit would have a message like py/modmath: Add option to work around -inf bug in a port's tgamma..

Can you please split the commit that way?

@projectgus projectgus force-pushed the bugfix/esp32_math_gamma_neg_inf branch from cdc3e4f to ce57eb3 Compare August 6, 2024 00:03
@projectgus
Copy link
Contributor Author

@dpgeorge Sure, have split and re-ran float tests on unix port and esp32 port.

This is needed for a workaround on esp32 port (in child commit),
which produces incorrect results otherwise.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
Without this commit, math.gamma(-float("inf")) returns inf instead of
raising a math domain ValueError. Needed for float/math_domain_special.py
test to pass on esp32.

Root cause is an upstream libm bug, has been reported to ESP-IDF.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
@dpgeorge dpgeorge force-pushed the bugfix/esp32_math_gamma_neg_inf branch from ce57eb3 to 6fead31 Compare August 7, 2024 04:11
@dpgeorge dpgeorge merged commit 6fead31 into micropython:master Aug 7, 2024
62 checks passed
@projectgus projectgus deleted the bugfix/esp32_math_gamma_neg_inf branch August 7, 2024 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants