{"record":{"id":"84627429c38c92c5","repo":"jax-ml/jax","slug":"dtype-must-be-a-complex-floating-point-type-got","errorCode":null,"errorMessage":"dtype must be a complex floating-point type; got {dtype}.","messagePattern":"dtype must be a complex floating-point type; got (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/linalg.py","lineNumber":3207,"sourceCode":"  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:\n  \"\"\"\n  Solves the Sylvester equation using Bartels-Stewart algorithm\n  .. math::\n\n    RY + YS^T = F\n\n  where R and S are upper triangular matrices following a Schur decomposition.","sourceCodeStart":3189,"sourceCodeEnd":3225,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/linalg.py#L3189-L3225","documentation":"jax.scipy.linalg.dft returns a complex matrix, so an explicitly passed dtype must be a complex floating subtype (complex64/complex128). The check runs after canonicalizing the user dtype.","triggerScenarios":"Calling dft(n, dtype=jnp.float32) or dtype=np.float64; passing a default real dtype variable.","commonSituations":"Reusing a dtype config meant for real-valued transforms; porting real-FFT code that assumed float output.","solutions":["Omit dtype to use the default complex dtype","Pass jnp.complex64 or jnp.complex128","Cast to real afterwards if you only need real parts"],"exampleFix":"# before\nF = linalg.dft(n, dtype=jnp.float32)\n# after\nF = linalg.dft(n, dtype=jnp.complex64)","handlingStrategy":"type-guard","validationCode":"dtype = jnp.complex64 if dtype is None else dtype\nassert jnp.issubdtype(dtype, jnp.complexfloating)","typeGuard":"def is_complex_dtype(dt) -> bool: return jnp.issubdtype(jnp.dtype(dt), jnp.complexfloating)","tryCatchPattern":null,"preventionTips":["Default to omitting dtype; centralize complex dtype constants"],"tags":["jax","scipy","linalg","dtype","dft"],"backgroundTag":"dtype-mismatch","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}