{"record":{"id":"5d6a35bb346985f7","repo":"jax-ml/jax","slug":"n-must-be-nonnegative","errorCode":null,"errorMessage":"N must be nonnegative","messagePattern":"N must be nonnegative","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":8153,"sourceCode":"           [3, 1],\n           [4, 1]], dtype=int32)\n\n    Generates the Vandermonde matrix in increasing order of powers, when\n    ``increasing=True``.\n\n    >>> jnp.vander(x, increasing=True)\n    Array([[ 1,  1,  1,  1],\n           [ 1,  2,  4,  8],\n           [ 1,  3,  9, 27],\n           [ 1,  4, 16, 64]], dtype=int32)\n  \"\"\"\n  x = util.ensure_arraylike(\"vander\", x)\n  if x.ndim != 1:\n    raise ValueError(\"x must be a one-dimensional array\")\n  N = x.shape[0] if N is None else core.concrete_or_error(\n    operator.index, N, \"'N' argument of jnp.vander()\")\n  if N < 0:\n    raise ValueError(\"N must be nonnegative\")\n\n  iota = lax.iota(x.dtype, N)\n  if not increasing:\n    iota = lax.sub(lax._const(iota, N - 1), iota)\n\n  return ufuncs.power(x[..., None], expand_dims(iota, tuple(range(x.ndim))))\n\n\n### Misc\n\n@export\ndef argwhere(\n    a: ArrayLike,\n    *,\n    size: int | None = None,\n    fill_value: ArrayLike | None = None,\n) -> Array:\n  \"\"\"Find the indices of nonzero array elements","sourceCodeStart":8135,"sourceCodeEnd":8171,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L8135-L8171","documentation":"Raised by jnp.vander when the explicitly passed number of columns N is negative, since a Vandermonde matrix cannot have a negative column count.","triggerScenarios":"jnp.vander(x, N=-3); N computed from a subtraction that can go negative (e.g. N = len(x) - k with k > len(x)).","commonSituations":"Sliding-window or polynomial-degree arithmetic producing negative N; passing a signed expression intended as an unsigned count.","solutions":["Clamp or validate N >= 0 before calling (max(N, 0) or an explicit check)","Fix the formula computing N so it cannot be negative","Omit N entirely to default to N = len(x)"],"exampleFix":"// before\njnp.vander(x, N=n - k)  # n - k may be negative\n// after\nN = max(n - k, 0)\njnp.vander(x, N=N)\n","handlingStrategy":"validation","validationCode":"N = max(int(N), 0) if N is not None else len(x)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp N to >= 0 before calling","Compute N defensively from lengths with max(..., 0)","Omit N when the default (len(x)) is acceptable"],"tags":["jax","vander","argument-validation"],"backgroundTag":"negative-dimension-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}