{"record":{"id":"c22869357a4797ef","repo":"tracel-ai/burn","slug":"float-cast-unsupported-target-dtype","errorCode":null,"errorMessage":"float_cast: unsupported target dtype {:?}","messagePattern":"float_cast: unsupported target dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/float.rs","lineNumber":875,"sourceCode":"                let result: Vec<f32> = f64_values.iter().map(|&v| v as f32).collect();\n                let bytes = Bytes::from_elems(result);\n                FlexTensor::new(bytes, Layout::contiguous(shape), DType::F32)\n            }\n            DType::F64 => {\n                let bytes = Bytes::from_elems(f64_values);\n                FlexTensor::new(bytes, Layout::contiguous(shape), DType::F64)\n            }\n            DType::F16 => {\n                let result: Vec<f16> = f64_values.iter().map(|&v| f16::from_f64(v)).collect();\n                let bytes = Bytes::from_elems(result);\n                FlexTensor::new(bytes, Layout::contiguous(shape), DType::F16)\n            }\n            DType::BF16 => {\n                let result: Vec<bf16> = f64_values.iter().map(|&v| bf16::from_f64(v)).collect();\n                let bytes = Bytes::from_elems(result);\n                FlexTensor::new(bytes, Layout::contiguous(shape), DType::BF16)\n            }\n            _ => panic!(\"float_cast: unsupported target dtype {:?}\", target_dtype),\n        }\n    }\n\n    fn float_exp(tensor: FloatTensor<Flex>) -> FloatTensor<Flex> {\n        unary::exp(tensor)\n    }\n\n    fn float_log(tensor: FloatTensor<Flex>) -> FloatTensor<Flex> {\n        unary::log(tensor)\n    }\n\n    fn float_log1p(tensor: FloatTensor<Flex>) -> FloatTensor<Flex> {\n        unary::log1p(tensor)\n    }\n\n    fn float_powf(lhs: FloatTensor<Flex>, rhs: FloatTensor<Flex>) -> FloatTensor<Flex> {\n        binary_op(lhs, rhs, |a: f32, b| a.powf(b), |a: f64, b| a.powf(b), None)\n    }","sourceCodeStart":857,"sourceCodeEnd":893,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/float.rs#L857-L893","documentation":"float_cast's target-side match materializes the f64 values into F32, F64, F16 or BF16 buffers; any other target dtype hits the panic arm. The target dtype requested is not a supported float dtype for this cast path on the flex backend.","triggerScenarios":"Calling tensor.to_dtype(float_cast) on burn-flex where the TARGET dtype is not F32/F64/F16/BF16, e.g. requesting Int or Bool output from the float cast entry point.","commonSituations":"Converting float tensors to integers for indexing (e.g. argmax results, quantization indices) through the wrong cast path; constructing a DType manually and passing an unexpected variant; API migrations where to_dtype targets changed.","solutions":["Cast to an integer via the integer cast path after the float cast, or use int_cast on the correct tensor kind.","Request a supported float target (F32/F64/F16/BF16) and convert to the final dtype in a second, kind-correct step.","Review the DType value being requested; construct targets from FloatDType variants, not raw DType.","Extend float_cast's target match in crates/burn-flex/src/ops/float.rs if new float targets are added upstream."],"exampleFix":"// before\nlet idx = probs.to_dtype(DType::I64); // unsupported target on float cast\n// after\nlet rounded = probs.to_dtype(burn::tensor::FloatDType::F32);\nlet idx = rounded.cast::<burn::tensor::i64>(); // kind-correct int cast","handlingStrategy":"type-guard","validationCode":"let target: FloatDType = FloatDType::F32; // only F32/F64/F16/BF16 are valid float targets\nassert!(matches!(target, FloatDType::F32 | FloatDType::F64 | FloatDType::F16 | FloatDType::BF16));","typeGuard":"fn is_supported_float_target(dtype: &DType) -> bool { matches!(dtype, DType::F32 | DType::F64 | DType::F16 | DType::BF16) }","tryCatchPattern":"// Validate the requested target before casting:\nif is_supported_float_target(&target_dtype) { let out = tensor.to_dtype(target_dtype); } else { /* route to int/bool cast */ }","preventionTips":["Construct cast targets from FloatDType variants, never raw DType values.","Cast Float->Int in two steps: float cast to F32/F64, then kind-correct int cast.","Search codebases for to_dtype calls with non-float targets when using burn-flex.","Keep a small wrapper around casts that enforces supported dtype pairs."],"tags":["rust","dtype","panic","burn","cast"],"backgroundTag":"unsupported-dtype","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"}