Skip to content

Commit a4b5e20

Browse files
Fix copy of wrapped SubArrays (#56)
Co-authored-by: Jack Coughlin <jack@johnbcoughlin.com>
1 parent bac4a78 commit a4b5e20

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "HybridArrays"
22
uuid = "1baab800-613f-4b0a-84e4-9cd3431bfbb9"
33
authors = ["Mateusz Baran <mateuszbaran89@gmail.com>"]
4-
version = "0.4.12"
4+
version = "0.4.13"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/abstractarray.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ function promote_rule(::Type{<:HybridArray{S,T,N,M,TDataA}}, ::Type{<:HybridArra
3636
HybridArray{S,TU,N,M,promote_type(TDataA, TDataB)::Type{<:AbstractArray{TU}}}
3737
end
3838

39-
@inline copy(a::HybridArray) = typeof(a)(copy(parent(a)))
39+
@inline copy(a::HybridArray{S, T, N, M}) where {S, T, N, M} = begin
40+
parentcopy = copy(parent(a))
41+
HybridArray{S, T, N, M, typeof(parentcopy)}(parentcopy)
42+
end
43+
4044

4145
homogenized_last(::StaticArrays.HeterogeneousBaseShape) = StaticArrays.Dynamic()
4246
homogenized_last(a::SOneTo) = last(a)

test/abstractarray.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ using StaticArrays: Dynamic
4747
M = HybridMatrix{2, Dynamic()}([1 2; 3 4])
4848
@test @inferred(copy(M))::HybridMatrix == M
4949
@test parent(copy(M)) !== parent(M)
50+
51+
@testset "subarrays" begin
52+
M = HybridMatrix{Dynamic(), 2}(rand(4, 2))
53+
ha = view(M, :, 1)
54+
@test copy(ha) == ha
55+
@test parent(copy(ha)) !== parent(ha)
56+
end
5057
end
5158

5259
@testset "similar" begin

0 commit comments

Comments
 (0)