{"record":{"id":"53d096e9197eb941","repo":"tracel-ai/burn","slug":"ndarray-supports-arrays-up-to-6-dimensions-receiv","errorCode":null,"errorMessage":"NdArray supports arrays up to 6 dimensions, received: {}","messagePattern":"NdArray supports arrays up to 6 dimensions, received: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-ndarray/src/tensor.rs","lineNumber":582,"sourceCode":"            },\n            false => $array.to_shape(dim).unwrap().as_standard_layout().into_shared(),\n        };\n        array.into_dyn()\n    }};\n    (\n        ty $ty:ty,\n        shape $shape:expr,\n        array $array:expr,\n        d $D:expr\n    ) => {{\n        match $D {\n            1 => reshape!(ty $ty, n 1, shape $shape, array $array),\n            2 => reshape!(ty $ty, n 2, shape $shape, array $array),\n            3 => reshape!(ty $ty, n 3, shape $shape, array $array),\n            4 => reshape!(ty $ty, n 4, shape $shape, array $array),\n            5 => reshape!(ty $ty, n 5, shape $shape, array $array),\n            6 => reshape!(ty $ty, n 6, shape $shape, array $array),\n            _ => core::panic!(\"NdArray supports arrays up to 6 dimensions, received: {}\", $D),\n        }\n    }};\n}\n\n/// Slice a tensor\n#[macro_export]\nmacro_rules! slice {\n    ($tensor:expr, $slices:expr) => {\n        slice!($tensor, $slices, F64, F32, I64, I32, I16, I8, U64, U32, U16, U8, Bool)\n    };\n    ($tensor:expr, $slices:expr, $($variant:ident),*) => {\n        match $tensor {\n            $(NdArrayTensor::$variant(s) => { NdArrayOps::slice(s.view(), $slices).into() })*\n        }\n    };\n}\n\nimpl NdArrayTensor {","sourceCodeStart":564,"sourceCodeEnd":600,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-ndarray/src/tensor.rs#L564-L600","documentation":"Dimension-limit guard in burn-ndarray's reshape macro: ndarray-backed tensors can hold at most 6 dimensions; the macro's match expands ranks 1–6 and panics for any D beyond that. It fires when a tensor op on the ndarray backend is asked to produce/reshape an array of 7+ dimensions — the failing input is the over-rank shape.","triggerScenarios":"Reshaping a tensor to (or operating on a tensor of) rank > 6, e.g. reshape to 7+ dimensions via tensor.reshape([...7+ dims...]) on burn-ndarray.","commonSituations":"Models stacking many axes (video batch x time x frames x channels x ...), nested loops of unsqueeze, or generic code building shapes dynamically that can exceed 6.","solutions":["Restructure the model to keep tensors at rank <= 6 (merge axes, e.g. fold batch*time into one dimension)","Merge adjacent dimensions before the op and re-expand afterwards","Switch to a backend without this rank limit (e.g. burn-torch) if high-rank ops are required"],"exampleFix":"// before\nlet x = x.reshape([2, 2, 2, 2, 2, 2, 2]); // 7-D -> panic\n// after\nlet x = x.reshape([2, 2, 2, 2, 2, 4]); // merged last two axes, rank 6","handlingStrategy":"validation","validationCode":"assert!(new_shape.len() <= 6, \"ndarray backend supports max rank 6\");","typeGuard":"fn rank_supported(shape: &[usize]) -> bool {\n    (1..=6).contains(&shape.len())\n}","tryCatchPattern":null,"preventionTips":["Design models to stay within rank 6 on ndarray","Merge time/sequence axes into the batch axis","Guard generic shape-building code with a rank check"],"tags":["rust","burn-ndarray","shape","rank-limit"],"backgroundTag":"unsupported-rank","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"}