{"record":{"id":"cdea75dcee188b13","repo":"jax-ml/jax","slug":"got-empty-index-range-in-select-range","errorCode":null,"errorMessage":"Got empty index range in select_range.","messagePattern":"Got empty index range in select_range\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/linalg.py","lineNumber":1837,"sourceCode":"  abs_tol = finfo.eps * t_norm\n  if tol is not None:\n    abs_tol = jnp.maximum(tol, abs_tol)\n\n  # In the worst case, when the absolute tolerance is eps*lambda_est_max and\n  # lambda_est_max = -lambda_est_min, we have to take as many bisection steps\n  # as there are bits in the mantissa plus 1.\n  # The proof is left as an exercise to the reader.\n  max_it = finfo.nmant + 1\n\n  # Determine the indices of the desired eigenvalues, based on select and\n  # select_range.\n  if select == 'a':\n    target_counts = jnp.arange(n, dtype=np.int32)\n  elif select == 'i':\n    if select_range is None:\n      raise ValueError(\"for select='i', select_range must be specified.\")\n    if select_range[0] > select_range[1]:\n      raise ValueError('Got empty index range in select_range.')\n    target_counts = jnp.arange(select_range[0], select_range[1] + 1, dtype=np.int32)\n  elif select == 'v':\n    # TODO(phawkins): requires dynamic shape support.\n    raise NotImplementedError(\"eigh_tridiagonal(..., select='v') is not \"\n                              \"implemented\")\n  else:\n    raise ValueError(\"'select must have a value in {'a', 'i', 'v'}.\")\n\n  # Run binary search for all desired eigenvalues in parallel, starting from\n  # the interval lightly wider than the estimated\n  # [lambda_est_min, lambda_est_max].\n  fudge = 2.1  # We widen starting interval the Gershgorin interval a bit.\n  norm_slack = jnp.array(n, alpha.dtype) * fudge * finfo.eps * t_norm\n  lower = lambda_est_min - norm_slack - 2 * fudge * pivmin\n  upper = lambda_est_max + norm_slack + fudge * pivmin\n\n  # Pre-broadcast the scalars used in the Sturm sequence for improved\n  # performance.","sourceCodeStart":1819,"sourceCodeEnd":1855,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/linalg.py#L1819-L1855","documentation":"With select='i', eigh_tridiagonal requires an ascending index range; if select_range[0] > select_range[1] the range is empty and no eigenvalues would be selected, so ValueError is raised.","triggerScenarios":"Calling eigh_tridiagonal(d, e, select='i', select_range=(5, 2)) or with swapped bounds produced by user input or a config mistake.","commonSituations":"Off-by-one or swapped (lo, hi) variables; ranges computed as (hi, lo) by mistake in a search routine.","solutions":["Swap the bounds so lo <= hi: select_range=(min(lo, hi), max(lo, hi))","Validate the range before calling and clamp/skip when empty"],"exampleFix":"// before\nw = jax.scipy.linalg.eigh_tridiagonal(d, e, select='i', select_range=(hi, lo))\n// after\nw = jax.scipy.linalg.eigh_tridiagonal(d, e, select='i', select_range=(lo, hi))","handlingStrategy":"validation","validationCode":"if select == 'i': assert select_range[0] <= select_range[1], 'select_range must be ascending'","typeGuard":"null","tryCatchPattern":null,"preventionTips":["Normalize ranges with (min(lo,hi), max(lo,hi)) at your API boundary","Add unit tests covering boundary and swapped ranges"],"tags":["jax","linalg","tridiagonal","argument-validation"],"backgroundTag":"invalid-argument-range","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}