{"record":{"id":"09511a39382ca56a","repo":"jax-ml/jax","slug":"x-dtype-np-dtype-dtype-is-not-supported","errorCode":null,"errorMessage":"x.dtype={np.dtype(dtype)} is not supported.","messagePattern":"x\\.dtype=(.+?) is not supported\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/scipy/special.py","lineNumber":1682,"sourceCode":"  \"\"\"\n  if not isinstance(series_order, int):\n    raise TypeError(\"series_order must be a Python integer.\")\n  if series_order < 0:\n    raise ValueError(\"series_order must be non-negative.\")\n  if series_order > 30:\n    raise ValueError(\"series_order must be <= 30.\")\n\n  x_arr = jnp.asarray(x)\n  dtype = lax.dtype(x_arr)\n\n  if dtype == np.float64:\n    lower_segment: np.ndarray = _LOGNDTR_FLOAT64_LOWER\n    upper_segment: np.ndarray = _LOGNDTR_FLOAT64_UPPER\n  elif dtype == np.float32:\n    lower_segment = _LOGNDTR_FLOAT32_LOWER\n    upper_segment = _LOGNDTR_FLOAT32_UPPER\n  else:\n    raise TypeError(f\"x.dtype={np.dtype(dtype)} is not supported.\")\n\n  # The basic idea here was ported from:\n  #   https://root.cern.ch/doc/v608/SpecFuncCephesInv_8cxx_source.html\n  # We copy the main idea, with a few changes\n  # * For x >> 1, and X ~ Normal(0, 1),\n  #     Log[P[X < x]] = Log[1 - P[X < -x]] approx -P[X < -x],\n  #     which extends the range of validity of this function.\n  # * We use one fixed series_order for all of 'x', rather than adaptive.\n  # * Our docstring properly reflects that this is an asymptotic series, not a\n  #   Taylor series. We also provided a correct bound on the remainder.\n  # * We need to use the max/min in the _log_ndtr_lower arg to avoid nan when\n  #   x=0. This happens even though the branch is unchosen because when x=0\n  #   the gradient of a select involves the calculation 1*dy+0*(-inf)=nan\n  #   regardless of whether dy is finite. Note that the minimum is a NOP if\n  #   the branch is chosen.\n  x_arr_gt_upper_segment = lax.gt(x_arr, upper_segment)\n  ndtr_arg = jnp.where(x_arr_gt_upper_segment, -x_arr,\n                       lax.max(x_arr, lower_segment))","sourceCodeStart":1664,"sourceCodeEnd":1700,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/scipy/special.py#L1664-L1700","documentation":"log_ndtr only supports float32 and float64 inputs; the implementation selects precomputed lower/upper segment tables keyed on those dtypes. Any other dtype (int, complex, bfloat16, float16) raises TypeError with the offending dtype.","triggerScenarios":"Calling log_ndtr(jnp.array([0, 1])) (int), log_ndtr on bfloat16/float16 tensors, or complex x. Reached via logcdf and _log_gauss_mass in distribution code with non-float inputs.","commonSituations":"log-probability computations on integer-encoded data; mixed-precision (bf16) training calling logcdf of a normal; assuming complex support for log Φ of complex arguments.","solutions":["Cast: log_ndtr(jnp.asarray(x, jnp.float32))","Promote to inexact dtype upstream so statistics always see float32/64","In bf16 pipelines, upcast around log_ndtr and downcast after"],"exampleFix":"// before\njax.scipy.special.log_ndtr(x)  # x is bfloat16\n// after\njax.scipy.special.log_ndtr(x.astype(jnp.float32))","handlingStrategy":"validation","validationCode":"x = jnp.asarray(x, jnp.float32)  # or float64\nlog_ndtr(x, series_order)","typeGuard":"def is_f32_f64(x):\n    return jnp.dtype(x) in (np.float32, np.float64)","tryCatchPattern":null,"preventionTips":["Upcast before log-CDF / log-gauss-mass computations","Add dtype checks where logcdf wraps log_ndtr"],"tags":["jax","scipy-special","log-ndtr","dtype-validation"],"backgroundTag":"unsupported-input-dtype","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}