{"record":{"id":"96c06d32dfe785a3","repo":"tracel-ai/burn","slug":"float-mask-fill-unsupported-dtype","errorCode":null,"errorMessage":"float_mask_fill: unsupported dtype {:?}","messagePattern":"float_mask_fill: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/float.rs","lineNumber":501,"sourceCode":"    fn float_mask_fill(\n        tensor: FloatTensor<Flex>,\n        mask: BoolTensor<Flex>,\n        value: Scalar,\n    ) -> FloatTensor<Flex> {\n        match tensor.dtype() {\n            DType::F32 => crate::ops::mask::mask_fill_f32(tensor, mask, value.to_f32().unwrap()),\n            DType::F64 => crate::ops::mask::mask_fill_f64(tensor, mask, value.to_f64().unwrap()),\n            DType::F16 => crate::ops::mask::mask_fill_f16(\n                tensor,\n                mask,\n                f16::from_f64(value.to_f64().unwrap()),\n            ),\n            DType::BF16 => crate::ops::mask::mask_fill_bf16(\n                tensor,\n                mask,\n                bf16::from_f64(value.to_f64().unwrap()),\n            ),\n            dtype => panic!(\"float_mask_fill: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    fn float_equal(\n        lhs: FloatTensor<Flex>,\n        rhs: FloatTensor<Flex>,\n        out_dtype: burn_std::BoolDType,\n    ) -> BoolTensor<Flex> {\n        crate::ops::comparison::equal(lhs, rhs, out_dtype)\n    }\n\n    fn float_equal_elem(\n        lhs: FloatTensor<Flex>,\n        rhs: Scalar,\n        out_dtype: burn_std::BoolDType,\n    ) -> BoolTensor<Flex> {\n        crate::ops::comparison::equal_elem(lhs, rhs.to_f64().unwrap(), out_dtype)\n    }","sourceCodeStart":483,"sourceCodeEnd":519,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/float.rs#L483-L519","documentation":"float_mask_fill fills masked positions with a scalar and is only implemented for F32/F64/F16/BF16; the scalar is converted via bf16::from_f64 style helpers per dtype. Any other tensor dtype reaching the op panics with the dtype. Like its siblings, this is an intentional exhaustive-match guard in the flex backend.","triggerScenarios":"Calling Tensor::mask_fill (boolean mask + scalar value) on a burn-flex tensor whose dtype is not one of the four float dtypes.","commonSituations":"Filling invalid entries in an integer tensor (e.g. -1 padding) with mask_fill; dtype drifted to Int after an argmax/indexing step; porting code from torch where masked_fill works on any dtype.","solutions":["Cast the tensor to a float dtype before mask_fill, e.g. tensor.to_dtype(FloatDType::F32).","For integer padding use int-friendly alternatives (e.g. mask_where on ints only if supported, or arithmetic with mask casts).","Double-check that an upstream cast/indexing op did not silently change the tensor to Int.","Add the missing dtype arm to float_mask_fill in crates/burn-flex/src/ops/float.rs if you control the backend build."],"exampleFix":"// before\nlet out = t_int.mask_fill(mask, 0.0); // panics: unsupported dtype I64\n// after\nlet out = t_int\n    .to_dtype(burn::tensor::FloatDType::F32)\n    .mask_fill(mask, 0.0);","handlingStrategy":"validation","validationCode":"assert!(matches!(tensor.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), \"mask_fill needs a float tensor, got {:?}\", tensor.dtype());","typeGuard":"fn is_float_dtype(dtype: &DType) -> bool { matches!(dtype, DType::F32 | DType::F64 | DType::F16 | DType::BF16) }","tryCatchPattern":"// Validate dtype before the call; panics are not catchable:\nif is_float_dtype(&tensor.dtype()) { let out = tensor.mask_fill(mask, value); }","preventionTips":["For integer masking needs, plan int-safe alternatives (arithmetic with mask casts).","Insert explicit to_dtype calls where float semantics are required.","Check tensor dtype after pipeline stages that transform tensors.","Keep burn-flex dtype support matrix handy when porting torch code."],"tags":["rust","dtype","panic","burn","mask"],"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"}