Skip to content

Add inf special cases in C implementation of gamma related functions #634

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
merged 3 commits into from
Feb 14, 2024

Conversation

amyoshino
Copy link
Member

@amyoshino amyoshino commented Feb 6, 2024

Description

gammainc C code does not have a special case for np.inf.

Instead of returning 0, 1 or nan it always return nan.

The solution is to add special cases conditions following scipy implementation: https://github.com/scipy/scipy/blob/4ecf5638c36c3a87b473056f5fffecfeddffd368/scipy/special/cephes/igam.c#L149-L151

Related Issue

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@amyoshino amyoshino changed the title change gamma.c function to support np.inf special cases Add inf special cases to gamma.c function Feb 6, 2024
@codecov-commenter
Copy link

codecov-commenter commented Feb 6, 2024

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (1091b44) 80.82% compared to head (a2b242c) 80.83%.
Report is 3 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #634   +/-   ##
=======================================
  Coverage   80.82%   80.83%           
=======================================
  Files         162      162           
  Lines       46744    46758   +14     
  Branches    11418    11420    +2     
=======================================
+ Hits        37783    37795   +12     
- Misses       6716     6717    +1     
- Partials     2245     2246    +1     
Files Coverage Δ
pytensor/scalar/math.py 87.34% <60.00%> (-0.45%) ⬇️

... and 1 file with indirect coverage changes

@ricardoV94
Copy link
Member

ricardoV94 commented Feb 6, 2024

You'll need to define methods like these for the old caches to be ignored, for all Ops that use these two functions.

def c_code_cache_version(self):
v = super().c_code_cache_version()
if v:
return (3, *v)
else:
return v

That and some tests and we're good to go!

@amyoshino
Copy link
Member Author

amyoshino commented Feb 7, 2024

You'll need to define methods like these for the old caches to be ignored, for all Ops that use these two functions.

def c_code_cache_version(self):
v = super().c_code_cache_version()
if v:
return (3, *v)
else:
return v

That and some tests and we're good to go!

Thanks for this information! I have added them to any function that uses GammaP or GammaQ in gamma.c. From

def c_code_cache_version(self):
I see that we need to return a "version" number, which I suppose it is 2, since it is the second time we change it. Let me know if my reasoning is wrong, I didn't find any other pointers that justify another choice.

I also added tests to test_math.py, I guess this is sufficient but let me know if I forget to add any other test place.

@amyoshino amyoshino marked this pull request as ready for review February 7, 2024 11:38
@ricardoV94
Copy link
Member

@amyoshino yes your reasoning is correct

@ricardoV94
Copy link
Member

This is great @amyoshino

@ricardoV94 ricardoV94 merged commit d8868cc into pymc-devs:main Feb 14, 2024
@ricardoV94 ricardoV94 changed the title Add inf special cases to gamma.c function Add inf special cases in C implementation of gamma related functions Feb 14, 2024
@amyoshino amyoshino deleted the gamma_c branch February 14, 2024 11:40
@amyoshino
Copy link
Member Author

Cool! One more step to close pymc-devs/pymc#6845 😄

@ricardoV94
Copy link
Member

Cool! One more step to close pymc-devs/pymc#6845 😄

Any day now xD

We plan to release sometime this week

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.

3 participants