Skip to content

Commit 63a6972

Browse files
authored
Merge pull request #460 from schmrlng/tuple_convert
Add general Tuple(::StaticArray) constructor and remove related convert method
2 parents 5087eca + 554d3d0 commit 63a6972

10 files changed

+14
-14
lines changed

src/convert.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@
99
@inline convert(::Type{SA}, sa::SA) where {SA<:StaticArray} = sa
1010
@inline convert(::Type{SA}, x::Tuple) where {SA<:StaticArray} = SA(x) # convert -> constructor. Hopefully no loops...
1111

12-
# A general way of going back to a tuple
13-
@inline function convert(::Type{Tuple}, a::StaticArray)
14-
unroll_tuple(a, Length(a))
15-
end
12+
# Constructing a Tuple from a StaticArray
13+
@inline Tuple(a::StaticArray) = unroll_tuple(a, Length(a))
1614

1715
@noinline function dimension_mismatch_fail(SA::Type, a::AbstractArray)
1816
error("Dimension mismatch. Expected input array of length $(length(SA)), got length $(length(a))")

test/FieldVector.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
@test length(p) === 3
1919
@test eltype(p) === Float64
2020

21+
@testinf Tuple(p) === (1.0, 2.0, 3.0)
22+
2123
@test (p + p) === Point3D(2.0, 4.0, 6.0)
2224

2325
@test (p[1], p[2], p[3]) === (p.x, p.y, p.z)
@@ -59,6 +61,8 @@
5961
@test length(p) === 2
6062
@test eltype(p) === Float64
6163

64+
@testinf Tuple(p) === (1.0, 2.0)
65+
6266
@test (p[1], p[2]) === (p.x, p.y)
6367
@test (p[1], p[2]) === (1.0, 2.0)
6468

test/MArray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
@test m[3] === 13
102102
@test m[4] === 14
103103

104-
@test Tuple(m) === (11, 12, 13, 14)
104+
@testinf Tuple(m) === (11, 12, 13, 14)
105105

106106
@test size(m) === (2, 2)
107107
@test size(typeof(m)) === (2, 2)

test/MMatrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
@test m[3] === 13
7777
@test m[4] === 14
7878

79-
@test Tuple(m) === (11, 12, 13, 14)
79+
@testinf Tuple(m) === (11, 12, 13, 14)
8080

8181
@test size(m) === (2, 2)
8282
@test size(typeof(m)) === (2, 2)

test/MVector.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
@test v[2] === 12
5757
@test v[3] === 13
5858

59-
@test Tuple(v) === (11, 12, 13)
59+
@testinf Tuple(v) === (11, 12, 13)
6060

6161
@test size(v) === (3,)
6262
@test size(typeof(v)) === (3,)

test/SArray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
@test m[3] === 13
9797
@test m[4] === 14
9898

99-
@test Tuple(m) === (11, 12, 13, 14)
99+
@testinf Tuple(m) === (11, 12, 13, 14)
100100

101101
@test size(m) === (2, 2)
102102
@test size(typeof(m)) === (2, 2)

test/SMatrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
@test m[3] === 13
7575
@test m[4] === 14
7676

77-
@test Tuple(m) === (11, 12, 13, 14)
77+
@testinf Tuple(m) === (11, 12, 13, 14)
7878

7979
@test size(m) === (2, 2)
8080
@test size(typeof(m)) === (2, 2)

test/SVector.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
@test v[2] === 12
5656
@test v[3] === 13
5757

58-
@test Tuple(v) === (11, 12, 13)
58+
@testinf Tuple(v) === (11, 12, 13)
5959

6060
@test size(v) === (3,)
6161
@test size(typeof(v)) === (3,)

test/Scalar.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
@test (Scalar(1) + Scalar(1.0))::Scalar{Float64} Scalar(2.0)
55
@test_throws ErrorException Scalar(2)[2]
66
@test Scalar(2)[] == 2
7-
@test Tuple(Scalar(2)) == (2,)
8-
@test Tuple(convert(Scalar{Float64}, [2.0])) == (2.0,)
7+
@testinf Tuple(Scalar(2)) === (2,)
8+
@testinf Tuple(convert(Scalar{Float64}, [2.0])) === (2.0,)
99
a = Array{Float64, 0}(undef)
1010
a[] = 2
1111
@test Scalar(a)[] == 2

test/core.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@
149149
@test StaticArrays.check_length(2) == nothing
150150
@test StaticArrays.check_length(StaticArrays.Dynamic()) == nothing
151151

152-
@test convert(Tuple, @SVector [2]) == (2,)
153-
154152
@testset "dimmatch" begin
155153
@test StaticArrays.dimmatch(3, 3)
156154
@test StaticArrays.dimmatch(3, StaticArrays.Dynamic())

0 commit comments

Comments
 (0)