Skip to content

Add special::i0: Modified Bessel i0 for real arguments as crate internal#71

Closed
SpookyYomo wants to merge 6 commits intoqsib-cbie:mainfrom
SpookyYomo:bessel
Closed

Add special::i0: Modified Bessel i0 for real arguments as crate internal#71
SpookyYomo wants to merge 6 commits intoqsib-cbie:mainfrom
SpookyYomo:bessel

Conversation

@SpookyYomo
Copy link
Copy Markdown
Contributor

With reference to discussion #53 (comment), only f32 and f64 implemented. Until we make the code more robust, I propose that it be kept crate internal only for firwin-related functions, until more concrete decisions around numeric types we wish to support and others are made.

ArtemiszenN and others added 2 commits March 5, 2025 20:01
Bessel i0 function written with reference to Numerical Recipes in C++,
currently only with f64.

Authored-by: ArtemiszenN <artemiszenn@gmail.com>
Signed-off-by: SpookyYomo <48710653+SpookyYomo@users.noreply.github.com>
Currently code is not ready for generic float, and requires more work.
@SpookyYomo SpookyYomo requested a review from trueb2 as a code owner March 7, 2025 18:48
@SpookyYomo
Copy link
Copy Markdown
Contributor Author

The clippy warning about float precision (especially for the f32 const array) makes it hard to keep track of the original const array used if we had to round it all off. Perhaps we allow clippy to ignore these warnings specific to this case?

@SpookyYomo SpookyYomo changed the title Modified Bessel i0 for real arguments Add special::i0: Modified Bessel i0 for real arguments as crate internal Mar 7, 2025
@SpookyYomo
Copy link
Copy Markdown
Contributor Author

SpookyYomo commented Mar 7, 2025

image

Since I wrote up the example Maturin bindings for #70 , I went ahead and tried up the i0_doub code here. Plotting code is as exposed in SpookyYomo@2b6129d.
Seems good enough in comparision against scipy's for use in firwin.

Absolute difference:
image

We also add unsafe bounds since the function is currently only intended
to be crate-internal.
This will allow for f32 implementation for generics later.
This is very hacky and just copies all the const arrays from f64 to f32.
Also not as accurate for very large arguments such as x>~20 being passed
to i0. (Correspondingly similar unit test for ~30 is not being tested in
f32).
@SpookyYomo
Copy link
Copy Markdown
Contributor Author

SpookyYomo commented Mar 9, 2025

Superceded by #73, as this PR used a function that was implemented differently form scipy.

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