Skip to content

MAINT: Handle overflow in i0 for large inputs like 713.0 - #32223

Merged
ngoldbaum merged 17 commits into
numpy:mainfrom
hariomlohardev:fix/i0-overflow-issue
Aug 21, 2026
Merged

ngoldbaum merged 17 commits into
numpy:mainfrom
hariomlohardev:fix/i0-overflow-issue

Conversation

@hariomlohardev

Copy link
Copy Markdown
Contributor

Using math log this overflow problem is solved
issue #32209

PR summary

This is the fix to an overflow issuse
np.i0(713.0) returns inf instead of a finite value

def _i0_2(x):
return exp(x) * _chbevl(32.0 / x - 2.0, _i0B) / sqrt(x)

changed to this

def _i0_2(x):
return exp(x + log(_chbevl(32.0 / x - 2.0, _i0B)) - 0.5 * log(x))

this is in file : lib_function_base_impl.py

THE MATH
using logs we can control the overflow of exp so that it will return and finite value and not inf
new math formula for function is
exp(x + log(val) - 0.5 * log(x))

First time committer introduction

Hi I'm Hariom Lohar (@hariomlohardev). I'm a Python developer interested in AI/AGI and right knwo learning basics in neural network and probability and statistics

I found this issue through exploring NumPy's codebase and noticed the i0() Bessel function had a numerical stability problem with large inputs. Since I have a math background and experience with numerical methods, I decided to fix it.

AI Disclosure

Using math log this overflow problem is solved
 issue numpy#32209
@jorenham

jorenham commented Aug 7, 2026

Copy link
Copy Markdown
Member

For the second time you ignored the AI disclosure. You're risking a ban.

@hariomlohardev

Copy link
Copy Markdown
Contributor Author

Hi @jorenham, I apologize for not filling in the AI Disclosure properly.

AI Disclosure: No AI tools were used.

I wrote all the code and math myself based on my understanding of:

  • Numerical overflow in exponential functions
  • Logarithmic transformations to avoid overflow
  • IEEE 754 floating-point arithmetic

I can explain the mathematical reasoning:
exp(x) * value / sqrt(x) overflows when exp(x) is too large.
Using logarithms: exp(x + log(value) - 0.5*log(x)) computes the same result without intermediate overflow.

Please let me know if you need any clarification on the implementation.

Thank you!

@jorenham

jorenham commented Aug 7, 2026

Copy link
Copy Markdown
Member

You did not fill in the AI disclosure in the PR, so I assumed this was a fully automated AI PR, of which we get quite a lot recently. So since you seem to be a human and even know what you're talking about, I'll re-open this.

In the future, be sure to state that you did or did not use AI in the AI disclosure in the PR template, as explained in our AI policy

@jorenham jorenham reopened this Aug 7, 2026
Comment thread numpy/lib/tests/test_function_base.py Resolved
Comment thread numpy/lib/_function_base_impl.py Resolved
Comment thread numpy/lib/_function_base_impl.py Resolved
@charris charris changed the title FIX: Handle overflow in i0 for large inputs like 713.0 MAINT: Handle overflow in i0 for large inputs like 713.0 Aug 7, 2026

@hariomlohardev hariomlohardev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks good

Comment thread numpy/lib/tests/test_function_base.py Resolved
Comment thread numpy/lib/tests/test_function_base.py Resolved
hariomlohardev and others added 2 commits August 8, 2026 07:07
Add test for i0 function to handle infinity correctly.

@hariomlohardev hariomlohardev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

looks good

@hariomlohardev hariomlohardev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

looks good to me

Comment thread numpy/lib/tests/test_function_base.py Resolved

@hariomlohardev hariomlohardev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

looks good and all done

@ngoldbaum

Copy link
Copy Markdown
Member

Looking good. I’d like someone besides me to look at this. I think it needs a release note too.

@ngoldbaum ngoldbaum added triage review Issue/PR to be discussed at the next triage meeting 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes labels Aug 8, 2026
@hariomlohardev

Copy link
Copy Markdown
Contributor Author

when this will merge

@ngoldbaum

Copy link
Copy Markdown
Member

It could be a while, it depends on how long it takes for other reviewers to weigh in. NumPy doesn’t move very quickly.

@hariomlohardev

This comment was marked as spam.

@hariomlohardev

This comment was marked as spam.

@jorenham

Copy link
Copy Markdown
Member

