From 01be772e2b9c69d5cc59ff492227060e1667bb2d Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Mon, 13 Oct 2025 16:20:06 -0400 Subject: [PATCH] Make view() propagate inbounds This matches Base behavior --- src/MArray.jl | 2 +- src/SizedArray.jl | 2 +- src/abstractarray.jl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MArray.jl b/src/MArray.jl index eeadb7ef..032fc31f 100644 --- a/src/MArray.jl +++ b/src/MArray.jl @@ -71,7 +71,7 @@ end return any(index -> index <: StaticVector{<:Any,Bool}, indices.parameters) end -function Base.view( +@propagate_inbounds function Base.view( a::MArray{S}, indices::Union{Integer, Colon, StaticVector, Base.Slice, SOneTo}..., ) where {S} diff --git a/src/SizedArray.jl b/src/SizedArray.jl index 12381a26..ed09d91e 100644 --- a/src/SizedArray.jl +++ b/src/SizedArray.jl @@ -155,7 +155,7 @@ end return Tuple{prod_size} end -function Base.view( +@propagate_inbounds function Base.view( a::SizedArray{S}, indices::Union{Integer, Colon, StaticVector, Base.Slice, SOneTo}..., ) where {S} diff --git a/src/abstractarray.jl b/src/abstractarray.jl index 85e9be1d..d54e5b3c 100644 --- a/src/abstractarray.jl +++ b/src/abstractarray.jl @@ -287,7 +287,7 @@ end # wrap elements in Scalar to be consistent with 0D views _maybewrapscalar(::Tuple{}, r::T) where {T} = Scalar{T}(r) _maybewrapscalar(_, r) = r -function Base.view(S::SArray, I::Union{Colon, Integer, SOneTo, StaticArray{<:Tuple, Int}, CartesianIndex}...) +@propagate_inbounds function Base.view(S::SArray, I::Union{Colon, Integer, SOneTo, StaticArray{<:Tuple, Int}, CartesianIndex}...) V = getindex(S, I...) _maybewrapscalar(Base.index_dimsum(I...), V) end