{"record":{"id":"f7fa6bf3998c0b0a","repo":"jax-ml/jax","slug":"two-argument-mode-is-available-only-when-mode-ps","errorCode":null,"errorMessage":"two-argument mode is available only when mode=='psd'","messagePattern":"two-argument mode is available only when mode=='psd'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/signal.py","lineNumber":664,"sourceCode":"  }\n\n  # Check/ normalize inputs\n  if boundary not in boundary_funcs:\n    raise ValueError(\n        f\"Unknown boundary option '{boundary}', \"\n        f\"must be one of: {list(boundary_funcs.keys())}\")\n\n  axis = core.concrete_or_error(operator.index, axis, \"axis of windowed-FFT\")\n  axis = canonicalize_axis(axis, x.ndim)\n\n  if y is None:\n    check_arraylike('spectral_helper', x)\n    x, = promote_dtypes_inexact(x)\n    y_arr = x  # place-holder for type checking\n    outershape = tuple_delete(x.shape, axis)\n  else:\n    if mode != 'psd':\n      raise ValueError(\"two-argument mode is available only when mode=='psd'\")\n    check_arraylike('spectral_helper', x, y)\n    x, y_arr = promote_dtypes_inexact(x, y)\n    if x.ndim != y_arr.ndim:\n      raise ValueError(\"two-arguments must have the same rank ({x.ndim} vs {y.ndim}).\")\n    # Check if we can broadcast the outer axes together\n    try:\n      outershape = jnp.broadcast_shapes(tuple_delete(x.shape, axis),\n                                        tuple_delete(y_arr.shape, axis))\n    except ValueError as err:\n      raise ValueError('x and y cannot be broadcast together.') from err\n\n  result_dtype = dtypes.to_complex_dtype(x.dtype)\n  freq_dtype = np.finfo(result_dtype).dtype\n\n  nperseg_int: int = 0\n  nfft_int: int = 0\n  noverlap_int: int = 0\n","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/signal.py#L646-L682","documentation":"Cross-spectral computation (two arrays x and y) is only meaningful for power spectral density estimation; STFT mode processes a single signal. Passing both x and y while mode is 'stft' violates that contract and raises this internal ValueError.","triggerScenarios":"Calling _spectral_helper(x, y, mode='stft', ...) with a non-None y. Public stft() never passes y; only csd (mode='psd') does.","commonSituations":"Using or copying jax internals to build custom transforms; monkeypatching stft to accept two signals.","solutions":["Use jax.scipy.signal.csd(x, y) for two-signal spectral analysis","For STFT of two signals, call stft on each and combine the complex outputs"],"exampleFix":"// before\n_ = _spectral_helper(x, y, fs, mode='stft', ...)  # internal misuse\n// after\nZx = jax.scipy.signal.stft(x)[2]\nZy = jax.scipy.signal.stft(y)[2]\ncross = Zx * jnp.conj(Zy)","handlingStrategy":"validation","validationCode":"assert mode == 'psd' or y is None  # two-argument form only for psd","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use csd() for two-signal analysis, stft() for one","Wrap internals only behind your own stable adapter"],"tags":["jax","scipy","internal-api","spectral-analysis"],"backgroundTag":"internal-api-misuse","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}