Skip to content

Commit 39c605c

Browse files
committed
improving coverage
1 parent f1465c4 commit 39c605c

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

src/StaticArraysCore.jl

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ end
7676
return nothing
7777
end
7878

79+
# Cast any Tuple to an TupleN{T}
80+
@inline convert_ntuple(::Type{T},d::T) where {T} = T # For zero-dimensional arrays
81+
@inline convert_ntuple(::Type{T},d::NTuple{N,T}) where {N,T} = d
82+
@generated function convert_ntuple(::Type{T}, d::NTuple{N,Any}) where {N,T}
83+
exprs = ntuple(i -> :(convert(T, d[$i])), Val(N))
84+
return quote
85+
Base.@_inline_meta
86+
$(Expr(:tuple, exprs...))
87+
end
88+
end
89+
7990

8091
"""
8192
SArray{S, T, N, L}(x::NTuple{L})
@@ -187,20 +198,6 @@ end
187198

188199
@inline MArray{S,T,N}(x::Tuple) where {S<:Tuple,T,N} = MArray{S,T,N,tuple_prod(S)}(x)
189200

190-
@generated function (::Type{MArray{S,T,N}})(::UndefInitializer) where {S,T,N}
191-
return quote
192-
$(Expr(:meta, :inline))
193-
MArray{S, T, N, $(tuple_prod(S))}(undef)
194-
end
195-
end
196-
197-
@generated function (::Type{MArray{S,T}})(::UndefInitializer) where {S,T}
198-
return quote
199-
$(Expr(:meta, :inline))
200-
MArray{S, T, $(tuple_length(S)), $(tuple_prod(S))}(undef)
201-
end
202-
end
203-
204201
"""
205202
MVector{S,T}(undef)
206203
MVector{S,T}(x::NTuple{S, T})
@@ -275,19 +272,6 @@ struct SizedArray{S<:Tuple,T,N,M,TData<:AbstractArray{T,M}} <: StaticArray{S,T,N
275272
end
276273
end
277274

278-
@inline function SizedArray{S,T,N,M}(a::AbstractArray) where {S<:Tuple,T,N,M}
279-
if eltype(a) == T && (M == 1 || M == ndims(a))
280-
a′ = M == 1 ? vec(a) : a
281-
return SizedArray{S,T,N,M,typeof(a′)}(a′)
282-
end
283-
return convert(SizedArray{S,T,N,M}, a)
284-
end
285-
286-
@inline function SizedArray{S,T,N}(a::AbstractArray) where {S<:Tuple,T,N}
287-
M = ndims(a) == N ? N : 1
288-
return SizedArray{S,T,N,M}(a)
289-
end
290-
291275
const SizedVector{S,T} = SizedArray{Tuple{S},T,1,1}
292276

293277
const SizedMatrix{S1,S2,T} = SizedArray{Tuple{S1,S2},T,2}

test/runtests.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ using StaticArraysCore: SizedArray, SizedVector, SizedMatrix
66

77
@testset "types" begin
88
@test SArray{Tuple{2},Int,1}((1, 2)) isa SArray
9+
@test SArray{Tuple{2},Float64,1}((1, 2)) isa SVector{2,Float64}
910
@test SVector{2,Int}((1, 2)) isa SVector
1011
@test SMatrix{1,2,Int}((1, 2)) isa SMatrix
1112

1213
@test MArray{Tuple{2},Int,1}((1, 2)) isa MArray
14+
@test MArray{Tuple{2},Int,1,2}(undef) isa MArray
15+
@test MArray{Tuple{2},Float64,1}((1, 2)) isa MVector{2,Float64}
1316
@test MVector{2,Int}((1, 2)) isa MVector
1417
@test MMatrix{1,2,Int}((1, 2)) isa MMatrix
1518

16-
@test SizedArray{Tuple{2},Int,1}([1, 2]) isa SizedArray
17-
@test SizedVector{2,Int}([1, 2]) isa SizedVector
18-
@test SizedMatrix{1,2,Int}(fill(0, 1, 2)) isa SizedMatrix
19+
@test SizedArray{Tuple{2},Int,2,1,Vector{Int}}([1, 2]) isa SizedArray
20+
@test SizedArray{Tuple{2},Int,2,1,Vector{Int}}(undef) isa SizedArray
1921
end
20-

0 commit comments

Comments
 (0)