Skip to content

Commit bb82cd5

Browse files
authored
Merge pull request #550 from BeastyBlacksmith/BeastyBlacksmith-no-tuple-copy
No tuple creation for SizedArrays
2 parents 786b6f0 + fc211ff commit bb82cd5

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

src/StaticArrays.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ const StaticArrayNoEltype{S, N, T} = StaticArray{S, T, N}
9898

9999
include("util.jl")
100100
include("traits.jl")
101-
include("convert.jl")
102101

103102
include("SUnitRange.jl")
104103
include("FieldVector.jl")
@@ -112,6 +111,8 @@ include("MMatrix.jl")
112111
include("SizedArray.jl")
113112
include("SDiagonal.jl")
114113

114+
include("convert.jl")
115+
115116
include("abstractarray.jl")
116117
include("indexing.jl")
117118
include("broadcast.jl")

src/abstractarray.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ reshape(a::Array, s::Size{S}) where {S} = s(a)
158158
@inline vec(a::StaticArray) = reshape(a, Size(prod(Size(typeof(a)))))
159159

160160
@inline copy(a::StaticArray) = typeof(a)(Tuple(a))
161+
@inline copy(a::SizedArray) = typeof(a)(copy(a.data))
161162

162163
@inline reverse(v::StaticVector) = typeof(v)(reverse(Tuple(v)))
163164

src/convert.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
@inline (::Type{SA})(x...) where {SA <: StaticArray} = SA(x)
55
@inline (::Type{SA})(a::StaticArray) where {SA<:StaticArray} = SA(Tuple(a))
6+
@inline (::Type{SA})(a::StaticArray) where {SA<:SizedArray} = SA(a.data)
67
@propagate_inbounds (::Type{SA})(a::AbstractArray) where {SA <: StaticArray} = convert(SA, a)
78

89
# this covers most conversions and "statically-sized reshapes"

test/abstractarray.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,14 @@ using StaticArrays, Test, LinearAlgebra
106106
end
107107

108108
@testset "copy" begin
109-
@test @inferred(copy(SMatrix{2, 2}([1 2; 3 4]))) === @SMatrix [1 2; 3 4]
110-
@test @inferred(copy(MMatrix{2, 2}([1 2; 3 4])))::MMatrix == [1 2; 3 4]
109+
M = [1 2; 3 4]
110+
SM = SMatrix{2, 2}(M)
111+
MM = MMatrix{2, 2}(M)
112+
SizeM = Size(2,2)(M)
113+
@test @inferred(copy(SM)) === @SMatrix [1 2; 3 4]
114+
@test @inferred(copy(MM))::MMatrix == M
115+
@test copy(SM).data !== M
116+
@test copy(SizeM).data !== M
111117
end
112118

113119
@testset "reverse" begin

test/convert.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
using StaticArrays, Test
2+
3+
@testset "Copy constructors" begin
4+
M = [1 2; 3 4]
5+
SizeM = Size(2,2)(M)
6+
@test typeof(SizeM)(SizeM).data === M
7+
end # testset

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ include("SizedArray.jl")
2525
include("SDiagonal.jl")
2626

2727
include("custom_types.jl")
28+
include("convert.jl")
2829
include("core.jl")
2930
include("abstractarray.jl")
3031
include("indexing.jl")

0 commit comments

Comments
 (0)