Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Views of SArray may use getindex to avoid the SubArray wrapper #908

Merged
merged 7 commits into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
views of SArray use indexing
  • Loading branch information
jishnub committed May 12, 2021
commit a62318ed5f094054103ee8d69151c82c6d7aff5f
3 changes: 3 additions & 0 deletions src/SArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,6 @@ end
function promote_rule(::Type{<:SArray{S,T,N,L}}, ::Type{<:SArray{S,U,N,L}}) where {S,T,U,N,L}
SArray{S,promote_type(T,U),N,L}
end

# SArrays may avoid the SubArray wrapper and consequently an additional level of indirection
Base.view(S::SArray, I...) = getindex(S, I...)
3 changes: 3 additions & 0 deletions test/SArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
@test_throws Exception m[1] = 1

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

@test (@view m[:, :]) == m
@test all(map(isequal, (@view m[1, 1]), m[1, 1]))
end

@testset "promotion" begin
Expand Down