{"record":{"id":"0e8fa3b5204da992","repo":"tracel-ai/burn","slug":"cat-unsupported-dtype","errorCode":null,"errorMessage":"cat: unsupported dtype {:?}","messagePattern":"cat: unsupported dtype (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-flex/src/ops/cat.rs","lineNumber":30,"sourceCode":"    if tensors.len() == 1 {\n        return tensors.into_iter().next().unwrap();\n    }\n\n    let dtype = tensors[0].dtype();\n    match dtype {\n        DType::F32 => cat_impl::<f32>(tensors, dim),\n        DType::F64 => cat_impl::<f64>(tensors, dim),\n        DType::F16 => cat_impl::<f16>(tensors, dim),\n        DType::BF16 => cat_impl::<bf16>(tensors, dim),\n        DType::I64 => cat_impl::<i64>(tensors, dim),\n        DType::I32 => cat_impl::<i32>(tensors, dim),\n        DType::I16 => cat_impl::<i16>(tensors, dim),\n        DType::I8 => cat_impl::<i8>(tensors, dim),\n        DType::U64 => cat_impl::<u64>(tensors, dim),\n        DType::U32 => cat_impl::<u32>(tensors, dim),\n        DType::U16 => cat_impl::<u16>(tensors, dim),\n        DType::U8 | DType::Bool(_) => cat_impl::<u8>(tensors, dim),\n        _ => panic!(\"cat: unsupported dtype {:?}\", dtype),\n    }\n}\n\nfn cat_impl<E: Element + bytemuck::Pod>(tensors: Vec<FlexTensor>, dim: usize) -> FlexTensor {\n    let dtype = tensors[0].dtype();\n    let first_shape = tensors[0].layout().shape();\n    let ndims = first_shape.num_dims();\n\n    assert!(\n        dim < ndims,\n        \"cat: dim {} out of bounds for {} dimensions\",\n        dim,\n        ndims\n    );\n\n    // Compute output shape: sum along cat dim, others must match\n    let mut out_dims = first_shape.to_vec();\n    out_dims[dim] = 0;","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-flex/src/ops/cat.rs#L12-L48","documentation":"cat in burn-flex dispatches concat on the dtype of the input tensors, instantiating cat_impl for every numeric type plus a special arm mapping U8 and Bool onto u8 storage. Any other dtype combination reaches the catch-all and panics. All tensors in the list must share the dtype — the dtype is taken from tensors[0].","triggerScenarios":"Concatenating tensors whose dtype is not one of the listed numeric types, or where the first tensor's dtype is unsupported (dtype is read from tensors[0]). Mismatched dtypes across the list can also misroute into the wrong typed cat_impl.","commonSituations":"Concatenating bool masks with u8 buffers where an exotic dtype alias slipped in; mixed float/int lists relying on promotion; empty or mismatched tensor lists after filtering.","solutions":["Cast all tensors to a common supported dtype before cat: tensors.iter().map(|t| t.cast(DType::F32)).collect().","Ensure tensors[0] has a supported dtype since the dispatch keys off it.","Normalize bool tensors explicitly (bool_empty/bool_into_int helpers) rather than relying on the U8|Bool arm."],"exampleFix":"// before\nlet out = cat(vec![a, b_f32], 0); // a is i64, b f32\n// after\nlet out = cat(vec![a.cast(DType::F32), b_f32], 0);","handlingStrategy":"validation","validationCode":"let dtype = tensors[0].dtype();\nif !matches!(dtype, DType::F64 | DType::F32 | DType::F16 | DType::BF16 | DType::I64 | DType::I32 | DType::I16 | DType::I8 | DType::U64 | DType::U32 | DType::U16 | DType::U8 | DType::Bool(_)) {\n    tensors = tensors.into_iter().map(|t| t.cast(DType::F32)).collect();\n}\nlet out = cat(tensors, dim);","typeGuard":"fn all_same_supported_dtype(ts: &[FlexTensor]) -> bool {\n    let d = ts[0].dtype();\n    ts.iter().all(|t| t.dtype() == d)\n}","tryCatchPattern":"let out = std::panic::catch_unwind(|| cat(tensors.clone(), dim))\n    .unwrap_or_else(|_| cat(tensors.iter().map(|t| t.cast(DType::F32)).collect(), dim));","preventionTips":["Cast all tensors to a shared dtype before concatenating.","Remember tensors[0]'s dtype drives the dispatch.","Normalize Bool to U8 (or rely on the Bool(_) arm) consistently.","Validate the list is non-empty and dtype-homogeneous in helpers."],"tags":["panic","dtype","concat","unsupported-dtype"],"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"}