Skip to content

Commit acebe89

Browse files
authored
Add tests for trivialtensorizer blocks (#357)
1 parent 5da41bb commit acebe89

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

src/LinearAlgebra/helper.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,9 @@ Base.length(b::BlockInterlacer) = mapreduce(sum,+,b.blocks)
712712

713713
# are all Ints, so finite dimensional
714714
function done(it::BlockInterlacer,st)
715-
for k=1:length(it.blocks)
716-
if st[end][k] < sum(it.blocks[k])
715+
lngs = st[end]
716+
for (k, (itk, lk)) in enumerate(zip(it.blocks, lngs))
717+
if lk < sum(itk)
717718
return false
718719
end
719720
end
@@ -729,10 +730,10 @@ function iterate(it::BlockInterlacer, (N,k,blkst,lngs))
729730

730731
if N > length(it.blocks)
731732
# increment to next block
732-
blkst = map(function(blit,blst)
733+
blkst = map(it.blocks,blkst) do blit,blst
733734
xblst = iterate(blit, blst...)
734735
xblst == nothing ? blst : (xblst[2],)
735-
end,it.blocks,blkst)
736+
end
736737
return iterate(it,(1,1,blkst,lngs))
737738
end
738739

test/runtests.jl

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -478,19 +478,33 @@ end
478478

479479
@testset "Tensorizer" begin
480480
@testset "TrivialTensorizer" begin
481-
ax = Ones{Int}(∞)
482-
t = ApproxFunBase.Tensorizer((ax,ax))
483-
v = collect(Iterators.take(t, 15))
484-
@test eltype(v) == eltype(t)
485-
@testset for (i, vi) in enumerate(v)
486-
@test vi == t[i]
487-
@test findfirst(t, vi) == i
481+
@testset "2D" begin
482+
ax = Ones{Int}(∞)
483+
t = ApproxFunBase.Tensorizer((ax,ax))
484+
v = collect(Iterators.take(t, 150))
485+
@test eltype(v) == eltype(t)
486+
@testset for (i, vi) in enumerate(v)
487+
blk = ApproxFunBase.block(t, i)
488+
@test i ApproxFunBase.blockrange(t, blk)
489+
@test vi == t[i]
490+
@test findfirst(t, vi) == i
491+
end
492+
end
493+
@testset "nD" begin
494+
ax = Ones{Int}(∞)
495+
t = ApproxFunBase.Tensorizer((ax,ax,ax))
496+
v = collect(Iterators.take(t, 150))
497+
@test eltype(v) == eltype(t)
498+
@testset for i in eachindex(v)
499+
blk = ApproxFunBase.block(t, i)
500+
@test i ApproxFunBase.blockrange(t, blk)
501+
end
488502
end
489503
end
490504
@testset "Tensorizer2D" begin
491505
ax = Ones{Int}(4)
492506
t = ApproxFunBase.Tensorizer((ax,ax))
493-
v = collect(Iterators.take(t, 15))
507+
v = collect(Iterators.take(t, 16))
494508
@test eltype(v) == eltype(t)
495509
@testset for (i, vi) in enumerate(v)
496510
@test findfirst(t, vi) == i

0 commit comments

Comments
 (0)