{"record":{"id":"e923101f1b731503","repo":"tracel-ai/burn","slug":"scalar-not-supported-for-dtype","errorCode":null,"errorMessage":"Scalar not supported for {dtype:?}","messagePattern":"Scalar not supported for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ir/src/scalar.rs","lineNumber":39,"sourceCode":"            ScalarIr::UInt(x) => x.hash(state),\n            ScalarIr::Bool(x) => x.hash(state),\n        }\n    }\n}\n\nimpl ScalarIr {\n    /// Creates a scalar with the specified data type.\n    pub fn new<E: ElementConversion>(value: E, dtype: &DType) -> Self {\n        if dtype.is_float() {\n            Self::Float(value.elem())\n        } else if dtype.is_int() {\n            Self::Int(value.elem())\n        } else if dtype.is_uint() {\n            Self::UInt(value.elem())\n        } else if dtype.is_bool() {\n            Self::Bool(value.elem())\n        } else {\n            unimplemented!(\"Scalar not supported for {dtype:?}\")\n        }\n    }\n\n    /// Converts and returns the converted element.\n    pub fn elem<E: Element>(self) -> E {\n        match self {\n            ScalarIr::Float(x) => x.elem(),\n            ScalarIr::Int(x) => x.elem(),\n            ScalarIr::UInt(x) => x.elem(),\n            ScalarIr::Bool(x) => x.elem(),\n        }\n    }\n}\n\n// The enums are similar, but both types have different roles:\n// - `Scalar`: runtime literal value\n// - `ScalarIr`: serializable literal representation (used for IR)\nimpl From<Scalar> for ScalarIr {","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ir/src/scalar.rs#L21-L57","documentation":"`Scalar::new` in burn-ir converts an `Element` value into the variant matching the target dtype. It covers int, uint, and bool dtypes (float is handled in the earlier match arms); any dtype outside these — e.g. quantized or exotic dtypes — reaches the catch-all `unimplemented!(\"Scalar not supported for {dtype:?}\")`.","triggerScenarios":"Constructing `Scalar::new(dtype, value)` with a dtype that is not a supported float/int/uint/bool type, e.g. when serializing a scalar operation parameterized by an unsupported dtype.","commonSituations":"Custom/extended dtypes (quantized, flex-specific dtypes) flowing into the IR's scalar representation; plugins or new backends introducing dtypes the IR doesn't model yet.","solutions":["Only create Scalar values for dtypes supported by burn-ir (float/int/uint/bool)","Convert the value to a supported dtype before wrapping it in a Scalar","Extend the match in `Scalar::new` if your fork introduces a new dtype","Check the dtype of the operation parameter that produces the scalar"],"exampleFix":"// before\nlet scalar = Scalar::new(DType::QInt8, value);\n// after\nlet scalar = Scalar::new(DType::I32, value.to_i32());","handlingStrategy":"validation","validationCode":"fn supported_for_scalar(dtype: DType) -> bool {\n    dtype.is_float() || dtype.is_int() || dtype.is_uint() || dtype.is_bool()\n}\nif !supported_for_scalar(dtype) {\n    // convert or reject before Scalar::new\n}","typeGuard":"fn scalar_supported(dtype: DType) -> bool {\n    dtype.is_float() || dtype.is_int() || dtype.is_uint() || dtype.is_bool()\n}","tryCatchPattern":"// unimplemented! panics are not catchable; pre-check instead\nif !scalar_supported(dtype) {\n    return Err(format!(\"Scalar not supported for {dtype:?}\"));\n}\nlet s = Scalar::new(dtype, value);","preventionTips":["Restrict scalar operation parameters to IR-supported dtypes","Convert custom/quantized dtypes to supported ones before IR construction","When adding dtypes to a fork, update Scalar::new and its test matrix","Review dtype provenance of operation arguments entering the IR"],"tags":["rust","dtype","scalar","burn-ir"],"backgroundTag":"unsupported-dtype-conversion","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}