{"record":{"id":"0d9b338b0a68476e","repo":"jax-ml/jax","slug":"corrcoef-dtype-must-be-a-subclass-of-float-or-com","errorCode":null,"errorMessage":"corrcoef: dtype must be a subclass of float or complex; got {dtype=}","messagePattern":"corrcoef: dtype must be a subclass of float or complex; got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/numpy/lax_numpy.py","lineNumber":9331,"sourceCode":"           [-1.,  1.]], dtype=float32)\n\n    The entries of the correlation matrix are normalized such that they\n    lie within the range -1 to +1, where +1 indicates perfect correlation\n    and -1 indicates perfect anti-correlation. For example, here is the\n    correlation of 100 points drawn from a 3-dimensional standard normal\n    distribution:\n\n    >>> key = jax.random.key(0)\n    >>> x = jax.random.normal(key, shape=(3, 100))\n    >>> with jnp.printoptions(precision=2):\n    ...   print(jnp.corrcoef(x))\n    [[1.   0.03 0.12]\n     [0.03 1.   0.01]\n     [0.12 0.01 1.  ]]\n  \"\"\"\n  util.check_arraylike(\"corrcoef\", x)\n  if dtype is not None and not dtypes.issubdtype(dtype, np.inexact):\n    raise ValueError(f\"corrcoef: dtype must be a subclass of float or complex; got {dtype=}\")\n  c = cov(x, y, rowvar, dtype=dtype)\n  if len(np.shape(c)) == 0:\n    # scalar - this should yield nan for values (nan/nan, inf/inf, 0/0), 1 otherwise\n    return ufuncs.divide(c, c)\n  d = diag(c)\n  stddev = ufuncs.sqrt(ufuncs.real(d)).astype(c.dtype)\n  c = c / stddev[:, None] / stddev[None, :]\n\n  real_part = clip(ufuncs.real(c), -1, 1)\n  if iscomplexobj(c):\n    complex_part = clip(ufuncs.imag(c), -1, 1)\n    c = lax.complex(real_part, complex_part)\n  else:\n    c = real_part\n  return c\n\n\n@export","sourceCodeStart":9313,"sourceCodeEnd":9349,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/numpy/lax_numpy.py#L9313-L9349","documentation":"jnp.corrcoef accepts a dtype parameter that must be an inexact (float or complex) dtype, since it is forwarded to cov for floating-point computation. A non-inexact dtype raises ValueError('corrcoef: dtype must be a subclass of float or complex; got {dtype=}') before any computation.","triggerScenarios":"jnp.corrcoef(x, dtype=jnp.int32) or any integer/bool dtype; passing np.int64 from a config.","commonSituations":"Users trying to control output precision assuming any dtype is allowed; templated code where dtype is injected and may be integral in some paths.","solutions":["Pass a float dtype: dtype=jnp.float32 / jnp.float64","Omit dtype entirely","Guard with jnp.issubdtype(dtype, jnp.inexact) check"],"exampleFix":"// before\njnp.corrcoef(x, dtype=jnp.int32)\n// after\njnp.corrcoef(x, dtype=jnp.float32)","handlingStrategy":"type-guard","validationCode":"if dtype is not None:\n    assert jnp.issubdtype(dtype, jnp.inexact), 'corrcoef dtype must be float/complex'\njnp.corrcoef(x, dtype=dtype)","typeGuard":"def is_inexact_dtype(d) -> bool:\n    return d is None or jnp.issubdtype(d, jnp.inexact)","tryCatchPattern":null,"preventionTips":["Use float dtypes only","Omit dtype when unsure","Guard config-driven dtype values"],"tags":["jax","corrcoef","dtype-validation"],"backgroundTag":"dtype-validation-failed","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}