Skip to content

Commit ade419b

Browse files
authored
Merge pull request #147 from Evizero/parent
add support for Base.parent
2 parents 0ecd53b + 8b918e4 commit ade419b

File tree

14 files changed

+29
-3
lines changed

14 files changed

+29
-3
lines changed

src/b-splines/b-splines.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,6 @@ include("cubic.jl")
126126
include("indexing.jl")
127127
include("prefiltering.jl")
128128
include("../filter1d.jl")
129+
130+
Base.parent{T,N,TCoefs,UT<:Union{BSpline{Linear},BSpline{Constant}}}(A::BSplineInterpolation{T,N,TCoefs,UT}) = A.coefs
131+
Base.parent{T,N,TCoefs,UT}(A::BSplineInterpolation{T,N,TCoefs,UT}) = throw(ArgumentError("The given BSplineInterpolation does not serve as a \"view\" for a parent array. This would only be true for Constant and Linear b-splines."))

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/b-splines/cubic.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ for (constructor, copier) in ((interpolate, identity), (interpolate!, copy))
1919
for (A, f) in ((A0, f0), (A1, f1))
2020
itp1 = @inferred(constructor(copier(A), BSpline(Cubic(BC())), GT()))
2121
@test @inferred(size(itp1)) == size(A)
22+
@test_throws ArgumentError parent(itp1)
2223

2324
# test that inner region is close to data
2425
for x in 3.1:.2:8.1

test/b-splines/linear.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ A2 = Float64[f(x,y) for x in 1:xmax, y in 1:ymax]
1717
for (constructor, copier) in ((interpolate, identity), (interpolate!, copy))
1818
itp1c = @inferred(constructor(copier(A1), BSpline(Linear()), OnCell()))
1919

20+
@test parent(itp1c) === itp1c.coefs
21+
2022
# Just interpolation
2123
for x in 1:.2:xmax
2224
@test (f(x),itp1c[x],atol=abs(0.1 * f(x)))

test/b-splines/mixed.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
1111
itp_b = @inferred(constructor(copier(A2), (BSpline(Quadratic(BC())), BSpline(Linear())), GT()))
1212
@test @inferred(size(itp_a)) == size(A2)
1313
@test @inferred(size(itp_b)) == size(A2)
14+
@test_throws ArgumentError parent(itp_a)
15+
@test_throws ArgumentError parent(itp_b)
1416

1517
for j = 2:N-1, i = 2:N-1
1618
@test (itp_a[i,j],A2[i,j],atol=sqrt(eps(A2[i,j])))

test/b-splines/quadratic.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ for (constructor, copier) in ((interpolate, x->x), (interpolate!, copy))
99
for BC in (Flat,Line,Free,Periodic,Reflect,Natural), GT in (OnGrid, OnCell)
1010
itp1 = @inferred(constructor(copier(A), BSpline(Quadratic(BC())), GT()))
1111
@test @inferred(size(itp1)) == size(A)
12+
@test_throws ArgumentError parent(itp1)
1213

1314
# test that inner region is close to data
1415
for x in 3.1:.2:8.1
@@ -64,4 +65,4 @@ let
6465
end
6566
end
6667

67-
end
68+
end

0 commit comments

Comments
 (0)