Skip to content

Commit 36b2249

Browse files
committed
add support for Base.parent
1 parent 0ecd53b commit 36b2249

File tree

10 files changed

+21
-2
lines changed

10 files changed

+21
-2
lines changed

src/b-splines/b-splines.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ function BSplineInterpolation{N,Tel,TWeights<:Real,IT<:DimSpec{BSpline},GT<:DimS
3030
BSplineInterpolation{T,N,typeof(A),IT,GT,pad}(A)
3131
end
3232

33+
Base.parent(A::BSplineInterpolation) = A.coefs
34+
3335
# Utilities for working either with scalars or tuples/tuple-types
3436
iextract{T<:BSpline}(::Type{T}, d) = T
3537
iextract(t, d) = t.parameters[d]

src/extrapolation/extrapolation.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ end
44
Extrapolation{T,ITPT,IT,GT,ET}(::Type{T}, N, itp::ITPT, ::Type{IT}, ::Type{GT}, et::ET) =
55
Extrapolation{T,N,ITPT,IT,GT,ET}(itp)
66

7+
Base.parent(A::Extrapolation) = A.itp
8+
79
# DimSpec{Flag} is not enough for extrapolation dispatch, since we allow nested tuples
810
# However, no tuples should be nested deeper than this; the first level is for different
911
# schemes in different dimensions, and the second level is for different schemes in

src/extrapolation/filled.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ function FilledExtrapolation{T,N,IT,GT}(itp::AbstractInterpolation{T,N,IT,GT}, f
99
FilledExtrapolation{T,N,typeof(itp),IT,GT,typeof(fillvalue)}(itp, fillvalue)
1010
end
1111

12+
Base.parent(A::FilledExtrapolation) = A.itp
13+
1214
"""
1315
`extrapolate(itp, fillvalue)` creates an extrapolation object that returns the `fillvalue` any time the indexes in `itp[x1,x2,...]` are out-of-bounds.
1416
"""

src/gridded/gridded.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ function GriddedInterpolation{N,TCoefs,TWeights<:Real,IT<:DimSpec{Gridded},pad}(
3333
GriddedInterpolation{T,N,TCoefs,IT,typeof(knts),pad}(knts, A)
3434
end
3535

36+
Base.parent(A::GriddedInterpolation) = A.coefs
37+
3638
# A type-stable version of map(collect, knots)
3739
mapcollect() = ()
3840
@inline mapcollect(k::AbstractVector) = (collect(k),)

src/scaling/scaling.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ end
1414
:(ScaledInterpolation{$T,$N,$ITPT,$IT,$GT,$RT}(itp, ranges))
1515
end
1616

17+
Base.parent(A::ScaledInterpolation) = A.itp
18+
1719
"""
1820
`scale(itp, xs, ys, ...)` scales an existing interpolation object to allow for indexing using other coordinate axes than unit ranges, by wrapping the interpolation object and transforming the indices from the provided axes onto unit ranges upon indexing.
1921

test/b-splines/constant.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
1717
itp3c = @inferred(constructor(copier(A3), BSpline(Constant()), OnCell()))
1818
itp3g = @inferred(constructor(copier(A3), BSpline(Constant()), OnGrid()))
1919

20+
@test parent(itp1c) === itp1c.coefs
21+
2022
# Evaluation on provided data points
2123
# 1D
2224
for i in 1:length(A1)
@@ -58,4 +60,4 @@ for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
5860
@test A1[N1] == itp1c[N1+.3]
5961
end
6062

61-
end
63+
end

test/extrapolation/non1.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ schemes = (
1515
)
1616

1717
for etp in map(E -> extrapolate(itpg, E()), schemes), x in xinds
18+
@test parent(etp) === itpg
1819
@test @inferred(getindex(etp, x)) A[x]
1920
end
2021

@@ -24,6 +25,7 @@ A = OffsetArray(Float64[f(x)*g(y) for x in xinds, y in yinds], xinds, yinds)
2425
itp2 = interpolate(A, BSpline(Linear()), OnGrid())
2526

2627
for (etp2,E) in map(E -> (extrapolate(itp2, E()), E), schemes)
28+
@test parent(etp2) === itp2
2729
E == Periodic && continue # g isn't periodic
2830
for y in yinds, x in xinds
2931
@test @inferred(getindex(etp2, x, y)) A[x, y]

test/extrapolation/runtests.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ etpg = extrapolate(itpg, Flat())
1717
@test etpg[10.1] == etpg[11] == etpg[148.298452] == A[end]
1818

1919
etpf = @inferred(extrapolate(itpg, NaN))
20+
@test typeof(etpf) <: Interpolations.FilledExtrapolation
21+
@test parent(etpf) === itpg
2022

2123
@test @inferred(size(etpf)) == (xmax,)
2224
@test isnan(@inferred(getindex(etpf, -2.5)))

test/gridded/gridded.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ for D in (Constant, Linear), G in (OnCell, OnGrid)
3737
A = rand(6,5)
3838
knots = (collect(linspace(1,size(A,1),size(A,1))),collect(linspace(1,size(A,2),size(A,2))))
3939
itp = @inferred(interpolate(knots, A, Gridded(D())))
40+
@test parent(itp) === A
4041
@inferred(getindex(itp, 2, 2))
4142
@inferred(getindex(itp, CartesianIndex((2,2))))
4243
for j = 2:size(A,2)-1, i = 2:size(A,1)-1
@@ -70,4 +71,4 @@ for D in (Constant, Linear), G in (OnCell, OnGrid)
7071
@test itp[4,1.2] A[2,6]
7172
end
7273

73-
end
74+
end

test/scaling/scaling.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ using Base.Test
99
itp = interpolate(1:1.0:10, BSpline(Linear()), OnGrid())
1010

1111
sitp = @inferred(scale(itp, -3:.5:1.5))
12+
@test typeof(sitp) <: Interpolations.ScaledInterpolation
13+
@test parent(sitp) === itp
1214

1315
for (x,y) in zip(-3:.05:1.5, 1:.1:10)
1416
@test sitp[x] y

0 commit comments

Comments
 (0)