{"record":{"id":"1af23ef3f978c6b0","repo":"jax-ml/jax","slug":"full-matrices-and-subset-by-index-cannot-be-both-b","errorCode":null,"errorMessage":"full_matrices and subset_by_index cannot be both be set.","messagePattern":"full_matrices and subset_by_index cannot be both be set\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/tpu/linalg/svd.py","lineNumber":192,"sourceCode":"\n  if subset_by_index is not None:\n    if len(subset_by_index) != 2:\n      raise ValueError('subset_by_index must be a tuple of size 2.')\n    # Make sure subset_by_index is a concrete tuple.\n    subset_by_index = (\n        operator.index(subset_by_index[0]),\n        operator.index(subset_by_index[1]),\n    )\n    if subset_by_index[0] >= subset_by_index[1]:\n      raise ValueError('Got empty index range in subset_by_index.')\n    if subset_by_index[0] < 0:\n      raise ValueError('Indices in subset_by_index must be non-negative.')\n    m, n = a.shape\n    rank = n if n < m else m\n    if subset_by_index[1] > rank:\n      raise ValueError('Index in subset_by_index[1] exceeds matrix size.')\n    if full_matrices and subset_by_index != (0, rank):\n      raise ValueError(\n          'full_matrices and subset_by_index cannot be both be set.'\n      )\n    # By convention, eigenvalues are numbered in non-decreasing order, while\n    # singular values are numbered non-increasing order, so change\n    # subset_by_index accordingly.\n    subset_by_index = (rank - subset_by_index[1], rank - subset_by_index[0])\n\n  m, n = a.shape\n  is_flip = False\n  if m < n:\n    a = a.T.conj()\n    m, n = a.shape\n    is_flip = True\n\n  u_out_null: Array | None\n  q: Array | None\n\n  if full_matrices and m > n:","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/tpu/linalg/svd.py#L174-L210","documentation":"full_matrices=True is incompatible with any subset_by_index other than the trivial full range (0, rank). A partial SVD cannot also request full-dimension U and Vt matrices.","triggerScenarios":"svd(a, full_matrices=True, subset_by_index=(0, k)) with k < min(m, n); note that subset_by_index=(0, rank) is explicitly allowed.","commonSituations":"Copy-pasting existing svd(..., full_matrices=True) code and adding subset_by_index for a top-k speedup; forgetting full_matrices defaults or was set for shape-compatibility downstream.","solutions":["Set full_matrices=False when using a partial subset_by_index.","Or pass subset_by_index=(0, rank) (equivalent to full range) if full_matrices=True is required.","Adjust downstream code that assumed U/Vt had full dims; with full_matrices=False shapes are (m, k) and (k, n)."],"exampleFix":"// before\nu, s, vt = svd(a, full_matrices=True, subset_by_index=(0, k))\n// after\nu, s, vt = svd(a, full_matrices=False, subset_by_index=(0, k))","handlingStrategy":"validation","validationCode":"rank = min(a.shape[-2], a.shape[-1])\nfull = full_matrices and sb in (None, (0, rank))\nu, s, vt = svd(a, full_matrices=full, subset_by_index=sb)","typeGuard":null,"tryCatchPattern":"try:\n    svd(a, full_matrices=True, subset_by_index=sb)\nexcept ValueError as e:\n    if 'cannot be both be set' in str(e):\n        u, s, vt = svd(a, full_matrices=False, subset_by_index=sb)\n    else: raise","preventionTips":["Treat subset_by_index as implying full_matrices=False in your wrappers.","For full SVD just omit subset_by_index."],"tags":["jax","tpu","svd","linalg","mutually-exclusive-args"],"backgroundTag":"conflicting-options","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}