{"record":{"id":"4134ddf300dc132d","repo":"jax-ml/jax","slug":"scale-must-be-none-sqrtn-or-n-got-scale-r","errorCode":null,"errorMessage":"scale must be None, 'sqrtn', or 'n'; got {scale!r}.","messagePattern":"scale must be None, 'sqrtn', or 'n'; got (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/linalg.py","lineNumber":3200,"sourceCode":"    n: size of the matrix.\n    scale: (optional) ``None`` (default, unscaled), ``'sqrtn'`` (scale by\n      :math:`1/\\sqrt{n}`, making the matrix unitary), or ``'n'`` (scale by\n      :math:`1/n`).\n    dtype: (optional) complex floating-point dtype for the output. Defaults to\n      JAX's default complex dtype.\n\n  Returns:\n    A DFT matrix of shape ``(n, n)``.\n\n  Examples:\n    >>> jax.scipy.linalg.dft(4).round(3)\n    Array([[ 1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j],\n           [ 1.+0.j, -0.-1.j, -1.+0.j,  0.+1.j],\n           [ 1.+0.j, -1.+0.j,  1.-0.j, -1.+0.j],\n           [ 1.+0.j,  0.+1.j, -1.+0.j, -0.-1.j]], dtype=complex64)\n  \"\"\"\n  if scale is not None and scale not in ('sqrtn', 'n'):\n    raise ValueError(\n        f\"scale must be None, 'sqrtn', or 'n'; got {scale!r}.\")\n  if dtype is None:\n    dtype = dtypes.default_complex_dtype()\n  else:\n    dtype = dtypes.check_and_canonicalize_user_dtype(dtype, \"dft\")\n    if not dtypes.issubdtype(dtype, np.complexfloating):\n      raise ValueError(\n          f\"dtype must be a complex floating-point type; got {dtype}.\")\n  a = jnp.arange(n, dtype=dtype)\n  omegas = jnp.exp(-2j * np.pi * a[:, None] * a[None, :] / n)\n  if scale == 'sqrtn':\n    omegas = omegas / jnp.sqrt(n)\n  elif scale == 'n':\n    omegas = omegas / n\n  return omegas\n\n\ndef _solve_sylvester_triangular_scan(R: Array, S: Array, F: Array) -> Array:","sourceCodeStart":3182,"sourceCodeEnd":3218,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/linalg.py#L3182-L3218","documentation":"jax.scipy.linalg.dft accepts scale=None (unscaled), 'sqrtn' (unitary), or 'n' (orthonormal-ish 1/n scaling). Any other value is rejected before constructing the twiddle-factor matrix.","triggerScenarios":"Calling dft(n, scale='sqrt_n'), scale=1, scale='Sqrtn', or passing a numeric scaling factor expecting it to be applied.","commonSituations":"Porting code that used numeric normalization from other libraries, or case/underscore typos in the string.","solutions":["Pass None, 'sqrtn', or 'n' exactly","Apply custom numeric scaling manually after the call"],"exampleFix":"# before\nF = linalg.dft(n, scale=1/math.sqrt(n))\n# after\nF = linalg.dft(n, scale='sqrtn')","handlingStrategy":"validation","validationCode":"if scale is not None and scale not in ('sqrtn','n'): raise ValueError(scale)","typeGuard":"def is_valid_scale(s) -> bool: return s is None or s in ('sqrtn', 'n')","tryCatchPattern":null,"preventionTips":["Treat scale as an enum, not a number"],"tags":["jax","scipy","linalg","dft","argument-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}