{"record":{"id":"c39083744500855b","repo":"jax-ml/jax","slug":"mode-must-be-right-or-left-got-mode-r","errorCode":null,"errorMessage":"mode must be 'right' or 'left', got {mode!r}","messagePattern":"mode must be 'right' or 'left', got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/linalg.py","lineNumber":1118,"sourceCode":"\n  Examples:\n    Use :func:`qr_multiply` to efficiently solve a least-squares problem.\n    For an overdetermined system ``A @ x ≈ b``, pass ``b`` as a 1-D row\n    via ``mode='right'`` to obtain ``Q^T @ b`` and ``R`` in one step:\n\n    >>> import jax\n    >>> import jax.numpy as jnp\n    >>> A = jnp.array([[1., 1.], [1., 2.], [1., 3.], [1., 4.]])\n    >>> b = jnp.array([2., 4., 5., 4.])\n    >>> Qtb, R = jax.scipy.linalg.qr_multiply(A, b, mode='right')\n    >>> x = jax.scipy.linalg.solve_triangular(R, Qtb)\n    >>> jnp.allclose(A.T @ A @ x, A.T @ b)\n    Array(True, dtype=bool)\n  \"\"\"\n  del overwrite_a, overwrite_c  # unused\n  a, c = promote_dtypes_inexact(jnp.asarray(a), jnp.asarray(c))\n  if mode not in ('right', 'left'):\n    raise ValueError(f\"mode must be 'right' or 'left', got {mode!r}\")\n\n  onedim = c.ndim == 1\n  if onedim:\n    c = c[:, None] if mode == 'left' else c[None, :]\n\n  m, n = a.shape[-2:]\n  k = min(m, n)\n\n  if mode == 'left':\n    if c.shape[-2] != k:\n      raise ValueError(\n          f\"Array shapes are not compatible for Q @ c operation: \"\n          f\"a has shape {tuple(a.shape)} so Q has {k} columns, \"\n          f\"but c has {c.shape[-2]} rows (expected {k}).\")\n  else:\n    if c.shape[-1] != m:\n      raise ValueError(\n          f\"Array shapes are not compatible for c @ Q operation: \"","sourceCodeStart":1100,"sourceCodeEnd":1136,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/linalg.py#L1100-L1136","documentation":"jax.scipy.linalg.qr_multiply applies Q from a QR decomposition to another matrix c, either from the left (mode='left', computes Q @ c) or right (mode='right', computes c @ Q). The mode argument must be one of those two strings; anything else raises ValueError.","triggerScenarios":"Calling jax.scipy.linalg.qr_multiply(a, c, mode='L'), mode=0, mode=None, or a typo like 'Left'.","commonSituations":"Porting scipy.linalg.qr_multiply code that uses the shorthand 'left'/'right' but passing a variable or incorrectly cased value; SciPy is case-sensitive too, so silent config drift (e.g. mode read from a config file) triggers this.","solutions":["Pass mode='left' or mode='right' exactly (lowercase)","If mode comes from user input/config, normalize with str(mode).lower() and validate against {'left','right'} before the call"],"exampleFix":"// before\nqr_multiply(a, c, mode=cfg.qr_side)  # cfg.qr_side == 'LEFT'\n// after\nmode = str(cfg.qr_side).lower()\nassert mode in ('left', 'right')\nqr_multiply(a, c, mode=mode)","handlingStrategy":"validation","validationCode":"mode = str(mode).lower(); assert mode in ('left', 'right'), f'bad mode {mode}'","typeGuard":"null","tryCatchPattern":null,"preventionTips":["Normalize casing of enum-like string params at your boundary","Use literals, not config-driven free-form strings, for mode args"],"tags":["jax","linalg","qr-decomposition","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}