@hariomlohardev please be patient. Spamming us won't help.

@hariomlohardev

Copy link
Copy Markdown
Contributor Author

@hariomlohardev please be patient. Spamming us won't help.

Thanks for the heads up, and sorry — I didn't mean to spam. My intent was just to let people on the related open issues know this fix is in progress so they're not duplicating effort, but I get how it can come across as pushy. I'll be more mindful about it going forward. Appreciate your patience!

@ngoldbaum ngoldbaum removed the triage review Issue/PR to be discussed at the next triage meeting label Aug 19, 2026
@ngoldbaum

Copy link
Copy Markdown
Member

We talked about this at a triage meeting and agreed this is fine to change. Can you add a release note? See doc/release/upcoming_changes/README.rst to learn how to do that.

@hariomlohardev

Copy link
Copy Markdown
Contributor Author

DONE SIR (❁´◡`❁)

@hariomlohardev hariomlohardev left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LGTM

@ngoldbaum
ngoldbaum merged commit 130a2e4 into numpy:main Aug 21, 2026
91 checks passed
hariomlohardev added a commit to hariomlohardev/hariomlohardev.github.io that referenced this pull request Aug 30, 2026
…that exist

About now says what the days actually go into — mathematics from axioms,
derivatives by hand, a Value graph with backprop and gradient descent in
NumPy before any framework — and points at micrograd_hk as the shipped
proof. Django/FastAPI/LangChain/RAG leave About; they stay in Contact,
where hiring people read, and as trailing keywords in the meta.

Work: spam_classifier, practice_code and pkg_jupy out, micrograd_hk, peek
and inkdown in. Edited in data.json, which is the file the homepage
actually renders (it overrides DEFAULT_DATA per key) — the DEFAULT_DATA
fallback in index.html now matches it, statuses included. The /projects
archive is generated from projects-data.json and is untouched, so the live
spam_classifier demo still works.

Open source: the fallback list no longer invents PRs. If the live fetch
fails, the four /000000 placeholder links are gone and what shows is three
real contributions — numpy/numpy#32223, static-analysis#1866, reflex#6861.

Portrait: was hotlinked from image.qwenlm.ai at 1.2 MB. Now repo-hosted,
30 KB webp with a 67 KB jpg fallback, 900x900, on both home and /about.

FAQ: 4 questions to 7 — why self-taught, the 18-month route, how to follow
along — and the FAQPage markup rebuilt to mirror all seven exactly, so the
rich result stays valid.

Head: title, description, og and twitter cards lead with AGI from first
principles; Person JSON-LD points its image at the portrait instead of a
certificate scan and gains the from-scratch topics. /about carries the
same Person object so the two pages stop contradicting each other.
hariomlohardev added a commit to hariomlohardev/hariomlohardev.github.io that referenced this pull request Sep 24, 2026
…that exist

About now says what the days actually go into — mathematics from axioms,
derivatives by hand, a Value graph with backprop and gradient descent in
NumPy before any framework — and points at micrograd_hk as the shipped
proof. Django/FastAPI/LangChain/RAG leave About; they stay in Contact,
where hiring people read, and as trailing keywords in the meta.

Work: spam_classifier, practice_code and pkg_jupy out, micrograd_hk, peek
and inkdown in. Edited in data.json, which is the file the homepage
actually renders (it overrides DEFAULT_DATA per key) — the DEFAULT_DATA
fallback in index.html now matches it, statuses included. The /projects
archive is generated from projects-data.json and is untouched, so the live
spam_classifier demo still works.

Open source: the fallback list no longer invents PRs. If the live fetch
fails, the four /000000 placeholder links are gone and what shows is three
real contributions — numpy/numpy#32223, static-analysis#1866, reflex#6861.

Portrait: was hotlinked from image.qwenlm.ai at 1.2 MB. Now repo-hosted,
30 KB webp with a 67 KB jpg fallback, 900x900, on both home and /about.

FAQ: 4 questions to 7 — why self-taught, the 18-month route, how to follow
along — and the FAQPage markup rebuilt to mirror all seven exactly, so the
rich result stays valid.

Head: title, description, og and twitter cards lead with AGI from first
principles; Person JSON-LD points its image at the portrait instead of a
certificate scan and gains the from-scratch topics. /about carries the
same Person object so the two pages stop contradicting each other.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

03 - Maintenance 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants