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

Skip to content

ENH: Add inverse digamma function#130

Merged
steppi merged 8 commits into
scipy:mainfrom
dschmitz89:digamma_inv
May 6, 2026
Merged

ENH: Add inverse digamma function#130
steppi merged 8 commits into
scipy:mainfrom
dschmitz89:digamma_inv

Conversation

@dschmitz89
Copy link
Copy Markdown
Contributor

Closes #129

Full disclosure: Most of the actual code was generated by a LLM. I pointed it to the reference and fine tuned the convergence criterion and the edge cases.

We will likely need to add a lot more tests, I will look into that in the coming weeks.

Comment thread include/xsf/digamma_inv.h Outdated
@dschmitz89
Copy link
Copy Markdown
Contributor Author

This PR is ready from my side.

Comment thread tests/xsf_tests/test_digamma_inv.cpp Outdated
@fbourgey fbourgey mentioned this pull request May 4, 2026
Copy link
Copy Markdown
Member

@fbourgey fbourgey left a comment

Choose a reason for hiding this comment

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

LGTM!

However, would it make sense to add XSF_HOST_DEVICE to allow compilation for both CPU and CUDA device code? cc @steppi to confirm.

Comment thread include/xsf/digamma_inv.h Outdated
const int max_iterations = 20; // avoid infinite loops in pathological cases
for (int i = 0; i < max_iterations; ++i) {
double psi_x = cephes::psi(x);
double psi1_x = cephes::zeta(2, x); // trigamma: psi'(x) = zeta(2, x)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
double psi1_x = cephes::zeta(2, x); // trigamma: psi'(x) = zeta(2, x)
double trigamma_x = cephes::zeta(2, x); // trigamma: psi'(x) = zeta(2, x)

@fbourgey
Copy link
Copy Markdown
Member

fbourgey commented May 5, 2026

For future reference, this PR implements
Screenshot 2026-05-05 at 4 34 32 PM

Reference: T. Minka, "Estimating a Dirichlet distribution", 2000. Appendix C

Comment thread include/xsf/digamma_inv.h Outdated
@dschmitz89
Copy link
Copy Markdown
Contributor Author

Reviews were addressed, let me know if anything else is missing. I did not test GPU support though.

Copy link
Copy Markdown
Member

@steppi steppi left a comment

Choose a reason for hiding this comment

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

Thanks @dschmitz89. Don't worry about GPU tests. The main point of those is to spot CuPy regressions so they don't show up for the first time when making a PR to update xsf in CuPy. We just need to make sure we add them before we eventually submit a CuPy PR for inverse digamma.

I'll merge this one now. For the immediate future, also feel free to merge on your own if you get a green checkmark and the go-ahead from @fbourgey.

@steppi steppi merged commit 8a9c72d into scipy:main May 6, 2026
4 of 6 checks passed
@dschmitz89 dschmitz89 deleted the digamma_inv branch May 8, 2026 18:06
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.

ENH: Inverse digamma function

3 participants