From 911acdaa1e841b708080e64c1639a1f6c075bdcd Mon Sep 17 00:00:00 2001 From: Brendan Harris Date: Tue, 19 Nov 2024 14:03:08 +1100 Subject: [PATCH] Update _maybe_dimnum to error if specified Integer dims are too large --- src/array/methods.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/array/methods.jl b/src/array/methods.jl index 1bcf72889..12b5ab1fc 100644 --- a/src/array/methods.jl +++ b/src/array/methods.jl @@ -535,6 +535,13 @@ function check_stack_dims(iter) end _maybe_dimnum(x, dim) = hasdim(x, dim) ? dimnum(x, dim) : ndims(x) + 1 +function _maybe_dimnum(x, dim::Integer) + if dim < ndims(x) + 2 + return dim + else + throw(ArgumentError(LazyString("cannot stack slices ndims(x) = ", ndims(x) + 1, " along dims = ", dim))) + end +end _maybe_dimnum(_, ::Colon) = Colon() _maybe_dimnum(x, dims::Tuple) = _maybe_dimnum.([x], dims)