tracel-ai/burn · error
NdArray supports arrays up to 6 dimensions, received: {}
Error message
NdArray supports arrays up to 6 dimensions, received: {} What it means
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.
Source
Thrown at crates/burn-ndarray/src/tensor.rs:582
},
false => $array.to_shape(dim).unwrap().as_standard_layout().into_shared(),
};
array.into_dyn()
}};
(
ty $ty:ty,
shape $shape:expr,
array $array:expr,
d $D:expr
) => {{
match $D {
1 => reshape!(ty $ty, n 1, shape $shape, array $array),
2 => reshape!(ty $ty, n 2, shape $shape, array $array),
3 => reshape!(ty $ty, n 3, shape $shape, array $array),
4 => reshape!(ty $ty, n 4, shape $shape, array $array),
5 => reshape!(ty $ty, n 5, shape $shape, array $array),
6 => reshape!(ty $ty, n 6, shape $shape, array $array),
_ => core::panic!("NdArray supports arrays up to 6 dimensions, received: {}", $D),
}
}};
}
/// Slice a tensor
#[macro_export]
macro_rules! slice {
($tensor:expr, $slices:expr) => {
slice!($tensor, $slices, F64, F32, I64, I32, I16, I8, U64, U32, U16, U8, Bool)
};
($tensor:expr, $slices:expr, $($variant:ident),*) => {
match $tensor {
$(NdArrayTensor::$variant(s) => { NdArrayOps::slice(s.view(), $slices).into() })*
}
};
}
impl NdArrayTensor {View on GitHub (pinned to d16f7ba2ed)
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
Example fix
// before let x = x.reshape([2, 2, 2, 2, 2, 2, 2]); // 7-D -> panic // after let x = x.reshape([2, 2, 2, 2, 2, 4]); // merged last two axes, rank 6
Defensive patterns
Strategy: validation
Validate before calling
assert!(new_shape.len() <= 6, "ndarray backend supports max rank 6");
Type guard
fn rank_supported(shape: &[usize]) -> bool {
(1..=6).contains(&shape.len())
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Matrix multiplication requires an array with at least 2 dime
- Dimensions are incompatible for matrix multiplication: LHS c
- Shape should be compatible shape={dim:?}: {err:?}
- broadcast_shape: incompatible dimensions {} and {} at positi
- Dimensions differ and cannot be broadcasted.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/53d096e9197eb941.
Report an issue: GitHub.