Skip to content

Commit 9470afd

Browse files
committed
Simplify inference's job on scaling infrastructure
1 parent 5511d40 commit 9470afd

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/b-splines/indexing.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ end
8686
# thats why we use this @noinline fence
8787
@noinline _promote_mul(a,b) = Base.promote_op(@functorize(*), a, b)
8888

89-
@noinline function getindex_return_type{T,N,TCoefs,IT<:DimSpec{BSpline},GT<:DimSpec{GridType},Pad}(::Type{BSplineInterpolation{T,N,TCoefs,IT,GT,Pad}}, argtypes)
89+
@noinline function getindex_return_type{T,N,TCoefs,IT<:DimSpec{BSpline},GT<:DimSpec{GridType},Pad}(::Type{BSplineInterpolation{T,N,TCoefs,IT,GT,Pad}}, argtypes::Tuple)
9090
reduce(_promote_mul, eltype(TCoefs), argtypes)
9191
end
9292

93+
function getindex_return_type{T,N,TCoefs,IT<:DimSpec{BSpline},GT<:DimSpec{GridType},Pad,I}(::Type{BSplineInterpolation{T,N,TCoefs,IT,GT,Pad}}, ::Type{I})
94+
_promote_mul(eltype(TCoefs), I)
95+
end
96+
9397
@generated function gradient!{T,N}(g::AbstractVector, itp::BSplineInterpolation{T,N}, xs::Number...)
9498
length(xs) == N || error("Can only be called with $N indexes")
9599
gradient_impl(itp)

src/scaling/scaling.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ end
129129
nelements(::Union{Type{NoInterp},Type{Constant}}) = 1
130130
nelements(::Type{Linear}) = 2
131131
nelements{Q<:Quadratic}(::Type{Q}) = 3
132+
133+
eachvalue_zero{R,BT<:Union{Type{NoInterp},Type{Constant}}}(::Type{R}, ::Type{BT}) =
134+
(zero(R),)
135+
eachvalue_zero{R}(::Type{R}, ::Type{Linear}) = (zero(R),zero(R))
136+
eachvalue_zero{R,Q<:Quadratic}(::Type{R}, ::Type{Q}) = (zero(R),zero(R),zero(R))
137+
132138
"""
133139
`eachvalue(sitp)` constructs an iterator for efficiently visiting each
134140
grid point of a ScaledInterpolation object in which a small grid is
@@ -159,18 +165,18 @@ which should be more efficient than
159165
end
160166
```
161167
"""
162-
@generated function eachvalue{T,N}(sitp::ScaledInterpolation{T,N})
168+
function eachvalue{T,N}(sitp::ScaledInterpolation{T,N})
163169
ITPT = basetype(sitp)
164170
IT = itptype(ITPT)
165-
itp_tail = ntuple(i->zero(getindex_return_type(ITPT, ntuple(i->Int, N-1))), nelements(bsplinetype(iextract(IT, 1))))
166-
quote
167-
dx_1 = coordlookup(sitp.ranges[1], 2) - coordlookup(sitp.ranges[1], 1)
168-
ScaledIterator(CartesianRange(ssize(sitp)), sitp, dx_1, 0, zero(dx_1), $itp_tail)
169-
end
171+
R = getindex_return_type(ITPT, Int)
172+
BT = bsplinetype(iextract(IT, 1))
173+
itp_tail = eachvalue_zero(R, BT)
174+
dx_1 = coordlookup(sitp.ranges[1], 2) - coordlookup(sitp.ranges[1], 1)
175+
ScaledIterator(CartesianRange(ssize(sitp)), sitp, dx_1, 0, zero(dx_1), itp_tail)
170176
end
171177

172-
start(iter::ScaledIterator) = start(iter.rng)
173-
done(iter::ScaledIterator, state) = done(iter.rng, state)
178+
@inline start(iter::ScaledIterator) = start(iter.rng)
179+
@inline done(iter::ScaledIterator, state) = done(iter.rng, state)
174180

175181
function index_gen1(::Union{Type{NoInterp}, Type{BSpline{Constant}}})
176182
quote

test/scaling/scaling.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ sitp32 = @inferred scale(interpolate(Float32[testfunction(x,y) for x in -5:.5:5,
5555
itp = interpolate(rand(3,3,3), BSpline(Quadratic(Flat())), OnCell())
5656
knots = map(d->1:10:21, 1:3)
5757
sitp = @inferred scale(itp, knots...)
58+
59+
iter = @inferred(eachvalue(sitp))
60+
state = @inferred(start(iter))
61+
@test !(@inferred(done(iter, state)))
62+
val, state = @inferred(next(iter, state))
63+
5864
function foo!(dest, sitp)
5965
i = 0
6066
for s in eachvalue(sitp)

0 commit comments

Comments
 (0)