Skip to content

Commit 9065539

Browse files
committed
fix copyat_or_push! for StaticArrays
1 parent a70c164 commit 9065539

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/utils.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ end
5252

5353
@inline function copyat_or_push!{T,perform_copy}(a::AbstractVector{T},i::Int,x,nc::Type{Val{perform_copy}}=Val{true})
5454
@inbounds if length(a) >= i
55-
if T <: Number || !perform_copy
55+
if T <: Number || T <: StaticArray || !perform_copy
56+
# TODO: Check for `setindex!`` if T <: StaticArray and use `copy!(b[i],a[i])`
57+
# or `b[i] = a[i]`, see #19
5658
a[i] = x
5759
else
5860
recursivecopy!(a[i],x)

test/copy_static_array_test.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ a = [vec]
1616
b = zeros(a)
1717
recursivecopy!(b, a)
1818
@test a[1] == b[1]
19+
copyat_or_push!(a, 2, b[1])
20+
@test a[2] == b[1]
21+
b[1] = 2*b[1]
22+
copyat_or_push!(a, 2, b[1])
23+
@test a[2] == b[1]
1924

2025
# Mutable FieldVector
2126
vec = MutableFV(1.,2.)
@@ -25,13 +30,23 @@ recursivecopy!(b, a)
2530
@test a[1] == b[1]
2631
a[1][1] *= 5
2732
@test a[1] != b[1]
33+
copyat_or_push!(a, 2, b[1])
34+
@test a[2] == b[1]
35+
b[1] = 2*b[1]
36+
copyat_or_push!(a, 2, b[1])
37+
@test a[2] == b[1]
2838

2939
# SArray
3040
vec = @SArray [1., 2.]
3141
a = [vec]
3242
b = zeros(a)
3343
recursivecopy!(b, a)
3444
@test a[1] == b[1]
45+
copyat_or_push!(a, 2, b[1])
46+
@test a[2] == b[1]
47+
b[1] = 2*b[1]
48+
copyat_or_push!(a, 2, b[1])
49+
@test a[2] == b[1]
3550

3651
# MArray
3752
vec = @MArray [1., 2.]
@@ -40,3 +55,8 @@ b = zeros(a)
4055
recursivecopy!(b, a)
4156
a[1][1] *= 5
4257
@test a[1] != b[1]
58+
copyat_or_push!(a, 2, b[1])
59+
@test a[2] == b[1]
60+
b[1] = 2*b[1]
61+
copyat_or_push!(a, 2, b[1])
62+
@test a[2] == b[1]

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ tic()
77
@time @testset "Partitions Tests" begin include("partitions_test.jl") end
88
@time @testset "VecOfArr Indexing Tests" begin include("basic_indexing.jl") end
99
@time @testset "VecOfArr Interface Tests" begin include("interface_tests.jl") end
10-
@time @testset "StaticArrays (recursivecopy!) Tests" begin include("copy_static_array_test.jl") end
10+
@time @testset "StaticArrays Tests" begin include("copy_static_array_test.jl") end
1111
toc()
1212
# Test the VectorOfArray code

0 commit comments

Comments
 (0)