{"record":{"id":"62f903913802cba7","repo":"jax-ml/jax","slug":"invalid-order-ord-for-vector-norm","errorCode":null,"errorMessage":"Invalid order '{ord}' for vector norm.","messagePattern":"Invalid order '(.+?)' for vector norm\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/linalg.py","lineNumber":1794,"sourceCode":"    return reductions.amax(ufuncs.abs(x), axis=axis, keepdims=keepdims, initial=0)\n  elif ord == -np.inf:\n    return reductions.amin(ufuncs.abs(x), axis=axis, keepdims=keepdims)\n  elif ord == 0:\n    return reductions.sum(x != 0, dtype=jnp.finfo(lax.dtype(x)).dtype,\n                          axis=axis, keepdims=keepdims)\n  elif ord == 1:\n    # Numpy has a special case for ord == 1 as an optimization. We don't\n    # really need the optimization (XLA could do it for us), but the Numpy\n    # code has slightly different type promotion semantics, so we need a\n    # special case too.\n    return reductions.sum(ufuncs.abs(x), axis=axis, keepdims=keepdims)\n  elif isinstance(ord, str):\n    msg = f\"Invalid order '{ord}' for vector norm.\"\n    if ord == \"inf\":\n      msg += \"Use 'jax.numpy.inf' instead.\"\n    if ord == \"-inf\":\n      msg += \"Use '-jax.numpy.inf' instead.\"\n    raise ValueError(msg)\n  else:\n    abs_x = ufuncs.abs(x)\n    ord_arr = lax._const(abs_x, ord)\n    ord_inv = lax._const(abs_x, 1. / ord_arr)\n    out = reductions.sum(abs_x ** ord_arr, axis=axis, keepdims=keepdims)\n    return ufuncs.power(out, ord_inv)\n\n@export\ndef vecdot(x1: ArrayLike, x2: ArrayLike, /, *, axis: int = -1,\n           precision: lax.PrecisionLike = None,\n           preferred_element_type: DTypeLike | None = None) -> Array:\n  \"\"\"Compute the (batched) vector conjugate dot product of two arrays.\n\n  JAX implementation of :func:`numpy.linalg.vecdot`.\n\n  Args:\n    x1: left-hand side array.\n    x2: right-hand side array. Size of ``x2[axis]`` must match size of ``x1[axis]``,","sourceCodeStart":1776,"sourceCodeEnd":1812,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/linalg.py#L1776-L1812","documentation":"jnp.linalg.vector_norm accepts numeric or the sentinel values jnp.inf/-jnp.inf for ord, but not the strings 'inf' or '-inf' (unlike NumPy, where numpy.inf is a float). Any other unrecognized string ord also triggers it. JAX deliberately rejects string spellings because its ord parameter is typed as int | str | float but only supports specific named orders ('fro', 'nuc' for matrix norm contexts) and numeric/inf values.","triggerScenarios":"Calling jnp.linalg.vector_norm(x, ord='inf') or ord='-inf'; passing an unsupported string like ord='l2' or ord=1.5-norm names.","commonSituations":"Porting NumPy/SciPy code that used ord=float('inf') or np.inf where the value got stringified (e.g. read from a config/CLI arg as 'inf'); copy-pasting sklearn-style string norm names into JAX code.","solutions":["Replace ord='inf' with ord=jnp.inf and ord='-inf' with ord=-jnp.inf (as the error message itself instructs).","If ord comes from config/CLI, convert it: ord = float(ord_str) so 'inf' becomes a real infinity float.","For L1/L2 use ord=1 / ord=2 (numeric)."],"exampleFix":"// before\nn = jnp.linalg.vector_norm(x, ord='inf')\n// after\nn = jnp.linalg.vector_norm(x, ord=float('inf'))","handlingStrategy":"validation","validationCode":"if isinstance(ord, str):\n    ord = float(ord)  # 'inf' -> inf; raises for genuinely bad names\nn = jnp.linalg.vector_norm(x, ord=ord)","typeGuard":"def valid_ord(o) -> bool:\n    return not isinstance(o, str)","tryCatchPattern":"try:\n    n = jnp.linalg.vector_norm(x, ord=ord)\nexcept ValueError as e:\n    if 'Invalid order' in str(e):\n        n = jnp.linalg.vector_norm(x, ord=float(ord))\n    else:\n        raise","preventionTips":["Convert CLI/config ord strings with float()","Use jnp.inf / -jnp.inf, never quoted strings"],"tags":["jax","linalg","norm","type-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}