{"record":{"id":"b24166befbb77488","repo":"tracel-ai/burn","slug":"svd-requires-a-float-tensor","errorCode":null,"errorMessage":"svd requires a float tensor","messagePattern":"svd requires a float tensor","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tensor/src/bridge/ops/float.rs","lineNumber":40,"sourceCode":"/// Singular value decomposition of a float tensor, dispatched to the active\n/// backend (`FloatTensorOps::float_svd`). Returns the three factors as\n/// tensors on the same device as the input.\npub(crate) fn svd(\n    tensor: BridgeTensor,\n    sweeps: usize,\n    swap: bool,\n) -> (BridgeTensor, BridgeTensor, BridgeTensor) {\n    let (kind, tensor) = tensor.into_parts();\n    match kind {\n        BridgeKind::Float => {\n            let (u, s, vt) = Dispatch::float_svd(tensor, sweeps, swap);\n            (\n                BridgeTensor::float(u),\n                BridgeTensor::float(s),\n                BridgeTensor::float(vt),\n            )\n        }\n        _ => panic!(\"svd requires a float tensor\"),\n    }\n}\n\nmacro_rules! q_bin_ops {\n    ($lhs:ident, $rhs:ident, $op:ident, $q_op:ident) => {{\n        let (lkind, lhs) = $lhs.into_parts();\n        let (rkind, rhs) = $rhs.into_parts();\n        match (lkind, rkind) {\n            (BridgeKind::Float, BridgeKind::Float) => BridgeTensor::float(Dispatch::$op(lhs, rhs)),\n            (BridgeKind::QFloat, BridgeKind::QFloat) => from_q_primitive(Dispatch::$q_op(lhs, rhs)),\n            (BridgeKind::QFloat, BridgeKind::Float) => {\n                let dtype = rhs.dtype();\n                BridgeTensor::float(Dispatch::$op(Dispatch::dequantize(lhs, dtype.into()), rhs))\n            }\n            (BridgeKind::Float, BridgeKind::QFloat) => {\n                let dtype = lhs.dtype();\n                BridgeTensor::float(Dispatch::$op(lhs, Dispatch::dequantize(rhs, dtype.into())))\n            }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tensor/src/bridge/ops/float.rs#L22-L58","documentation":"The float bridge's svd only computes singular value decomposition for float dtypes; any other tensor kind reaching the svd entry point panics with 'svd requires a float tensor'. It is a dtype precondition check inside the bridge's match over element kinds.","triggerScenarios":"Calling tensor.svd() on a tensor whose dtype/kind is not a floating-point type (e.g. Int or quantized) — such as running SVD on integer matrices without converting to float first.","commonSituations":"Loading integer data (e.g. image arrays, index tables) and computing SVD directly; dtype changes from quantization or checkpoint loading leaving matrices in Int form; generic code losing the Float type parameter.","solutions":["Convert the tensor to a float dtype before calling svd: tensor.float() / .to_dtype(FLOAT32)","Fix upstream code so the matrix stays Float (f32/f64) — e.g. convert loaded data with TensorData::convert::<f32>()","Verify the tensor type parameter is Tensor<B, D, Float>, not Int or QFloat, at the SVD call site"],"exampleFix":"// before\nlet (u, s, vt) = int_matrix.svd();\n// after\nlet (u, s, vt) = int_matrix.float().svd();","handlingStrategy":"validation","validationCode":"fn svd_checked<B: Backend, const D: usize>(m: Tensor<B, D, Float>) -> (Tensor<B, D, Float>, Tensor<B, D, Float>, Tensor<B, D, Float>) {\n    m.svd() // only call on Float-typed tensors; convert ints first with .float()\n}","typeGuard":"fn ensure_float<B: Backend, const D: usize>(t: Tensor<B, D, Int>) -> Tensor<B, D, Float> { t.float() }","tryCatchPattern":"std::panic::catch_unwind(|| matrix.svd())\n    .map_err(|_| \"svd requires a float tensor; call .float() first\")?;","preventionTips":["Only invoke svd on Tensor<B, D, Float> values","Convert integer-loaded matrices to float at ingestion time","Add dtype assertions before linear-algebra calls (svd, qr, eig) in shared numerics code"],"tags":["rust","burn","svd","dtype-mismatch","linear-algebra"],"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"}