{"record":{"id":"d92b0e0f6cbc54c1","repo":"tracel-ai/burn","slug":"expected-kind-kind-got-dtype-dtype","errorCode":null,"errorMessage":"Expected kind {kind:?}, got dtype {dtype:?}","messagePattern":"Expected kind (.+?), got dtype (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tensor/src/tensor/api/extension.rs","lineNumber":46,"sourceCode":"    ///\n    /// This is the inverse of [`Tensor::into_bridge`] and is primarily intended\n    /// for backend extensions, to wrap the output of a custom operation back into\n    /// the high-level tensor API.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the [`BridgeTensor`] variant does not match the tensor kind `K`\n    /// (e.g. passing an int [`BridgeTensor`] when `K` is [`Float`](crate::Float).\n    pub fn from_bridge(tensor: BridgeTensor) -> Self {\n        let dtype = tensor.dtype();\n        match (tensor.kind(), K::KIND) {\n            (BridgeKind::Bool, Kind::Bool) if dtype.is_bool() => Self::new(tensor),\n            (BridgeKind::Int, Kind::Int) if dtype.is_int() || dtype.is_uint() => Self::new(tensor),\n            (BridgeKind::Float, Kind::Float) if dtype.is_float() => Self::new(tensor),\n            (BridgeKind::QFloat, Kind::Float) if matches!(dtype, DType::QFloat(_)) => {\n                Self::new(tensor)\n            }\n            (_, kind) => panic!(\"Expected kind {kind:?}, got dtype {dtype:?}\"),\n        }\n    }\n\n    /// Converts from a dispatch tensor into a tensor.\n    ///\n    /// # Panics\n    /// Panis if the dispatch dtype does not match the tensor kind `K`.\n    pub fn from_dispatch(tensor: DispatchTensor) -> Self {\n        match (tensor.dtype(), K::KIND) {\n            (DType::QFloat(_), Kind::Float) => Self::new(BridgeTensor::qfloat(tensor)),\n            (dtype, Kind::Float) if dtype.is_float() => Self::new(BridgeTensor::float(tensor)),\n            (dtype, Kind::Int) if dtype.is_int() || dtype.is_uint() => {\n                Self::new(BridgeTensor::int(tensor))\n            }\n            (dtype, Kind::Bool) if dtype.is_bool() => Self::new(BridgeTensor::bool(tensor)),\n            (dtype, kind) => panic!(\"Expected kind {kind:?}, got dtype {dtype:?}\"),\n        }\n    }","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tensor/src/tensor/api/extension.rs#L28-L64","documentation":"Bridge-kind mismatch guard in `Tensor::from_bridge`: the BridgeTensor variant must match the target tensor kind K (and its dtype); e.g. wrapping an int BridgeTensor as `Tensor<B, D, Float>` hits the fallthrough and panics with the expected kind and the actual dtype. The failing input is the mis-typed BridgeTensor handed back by a custom backend op.","triggerScenarios":"Thrown at crates/burn-tensor/src/tensor/api/extension.rs:46 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Return the BridgeTensor with the kind/dtype matching the tensor type it will be wrapped into.","Change the annotated tensor kind (Float/Int/Bool) on the receiving side to match the bridge value.","Convert the bridge tensor's dtype before calling from_bridge."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}