Skip to content

Commit fb67ea4

Browse files
committed
Fix some constructors
1 parent 025a991 commit fb67ea4

File tree

5 files changed

+11
-2
lines changed

5 files changed

+11
-2
lines changed

src/MArray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ end
7171
end
7272
end
7373

74-
@inline MArray(a::StaticArray) = MArray{size_tuple(typeof(a))}(Tuple(a))
74+
@inline MArray(a::StaticArray) = MArray{size_tuple(Size(a))}(Tuple(a))
7575

7676
# Simplified show for the type
7777
show(io::IO, ::Type{MArray{S, T, N}}) where {S, T, N} = print(io, "MArray{$S,$T,$N}")

src/SArray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
end
5151
end
5252

53-
@inline SArray(a::StaticArray) = SArray{size_tuple(a)}(Tuple(a)) # TODO fixme
53+
@inline SArray(a::StaticArray) = SArray{size_tuple(Size(a))}(Tuple(a))
5454

5555
# Simplified show for the type
5656
show(io::IO, ::Type{SArray{S, T, N}}) where {S, T, N} = print(io, "SArray{$S,$T,$N}")

src/traits.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Length(::Type{SA}) where {SA <: StaticArray} = Length(Size(SA))
8686

8787
@pure @inline Base.sub2ind(::Size{S}, x::Int...) where {S} = sub2ind(S, x...)
8888

89+
@pure size_tuple(::Size{S}) where {S} = Tuple{S...}
90+
8991
# Some @pure convenience functions for `Length`
9092
@pure get(::Length{L}) where {L} = L
9193

test/MArray.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
@test MArray{Tuple{2,2},Int}((1,2,3,4)).data === (1,2,3,4)
2828
@test MArray{Tuple{2,2}}((1,2,3,4)).data === (1,2,3,4)
2929

30+
@test MArray(SVector(1,2)) isa MArray{Tuple{2}}
31+
# Constructors should create a copy (#335)
32+
v = MArray{Tuple{2}}(1,2)
33+
@test MArray(v) !== v && MArray(v) == v
34+
3035
@test ((@MArray [1])::MArray{Tuple{1}}).data === (1,)
3136
@test ((@MArray [1,2])::MArray{Tuple{2}}).data === (1,2)
3237
@test ((@MArray Float64[1,2,3])::MArray{Tuple{3}}).data === (1.0, 2.0, 3.0)

test/SArray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
@test SArray{Tuple{2,2},Int}((1,2,3,4)).data === (1,2,3,4)
2626
@test SArray{Tuple{2,2}}((1,2,3,4)).data === (1,2,3,4)
2727

28+
@test SArray(SArray{Tuple{2}}(1,2)) === SArray{Tuple{2}}(1,2)
29+
2830
@test ((@SArray [1])::SArray{Tuple{1}}).data === (1,)
2931
@test ((@SArray [1,2])::SArray{Tuple{2}}).data === (1,2)
3032
@test ((@SArray Float64[1,2,3])::SArray{Tuple{3}}).data === (1.0, 2.0, 3.0)

0 commit comments

Comments
 (0)