Skip to content

Commit 837ed28

Browse files
rdeitstimholy
authored andcommitted
speed up size, lbounds, and ubounds with @generated functions (#132)
speed up size, lbounds, and ubounds with @generated functions
1 parent 422a934 commit 837ed28

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/Interpolations.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,12 @@ immutable InPlace <: Flag end
6868
immutable InPlaceQ <: Flag end
6969
typealias Natural Line
7070

71-
# TODO: size might have to be faster?
72-
size{T,N}(itp::AbstractInterpolation{T,N}) = ntuple(i->size(itp,i), N)::NTuple{N,Int}
71+
@generated size{T, N}(itp::AbstractInterpolation{T,N}) = Expr(:tuple, [:(size(itp, $i)) for i in 1:N]...)
7372
size(exp::AbstractExtrapolation, d) = size(exp.itp, d)
7473
bounds{T,N}(itp::AbstractInterpolation{T,N}) = tuple(zip(lbounds(itp), ubounds(itp))...)
7574
bounds{T,N}(itp::AbstractInterpolation{T,N}, d) = (lbound(itp,d),ubound(itp,d))
76-
lbounds{T,N}(itp::AbstractInterpolation{T,N}) = ntuple(i->lbound(itp,i), N)::NTuple{N,T}
77-
ubounds{T,N}(itp::AbstractInterpolation{T,N}) = ntuple(i->ubound(itp,i), N)::NTuple{N,T}
75+
@generated lbounds{T,N}(itp::AbstractInterpolation{T,N}) = Expr(:tuple, [:(lbound(itp, $i)) for i in 1:N]...)
76+
@generated ubounds{T,N}(itp::AbstractInterpolation{T,N}) = Expr(:tuple, [:(ubound(itp, $i)) for i in 1:N]...)
7877
lbound{T,N}(itp::AbstractInterpolation{T,N}, d) = 1
7978
ubound{T,N}(itp::AbstractInterpolation{T,N}, d) = size(itp, d)
8079
itptype{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = IT

0 commit comments

Comments
 (0)