Skip to content

Fix return type for setindex!(::SizedArray, ...) #1007

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

Merged
merged 1 commit into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/SizedArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ end
end

@propagate_inbounds getindex(a::SizedArray, i::Int) = getindex(a.data, i)
@propagate_inbounds setindex!(a::SizedArray, v, i::Int) = setindex!(a.data, v, i)
@propagate_inbounds setindex!(a::SizedArray, v, i::Int) = (setindex!(a.data, v, i); a)

Base.parent(sa::SizedArray) = sa.data

Expand Down
2 changes: 2 additions & 0 deletions test/MMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
m[3] = 13
m[4] = 14
@test m.data === (11, 12, 13, 14)
@test setindex!(m, 13, 3) === m
@test setindex!(m, 12, 2, 1) === m

m = @MMatrix [0 0; 0 0]
m[1] = Int8(11)
Expand Down
1 change: 1 addition & 0 deletions test/MVector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
v[2] = 12
v[3] = 13
@test v.data === (11, 12, 13)
@test setindex!(v, 13, 3) === v

v = @MVector [1.,2.,3.]
v[1] = Float16(11)
Expand Down
18 changes: 15 additions & 3 deletions test/SizedArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,23 @@
end

# setindex
sa = SizedArray{Tuple{2}, Int, 1}([3, 4])
sa[1] = 2
@test sa.data == [2, 4]
@testset "setindex" begin
sa = SizedArray{Tuple{2}, Int, 1}([3, 4])
sa[1] = 2
@test sa.data == [2, 4]
@test setindex!(sa, 2, 1) === sa

sm = SizedArray{Tuple{4,3}}(rand(4, 3))
sm[1] = 2
@test sa.data[1] == 2
sm[2, 3] = 4
@test sm.data[2, 3] == 4
@test setindex!(sm, 0.5, 1) === sm
@test setindex!(sm, 0.5, 2, 3) === sm
end

# parent
sa = SizedArray{Tuple{2}, Int, 1}([3, 4])
@test parent(sa) === sa.data

# pointer
Expand Down