{"record":{"id":"347f52c979dce411","repo":"jax-ml/jax","slug":"can-only-convert-from-an-extended-dtype-on-an-arra","errorCode":null,"errorMessage":"can only convert from an extended dtype on an array type,but got {type(x)}","messagePattern":"can only convert from an extended dtype on an array type,but got (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/lax/lax.py","lineNumber":5559,"sourceCode":"    assert False  # unreachable, see isinstance check above\n\nto_edtype_p = Primitive('to_edtype')\nto_edtype_p.def_impl(partial(dispatch.apply_primitive, to_edtype_p))\nto_edtype_p.def_abstract_eval(_to_edtype_abstract_eval)\nad.defjvp(to_edtype_p,\n          lambda t, x, edtype:\n          convert_element_type(t, core.primal_dtype_to_tangent_dtype(edtype)))\nad.primitive_transposes[to_edtype_p] = \\\n    lambda ct, x, edtype: [from_edtype_p.bind(ct, dtype=x.aval.dtype)]\nbatching.defvectorized(to_edtype_p)\nmlir.register_lowering(to_edtype_p, lambda _, x, **__: [x])\n\n\ndef _from_edtype_abstract_eval(x, *, dtype):\n  assert (isinstance(x.dtype, dtypes.ExtendedDType) and\n          not isinstance(dtype, dtypes.ExtendedDType))\n  if not isinstance(x, ShapedArray):\n    raise TypeError(\"can only convert from an extended dtype on an array type,\"\n                    f\"but got {type(x)}\")\n  if convert_from := getattr(x.dtype._rules, 'convert_from', None):\n    allow_conversion = convert_from(x.dtype, dtype)\n  else:\n    allow_conversion = x.dtype._rules.allow_conversion\n  if not allow_conversion:\n    raise ValueError(\n        f\"Cannot convert_element_type from {dtype_to_string(x.dtype)} \"\n        f\"to {dtype_to_string(dtype)}\")\n  rep_aval = core.physical_element_aval(x.dtype)\n  assert tuple(rep_aval.sharding.spec) == (None,) * rep_aval.ndim\n  if rep_aval.dtype != dtype:\n    raise ValueError(\n        \"can only convert from extended dtype to its representation dtype, \"\n        f\"but tried to convert from {dtype_to_string(x.dtype)} to \"\n        f\"{dtype_to_string(dtype)} which doesn't match the representation type \"\n        f\"{dtype_to_string(rep_aval.dtype)}.\")\n  if isinstance(x, ShapedArray):","sourceCodeStart":5541,"sourceCodeEnd":5577,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/lax/lax.py#L5541-L5577","documentation":"Mirror of error 903 for the reverse direction: converting FROM an extended dtype requires the input aval to be a ShapedArray. Other aval types (dynamic-shape arrays, tokens, etc.) cannot carry the shape/dtype update needed for the conversion, so TypeError is raised.","triggerScenarios":"convert_element_type(x_with_edtype, standard_dtype) where x's aval is not ShapedArray, typically under shape polymorphism/export with symbolic dims.","commonSituations":"jax.experimental.export pipelines with extended dtypes; custom primitives with non-standard avals; tracing internals producing abstract avals without concrete shapes.","solutions":["Use static shapes for the operand when converting out of an extended dtype","Check isinstance(aval, ShapedArray) before issuing the conversion in meta-code","Update JAX in case newer releases support DShapedArray here","Convert via the physical representation using bitcast/reshape instead"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"from jax.core import ShapedArray\nassert isinstance(aval, ShapedArray)","typeGuard":"def is_shaped_aval(aval) -> bool:\n    from jax.core import ShapedArray\n    return isinstance(aval, ShapedArray)","tryCatchPattern":"try:\n    y = lax.convert_element_type(x_ed, dt)\nexcept TypeError:\n    raise RuntimeError('conversion from extended dtype needs static shapes') from None","preventionTips":["Use static shapes when converting out of extended dtypes","Avoid extended dtypes inside symbolic-shape export paths","Smoke-test conversions in tracing contexts during upgrades"],"tags":["jax","extended-dtype","abstract-eval","typeerror"],"backgroundTag":"unsupported-aval-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}