Skip to content

Commit e7926e6

Browse files
authored
improve inference in tensorizer length (#358)
1 parent acebe89 commit e7926e6

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Multivariate/TensorSpace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const TrivialTensorizer{d} = Tensorizer{NTuple{d,Ones{Int,1,Tuple{OneToInf{Int}}
2929

3030
eltype(::Type{<:Tensorizer{<:Tuple{Vararg{Any,N}}}}) where {N} = NTuple{N,Int}
3131
dimensions(a::Tensorizer) = map(sum,a.blocks)
32-
Base.length(a::Tensorizer) = mapreduce(sum,*,a.blocks)
32+
Base.length(a::Tensorizer) = reduce(*, dimensions(a)) # easier type-inference than mapreduce
3333

3434
Base.keys(a::Tensorizer) = oneto(length(a))
3535

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ end
481481
@testset "2D" begin
482482
ax = Ones{Int}(∞)
483483
t = ApproxFunBase.Tensorizer((ax,ax))
484+
@test (@inferred length(t)) == length(ax)^2
484485
v = collect(Iterators.take(t, 150))
485486
@test eltype(v) == eltype(t)
486487
@testset for (i, vi) in enumerate(v)
@@ -495,7 +496,7 @@ end
495496
t = ApproxFunBase.Tensorizer((ax,ax,ax))
496497
v = collect(Iterators.take(t, 150))
497498
@test eltype(v) == eltype(t)
498-
@testset for i in eachindex(v)
499+
@testset for (i,vi) in enumerate(v)
499500
blk = ApproxFunBase.block(t, i)
500501
@test i ApproxFunBase.blockrange(t, blk)
501502
end

0 commit comments

Comments
 (0)