{"record":{"id":"35b9b6baf25a1703","repo":"jax-ml/jax","slug":"the-out-argument-to-jnp-compress-is-not-supporte","errorCode":null,"errorMessage":"The 'out' argument to jnp.compress is not supported.","messagePattern":"The 'out' argument to jnp\\.compress is not supported\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":9047,"sourceCode":"    Array([[ 1,  3],\n           [ 5,  7],\n           [ 9, 11]], dtype=int32)\n\n    The optional ``size`` argument lets you specify a static output size so\n    that the output is statically-shaped, and so this function can be used\n    with transformations like :func:`~jax.jit` and :func:`~jax.vmap`:\n\n    >>> f = lambda c, a: jnp.extract(c, a, size=len(a), fill_value=0)\n    >>> mask = (a % 3 == 0)\n    >>> jax.vmap(f)(mask, a)\n    Array([[ 3,  0,  0,  0],\n           [ 6,  0,  0,  0],\n           [ 9, 12,  0,  0]], dtype=int32)\n  \"\"\"\n  condition_arr, arr, fill_value = util.ensure_arraylike(\"compress\", condition, a, fill_value)\n  condition_arr = condition_arr.astype(bool)\n  if out is not None:\n    raise NotImplementedError(\"The 'out' argument to jnp.compress is not supported.\")\n  if condition_arr.ndim != 1:\n    raise ValueError(\"condition must be a 1D array\")\n  if axis is None:\n    axis = 0\n    arr = ravel(arr)\n  else:\n    arr = moveaxis(arr, axis, 0)\n  condition_arr, extra = condition_arr[:arr.shape[0]], condition_arr[arr.shape[0]:]\n  arr = arr[:condition_arr.shape[0]]\n\n  if size is None:\n    msg = (\"The size argument of jnp.compress must be specified in order to use \"\n           \"jnp.compress within JAX transformations like jax.jit, jax.vmap, and \"\n           \"jax.grad. For more information, refer to the jnp.compress documentation.\")\n    condition_arr = core.concrete_or_error(None, condition_arr, msg)\n    extra = core.concrete_or_error(None, extra, msg)\n    if extra.any():\n      raise ValueError(\"condition contains entries that are out of bounds\")","sourceCodeStart":9029,"sourceCodeEnd":9065,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L9029-L9065","documentation":"jnp.compress does not support writing results into a preallocated output array, so passing a non-None value for the out parameter raises NotImplementedError. JAX arrays are immutable and functions are pure, so out-style in-place semantics from NumPy are generally unsupported.","triggerScenarios":"Calling jnp.compress(condition, a, out=my_array) with any non-None out argument.","commonSituations":"Porting NumPy code that uses out= to reuse buffers; copy-pasting numpy.compress calls into JAX codebases.","solutions":["Remove the out argument and use the return value: result = jnp.compress(condition, a)","If buffer reuse was for memory reasons, note JAX's functional model makes it unnecessary","For NumPy interop, drop out= and assign afterwards: buf[:] = jnp.compress(condition, a)"],"exampleFix":"// before\nnp.compress(cond, a, out=buf)\n// after\nbuf = jnp.compress(cond, a)","handlingStrategy":"type-guard","validationCode":"assert out is None, 'jnp.compress does not support out='","typeGuard":null,"tryCatchPattern":"try:\n    result = jnp.compress(cond, a, out=out)\nexcept NotImplementedError:\n    result = jnp.compress(cond, a)  # out unsupported","preventionTips":["Never pass out= to jnp functions; JAX is functional","Grep ported NumPy code for out= arguments","Bind results via assignment, not output buffers"],"tags":["jax","unsupported-argument","numpy-compat","out-parameter"],"backgroundTag":"unsupported-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}