{"record":{"id":"c319ef82afa20c6a","repo":"jax-ml/jax","slug":"diagonal-and-off-diagonal-values-must-have-same-dt","errorCode":null,"errorMessage":"diagonal and off-diagonal values must have same dtype, got {alpha.dtype} and {beta.dtype}","messagePattern":"diagonal and off-diagonal values must have same dtype, got (.+?) and (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/linalg.py","lineNumber":1782,"sourceCode":"        q, count = sturm_step(start + j, q, count)\n      return start + unroll_cnt, q, count\n\n    i, q, count = unrolled_steps((i, q, count))\n\n    # Run the remaining steps of the Sturm sequence using a partially\n    # unrolled while loop.\n    unroll_cnt = blocksize\n    def cond(iqc):\n      i, q, count = iqc\n      return jnp.less(i, n)\n    _, _, count = lax.while_loop(cond, unrolled_steps, (i, q, count))\n    return count\n\n  alpha = jnp.asarray(d)\n  beta = jnp.asarray(e)\n  supported_dtypes = (np.float32, np.float64, np.complex64, np.complex128)\n  if alpha.dtype != beta.dtype:\n    raise TypeError(\"diagonal and off-diagonal values must have same dtype, \"\n                    f\"got {alpha.dtype} and {beta.dtype}\")\n  if alpha.dtype not in supported_dtypes or beta.dtype not in supported_dtypes:\n    raise TypeError(\"Only float32 and float64 inputs are supported as inputs \"\n                    \"to jax.scipy.linalg.eigh_tridiagonal, got \"\n                    f\"{alpha.dtype} and {beta.dtype}\")\n  n = alpha.shape[0]\n  if n <= 1:\n    if eigvals_only:\n      return jnp.real(alpha)\n    else:\n      return jnp.real(alpha), jnp.eye(n, dtype=alpha.dtype)\n\n  if dtypes.issubdtype(alpha.dtype, np.complexfloating):\n    alpha = jnp.real(alpha)\n    beta_sq = jnp.real(beta * jnp.conj(beta))\n    beta_abs = jnp.sqrt(beta_sq)\n  else:\n    beta_abs = jnp.abs(beta)","sourceCodeStart":1764,"sourceCodeEnd":1800,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/linalg.py#L1764-L1800","documentation":"eigh_tridiagonal solves the symmetric tridiagonal eigenproblem from diagonal d and off-diagonal e; the underlying kernels require both arrays to share one dtype. If alpha.dtype != beta.dtype (e.g. float32 d with float64 e), TypeError is raised.","triggerScenarios":"Calling jax.scipy.linalg.eigh_tridiagonal(d.astype(jnp.float32), e) where e remained float64, or mixing precisions from different data sources.","commonSituations":"Loading d and e from datasets stored at different precisions; x64 enabled globally so literals default to float64 while d was constructed float32.","solutions":["Cast both to the same dtype: eigh_tridiagonal(d.astype(e.dtype), e)","Construct both arrays with an explicit common dtype from the start"],"exampleFix":"// before\nw, v = jax.scipy.linalg.eigh_tridiagonal(d_f32, e_f64)\n// after\nw, v = jax.scipy.linalg.eigh_tridiagonal(d_f32, e_f64.astype(d_f32.dtype))","handlingStrategy":"type-guard","validationCode":"if d.dtype != e.dtype: d, e = jnp.asarray(d, e.dtype), jnp.asarray(e, d.dtype)","typeGuard":"def same_dtype(d, e): return np.asarray(d).dtype == np.asarray(e).dtype","tryCatchPattern":null,"preventionTips":["Construct d and e with an explicit shared dtype","Watch mixed-precision data loaders feeding tridiagonal solvers"],"tags":["jax","linalg","tridiagonal","dtype"],"backgroundTag":"dtype-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}