Skip to content

Commit b150a8c

Browse files
mateuszbaranc42f
authored andcommitted
Faster similar for SizedArray (#625)
1 parent d76b585 commit b150a8c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/SizedArray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct SizedArray{S <: Tuple, T, N, M} <: StaticArray{S, T, N}
2020
end
2121

2222
function SizedArray{S, T, N, M}(::UndefInitializer) where {S, T, N, M}
23-
new{S, T, N, M}(Array{T, M}(undef, S.parameters...))
23+
new{S, T, N, M}(Array{T, M}(undef, size_to_tuple(S)...))
2424
end
2525
end
2626

src/util.jl

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ end
3838
@pure tuple_minimum(T::Type{<:Tuple}) = length(T.parameters) == 0 ? 0 : minimum(tuple(T.parameters...))
3939
@pure tuple_minimum(T::Tuple) = minimum(T)
4040

41+
"""
42+
size_to_tuple(::Type{S}) where S<:Tuple
43+
44+
Converts a size given by `Tuple{N, M, ...}` into a tuple `(N, M, ...)`.
45+
"""
46+
@pure function size_to_tuple(::Type{S}) where S<:Tuple
47+
return tuple(S.parameters...)
48+
end
49+
4150
# Something doesn't match up type wise
4251
function check_array_parameters(Size, T, N, L)
4352
(!isa(Size, DataType) || (Size.name !== Tuple.name)) && throw(ArgumentError("Static Array parameter Size must be a Tuple type, got $Size"))

0 commit comments

Comments
 (0)