{"record":{"id":"1b16333896bfcf79","repo":"jax-ml/jax","slug":"expected-search-dim-5-matrix-dim-got-k-5","errorCode":null,"errorMessage":"expected search dim * 5 < matrix dim (got {k * 5}, {n})","messagePattern":"expected search dim \\* 5 < matrix dim \\(got (.+?), (.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/experimental/sparse/linalg.py","lineNumber":256,"sourceCode":"    state = jax.lax.while_loop(cond, body, state)\n    diagnostics = None\n  i, X, _P, _R, _converged, theta = state\n\n  if debug:\n    assert diagnostics is not None\n    return theta[0, :], X, i, diagnostics\n  return theta[0, :], X, i\n\n\ndef _check_inputs(A, X):\n  n, k = X.shape\n  dt = X.dtype\n\n  if k == 0:\n    raise ValueError(f'must have search dim > 0, got {k}')\n\n  if k * 5 >= n:\n    raise ValueError(f'expected search dim * 5 < matrix dim (got {k * 5}, {n})')\n\n  test_output = A(jnp.zeros((n, 1), dtype=X.dtype))\n\n  if test_output.dtype != dt:\n    raise ValueError(\n        f'A, X must have same dtypes (were {test_output.dtype}, {dt})')\n\n  if test_output.shape != (n, 1):\n    s = test_output.shape\n    raise ValueError(f'A must be ({n}, {n}) matrix A, got output {s}')\n\n\ndef _mm(a, b, precision=jax.lax.Precision.HIGHEST):\n  return jax.lax.dot(a, b, precision=(precision, precision))\n\ndef _generate_diagnostics(prev_XPR, X, P, R, theta, converged, adj_resid):\n  k = X.shape[1]\n  assert X.shape == P.shape","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/experimental/sparse/linalg.py#L238-L274","documentation":"LOBPCG in jax.experimental.sparse.linalg requires the search dimension k to satisfy k*5 < n where n is the matrix dimension. The algorithm needs the block to be small relative to the problem size for convergence guarantees and efficiency.","triggerScenarios":"Calling lobpcg_standard with a block X whose width k is too large relative to the number of rows n (k*5 >= n).","commonSituations":"Requesting a large fraction of eigenpairs with LOBPCG; small test matrices; if you need many eigenpairs use dense jax.numpy.linalg.eigh.","solutions":["Reduce the number of requested eigenpairs k so that k < n/5","Use dense eigendecomposition (jnp.linalg.eigh) on the todense() matrix if most eigenpairs are needed","Increase the problem size n if it was accidentally truncated"],"exampleFix":"// before\ntheta, U, _ = lobpcg_standard(A, jnp.zeros((100, 25)))  # 25*5 >= 100\n// after\ntheta, U, _ = lobpcg_standard(A, jnp.zeros((100, 10)))  # 10*5 < 100","handlingStrategy":"validation","validationCode":"n, k = X.shape\nassert 0 < k and k * 5 < n, f'require k*5 < n, got k={k}, n={n}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Request few eigenpairs (k much smaller than n/5)","Switch to jnp.linalg.eigh(M.todense()) when many eigenpairs are needed"],"tags":["jax","sparse","lobpcg","validation"],"backgroundTag":"eigensolver-invalid-block-size","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}