Skip to content

Commit 69e2699

Browse files
committed
wrap elements in Scalar
1 parent b7cf166 commit 69e2699

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/abstractarray.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,8 @@ if VERSION >= v"1.6.0-DEV.1334"
297297
end
298298

299299
# SArrays may avoid the SubArray wrapper and consequently an additional level of indirection
300-
Base.view(S::SArray, I...) = getindex(S, I...)
300+
# The output may use the broadcasting machinery defined for StaticArrays (see issue #892)
301+
# wrap elements in Scalar to be consistent with 0D views
302+
_maybewrapscalar(S::SArray{<:Any,T}, r::T) where {T} = Scalar{T}(r)
303+
_maybewrapscalar(S, r) = r
304+
Base.view(S::SArray, I...) = _maybewrapscalar(S, getindex(S, I...))

test/SArray.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,9 @@
140140

141141
@test Base.dataids(m) === ()
142142

143-
@test (@view m[:, :]) == m
144-
@test all(map(isequal, (@view m[1, 1]), m[1, 1]))
143+
@test (@view m[:, :]) === m
144+
@test (@view m[:, 1]) === @SArray [11, 12]
145+
@test (@view m[1, 1])[] === m[1, 1]
145146
end
146147

147148
@testset "promotion" begin

0 commit comments

Comments
 (0)