{"record":{"id":"2f45aeec6cea6bec","repo":"jax-ml/jax","slug":"noverlap-must-be-less-than-nperseg","errorCode":null,"errorMessage":"noverlap must be less than nperseg.","messagePattern":"noverlap must be less than nperseg\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/signal.py","lineNumber":732,"sourceCode":"  x = jnp.moveaxis(x, axis, -1)\n  if y is not None and y_arr.ndim > 1:\n    y_arr = jnp.moveaxis(y_arr, axis, -1)\n\n  # Check if x and y are the same length, zero-pad if necessary\n  if y is not None and x.shape[-1] != y_arr.shape[-1]:\n    if x.shape[-1] < y_arr.shape[-1]:\n      pad_shape = list(x.shape)\n      pad_shape[-1] = y_arr.shape[-1] - x.shape[-1]\n      x = jnp.concatenate((x, jnp.zeros_like(x, shape=pad_shape)), -1)\n    else:\n      pad_shape = list(y_arr.shape)\n      pad_shape[-1] = x.shape[-1] - y_arr.shape[-1]\n      y_arr = jnp.concatenate((y_arr, jnp.zeros_like(x, shape=pad_shape)), -1)\n\n  if nfft_int < nperseg_int:\n    raise ValueError('nfft must be greater than or equal to nperseg.')\n  if noverlap_int >= nperseg_int:\n    raise ValueError('noverlap must be less than nperseg.')\n  nstep = nperseg_int - noverlap_int\n\n  # Apply paddings\n  if boundary is not None:\n    ext_func = boundary_funcs[boundary]\n    x = ext_func(x, nperseg_int // 2, axis=-1)\n    if y is not None:\n      y_arr = ext_func(y_arr, nperseg_int // 2, axis=-1)\n\n  if padded:\n    # Pad to integer number of windowed segments\n    # I.e make x.shape[-1] = nperseg + (nseg-1)*nstep, with integer nseg\n    nadd = (-(x.shape[-1]-nperseg_int) % nstep) % nperseg_int\n    x = jnp.concatenate((x, jnp.zeros_like(x, shape=(*x.shape[:-1], nadd))), axis=-1)\n    if y is not None:\n      y_arr = jnp.concatenate((y_arr, jnp.zeros_like(x, shape=(*y_arr.shape[:-1], nadd))), axis=-1)\n\n  # Handle detrending and window functions","sourceCodeStart":714,"sourceCodeEnd":750,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/signal.py#L714-L750","documentation":"Segments overlap by noverlap samples, requiring at least one new sample per step (nstep = nperseg - noverlap > 0). noverlap >= nperseg would make step size zero or negative, producing no progress, so it is rejected.","triggerScenarios":"stft(x, nperseg=256, noverlap=256); using noverlap = nperseg for 'maximum overlap'; scipy-style defaults copied onto a smaller nperseg.","commonSituations":"High-overlap analysis settings where overlap ratio is rounded up to the full segment length; parameter sweeps that hit the boundary.","solutions":["Reduce noverlap to at most nperseg - 1 (typically int(nperseg * 0.75))","If noverlap is derived, clamp: noverlap = min(nperseg - 1, noverlap)","When wanting maximal overlap with hop 1, set noverlap = nperseg - 1"],"exampleFix":"// before\njax.scipy.signal.stft(x, nperseg=256, noverlap=256)\n// after\njax.scipy.signal.stft(x, nperseg=256, noverlap=255)","handlingStrategy":"validation","validationCode":"noverlap = min(int(noverlap), int(nperseg) - 1) if noverlap is not None else None","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Derive noverlap from a ratio: noverlap = int(0.75 * nperseg)","Recheck noverlag/noverlap whenever nperseg changes in sweeps"],"tags":["jax","scipy","stft","overlap","argument-validation"],"backgroundTag":"overlap-exceeds-segment-length","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}