Skip to content

Commit

Permalink
Remove Compat dependency and don't export gradient, gradient!, hessia…
Browse files Browse the repository at this point in the history
…n, hessian!
  • Loading branch information
timholy committed Aug 11, 2018
1 parent 18cc592 commit 8f027e8
Show file tree
Hide file tree
Showing 35 changed files with 66 additions and 101 deletions.
4 changes: 1 addition & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
julia 0.6
julia 0.7

ShowItLikeYouBuildIt
WoodburyMatrices 0.1.5
Ratios
AxisAlgorithms 0.3.0
OffsetArrays
Compat 0.59
21 changes: 2 additions & 19 deletions src/Interpolations.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
VERSION < v"0.7.0-beta2.199" && __precompile__()

module Interpolations

export
Expand All @@ -8,12 +6,6 @@ export
extrapolate,
scale,

gradient!,
gradient1,
hessian!,
hessian,
hessian1,

AbstractInterpolation,
AbstractExtrapolation,

Expand All @@ -37,21 +29,12 @@ export
# extrapolation/extrapolation.jl
# scaling/scaling.jl

using Compat
using Compat.LinearAlgebra, Compat.SparseArrays
using LinearAlgebra, SparseArrays
using WoodburyMatrices, Ratios, AxisAlgorithms, OffsetArrays

import Base: convert, size, getindex, promote_rule,
import Base: convert, size, axes, getindex, promote_rule,
ndims, eltype, checkbounds

@static if VERSION < v"0.7.0-DEV.3449"
import Base: gradient
else
import LinearAlgebra: gradient
end

import Compat: axes

abstract type Flag end
abstract type InterpolationType <: Flag end
struct NoInterp <: InterpolationType end
Expand Down
7 changes: 1 addition & 6 deletions src/b-splines/prefiltering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ end
padded_similar(::Type{TC}, inds::Tuple{Vararg{Base.OneTo{Int}}}) where TC = Array{TC}(undef, length.(inds))
padded_similar(::Type{TC}, inds) where TC = OffsetArray{TC}(undef, inds)

# despite Compat, julia doesn't support 0.6 copy! with CartesianIndices argument
@static if isdefined(Base, :CartesianIndices)
ct!(coefs, indscp, A, indsA) = copyto!(coefs, CartesianIndices(indscp), A, CartesianIndices(indsA))
else
ct!(coefs, indscp, A, indsA) = copyto!(coefs, CartesianRange(indscp), A, CartesianRange(indsA))
end
ct!(coefs, indscp, A, indsA) = copyto!(coefs, CartesianIndices(indscp), A, CartesianIndices(indsA))

copy_with_padding(A, ::Type{IT}) where {IT} = copy_with_padding(eltype(A), A, IT)
function copy_with_padding(::Type{TC}, A, ::Type{IT}) where {TC,IT<:DimSpec{InterpolationType}}
Expand Down
2 changes: 1 addition & 1 deletion test/b-splines/constant.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ConstantTests

using Interpolations
using Compat.Test
using Test

# Instantiation
N1 = 10
Expand Down
15 changes: 7 additions & 8 deletions test/b-splines/cubic.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module CubicTests

using Compat.Test
using Test
using Interpolations

for (constructor, copier) in ((interpolate, identity), (interpolate!, copy))
Expand Down Expand Up @@ -55,8 +55,7 @@ end

module CubicGradientTests

using Interpolations, Compat.Test, Compat.LinearAlgebra
using Compat: range
using Interpolations, Test, LinearAlgebra

ix = 1:15
f(x) = cos((x-1)*2pi/(length(ix)-1))
Expand All @@ -71,16 +70,16 @@ for (constructor, copier) in ((interpolate, identity), (interpolate!, copy))
itp = constructor(copier(A), BSpline(Cubic(BC())), GT())
# test that inner region is close to data
for x in range(ix[5], stop=ix[end-4], length=100)
@test (g(x),(gradient(itp,x))[1],atol=cbrt(cbrt(eps(g(x)))))
@test (g(x),(Interpolations.gradient(itp,x))[1],atol=cbrt(cbrt(eps(g(x)))))
end
end
end
itp_flat_g = interpolate(A, BSpline(Cubic(Flat())), OnGrid())
@test ((gradient(itp_flat_g,1))[1],0,atol=eps())
@test ((gradient(itp_flat_g,ix[end]))[1],0,atol=eps())
@test ((Interpolations.gradient(itp_flat_g,1))[1],0,atol=eps())
@test ((Interpolations.gradient(itp_flat_g,ix[end]))[1],0,atol=eps())

