Skip to content

Add tests for TrivialTensorizer blocks #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/LinearAlgebra/helper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,9 @@ Base.length(b::BlockInterlacer) = mapreduce(sum,+,b.blocks)

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

if N > length(it.blocks)
# increment to next block
blkst = map(function(blit,blst)
blkst = map(it.blocks,blkst) do blit,blst
xblst = iterate(blit, blst...)
xblst == nothing ? blst : (xblst[2],)
end,it.blocks,blkst)
end
return iterate(it,(1,1,blkst,lngs))
end

Expand Down
30 changes: 22 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -478,19 +478,33 @@ end

@testset "Tensorizer" begin
@testset "TrivialTensorizer" begin
ax = Ones{Int}(∞)
t = ApproxFunBase.Tensorizer((ax,ax))
v = collect(Iterators.take(t, 15))
@test eltype(v) == eltype(t)
@testset for (i, vi) in enumerate(v)
@test vi == t[i]
@test findfirst(t, vi) == i
@testset "2D" begin
ax = Ones{Int}(∞)
t = ApproxFunBase.Tensorizer((ax,ax))
v = collect(Iterators.take(t, 150))
@test eltype(v) == eltype(t)
@testset for (i, vi) in enumerate(v)
blk = ApproxFunBase.block(t, i)
@test i ∈ ApproxFunBase.blockrange(t, blk)
@test vi == t[i]
@test findfirst(t, vi) == i
end
end
@testset "nD" begin
ax = Ones{Int}(∞)
t = ApproxFunBase.Tensorizer((ax,ax,ax))
v = collect(Iterators.take(t, 150))
@test eltype(v) == eltype(t)
@testset for i in eachindex(v)
blk = ApproxFunBase.block(t, i)
@test i ∈ ApproxFunBase.blockrange(t, blk)
end
end
end
@testset "Tensorizer2D" begin
ax = Ones{Int}(4)
t = ApproxFunBase.Tensorizer((ax,ax))
v = collect(Iterators.take(t, 15))
v = collect(Iterators.take(t, 16))
@test eltype(v) == eltype(t)
@testset for (i, vi) in enumerate(v)
@test findfirst(t, vi) == i
Expand Down