{"record":{"id":"12c2fb502cea66b9","repo":"jax-ml/jax","slug":"ddof-and-correction-can-t-be-provided-simultaneous","errorCode":null,"errorMessage":"ddof and correction can't be provided simultaneously.","messagePattern":"ddof and correction can't be provided simultaneously\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":1121,"sourceCode":"     [ 3.33]\n     [10.92]]\n\n    To include specific elements of the array to compute variance, you can use\n    ``where``.\n\n    >>> where = jnp.array([[1, 0, 1, 0],\n    ...                    [0, 1, 1, 0],\n    ...                    [1, 1, 1, 0]], dtype=bool)\n    >>> with jnp.printoptions(precision=2, suppress=True):\n    ...   print(jnp.var(x, axis=1, keepdims=True, where=where))\n    [[2.25]\n     [4.  ]\n     [6.22]]\n  \"\"\"\n  if correction is None:\n    correction = ddof\n  elif not isinstance(ddof, int) or ddof != 0:\n    raise ValueError(\"ddof and correction can't be provided simultaneously.\")\n  a = ensure_arraylike(\"var\", a)\n  return _var(a, axis=_ensure_optional_axes(axis), dtype=dtype, out=out, correction=correction, keepdims=keepdims,\n              where=where, a_mean=mean)\n\n@api.jit(static_argnames=('axis', 'dtype', 'keepdims'))\ndef _var(a: Array, *, axis: Axis = None, dtype: DTypeLike | None = None,\n         out: None = None, correction: int | float = 0, keepdims: bool = False,\n         where: ArrayLike | None = None, a_mean: ArrayLike | None = None) -> Array:\n  where = check_where(\"var\", where)\n  if dtype is not None:\n    dtype = dtypes.check_and_canonicalize_user_dtype(dtype, \"var\")\n  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.var is not supported.\")\n\n  computation_dtype, dtype = _var_promote_types(a.dtype, dtype)\n  a = lax.asarray(a).astype(computation_dtype)\n  if a_mean is None:\n    a_mean = mean(a, axis, dtype=computation_dtype, keepdims=True, where=where)","sourceCodeStart":1103,"sourceCodeEnd":1139,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L1103-L1139","documentation":"jnp.var accepts both the legacy numpy parameter ddof and the JAX-specific correction; they parameterize the same degrees-of-freedom adjustment, so both cannot be meaningfully given at once. correction defaults to ddof when correction is None; supplying a non-zero ddof together with correction raises.","triggerScenarios":"jnp.var(x, ddof=1, correction=1) raises; ddof=0 with correction is allowed (ddof=0 is the no-op default); any non-zero or non-int ddof alongside correction raises.","commonSituations":"Code written for newer JAX (correction) refactored or wrapped around older numpy-style code that passes ddof; wrapper functions forwarding both parameters with defaults like ddof=1.","solutions":["Remove ddof and keep correction (preferred modern JAX API)","Or remove correction and keep ddof for numpy parity","In wrappers, only forward whichever parameter the caller actually set (use sentinel defaults)"],"exampleFix":"// before\njnp.var(x, ddof=1, correction=1)\n// after\njnp.var(x, correction=1)","handlingStrategy":"validation","validationCode":"def safe_var(x, ddof=0, correction=None):\n    if correction is not None:\n        return jnp.var(x, correction=correction)\n    return jnp.var(x, ddof=ddof)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on correction= in modern JAX code","Use sentinel defaults (None) so wrappers forward only one parameter"],"tags":["jax","var","ddof","parameter-conflict"],"backgroundTag":"conflicting-parameters","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}