itp_flat_c = interpolate(A, BSpline(Cubic(Flat())), OnCell())
@test ((gradient(itp_flat_c,0.5))[1],0,atol=eps())
@test ((gradient(itp_flat_c,ix[end] + 0.5))[1],0,atol=eps())
@test ((Interpolations.gradient(itp_flat_c,0.5))[1],0,atol=eps())
@test ((Interpolations.gradient(itp_flat_c,ix[end] + 0.5))[1],0,atol=eps())

end
3 changes: 1 addition & 2 deletions test/b-splines/function-call-syntax.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module ExtrapFunctionCallSyntax

using Compat.Test, Interpolations, DualNumbers
using Compat: range
using Test, Interpolations, DualNumbers

# Test if b-spline interpolation by function syntax yields identical results
f(x) = sin((x-3)*2pi/9 - 1)
Expand Down
2 changes: 1 addition & 1 deletion test/b-splines/linear.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module LinearTests

using Interpolations
using Compat.Test
using Test

xmax = 10
g1(x) = sin((x-3)*2pi/(xmax-1)-1)
Expand Down
2 changes: 1 addition & 1 deletion test/b-splines/mixed.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module MixedTests

using Interpolations, Compat, Compat.Test, Compat.SharedArrays, Compat.Random
using Interpolations, Test, SharedArrays, Random

N = 10

Expand Down
1 change: 0 additions & 1 deletion test/b-splines/multivalued.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module NonNumeric
# Test interpolation with a multi-valued type

using Interpolations
using Compat

import Base: +, -, *, /

Expand Down
3 changes: 1 addition & 2 deletions test/b-splines/non1.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Non1Tests

using Interpolations, OffsetArrays, AxisAlgorithms, Compat.Test
using Compat: axes
using Interpolations, OffsetArrays, AxisAlgorithms, Test

# At present, for a particular type of non-1 array you need to specialize this function
function AxisAlgorithms.A_ldiv_B_md!(dest::OffsetArray, F, src::OffsetArray, dim::Integer, b::AbstractVector)
Expand Down
2 changes: 1 addition & 1 deletion test/b-splines/quadratic.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module QuadraticTests

using Interpolations, Compat.Test
using Interpolations, Test

for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
f(x) = sin((x-3)*2pi/9 - 1)
Expand Down
2 changes: 1 addition & 1 deletion test/convenience-constructors.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module ConvenienceConstructorTests

using Interpolations
using Compat.Test
using Test
using Base.Cartesian

# unit test setup
Expand Down
2 changes: 1 addition & 1 deletion test/extrapolation/function-call-syntax.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ExtrapFunctionCallSyntax

using Compat.Test, Interpolations, DualNumbers
using Test, Interpolations, DualNumbers

# Test if extrapolation by function syntax yields identical results
f(x) = sin((x-3)*2pi/9 - 1)
Expand Down
2 changes: 1 addition & 1 deletion test/extrapolation/non1.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ExtrapNon1

using Compat.Test, Interpolations, OffsetArrays
using Test, Interpolations, OffsetArrays

f(x) = sin((x-3)*2pi/9 - 1)
xinds = -3:6
Expand Down
4 changes: 2 additions & 2 deletions test/extrapolation/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module ExtrapTests

using Compat.Test, DualNumbers
using DualNumbers
using Interpolations

using Test

f(x) = sin((x-3)*2pi/9 - 1)
xmax = 10
Expand Down
2 changes: 1 addition & 1 deletion test/extrapolation/type-stability.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ExtrapTypeStability

using Compat.Test, Interpolations, DualNumbers
using Test, Interpolations, DualNumbers

# Test type-stability of 1-dimensional extrapolation
f(x) = sin((x-3)*2pi/9 - 1)
Expand Down
38 changes: 19 additions & 19 deletions test/gradient.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GradientTests

using Compat, Compat.Test, Interpolations, DualNumbers, Compat.LinearAlgebra
using Test, Interpolations, DualNumbers, LinearAlgebra

