{"record":{"id":"e764bda0c53df2d7","repo":"jax-ml/jax","slug":"trans-value-must-be-0-1-or-2-got-trans","errorCode":null,"errorMessage":"'trans' value must be 0, 1, or 2, got {trans}","messagePattern":"'trans' value must be 0, 1, or 2, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/linalg.py","lineNumber":1823,"sourceCode":"\n\ndef _lu_solve_core(lu: Array, permutation: Array, b: Array, trans: int) -> Array:\n  m = lu.shape[0]\n  x = lax.reshape(b, (m, math.prod(b.shape[1:])))\n  if trans == 0:\n    x = x[permutation, :]\n    x = triangular_solve(lu, x, left_side=True, lower=True, unit_diagonal=True)\n    x = triangular_solve(lu, x, left_side=True, lower=False)\n  elif trans == 1 or trans == 2:\n    conj = trans == 2\n    x = triangular_solve(lu, x, left_side=True, lower=False, transpose_a=True,\n                         conjugate_a=conj)\n    x = triangular_solve(lu, x, left_side=True, lower=True, unit_diagonal=True,\n                         transpose_a=True, conjugate_a=conj)\n    _, ind = lax.sort_key_val(permutation, lax.iota('int32', permutation.shape[0]))\n    x = x[ind, :]\n  else:\n    raise ValueError(f\"'trans' value must be 0, 1, or 2, got {trans}\")\n  return lax.reshape(x, b.shape)\n\n\n@api.jit(static_argnums=(3,))\ndef _lu_solve(lu: Array, permutation: Array, b: Array, trans: int) -> Array:\n  if len(lu.shape) < 2 or lu.shape[-1] != lu.shape[-2]:\n    raise ValueError(\"last two dimensions of LU decomposition must be equal, \"\n                     \"got shape {}\".format(lu.shape))\n  if len(b.shape) < 1:\n    raise ValueError(\"b matrix must have rank >= 1, got shape {}\"\n                     .format(b.shape))\n  # Broadcasting follows NumPy's convention for linalg.solve: the RHS is\n  # treated as a (batched) vector if the number of dimensions differ by 1.\n  # Otherwise, broadcasting rules apply.\n  rhs_vector = lu.ndim == b.ndim + 1\n  if rhs_vector:\n    if b.shape[-1] != lu.shape[-1]:\n      raise ValueError(\"When LU decomposition matrix and b have the same \"","sourceCodeStart":1805,"sourceCodeEnd":1841,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/linalg.py#L1805-L1841","documentation":"jax/_src/lax/linalg.py:1823 in _lu_solve_core. The trans parameter selects the solve variant: 0 = A x = b, 1 = A^T x = b, 2 = A^H x = b. Any other integer falls through the if/elif chain and raises ValueError — it is a static Python int (the function is jitted with static_argnums for it), so this is a plain caller bug.","triggerScenarios":"Calling jax.lax.linalg.lu_solve(lu, permutation, b, trans) with trans not in {0, 1, 2}, e.g. passing -1, 3, a bool, or a string like 'T' (SciPy convention).","commonSituations":"Porting SciPy/BLAS conventions where trans is 'N'/'T'/'C' or 0-indexed enums differ; passing a NumPy integer or config flag that drifts from expected values after a refactor.","solutions":["Map your convention explicitly: {'N': 0, 'T': 1, 'C': 2}[mode] before calling","Validate trans at the API boundary: assert trans in (0, 1, 2)"],"exampleFix":"// before\nx = jax.lax.linalg.lu_solve(lu, p, b, trans='T')\n// after\nx = jax.lax.linalg.lu_solve(lu, p, b, trans={'N':0,'T':1,'C':2}['T'])","handlingStrategy":"validation","validationCode":"TRANS = {'N': 0, 'T': 1, 'C': 2}\nassert trans in (0, 1, 2)","typeGuard":"def valid_trans(t) -> bool:\n    return t in (0, 1, 2)","tryCatchPattern":null,"preventionTips":["Map SciPy letter codes to 0/1/2 at the boundary"],"tags":["jax","lu-solve","invalid-argument","api-misuse"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}