Skip to content

Commit d2a5aa7

Browse files
committed
Define general constructor with construct_type
1 parent 63b1f67 commit d2a5aa7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/convert.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,15 @@ _no_precise_constructor(SA, ::Type{Tuple{N}}) where {N} = throw(DimensionMismatc
8989
_no_precise_constructor(SA, SZ::Type{<:Tuple}) = throw(DimensionMismatch("No precise constructor for $SA found. Size of input was $SZ."))
9090
_no_precise_constructor(SA) = throw(DimensionMismatch("No precise constructor for $SA found. Input is not static sized."))
9191

92-
(::Type{SA})(x::Tuple{Tuple{Tuple{<:Tuple}}}) where {SA <: StaticArray} =
93-
throw(DimensionMismatch("No precise constructor for $SA found. Length of input was $(length(x[1][1][1]))."))
94-
95-
@inline (::Type{SA})(x...) where {SA <: StaticArray} = SA(x)
96-
@inline (::Type{SA})(a::StaticArray) where {SA<:StaticArray} = SA(Tuple(a))
97-
@inline (::Type{SA})(a::StaticArray) where {SA<:SizedArray} = SA(a.data)
92+
@inline (::Type{SA})(x...) where {SA <: StaticArray} = construct_type(SA, Args(x))(x)
93+
@inline function (::Type{SA})(x::Tuple) where {SA <: Union{SArray, MArray, SHermitianCompact, SizedArray}}
94+
SA′ = construct_type(SA, x)
95+
x isa eltype(SA′) ? SA′((x,)) : SA′(x)
96+
end
97+
@inline function (::Type{SA})(sa::StaticArray) where {SA <: StaticArray}
98+
SA′ = construct_type(SA, sa)
99+
sa isa eltype(SA′) ? SA′((sa,)) : SA′(Tuple(sa))
100+
end
98101
@propagate_inbounds (::Type{SA})(a::AbstractArray) where {SA <: StaticArray} = convert(SA, a)
99102

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

0 commit comments

Comments
 (0)