{"record":{"id":"ae1bcd1e23a7c6cf","repo":"tracel-ai/burn","slug":"data-type-mismatch","errorCode":null,"errorMessage":"Data type mismatch","messagePattern":"Data type mismatch","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/ops/module.rs","lineNumber":49,"sourceCode":"    // Converts NdArrayStorage to SharedArray for compatibility with existing operations.\n    (inp($($x:tt),+), opt($($opt:tt),*), $element:ident, $op:expr) => {{\n        #[allow(unused_parens, unreachable_patterns)]\n        match ($($x),+) {\n            ($(NdArrayTensor::F32($x)),+) => {\n                type $element = f32;\n                $op(\n                    $($x.into_shared()),+\n                    $(, $opt.map(|o| match o { NdArrayTensor::F32(val) => val.into_shared(), _ => panic!(\"Optional argument type mismatch\") }))*\n                )\n            }\n            ($(NdArrayTensor::F64($x)),+) => {\n                type $element = f64;\n                $op(\n                    $($x.into_shared()),+\n                    $(, $opt.map(|o| match o { NdArrayTensor::F64(val) => val.into_shared(), _ => panic!(\"Optional argument type mismatch\") }))*\n                )\n            }\n            _ => panic!(\"Data type mismatch\"),\n        }\n    }};\n}\n\nimpl ModuleOps<Self> for NdArray {\n    fn conv2d(\n        x: NdArrayTensor,\n        weight: NdArrayTensor,\n        bias: Option<NdArrayTensor>,\n        options: ConvOptions<2>,\n    ) -> NdArrayTensor {\n        let (x, options) = pad_asymmetric_conv_input::<NdArray, 2>(x, options);\n        module_op!(inp(x, weight), opt(bias), E, |x, weight, bias| {\n            #[cfg(feature = \"simd\")]\n            let (x, weight, bias) = match try_conv2d_simd(x, weight, bias, options.clone()) {\n                Ok(out) => return out.into(),\n                Err(args) => args,\n            };","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/ops/module.rs#L31-L67","documentation":"The module_op! macro matches the tensor dtype variants F32 then F64; if the underlying NdArrayTensor is neither (i.e. an int/bool tensor was passed to a float module op), the wildcard arm panics with 'Data type mismatch'. Module ops like conv2d/interpolate are float-only.","triggerScenarios":"Passing an integer or bool tensor to a module op such as conv2d, pool2d, or interpolate; a generic function that lost its float element-type bound and received an int tensor.","commonSituations":"Using int tensors from argmax/argwhere output directly in conv/pool ops; forgetting to convert embeddings/indices back to float; generic code without the Float element-type bound.","solutions":["Ensure the input is a float tensor: cast with tensor.cast::<f32>() (or the backend's float element type) before the module op.","Check the element type parameter of your Tensor<Backend, D> — module ops require E: Float.","Convert int outputs (argmax, etc.) to float before feeding back into conv/pool layers.","Add explicit float type annotations on tensors passed to module ops."],"exampleFix":"// before\nlet x = logits.argmax(1); // int tensor\nlet y = conv2d(x, weight, None, options); // panic: Data type mismatch\n// after\nlet xf = x.cast::<f32>();\nlet y = conv2d(xf, weight, None, options);","handlingStrategy":"validation","validationCode":"fn ensure_float_input<E: burn::tensor::Float>(t: &Tensor<NdArray<E>, D>) { /* compile-time: E: Float bound excludes ints */ }","typeGuard":"// enforce at type level: only accept tensors with a Float element type\nfn conv_input<E: burn::tensor::element::Float>(x: Tensor<NdArray<E>, 3>) -> Tensor<NdArray<E>, 3> { x }","tryCatchPattern":null,"preventionTips":["Cast int op outputs (argmax, comparisons) to float before feeding module ops.","Keep generic bounds as E: Float so int tensors fail at compile time.","Never pass index tensors into conv/pool/interpolate ops."],"tags":["rust","burn-ndarray","dtype","macro"],"backgroundTag":"dtype-mismatch","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"}