jax-ml/jax · error · ValueError
Order of derivative must be positive
Error message
Order of derivative must be positive
What it means
jnp.polyder requires the derivative order m to be a non-negative integer; negative orders are rejected because integration (polyint) is a separate API.
Source
Thrown at jax/_src/numpy/polynomial.py:623
The first order derivative of the polynomial :math:`2 x^3 - 5 x^2 + 3 x - 1`
is :math:`6 x^2 - 10 x +3`:
>>> p = jnp.array([2, -5, 3, -1])
>>> jnp.polyder(p)
Array([ 6., -10., 3.], dtype=float32)
and its second order derivative is :math:`12 x - 10`:
>>> jnp.polyder(p, m=2)
Array([ 12., -10.], dtype=float32)
"""
p = ensure_arraylike("polyder", p)
m = core.concrete_or_error(operator.index, m, "'m' argument of jnp.polyder")
p_arr, = promote_dtypes_inexact(p)
del p
if m < 0:
raise ValueError("Order of derivative must be positive")
if m == 0:
return p_arr
coeff = (arange(m, len(p_arr), dtype=p_arr.dtype)[np.newaxis]
- arange(m, dtype=p_arr.dtype)[:, np.newaxis]).prod(0)
return p_arr[:-m] * coeff[::-1]
@export
def polymul(a1: ArrayLike, a2: ArrayLike, *, trim_leading_zeros: bool = False) -> Array:
r"""Returns the product of two polynomials.
JAX implementation of :func:`numpy.polymul`.
Args:
a1: 1D array of polynomial coefficients.
a2: 1D array of polynomial coefficients.
trim_leading_zeros: Default is ``False``. If ``True`` removes the leading
zeros in the return value to match the result of numpy. But prevents theView on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Use jnp.polyder only with m >= 0
- Use jnp.polyint for negative-order intent
- Clamp or validate m at the call site
Example fix
// before jnp.polyder(p, m=-1) // after jnp.polyint(p, m=1)
Defensive patterns
Strategy: validation
Validate before calling
m = int(m) assert m >= 0, 'polyder order must be >= 0'
Prevention
- Guard order parameters in loops that decrement m
- Use polyint for integration semantics
When it happens
Trigger: Calling jnp.polyder(p, m=-1) or any negative integer order.
Common situations: Loop variables for differentiation order going negative; mixing up polyint/polyder sign conventions; user-supplied order parameter not validated.
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/260f21d7d710acbb.
Report an issue: GitHub.