Skip to content

FEAT: add spence#9

Open
ColmTalbot wants to merge 5 commits intoJAXtronomy:mainfrom
ColmTalbot:spence
Open

FEAT: add spence#9
ColmTalbot wants to merge 5 commits intoJAXtronomy:mainfrom
ColmTalbot:spence

Conversation

@ColmTalbot
Copy link

This is an implementation I have of scipy.special.spence for complex input. jax.scipy.special implements the function for real inputs.

This has significant over lap with polylog/Li but matches the scipy API more closely (scipy uses a slightly unusual definition). The current implementation Li gives the generic polylogarithm while this should match

spence(z) = Li(2, 1 - z)

There are also some differences for complex inputs and I think this implementation matches scipy better, for example

In [10]: spence(2 - 0.1j)
Out[10]: np.complex128(-0.8234321080805467+0.06929202401162238j)

In [11]: spexial.spence(2 - 0.1j)
Out[11]: Array(-0.8234399+0.06928854j, dtype=complex64)

In [12]: spexial.Li(2, 1 - (2 - 0.1j))
Out[12]: Array(nan+0.j, dtype=complex64)

@codecov
Copy link

codecov bot commented Oct 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/spexial/__init__.py 100.00% <100.00%> (ø)
src/spexial/_src/spence.py 100.00% <100.00%> (ø)

@nstarman nstarman requested a review from jnibauer October 18, 2024 19:09
@nstarman nstarman added this to the v0.1.0 milestone Oct 18, 2024
Copy link
Collaborator

@cgiovanetti cgiovanetti left a comment

Choose a reason for hiding this comment

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

Looks great, sounds like we could also kill polylog/Li if we implement this? I'd prefer that since scipy.special doesn't have polylog.

@ColmTalbot
Copy link
Author

@cgiovanetti personally, I think it's okay to have things that don't have a direct scipy equivalent, and it is documented as such. Do you use polylog with n != 2? If yes, I think we should keep it, if not I could happily go either way.

@ColmTalbot
Copy link
Author

I'll add some tests into https://github.com/JAXtronomy/spexial/tree/main/tests/regression matching what is done for gegenbauer.

@cgiovanetti
Copy link
Collaborator

@cgiovanetti personally, I think it's okay to have things that don't have a direct scipy equivalent, and it is documented as such. Do you use polylog with n != 2? If yes, I think we should keep it, if not I could happily go either way.

Yeah, we do allow all n < 60 I think. So if you think that it's still useful then I'm happy to leave it, though maybe we should flag somehow that it's not set up for complex inputs.

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.

4 participants