{"record":{"id":"573d0e8c6d4d44bd","repo":"jax-ml/jax","slug":"the-out-argument-to-jnp-ptp-is-not-supported","errorCode":null,"errorMessage":"The 'out' argument to jnp.ptp is not supported.","messagePattern":"The 'out' argument to jnp\\.ptp is not supported\\.","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/reductions.py","lineNumber":1335,"sourceCode":"\n    >>> jnp.ptp(x, axis=1)\n    Array([4, 7, 6], dtype=int32)\n\n    To preserve the dimensions of input, you can set ``keepdims=True``.\n\n    >>> jnp.ptp(x, axis=1, keepdims=True)\n    Array([[4],\n           [7],\n           [6]], dtype=int32)\n  \"\"\"\n  a = ensure_arraylike(\"ptp\", a)\n  return _ptp(a, _ensure_optional_axes(axis), out, keepdims)\n\n@api.jit(static_argnames=('axis', 'keepdims'))\ndef _ptp(a: Array, axis: Axis = None, out: None = None,\n         keepdims: bool = False) -> Array:\n  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.ptp is not supported.\")\n  x = amax(a, axis=axis, keepdims=keepdims)\n  y = amin(a, axis=axis, keepdims=keepdims)\n  return lax.sub(x, y)\n\n\n@export\n@api.jit(static_argnames=('axis', 'keepdims'))\ndef count_nonzero(a: ArrayLike, axis: Axis = None,\n                  keepdims: bool = False) -> Array:\n  r\"\"\"Return the number of nonzero elements along a given axis.\n\n  JAX implementation of :func:`numpy.count_nonzero`.\n\n  Args:\n    a: input array.\n    axis: optional, int or sequence of ints, default=None. Axis along which the\n      number of nonzeros are counted. If None, counts within the flattened array.\n    keepdims: bool, default=False. If true, reduced axes are left in the result","sourceCodeStart":1317,"sourceCodeEnd":1353,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/reductions.py#L1317-L1353","documentation":"jnp.ptp (peak-to-peak) rejects the NumPy-style out= argument because JAX arrays are immutable and cannot be written in place. The out parameter exists only for signature parity.","triggerScenarios":"Calling jnp.ptp(a, axis=0, out=buf) or passing a third positional argument.","commonSituations":"Mechanical NumPy→JAX ports that keep out= kwargs; older code targeting buffer reuse on constrained devices.","solutions":["Remove out and assign the result: rng = jnp.ptp(a, axis=0)","Replace buffer-reuse patterns with jit-compiled functions returning the value"],"exampleFix":"// before\njnp.ptp(a, out=buf)\n// after\nbuf = jnp.ptp(a)","handlingStrategy":"validation","validationCode":"assert out is None or out is ..., 'jnp.ptp does not support out'\nresult = jnp.ptp(a, axis=axis)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remove out= when porting ptp","Use return-value assignment instead of buffer writes"],"tags":["jax","numpy","ptp","out-argument"],"backgroundTag":"unsupported-out-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}