Skip to content

Commit 6811a56

Browse files
Fix PyPy build failures: handle float overflow without OverflowError
PyPy follows IEEE 754 strictly and produces inf instead of raising OverflowError on float overflow. Add an isfinite() guard after the Izhikevich neuron voltage update so the overflow reset works on both CPython and PyPy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0d43d10 commit 6811a56

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

neat/iznn/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
http://www.izhikevich.org/publications/spikes.pdf
1010
"""
1111

12+
from math import isfinite
13+
1214
from neat.attributes import FloatAttribute
1315
from neat.genes import BaseGene, DefaultConnectionGene
1416
from neat.genome import DefaultGenomeConfig, DefaultGenome
@@ -109,6 +111,12 @@ def advance(self, dt_msec):
109111
self.v = self.c
110112
self.u = self.b * self.v
111113

114+
# PyPy (and other runtimes) may produce inf/nan instead of raising
115+
# OverflowError. Apply the same reset in that case.
116+
if not isfinite(self.v) or not isfinite(self.u):
117+
self.v = self.c
118+
self.u = self.b * self.v
119+
112120
self.fired = 0.0
113121
if self.v > 30.0:
114122
# Output spike and reset.

0 commit comments

Comments
 (0)