nx = 10
f1(x) = sin((x-3)*2pi/(nx-1) - 1)
Expand All @@ -13,8 +13,8 @@ itp1 = interpolate(Float64[f1(x) for x in 1:nx-1],
g = Array{Float64}(undef, 1)

for x in 1:nx
@test gradient(itp1, x)[1] == 0
@test gradient!(g, itp1, x)[1] == 0
@test Interpolations.gradient(itp1, x)[1] == 0
@test Interpolations.gradient!(g, itp1, x)[1] == 0
@test g[1] == 0
end

Expand All @@ -25,14 +25,14 @@ itp2 = interpolate((1:nx-1,), Float64[f1(x) for x in 1:nx-1],
Gridded(Linear()))
for itp in (itp1, itp2)
for x in 2.5:nx-1.5
@test (g1(x),(gradient(itp,x))[1],atol=abs(0.1 * g1(x)))
@test (g1(x),(gradient!(g,itp,x))[1],atol=abs(0.1 * g1(x)))
@test (g1(x),(Interpolations.gradient(itp,x))[1],atol=abs(0.1 * g1(x)))
@test (g1(x),(Interpolations.gradient!(g,itp,x))[1],atol=abs(0.1 * g1(x)))
@test (g1(x),g[1],atol=abs(0.1 * g1(x)))
end

for i = 1:10
x = rand()*(nx-2)+1.5
gtmp = gradient(itp, x)[1]
gtmp = Interpolations.gradient(itp, x)[1]
xd = dual(x, 1)
@test epsilon(itp[xd]) gtmp
end
Expand All @@ -44,23 +44,23 @@ itp_grid = interpolate(knots, Float64[f1(x) for x in knots[1]],
Gridded(Linear()))

for x in 1.5:0.5:nx-1.5
@test (g1(x),(gradient(itp_grid,x))[1],atol=abs(0.5 * g1(x)))
@test (g1(x),(gradient!(g,itp_grid,x))[1],atol=abs(0.5 * g1(x)))
@test (g1(x),(Interpolations.gradient(itp_grid,x))[1],atol=abs(0.5 * g1(x)))
@test (g1(x),(Interpolations.gradient!(g,itp_grid,x))[1],atol=abs(0.5 * g1(x)))
@test (g1(x),g[1],atol=abs(0.5 * g1(x)))
end

# Since Quadratic is OnCell in the domain, check gradients at grid points
itp1 = interpolate(Float64[f1(x) for x in 1:nx-1],
BSpline(Quadratic(Periodic())), OnCell())
for x in 2:nx-1
@test (g1(x),(gradient(itp1,x))[1],atol=abs(0.05 * g1(x)))
@test (g1(x),(gradient!(g,itp1,x))[1],atol=abs(0.05 * g1(x)))
@test (g1(x),(Interpolations.gradient(itp1,x))[1],atol=abs(0.05 * g1(x)))
@test (g1(x),(Interpolations.gradient!(g,itp1,x))[1],atol=abs(0.05 * g1(x)))
@test (g1(x),g[1],atol=abs(0.1 * g1(x)))
end

for i = 1:10
x = rand()*(nx-2)+1.5
gtmp = gradient(itp1, x)[1]
gtmp = Interpolations.gradient(itp1, x)[1]
xd = dual(x, 1)
@test epsilon(itp1[xd]) gtmp
end
Expand All @@ -79,30 +79,30 @@ y = qfunc(xg)
iq = interpolate(y, BSpline(Quadratic(Free())), OnCell())
x = 1.8
@test iq[x] qfunc(x)
@test (gradient(iq,x))[1] dqfunc(x)
@test (Interpolations.gradient(iq,x))[1] dqfunc(x)

# 2d (biquadratic)
p = [(x-1.75)^2 for x = 1:7]
A = p*p'
iq = interpolate(A, BSpline(Quadratic(Free())), OnCell())
@test iq[4,4] (4 - 1.75) ^ 4
@test iq[4,3] (4 - 1.75) ^ 2 * (3 - 1.75) ^ 2
g = gradient(iq, 4, 3)
g = Interpolations.gradient(iq, 4, 3)
@test g[1] 2 * (4 - 1.75) * (3 - 1.75) ^ 2
@test g[2] 2 * (4 - 1.75) ^ 2 * (3 - 1.75)

iq = interpolate!(copy(A), BSpline(Quadratic(InPlace())), OnCell())
@test iq[4,4] (4 - 1.75) ^ 4
@test iq[4,3] (4 - 1.75) ^ 2 * (3 - 1.75) ^ 2
g = gradient(iq, 4, 3)
g = Interpolations.gradient(iq, 4, 3)
@test (g[1],2 * (4 - 1.75) * (3 - 1.75) ^ 2,atol=0.03)
@test (g[2],2 * (4 - 1.75) ^ 2 * (3 - 1.75),atol=0.2)

# InPlaceQ is exact for an underlying quadratic
iq = interpolate!(copy(A), BSpline(Quadratic(InPlaceQ())), OnCell())
@test iq[4,4] (4 - 1.75) ^ 4
@test iq[4,3] (4 - 1.75) ^ 2 * (3 - 1.75) ^ 2
g = gradient(iq, 4, 3)
g = Interpolations.gradient(iq, 4, 3)
@test g[1] 2 * (4 - 1.75) * (3 - 1.75) ^ 2
@test g[2] 2 * (4 - 1.75) ^ 2 * (3 - 1.75)

Expand All @@ -119,19 +119,19 @@ for BC in (Flat,Line,Free,Periodic,Reflect,Natural), GT in (OnGrid, OnCell)
y = rand()*(nx-2)+1.5
xd = dual(x, 1)
yd = dual(y, 1)
gtmp = gradient(itp_a, x, y)
gtmp = Interpolations.gradient(itp_a, x, y)
@test length(gtmp) == 2
@test epsilon(itp_a[xd,y]) gtmp[1]
@test epsilon(itp_a[x,yd]) gtmp[2]
gtmp = gradient(itp_b, x, y)
gtmp = Interpolations.gradient(itp_b, x, y)
@test length(gtmp) == 2
@test epsilon(itp_b[xd,y]) gtmp[1]
@test epsilon(itp_b[x,yd]) gtmp[2]
ix, iy = round(Int, x), round(Int, y)
gtmp = gradient(itp_c, ix, y)
gtmp = Interpolations.gradient(itp_c, ix, y)
@test length(gtmp) == 1
@test epsilon(itp_c[ix,yd]) gtmp[1]
gtmp = gradient(itp_d, x, iy)
gtmp = Interpolations.gradient(itp_d, x, iy)
@test length(gtmp) == 1
@test epsilon(itp_d[xd,iy]) gtmp[1]
end
Expand Down
2 changes: 1 addition & 1 deletion test/grid.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module GridTests

using Interpolations, Compat.Test
using Interpolations, Test

# On-grid values
A = randn(4,10)
Expand Down
3 changes: 1 addition & 2 deletions test/gridded/function-call-syntax.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module GriddedFunctionCallSyntax

using Interpolations, Compat.Test
using Compat: range
using Interpolations, Test

for D in (Constant, Linear), G in (OnCell, OnGrid)
## 1D
Expand Down
3 changes: 1 addition & 2 deletions test/gridded/gridded.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module LinearTests

using Interpolations, Compat.Test
using Compat: range
using Interpolations, Test

for D in (Constant, Linear), G in (OnCell, OnGrid)
## 1D
Expand Down
3 changes: 1 addition & 2 deletions test/gridded/mixed.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module MixedTests

using Interpolations, Compat.Test
using Compat: range
using Interpolations, Test

A = rand(6,5)
knots = (collect(range(1, stop=size(A,1), length=size(A,1))),collect(range(1, stop=size(A,2), length=size(A,2))))
Expand Down
2 changes: 1 addition & 1 deletion test/io.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module IOTests

using Compat.Test
using Interpolations
using Test

SPACE = " "

Expand Down
2 changes: 1 addition & 1 deletion test/issues/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Issue34

using Interpolations, Compat.Test
using Interpolations, Test

A = rand(1:20, 100, 100)

Expand Down
2 changes: 1 addition & 1 deletion test/linear.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Linear1DTests
println("Testing Linear interpolation in 1D...")
using Interpolations, Compat.Test
using Interpolations, Test

f(x) = sin((x-3)*2pi/9 - 1)
xmax = 10
Expand Down
Loading

0 comments on commit 8f027e8

Please sign in to comment.