{"record":{"id":"49316b5149d9797c","repo":"tracel-ai/burn","slug":"the-input-tensor-to-linalg-det-should-have-float","errorCode":null,"errorMessage":"The input tensor to linalg::det should have float dtype.","messagePattern":"The input tensor to linalg::det should have float dtype\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-tensor/src/tensor/linalg/det.rs","lineNumber":163,"sourceCode":"    let batched_range_tensor = range.expand(expand_dims);\n    let n_row_swaps = squeezed_pivots\n        .not_equal(batched_range_tensor)\n        .int()\n        .sum_dim(D1 - 1);\n    let odd_mask = n_row_swaps.clone().remainder_scalar(2).equal_scalar(1);\n    let p_det = n_row_swaps\n        .cast(working_float_dtype)\n        .ones_like()\n        .mask_fill(odd_mask, -1.0)\n        .squeeze_dim(D1 - 1);\n\n    // Compute the determinant of U\n    let u_diag = linalg::diag::<D, D1, _>(lu);\n    let mut u_det = u_diag.clone().prod_dim(D1 - 1).squeeze_dim(D1 - 1);\n    let eps = tensor\n        .dtype()\n        .finfo()\n        .expect(\"The input tensor to linalg::det should have float dtype.\")\n        .epsilon;\n    let n = dims[D - 1]; // The input tensor contains n by n matrices\n    let threshold = u_diag.clone().abs().max_dim(D1 - 1) * (n as f64).sqrt() * eps;\n    let near_zero = u_diag.abs().lower_equal(threshold);\n    let singular_mask = near_zero.any_dim(D1 - 1).squeeze_dim::<D2>(D1 - 1);\n    u_det = u_det.mask_fill(singular_mask, 0.0);\n\n    let final_det = p_det * u_det;\n\n    // Cast back to original dtypes\n    if needs_upcast {\n        final_det.cast(original_dtype)\n    } else {\n        final_det\n    }\n}\n","sourceCodeStart":145,"sourceCodeEnd":180,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-tensor/src/tensor/linalg/det.rs#L145-L180","documentation":"linalg::det computes the determinant via LU decomposition and queries the dtype's floating-point info (machine epsilon) to build a singularity threshold. If the tensor's dtype is not a float (int, bool, etc.), finfo() returns None and the expect panics.","triggerScenarios":"Calling `tensor.det()` on a tensor with an integer or bool dtype; creating a tensor with `Tensor::<D, Int>` or casting to int before computing the determinant.","commonSituations":"Passing integer adjacency/count matrices directly to det; forgetting `.float()` after loading integer image masks; switching backends/dtypes and silently ending up with an int tensor.","solutions":["Cast the tensor to a float dtype before calling det: `tensor.float()`","Create the input as a float tensor (`Tensor::<..., Float>` or with f32/f64 dtype)","Validate `tensor.dtype()` is a float kind in calling code before invoking det","Use f64 dtype for numerical stability of the LU-based determinant"],"exampleFix":"// before\nlet d = int_tensor.det();\n// after\nlet d = int_tensor.float().det();","handlingStrategy":"type-guard","validationCode":"if !matches!(tensor.dtype(), DType::F32 | DType::F64 | DType::BF16 | DType::F16) {\n    tensor = tensor.float();\n}\nlet d = tensor.det();","typeGuard":"fn is_float_dtype(dt: DType) -> bool {\n    matches!(dt, DType::F32 | DType::F64 | DType::BF16 | DType::F16)\n}","tryCatchPattern":null,"preventionTips":["Cast to .float() before linalg operations","Type tensors as Float at construction when they feed numeric linear algebra","Validate dtypes at API boundaries when loading external data"],"tags":["dtype","linalg","validation","burn-tensor"],"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"}