Affected Files
ivy/functional/backends/numpy/elementwise.py:749
ivy/functional/backends/numpy/experimental/statistical.py:567
Current Code
# ivy/functional/backends/numpy/elementwise.py:749
def trapz(y, /, *, x=None, dx=1.0, axis=-1, out=None):
return np.trapz(y, x=x, dx=dx, axis=axis)
# ivy/functional/backends/numpy/experimental/statistical.py:567
integral = np.trapz(y, t)
Root Cause
numpy.trapz was deprecated in NumPy 2.0 (2023-08-18) and fully removed in NumPy 2.4.0 (2025-12-20). In NumPy >= 2.4.0, any call to np.trapz() raises:
AttributeError: module 'numpy' has no attribute 'trapz'
Ivy defines its own trapz API across multiple backends (torch, jax, tensorflow, numpy). The numpy backend directly delegates to np.trapz, which will break.
Impact
- Severity: High — hard crash at runtime on NumPy >= 2.4.0
- The numpy backend
trapz() is called via ivy.trapz() → backend dispatch → np.trapz()
- Also affects the numpy frontend:
ivy.functional.frontends.numpy.trapz() → ivy.trapz() → numpy backend → np.trapz()
- The experimental
igamma_cal function in statistical.py is also affected
Solution
# ivy/functional/backends/numpy/elementwise.py:749
# Before:
return np.trapz(y, x=x, dx=dx, axis=axis)
# After:
return np.trapezoid(y, x=x, dx=dx, axis=axis)
# ivy/functional/backends/numpy/experimental/statistical.py:567
# Before:
integral = np.trapz(y, t)
# After:
integral = np.trapezoid(y, t)
trapezoid has the same signature: trapezoid(y, x=None, dx=1.0, axis=-1).
For NumPy < 2.0 backward compatibility:
try:
from numpy import trapezoid
except ImportError:
from numpy import trapz as trapezoid
References
Affected Files
ivy/functional/backends/numpy/elementwise.py:749ivy/functional/backends/numpy/experimental/statistical.py:567Current Code
Root Cause
numpy.trapzwas deprecated in NumPy 2.0 (2023-08-18) and fully removed in NumPy 2.4.0 (2025-12-20). In NumPy >= 2.4.0, any call tonp.trapz()raises:Ivy defines its own
trapzAPI across multiple backends (torch, jax, tensorflow, numpy). The numpy backend directly delegates tonp.trapz, which will break.Impact
trapz()is called viaivy.trapz()→ backend dispatch →np.trapz()ivy.functional.frontends.numpy.trapz()→ivy.trapz()→ numpy backend →np.trapz()igamma_calfunction in statistical.py is also affectedSolution
trapezoidhas the same signature:trapezoid(y, x=None, dx=1.0, axis=-1).For NumPy < 2.0 backward compatibility:
References