jax-ml/jax · error · ValueError

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

Error message

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

What it means

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.

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)

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.

Related errors


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