Skip to content

Commit 8b918e4

Browse files
committed
disallow parent for BSplines other than Constant and Linear
1 parent 36b2249 commit 8b918e4

File tree

5 files changed

+10
-3
lines changed

5 files changed

+10
-3
lines changed

src/b-splines/b-splines.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ 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-
3533
# Utilities for working either with scalars or tuples/tuple-types
3634
iextract{T<:BSpline}(::Type{T}, d) = T
3735
iextract(t, d) = t.parameters[d]
@@ -128,3 +126,6 @@ include("cubic.jl")
128126
include("indexing.jl")
129127
include("prefiltering.jl")
130128
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."))

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)