Skip to content

Comments

fix complex sph_bessel_j kernel sqrt branch#96

Draft
lucascolley wants to merge 2 commits intoscipy:mainfrom
lucascolley:complex_sph_bessel_aarch
Draft

fix complex sph_bessel_j kernel sqrt branch#96
lucascolley wants to merge 2 commits intoscipy:mainfrom
lucascolley:complex_sph_bessel_aarch

Conversation

@lucascolley
Copy link
Member

@lucascolley lucascolley commented Feb 11, 2026

scipy/scipy#23700 (comment) @steppi

AI tools used: ChatGPT

The SciPy tests seem to pass on osx-arm64 with this change.

}

std::complex<T> out = std::sqrt(static_cast<T>(M_PI_2) / z) * cyl_bessel_j(n + 1 / static_cast<T>(2), z);
std::complex<T> out = std::sqrt(static_cast<T>(M_PI_2)) * cyl_bessel_j(n + static_cast<T>(0.5), z) / std::sqrt(z);
Copy link
Collaborator

@steppi steppi Feb 12, 2026

Choose a reason for hiding this comment

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

This looks viable. I suggest putting

inline constexpr double SQRT_PI_2 = 1.2533141373155003;

in a detail namespace in this file, and then replacing the above with

std::complex<T> out = static_cast<T>(detail::SQRT_PI_2) * cyl_bessel_j(n + static_cast<T>(0.5), z) / std::sqrt(z);

using inline constexpr let's us sprinkle constants in whichever headers they are needed without running afoul of the one definition rule.

@steppi
Copy link
Collaborator

steppi commented Feb 12, 2026

Thanks @lucascolley. I think this will work. See the comment about defining a constant to use here. Also, the fix is needed in the similar line in each of the spherical bessel functions defined in this header.

@lucascolley
Copy link
Member Author

Do we have the relevant test coverage in this repo?

@steppi
Copy link
Collaborator

steppi commented Feb 12, 2026

Do we have the relevant test coverage in this repo?

Yes, all cases from the scipy.special tests as of version 1.16 are included in the test suite here. I guess it's just a matter of adding ubuntu-24.04-arm to the runs-on matrix.

@steppi
Copy link
Collaborator

steppi commented Feb 12, 2026

I did not expect that. I'll have to look into why the relevant cases aren't there.

@steppi
Copy link
Collaborator

steppi commented Feb 12, 2026

I found that xsref has no tables for the spherical bessel functions. I think this is because the public SciPy functions are regular functions that wrap ufuncs instead of ufuncs themselves. I used a script to automatically generate all of the tables based on what functions get called on what arguments in scipy special's test suite, and private ufuncs with public wrappers only got included if I manually added them.

It shouldn't be too bad to add the tables. I might have time over the weekend.

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.

2 participants