Skip to content

Commit e07ad4f

Browse files
committed
Tests and refinement
1 parent 3d55528 commit e07ad4f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/flatten.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Special case flatten of iterators of static arrays.
22
import Base.Iterators: flatten_iteratorsize, flatten_length
3-
flatten_iteratorsize(::Union{Base.HasShape, Base.HasLength}, ::Type{<:Union{SArray,MArray}}) = Base.HasLength()
4-
function flatten_length(f, T::Type{<:Union{SArray,MArray}})
3+
flatten_iteratorsize(::Union{Base.HasShape, Base.HasLength}, ::Type{<:StaticArray}) = Base.HasLength()
4+
function flatten_length(f, T::Type{<:StaticArray})
55
length(T)*length(f.it)
66
end

test/flatten.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using StaticArrays, Test
2+
3+
@testset "Iterators.flatten" begin
4+
for x in [SVector(1.0, 2.0), MVector(1.0, 2.0),
5+
@SMatrix([1.0 2.0; 3.0 4.0]), @MMatrix([1.0 2.0]),
6+
Size(1,2)([1.0 2.0])
7+
]
8+
X = [x,x,x]
9+
@test length(Iterators.flatten(X)) == length(X)*length(x)
10+
@test collect(Iterators.flatten(typeof(x)[])) == []
11+
@test collect(Iterators.flatten(X)) == [x..., x..., x...]
12+
end
13+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ include("lu.jl")
4040
Random.seed!(42); include("qr.jl")
4141
Random.seed!(42); include("chol.jl") # hermitian_type(::Type{Any}) for block algorithm
4242
include("deque.jl")
43+
include("flatten.jl")
4344
include("io.jl")
4445
include("svd.jl")
4546
Random.seed!(42); include("fixed_size_arrays.jl")

0 commit comments

Comments
 (0)