jax-ml/jax · error · ValueError
Order of integral must be positive (see polyder)
Error message
Order of integral must be positive (see polyder)
What it means
jnp.polyint computes the m-th antiderivative; m must be a non-negative integer. A negative m raises this error because differentiation is handled by a separate function, jnp.polyder.
Source
Thrown at jax/_src/numpy/polynomial.py:565
>>> jnp.polyint(p, m=2)
Array([1., 2., 3., 0., 0.], dtype=float32)
When ``m>=2``, the constants ``k`` should be provided as an array having
``m`` elements. The second order integration of the polynomial
:math:`12 x^2 + 12 x + 6` with the constants ``k=[4, 5]`` is
:math:`x^4 + 2 x^3 + 3 x^2 + 4 x + 5`:
>>> jnp.polyint(p, m=2, k=jnp.array([4, 5]))
Array([1., 2., 3., 4., 5.], dtype=float32)
"""
m = core.concrete_or_error(operator.index, m, "'m' argument of jnp.polyint")
k = 0 if k is None else k
p, k = ensure_arraylike("polyint", p, k)
p_arr, k_arr = promote_dtypes_inexact(p, k)
del p, k
if m < 0:
raise ValueError("Order of integral must be positive (see polyder)")
k_arr = atleast_1d(k_arr)
if len(k_arr) == 1:
k_arr = full((m,), k_arr[0])
if k_arr.shape != (m,):
raise ValueError("k must be a scalar or a rank-1 array of length 1 or m.")
if m == 0:
return p_arr
else:
grid = (arange(len(p_arr) + m, dtype=p_arr.dtype)[np.newaxis]
- arange(m, dtype=p_arr.dtype)[:, np.newaxis])
coeff = maximum(1, grid).prod(0)[::-1]
return true_divide(concatenate((p_arr, k_arr)), coeff)
@export
@api.jit(static_argnames=('m',))
def polyder(p: ArrayLike, m: int = 1) -> Array:
r"""Returns the coefficients of the derivative of specified order of a polynomial.View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use jnp.polyder for negative-order intent (differentiation)
- Take abs(m) or clamp m to >= 0 if the sign is a bug
- Guard with m = max(m, 0) before calling
Example fix
// before jnp.polyint(p, m=-2) // after from jax._src.numpy.polynomial import polyder polyder(p, m=2)
Defensive patterns
Strategy: validation
Validate before calling
m = max(int(m), 0) # or reject negatives explicitly before polyint
Type guard
null
Prevention
- Treat negative m as a call to polyder
- Validate integer order parameters at API boundaries
When it happens
Trigger: Calling jnp.polyint(p, m=-1) (or any negative m). m is converted with operator.index, so floats raise a separate concreteness/type error, but any negative int hits this branch.
Common situations: Sign confusion between integration and differentiation orders; dynamically computed m that can go negative in loops (e.g. repeatedly differentiating/integrating).
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- `compute_on`'s compute_type argument must be a string.
- Argument '{x}' of type '{typ}' is not a valid JAX type
- Argument '{arg}' of type {type(arg)} is not a valid JAX type
- Expected kind to be a dtype, string, or tuple; got {kind=}
- at least one array or dtype is required
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/c3423da15fce3315.
Report an issue: GitHub.