Skip to content

Commit

Permalink
Merge pull request #115 from tlycken/jl0.5
Browse files Browse the repository at this point in the history
Fix warnings and errors on Julia 0.5 (replaces #113)
  • Loading branch information
Tomas Lycken authored Aug 14, 2016
2 parents 042ee2e + 85ca4b6 commit e846450
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 99 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ julia 0.4
WoodburyMatrices 0.1.5
Ratios
AxisAlgorithms
Compat 0.8.0
9 changes: 5 additions & 4 deletions src/Interpolations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export
# extrapolation/extrapolation.jl
# scaling/scaling.jl

using Compat
using WoodburyMatrices, Ratios, AxisAlgorithms

import Base: convert, size, getindex, gradient, scale, promote_rule, ndims, eltype
Expand Down Expand Up @@ -71,16 +72,16 @@ ubounds{T,N}(itp::AbstractInterpolation{T,N}) = ntuple(i->ubound(itp,i), N)::NTu
lbound{T,N}(itp::AbstractInterpolation{T,N}, d) = 1
ubound{T,N}(itp::AbstractInterpolation{T,N}, d) = size(itp, d)
itptype{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = IT
itptype{ITP<:AbstractInterpolation}(::Type{ITP}) = itptype(super(ITP))
itptype{ITP<:AbstractInterpolation}(::Type{ITP}) = itptype(supertype(ITP))
itptype(itp::AbstractInterpolation ) = itptype(typeof(itp))
gridtype{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = GT
gridtype{ITP<:AbstractInterpolation}(::Type{ITP}) = gridtype(super(ITP))
gridtype{ITP<:AbstractInterpolation}(::Type{ITP}) = gridtype(supertype(ITP))
gridtype(itp::AbstractInterpolation) = gridtype(typeof(itp))
ndims{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = N
ndims{ITP<:AbstractInterpolation}(::Type{ITP}) = ndims(super(ITP))
ndims{ITP<:AbstractInterpolation}(::Type{ITP}) = ndims(supertype(ITP))
ndims(itp::AbstractInterpolation) = ndims(typeof(itp))
eltype{T,N,IT<:DimSpec{InterpolationType},GT<:DimSpec{GridType}}(::Type{AbstractInterpolation{T,N,IT,GT}}) = T
eltype{ITP<:AbstractInterpolation}(::Type{ITP}) = eltype(super(ITP))
eltype{ITP<:AbstractInterpolation}(::Type{ITP}) = eltype(supertype(ITP))
eltype(itp::AbstractInterpolation) = eltype(typeof(itp))
count_interp_dims{T<:AbstractInterpolation}(::Type{T}, N) = N

Expand Down
1 change: 0 additions & 1 deletion src/b-splines/b-splines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ end

# Utilities for working either with scalars or tuples/tuple-types
iextract{T<:BSpline}(::Type{T}, d) = T
iextract{T<:GridType}(::Type{T}, d) = T
iextract(t, d) = t.parameters[d]
padding{T,N,TCoefs,IT,GT,pad}(::Type{BSplineInterpolation{T,N,TCoefs,IT,GT,pad}}) = pad
padding(itp::AbstractInterpolation) = padding(typeof(itp))
Expand Down
10 changes: 5 additions & 5 deletions src/b-splines/constant.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Constant
`define_indices_d` for a constant b-spline calculates `ix_d = round(Int,x_d)`
"""
function define_indices_d(::Type{BSpline{Constant}}, d, pad)
symix, symx = symbol("ix_",d), symbol("x_",d)
symix, symx = Symbol("ix_",d), Symbol("x_",d)
:($symix = clamp(round(Int, $symx), 1, size(itp, $d)))
end

Expand All @@ -19,7 +19,7 @@ end
with the general b-spline framework
"""
function coefficients(::Type{BSpline{Constant}}, N, d)
sym, symx = symbol("c_",d), symbol("x_",d)
sym, symx = Symbol("c_",d), Symbol("x_",d)
:($sym = 1)
end

Expand All @@ -28,7 +28,7 @@ end
compatibility with the general b-spline framework
"""
function gradient_coefficients(::Type{BSpline{Constant}}, d)
sym, symx = symbol("c_",d), symbol("x_",d)
sym, symx = Symbol("c_",d), Symbol("x_",d)
:($sym = 0)
end

Expand All @@ -37,14 +37,14 @@ end
compatibility with the general b-spline framework
"""
function hessian_coefficients(::Type{BSpline{Constant}}, d)
sym = symbol("c_",d)
sym = Symbol("c_",d)
:($sym = 0)
end

function index_gen{IT<:DimSpec{BSpline}}(::Type{BSpline{Constant}}, ::Type{IT}, N::Integer, offsets...)
if (length(offsets) < N)
d = length(offsets)+1
sym = symbol("c_", d)
sym = Symbol("c_", d)
return :($sym * $(index_gen(IT, N, offsets..., 0)))
else
indices = [offsetsym(offsets[d], d) for d = 1:N]
Expand Down
32 changes: 16 additions & 16 deletions src/b-splines/cubic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Cubic
`Cubic`), as well as auxiliary quantities `ixm_d`, `ixp_d` and `ixpp_d`
"""
function define_indices_d{BC}(::Type{BSpline{Cubic{BC}}}, d, pad)
symix, symixm, symixp = symbol("ix_",d), symbol("ixm_",d), symbol("ixp_",d)
symixpp, symx, symfx = symbol("ixpp_",d), symbol("x_",d), symbol("fx_",d)
symix, symixm, symixp = Symbol("ix_",d), Symbol("ixm_",d), Symbol("ixp_",d)
symixpp, symx, symfx = Symbol("ixpp_",d), Symbol("x_",d), Symbol("fx_",d)
quote
# ensure that all of ix_d, ixm_d, ixp_d, and ixpp_d are in-bounds no
# matter the value of pad
Expand All @@ -53,8 +53,8 @@ If any `ixX_d` for `x ∈ {m, p, pp}` (note: not `c_d`) should fall outside of
the data interval, they wrap around.
"""
function define_indices_d(::Type{BSpline{Cubic{Periodic}}}, d, pad)
symix, symixm, symixp = symbol("ix_",d), symbol("ixm_",d), symbol("ixp_",d)
symixpp, symx, symfx = symbol("ixpp_",d), symbol("x_",d), symbol("fx_",d)
symix, symixm, symixp = Symbol("ix_",d), Symbol("ixm_",d), Symbol("ixp_",d)
symixpp, symx, symfx = Symbol("ixpp_",d), Symbol("x_",d), Symbol("fx_",d)
quote
$symix = clamp(floor(Int, $symx), 1, size(itp,$d))
$symfx = $symx - $symix
Expand All @@ -80,11 +80,11 @@ where `p` and `q` are defined in the docstring entry for `Cubic`, and
`fx_d` in the docstring entry for `define_indices_d`.
"""
function coefficients{C<:Cubic}(::Type{BSpline{C}}, N, d)
symm, sym = symbol("cm_",d), symbol("c_",d)
symp, sympp = symbol("cp_",d) ,symbol("cpp_",d)
symfx = symbol("fx_",d)
symfx_cub = symbol("fx_cub_", d)
sym_1m_fx_cub = symbol("one_m_fx_cub_", d)
symm, sym = Symbol("cm_",d), Symbol("c_",d)
symp, sympp = Symbol("cp_",d) ,Symbol("cpp_",d)
symfx = Symbol("fx_",d)
symfx_cub = Symbol("fx_cub_", d)
sym_1m_fx_cub = Symbol("one_m_fx_cub_", d)
quote
$symfx_cub = cub($symfx)
$sym_1m_fx_cub = cub(1-$symfx)
Expand All @@ -108,10 +108,10 @@ where `p` and `q` are defined in the docstring entry for `Cubic`, and
`fx_d` in the docstring entry for `define_indices_d`.
"""
function gradient_coefficients{C<:Cubic}(::Type{BSpline{C}}, d)
symm, sym, symp, sympp = symbol("cm_",d), symbol("c_",d), symbol("cp_",d), symbol("cpp_",d)
symfx = symbol("fx_",d)
symfx_sqr = symbol("fx_sqr_", d)
sym_1m_fx_sqr = symbol("one_m_fx_sqr_", d)
symm, sym, symp, sympp = Symbol("cm_",d), Symbol("c_",d), Symbol("cp_",d), Symbol("cpp_",d)
symfx = Symbol("fx_",d)
symfx_sqr = Symbol("fx_sqr_", d)
sym_1m_fx_sqr = Symbol("one_m_fx_sqr_", d)
quote
$symfx_sqr = sqr($symfx)
$sym_1m_fx_sqr = sqr(1 - $symfx)
Expand All @@ -136,8 +136,8 @@ where `p` and `q` are defined in the docstring entry for `Cubic`, and
`fx_d` in the docstring entry for `define_indices_d`.
"""
function hessian_coefficients{C<:Cubic}(::Type{BSpline{C}}, d)
symm, sym, symp, sympp = symbol("cm_",d), symbol("c_",d), symbol("cp_",d), symbol("cpp_",d)
symfx = symbol("fx_",d)
symm, sym, symp, sympp = Symbol("cm_",d), Symbol("c_",d), Symbol("cp_",d), Symbol("cpp_",d)
symfx = Symbol("fx_",d)
quote
$symm = 1 - $symfx
$sym = 3 * $symfx - 2
Expand All @@ -149,7 +149,7 @@ end
function index_gen{C<:Cubic,IT<:DimSpec{BSpline}}(::Type{BSpline{C}}, ::Type{IT}, N::Integer, offsets...)
if length(offsets) < N
d = length(offsets)+1
symm, sym, symp, sympp = symbol("cm_",d), symbol("c_",d), symbol("cp_",d), symbol("cpp_",d)
symm, sym, symp, sympp = Symbol("cm_",d), Symbol("c_",d), Symbol("cp_",d), Symbol("cpp_",d)
return :($symm * $(index_gen(IT, N, offsets...,-1)) + $sym * $(index_gen(IT, N, offsets..., 0)) +
$symp * $(index_gen(IT, N, offsets..., 1)) + $sympp * $(index_gen(IT, N, offsets..., 2)))
else
Expand Down
23 changes: 13 additions & 10 deletions src/b-splines/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ end
function getindex_return_type{T,N,TCoefs,IT<:DimSpec{BSpline},GT<:DimSpec{GridType},Pad}(::Type{BSplineInterpolation{T,N,TCoefs,IT,GT,Pad}}, argtypes)
Tret = eltype(TCoefs)
for a in argtypes
Tret = Base.promote_op(Base.MulFun, Tret, a)
Tret = Base.promote_op(@functorize(*), Tret, a) # the macro is used to support julia 0.4
end
Tret
end
Expand All @@ -98,11 +98,14 @@ end
:(gradient!(g, itp, $(args...)))
end

@generated function gradient{T,N}(itp::AbstractInterpolation{T,N}, xs...)
n = count_interp_dims(itp, N)
Tg = promote_type(T, [x <: AbstractArray ? eltype(x) : x for x in xs]...)
xargs = [:(xs[$d]) for d in 1:length(xs)]
:(gradient!(Array($Tg,$n), itp, $(xargs...)))
# @eval uglyness required for disambiguation with method in Base
for R in [:Real, :Any]
@eval @generated function gradient{T,N}(itp::AbstractInterpolation{T,N}, xs::$R...)
n = count_interp_dims(itp, N)
Tg = promote_type(T, [x <: AbstractArray ? eltype(x) : x for x in xs]...)
xargs = [:(xs[$d]) for d in 1:length(xs)]
:(gradient!(Array($Tg,$n), itp, $(xargs...)))
end
end

gradient1{T}(itp::AbstractInterpolation{T,1}, x) = gradient(itp, x)[1]
Expand Down Expand Up @@ -155,7 +158,7 @@ end

hessian1{T}(itp::AbstractInterpolation{T,1}, x) = hessian(itp, x)[1,1]

offsetsym(off, d) = off == -1 ? symbol("ixm_", d) :
off == 0 ? symbol("ix_", d) :
off == 1 ? symbol("ixp_", d) :
off == 2 ? symbol("ixpp_", d) : error("offset $off not recognized")
offsetsym(off, d) = off == -1 ? Symbol("ixm_", d) :
off == 0 ? Symbol("ix_", d) :
off == 1 ? Symbol("ixp_", d) :
off == 2 ? Symbol("ixpp_", d) : error("offset $off not recognized")
12 changes: 6 additions & 6 deletions src/b-splines/linear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Linear
`Linear`), as well as the auxiliary quantity `ixp_d`
"""
function define_indices_d(::Type{BSpline{Linear}}, d, pad)
symix, symixp, symfx, symx = symbol("ix_",d), symbol("ixp_",d), symbol("fx_",d), symbol("x_",d)
symix, symixp, symfx, symx = Symbol("ix_",d), Symbol("ixp_",d), Symbol("fx_",d), Symbol("x_",d)
quote
$symix = clamp(floor(Int, $symx), 1, size(itp, $d)-1)
$symixp = $symix + 1
Expand All @@ -46,7 +46,7 @@ where `p` is defined in the docstring entry for `Linear` and `fx_d` in the
docstring entry for `define_indices_d`.
"""
function coefficients(::Type{BSpline{Linear}}, N, d)
sym, symp, symfx = symbol("c_",d), symbol("cp_",d), symbol("fx_",d)
sym, symp, symfx = Symbol("c_",d), Symbol("cp_",d), Symbol("fx_",d)
quote
$sym = 1 - $symfx
$symp = $symfx
Expand All @@ -64,7 +64,7 @@ where `p` is defined in the docstring entry for `Linear`, and `fx_d` in the
docstring entry for `define_indices_d`.
"""
function gradient_coefficients(::Type{BSpline{Linear}}, d)
sym, symp, symfx = symbol("c_",d), symbol("cp_",d), symbol("fx_",d)
sym, symp, symfx = Symbol("c_",d), Symbol("cp_",d), Symbol("fx_",d)
quote
$sym = -1
$symp = 1
Expand All @@ -82,7 +82,7 @@ where `p` is defined in the docstring entry for `Linear`, and `fx_d` in the
docstring entry for `define_indices_d`. (These are both ≡ 0.)
"""
function hessian_coefficients(::Type{BSpline{Linear}}, d)
sym, symp = symbol("c_",d), symbol("cp_",d)
sym, symp = Symbol("c_",d), Symbol("cp_",d)
quote
$sym = $symp = 0
end
Expand All @@ -93,8 +93,8 @@ end
function index_gen{IT<:DimSpec{BSpline}}(::Type{BSpline{Linear}}, ::Type{IT}, N::Integer, offsets...)
if length(offsets) < N
d = length(offsets)+1
sym = symbol("c_", d)
symp = symbol("cp_", d)
sym = Symbol("c_", d)
symp = Symbol("cp_", d)
return :($sym * $(index_gen(IT, N, offsets..., 0)) + $symp * $(index_gen(IT, N, offsets..., 1)))
else
indices = [offsetsym(offsets[d], d) for d = 1:N]
Expand Down
24 changes: 12 additions & 12 deletions src/b-splines/quadratic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ Quadratic
`Quadratic`), as well as auxiliary quantities `ixm_d` and `ixp_d`
"""
function define_indices_d{BC}(::Type{BSpline{Quadratic{BC}}}, d, pad)
symix, symixm, symixp = symbol("ix_",d), symbol("ixm_",d), symbol("ixp_",d)
symx, symfx = symbol("x_",d), symbol("fx_",d)
symix, symixm, symixp = Symbol("ix_",d), Symbol("ixm_",d), Symbol("ixp_",d)
symx, symfx = Symbol("x_",d), Symbol("fx_",d)
quote
# ensure that all three ix_d, ixm_d, and ixp_d are in-bounds no matter
# the value of pad
Expand All @@ -42,8 +42,8 @@ function define_indices_d{BC}(::Type{BSpline{Quadratic{BC}}}, d, pad)
end
end
function define_indices_d(::Type{BSpline{Quadratic{Periodic}}}, d, pad)
symix, symixm, symixp = symbol("ix_",d), symbol("ixm_",d), symbol("ixp_",d)
symx, symfx = symbol("x_",d), symbol("fx_",d)
symix, symixm, symixp = Symbol("ix_",d), Symbol("ixm_",d), Symbol("ixp_",d)
symx, symfx = Symbol("x_",d), Symbol("fx_",d)
quote
$symix = clamp(round(Int, $symx), 1, size(itp,$d))
$symfx = $symx - $symix
Expand All @@ -52,8 +52,8 @@ function define_indices_d(::Type{BSpline{Quadratic{Periodic}}}, d, pad)
end
end
function define_indices_d{BC<:Union{InPlace,InPlaceQ}}(::Type{BSpline{Quadratic{BC}}}, d, pad)
symix, symixm, symixp = symbol("ix_",d), symbol("ixm_",d), symbol("ixp_",d)
symx, symfx = symbol("x_",d), symbol("fx_",d)
symix, symixm, symixp = Symbol("ix_",d), Symbol("ixm_",d), Symbol("ixp_",d)
symx, symfx = Symbol("x_",d), Symbol("fx_",d)
pad == 0 || error("Use $BC only with interpolate!")
quote
# ensure that all three ix_d, ixm_d, and ixp_d are in-bounds no matter
Expand All @@ -78,8 +78,8 @@ where `p` and `q` are defined in the docstring entry for `Quadratic`, and
`fx_d` in the docstring entry for `define_indices_d`.
"""
function coefficients{Q<:Quadratic}(::Type{BSpline{Q}}, N, d)
symm, sym, symp = symbol("cm_",d), symbol("c_",d), symbol("cp_",d)
symfx = symbol("fx_",d)
symm, sym, symp = Symbol("cm_",d), Symbol("c_",d), Symbol("cp_",d)
symfx = Symbol("fx_",d)
quote
$symm = sqr($symfx - SimpleRatio(1,2))/2
$sym = SimpleRatio(3,4) - sqr($symfx)
Expand All @@ -99,8 +99,8 @@ where `p` and `q` are defined in the docstring entry for `Quadratic`, and
`fx_d` in the docstring entry for `define_indices_d`.
"""
function gradient_coefficients{Q<:Quadratic}(::Type{BSpline{Q}}, d)
symm, sym, symp = symbol("cm_",d), symbol("c_",d), symbol("cp_",d)
symfx = symbol("fx_",d)
symm, sym, symp = Symbol("cm_",d), Symbol("c_",d), Symbol("cp_",d)
symfx = Symbol("fx_",d)
quote
$symm = $symfx - SimpleRatio(1,2)
$sym = -2 * $symfx
Expand All @@ -120,7 +120,7 @@ where `p` and `q` are defined in the docstring entry for `Quadratic`, and
`fx_d` in the docstring entry for `define_indices_d`.
"""
function hessian_coefficients{Q<:Quadratic}(::Type{BSpline{Q}}, d)
symm, sym, symp = symbol("cm_",d), symbol("c_",d), symbol("cp_",d)
symm, sym, symp = Symbol("cm_",d), Symbol("c_",d), Symbol("cp_",d)
quote
$symm = 1
$sym = -2
Expand All @@ -133,7 +133,7 @@ end
function index_gen{Q<:Quadratic,IT<:DimSpec{BSpline}}(::Type{BSpline{Q}}, ::Type{IT}, N::Integer, offsets...)
if length(offsets) < N
d = length(offsets)+1
symm, sym, symp = symbol("cm_",d), symbol("c_",d), symbol("cp_",d)
symm, sym, symp = Symbol("cm_",d), Symbol("c_",d), Symbol("cp_",d)
return :($symm * $(index_gen(IT, N, offsets...,-1)) + $sym * $(index_gen(IT, N, offsets..., 0)) +
$symp * $(index_gen(IT, N, offsets..., 1)))
else
Expand Down
4 changes: 2 additions & 2 deletions src/extrapolation/extrapolation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ and indices. The heavy lifting is done by the `extrap_prep` function; see
`?extrap_prep` for details.
"""
function getindex_impl{T,N,ITPT,IT,GT,ET}(etp::Type{Extrapolation{T,N,ITPT,IT,GT,ET}}, xs...)
coords = [symbol("xs_",d) for d in 1:N]
coords = [Symbol("xs_",d) for d in 1:N]
quote
@nexprs $N d->(xs_d = xs[d])
$(extrap_prep(ET, Val{N}()))
Expand All @@ -60,7 +60,7 @@ end


function gradient!_impl{T,N,ITPT,IT,GT,ET}(g, etp::Type{Extrapolation{T,N,ITPT,IT,GT,ET}}, xs...)
coords = [symbol("xs_", d) for d in 1:N]
coords = [Symbol("xs_", d) for d in 1:N]
quote
@nexprs $N d->(xs_d = xs[d])
$(extrap_prep(Val{:gradient}(), ET, Val{N}()))
Expand Down
10 changes: 5 additions & 5 deletions src/extrapolation/flat.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
function extrap_prep{N,d}(::Type{Flat}, ::Val{N}, ::Val{d})
xs_d = symbol("xs_", d)
xs_d = Symbol("xs_", d)
:($xs_d = clamp($xs_d, lbound(etp, $d), ubound(etp, $d)))
end

function extrap_prep{N,d}(::Type{Flat}, ::Val{N}, ::Val{d}, ::Val{:lo})
xs_d = symbol("xs_", d)
xs_d = Symbol("xs_", d)
:($xs_d = max($xs_d, lbound(etp, $d)))
end

function extrap_prep{N,d}(::Type{Flat}, ::Val{N}, ::Val{d}, ::Val{:hi})
xs_d = symbol("xs_", d)
xs_d = Symbol("xs_", d)
:($xs_d = min($xs_d, ubound(etp, $d)))
end

function extrap_prep{N,d}(::Val{:gradient}, ::Type{Flat}, ::Val{N}, ::Val{d}, ::Val{:lo})
coords = [symbol("xs_", k) for k in 1:N]
coords = [Symbol("xs_", k) for k in 1:N]
xs_d = coords[d]

quote
Expand All @@ -28,7 +28,7 @@ function extrap_prep{N,d}(::Val{:gradient}, ::Type{Flat}, ::Val{N}, ::Val{d}, ::
end

function extrap_prep{N,d}(::Val{:gradient}, ::Type{Flat}, ::Val{N}, ::Val{d}, ::Val{:hi})
coords = [symbol("xs_", k) for k in 1:N]
coords = [Symbol("xs_", k) for k in 1:N]
xs_d = coords[d]

quote
Expand Down
4 changes: 2 additions & 2 deletions src/extrapolation/linear.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function extrap_prep{N,d}(::Type{Linear}, ::Val{N}, ::Val{d}, ::Val{:lo})
coords = [symbol("xs_", k) for k in 1:N]
coords = [Symbol("xs_", k) for k in 1:N]
xs_d = coords[d]
quote
if $xs_d < lbound(etp.itp, $d)
Expand All @@ -9,7 +9,7 @@ function extrap_prep{N,d}(::Type{Linear}, ::Val{N}, ::Val{d}, ::Val{:lo})
end
end
function extrap_prep{N,d}(::Type{Linear}, ::Val{N}, ::Val{d}, ::Val{:hi})
coords = [symbol("xs_", k) for k in 1:N]
coords = [Symbol("xs_", k) for k in 1:N]
xs_d = coords[d]
quote
if $xs_d > ubound(etp, $d)
Expand Down
Loading

0 comments on commit e846450

Please sign in to comment.