Skip to content

Commit 19fb052

Browse files
authored
pretty printing for BlockInterlacer and CachedIterator (#411)
* pretty printing for BlockInterlacer and CachedIterator * Add tests * update tests * int vectors in BlockInterlacer
1 parent 1ee0cd7 commit 19fb052

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/LinearAlgebra/helper.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ end
537537
CachedIterator{T,IT}(it::IT, state) where {T,IT} = CachedIterator{T,IT}(it,T[],state,0)
538538
CachedIterator(it::IT) where IT = CachedIterator{eltype(it),IT}(it, ())
539539

540+
function Base.show(io::IO, c::CachedIterator)
541+
print(io, "Cached ", c.iterator, " with ", c.length, " stored elements, and state = ", c.state)
542+
end
543+
540544
function resize!(it::CachedIterator{T},n::Integer) where {T}
541545
m = it.length
542546
if n > m
@@ -668,12 +672,12 @@ conv(x::AbstractFill, y::AbstractFill) = DSP.conv(x, y)
668672
# TODO: cache sums
669673

670674

671-
struct BlockInterlacer{DMS<:Tuple}
675+
struct BlockInterlacer{DMS<:Tuple{Vararg{AbstractVector{Int}}}}
672676
blocks::DMS
673677
end
674678

675679

676-
const TrivialInterlacer{d} = BlockInterlacer{<:NTuple{d,Ones}}
680+
const TrivialInterlacer{d} = BlockInterlacer{<:NTuple{d,Ones{Int}}}
677681

678682
BlockInterlacer(v::AbstractVector) = BlockInterlacer(Tuple(v))
679683

@@ -685,6 +689,8 @@ length(b::BlockInterlacer) = mapreduce(sum,+,b.blocks)
685689

686690
Base.IteratorSize(::Type{BlockInterlacer{T}}) where {T} = _IteratorSize(T)
687691

692+
Base.show(io::IO, B::BlockInterlacer) = print(io, BlockInterlacer, "(", B.blocks, ")")
693+
688694
# the state is always (whichblock,curblock,cursubblock,curcoefficients)
689695
# start(it::BlockInterlacer) = (1,1,map(start,it.blocks),ntuple(zero,length(it.blocks)))
690696

test/show.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,10 @@
6767
@test startswith(s, "ConstantOperator")
6868
end
6969
end
70+
@testset "Iterators" begin
71+
B = ApproxFunBase.BlockInterlacer((Ones{Int}(2), Ones{Int}(2)))
72+
@test repr(B) == "ApproxFunBase.BlockInterlacer((Ones(2), Ones(2)))"
73+
C = cache(B)
74+
@test contains(repr(C), "Cached " * repr(B))
75+
end
7076
end

0 commit comments

Comments
 (0)