jax-ml/jax · error · ValueError

scale must be None, 'sqrtn', or 'n'; got

Error message

scale must be None, 'sqrtn', or 'n'; got {scale!r}.

What it means

jax.scipy.linalg.dft accepts only three defined scale conventions: unscaled, 'sqrtn' (unitary), and 'n'. The constructor fires when the scale argument is any other string.

Solutions

  1. Pass None, 'sqrtn', or 'n' exactly
  2. Apply custom numeric scaling manually after the call

Example fix

# before
F = linalg.dft(n, scale=1/math.sqrt(n))
# after
F = linalg.dft(n, scale='sqrtn')
Defensive patterns

Strategy: validation

Validate before calling

if scale is not None and scale not in ('sqrtn','n'): raise ValueError(scale)

Type guard

def is_valid_scale(s) -> bool: return s is None or s in ('sqrtn', 'n')

Prevention

When it happens

Trigger: Calling dft(n, scale='sqrt_n'), scale=1, scale='Sqrtn', or passing a numeric scaling factor expecting it to be applied.

Common situations: Porting code that used numeric normalization from other libraries, or case/underscore typos in the string.

Understand the failure class

Background: "invalid argument", "unknown mode", "not supported": invalid enum-like argument errors explained — this error's family across 19 libraries.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/4134ddf300dc132d. Report an issue: GitHub.

Appendix: source

Thrown at jax/_src/scipy/linalg.py:3200

    n: size of the matrix.
    scale: (optional) ``None`` (default, unscaled), ``'sqrtn'`` (scale by
      :math:`1/\sqrt{n}`, making the matrix unitary), or ``'n'`` (scale by
      :math:`1/n`).
    dtype: (optional) complex floating-point dtype for the output. Defaults to
      JAX's default complex dtype.

  Returns:
    A DFT matrix of shape ``(n, n)``.

  Examples:
    >>> jax.scipy.linalg.dft(4).round(3)
    Array([[ 1.+0.j,  1.+0.j,  1.+0.j,  1.+0.j],
           [ 1.+0.j, -0.-1.j, -1.+0.j,  0.+1.j],
           [ 1.+0.j, -1.+0.j,  1.-0.j, -1.+0.j],
           [ 1.+0.j,  0.+1.j, -1.+0.j, -0.-1.j]], dtype=complex64)
  """
  if scale is not None and scale not in ('sqrtn', 'n'):
    raise ValueError(
        f"scale must be None, 'sqrtn', or 'n'; got {scale!r}.")
  if dtype is None:
    dtype = dtypes.default_complex_dtype()
  else:
    dtype = dtypes.check_and_canonicalize_user_dtype(dtype, "dft")
    if not dtypes.issubdtype(dtype, np.complexfloating):
      raise ValueError(
          f"dtype must be a complex floating-point type; got {dtype}.")
  a = jnp.arange(n, dtype=dtype)
  omegas = jnp.exp(-2j * np.pi * a[:, None] * a[None, :] / n)
  if scale == 'sqrtn':
    omegas = omegas / jnp.sqrt(n)
  elif scale == 'n':
    omegas = omegas / n
  return omegas


def _solve_sylvester_triangular_scan(R: Array, S: Array, F: Array) -> Array:

View on GitHub (pinned to 1e1c6a8fc0)