Skip to content

Commit

Permalink
Update _maybe_dimnum to error if specified Integer dims are too large
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanjohnharris authored Nov 19, 2024
1 parent f868ddf commit 911acda
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/array/methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 911acda

Please sign in to comment.