File: leanpass/tensor.py
These functions directly call NumPy's log, exp, and np.exp(-x) without guarding against domain errors or overflow:
log will produce -inf/nan for non‑positive inputs.
exp can overflow for large positive values, yielding inf.
sigmoid uses np.exp(-x) which overflows for large negative x.
softmax shifts by the max but still calls np.exp on the shifted values; extreme values can still overflow.
Fix:
- Clamp inputs for
log (e.g., np.log(np.clip(self.data, eps, None))).
- Use
np.exp(np.clip(self.data, a_min, a_max)) or np.where to avoid overflow in exp and sigmoid.
- In
softmax, after shifting, also clip the exponentials or use np.exp(np.clip(shifted, a_min, a_max)).
- Document the expected input ranges.
File: leanpass/tensor.py
Filed automatically by ai-issue-scan.
File:
leanpass/tensor.pyThese functions directly call NumPy's
log,exp, andnp.exp(-x)without guarding against domain errors or overflow:logwill produce-inf/nanfor non‑positive inputs.expcan overflow for large positive values, yieldinginf.sigmoidusesnp.exp(-x)which overflows for large negativex.softmaxshifts by the max but still callsnp.expon the shifted values; extreme values can still overflow.Fix:
log(e.g.,np.log(np.clip(self.data, eps, None))).np.exp(np.clip(self.data, a_min, a_max))ornp.whereto avoid overflow inexpandsigmoid.softmax, after shifting, also clip the exponentials or usenp.exp(np.clip(shifted, a_min, a_max)).File:
leanpass/tensor.pyFiled automatically by ai-issue-scan.