{"record":{"id":"44974ba9ca51c664","repo":"tracel-ai/burn","slug":"float-mask-where-unsupported-dtype","errorCode":null,"errorMessage":"float_mask_where: unsupported dtype {:?}","messagePattern":"float_mask_where: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/float.rs","lineNumber":479,"sourceCode":"    fn float_slice_assign(\n        tensor: FloatTensor<Flex>,\n        slices: &[Slice],\n        value: FloatTensor<Flex>,\n    ) -> FloatTensor<Flex> {\n        crate::ops::slice::slice_assign(tensor, slices, value)\n    }\n\n    fn float_mask_where(\n        tensor: FloatTensor<Flex>,\n        mask: BoolTensor<Flex>,\n        value: FloatTensor<Flex>,\n    ) -> FloatTensor<Flex> {\n        match tensor.dtype() {\n            DType::F32 => crate::ops::mask::mask_where_f32(tensor, mask, value),\n            DType::F64 => crate::ops::mask::mask_where_f64(tensor, mask, value),\n            DType::F16 => crate::ops::mask::mask_where_f16(tensor, mask, value),\n            DType::BF16 => crate::ops::mask::mask_where_bf16(tensor, mask, value),\n            dtype => panic!(\"float_mask_where: unsupported dtype {:?}\", dtype),\n        }\n    }\n\n    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,","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/float.rs#L461-L497","documentation":"float_mask_where selects elements from a value tensor based on a boolean mask, and only implements F32/F64/F16/BF16. A tensor with any other dtype (Int, Bool, etc.) that reaches this float op triggers a panic naming the dtype. The backend guards its typed mask kernels with an exhaustive match.","triggerScenarios":"Calling Tensor::mask_where (or where-style conditional select) on burn-flex with a tensor whose dtype is not one of the four float dtypes.","commonSituations":"Applying mask_where to an integer tensor (e.g. replacing out-of-range indices) when the backend only floats it; mixing dtype tensors so inference picked Int; migrating code from another backend that supported int mask_where.","solutions":["Cast the value tensor to a float dtype before mask_where: tensor.to_dtype(FloatDType::F32).","Confirm the mask argument is a Bool tensor and the value tensor is Float; cast each accordingly.","Restructure logic so integer replacement uses int-compatible ops instead of float_mask_where.","Extend float_mask_where with the required dtype arm if int support is genuinely needed."],"exampleFix":"// before\nlet out = values_i64.mask_where(mask, other_i64); // panics on burn-flex\n// after\nlet out = values_i64\n    .to_dtype(burn::tensor::FloatDType::F32)\n    .mask_where(mask, other_i64.to_dtype(burn::tensor::FloatDType::F32));","handlingStrategy":"validation","validationCode":"assert!(matches!(tensor.dtype(), DType::F32 | DType::F64 | DType::F16 | DType::BF16), \"mask_where 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":"// Guard before calling; panics abort the thread:\nif is_float_dtype(&values.dtype()) { out = values.mask_where(mask, other); }","preventionTips":["Ensure mask tensors are Bool and value tensors are Float before mask ops.","Cast right after argmax/topk/comparison ops that produce Int tensors.","Prefer strongly-typed Tensor generics over AnyKind where possible.","Document required dtypes in helper function docs."],"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"}