{"record":{"id":"3e8df90aa87ceca8","repo":"jax-ml/jax","slug":"the-argument-side-must-be-either-right-or-lef","errorCode":null,"errorMessage":"The argument `side` must be either 'right' or 'left'.","messagePattern":"The argument `side` must be either 'right' or 'left'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/linalg.py","lineNumber":2135,"sourceCode":"    ...     print(P)\n    [[4.79 3.25 1.23]\n     [3.25 3.06 2.01]\n     [1.23 2.01 2.91]]\n\n    The original matrix can be reconstructed by multiplying the U and P:\n\n    >>> a_reconstructed = U @ P\n    >>> jnp.allclose(a, a_reconstructed)\n    Array(True, dtype=bool)\n\n  .. _QDWH: https://epubs.siam.org/doi/abs/10.1137/090774999\n  \"\"\"\n  arr = jnp.asarray(a)\n  if arr.ndim < 2:\n    raise ValueError(\"The input `a` must be at least a 2-D array.\")\n\n  if side not in [\"right\", \"left\"]:\n    raise ValueError(\"The argument `side` must be either 'right' or 'left'.\")\n\n  sig = \"(m,n)->(m,n),(n,n)\" if side == \"right\" else \"(m,n)->(m,n),(m,m)\"\n  return jnp_vectorize.vectorize(\n      partial(_polar_2d, side=side, method=method, eps=eps,\n              max_iterations=max_iterations),\n      signature=sig)(arr)\n\n\n@jit\ndef _sqrtm_triu(T: Array) -> Array:\n  \"\"\"\n  Implements Björck, Å., & Hammarling, S. (1983).\n      \"A Schur method for the square root of a matrix\". Linear algebra and\n      its applications\", 52, 127-140.\n  \"\"\"\n  diag = jnp.sqrt(jnp.diag(T))\n  n = diag.size\n  U = jnp.diag(diag)","sourceCodeStart":2117,"sourceCodeEnd":2153,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/linalg.py#L2117-L2153","documentation":"polar validates the side keyword, which controls whether the factorization is A = UH (side='right') or A = HU (side='left'). Only the exact lowercase strings 'right' and 'left' are accepted; anything else hits the ValueError branch before any computation starts.","triggerScenarios":"Calling polar(a, side='RIGHT'), side='both', side=None, or passing a user/config-supplied string without validation.","commonSituations":"Config-driven code where side comes from a settings file; case or spelling mistakes when porting code from another library.","solutions":["Pass side='right' or side='left' exactly (lowercase)","Omit side to use the default 'right'","Validate/normalize the config value before calling"],"exampleFix":"# before\nU, H = polar(a, side='both')\n# after\nU, H = polar(a, side='left')","handlingStrategy":"validation","validationCode":"side = side.lower() if isinstance(side, str) else side\nif side not in ('right', 'left'):\n    raise ValueError(f\"side must be 'right' or 'left', got {side!r}\")\nU, H = polar(a, side=side)","typeGuard":"def is_valid_side(s) -> bool:\n    return isinstance(s, str) and s in ('right', 'left')","tryCatchPattern":"try:\n    polar(a, side=side)\nexcept ValueError as e:\n    if \"side must be either\" in str(e):\n        side = 'right'; polar(a, side=side)\n    else: raise","preventionTips":["Normalize case for mode-like strings at input boundaries","Use Literal['right','left'] typing on internal helpers","Test both side values in unit tests"],"tags":["jax","argument-validation","polar-decomposition"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}