Skip to content

Commit 0a993fd

Browse files
authored
Deprecate CamelCase convenience for snake_case constructors (#501)
Specifically, deprecate LinearInterpolation, ConstantInterpolation, and CubicSplineInterpolation in favor of linear_interpolation, constant_interpolation, and cubic_spline_interpolation, respectively since these are merely functions and not types.
1 parent 5dd4e13 commit 0a993fd

17 files changed

+92
-87
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ A = log.(xs)
3939
```
4040
Create linear interpolation object without extrapolation
4141
```julia
42-
interp_linear = LinearInterpolation(xs, A)
42+
interp_linear = linear_interpolation(xs, A)
4343
interp_linear(3) # exactly log(3)
4444
interp_linear(3.1) # approximately log(3.1)
4545
interp_linear(0.9) # outside grid: error
4646
```
4747
Create linear interpolation object with extrapolation
4848
```julia
49-
interp_linear_extrap = LinearInterpolation(xs, A,extrapolation_bc=Line())
49+
interp_linear_extrap = linear_interpolation(xs, A,extrapolation_bc=Line())
5050
interp_linear_extrap(0.9) # outside grid: linear extrapolation
5151
```
5252

docs/src/convenience-construction.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
## Convenience notation
33

4-
For constant, linear, and cubic spline interpolations, `ConstantInterpolation`, `LinearInterpolation`, and `CubicSplineInterpolation`
4+
For constant, linear, and cubic spline interpolations, `constant_interpolation`, `linear_interpolation`, and `cubic_spline_interpolation`
55
can be used to create interpolating and extrapolating objects handily.
66

77
### Motivating Example
@@ -11,7 +11,7 @@ extrap_full = extrapolate(scale(interpolate(A, BSpline(Linear())), xs), Line())
1111
```
1212
can be written as the more readable
1313
```julia
14-
extrap = LinearInterpolation(xs, A, extrapolation_bc = Line())
14+
extrap = linear_interpolation(xs, A, extrapolation_bc = Line())
1515
```
1616
by using the convenience constructor.
1717

@@ -23,12 +23,12 @@ xs = 1:0.2:5
2323
A = [f(x) for x in xs]
2424

2525
# linear interpolation
26-
interp_linear = LinearInterpolation(xs, A)
26+
interp_linear = linear_interpolation(xs, A)
2727
interp_linear(3) # exactly log(3)
2828
interp_linear(3.1) # approximately log(3.1)
2929

3030
# cubic spline interpolation
31-
interp_cubic = CubicSplineInterpolation(xs, A)
31+
interp_cubic = cubic_spline_interpolation(xs, A)
3232
interp_cubic(3) # exactly log(3)
3333
interp_cubic(3.1) # approximately log(3.1)
3434
```
@@ -40,12 +40,12 @@ ys = 2:0.1:5
4040
A = [f(x,y) for x in xs, y in ys]
4141

4242
# linear interpolation
43-
interp_linear = LinearInterpolation((xs, ys), A)
43+
interp_linear = linear_interpolation((xs, ys), A)
4444
interp_linear(3, 2) # exactly log(3 + 2)
4545
interp_linear(3.1, 2.1) # approximately log(3.1 + 2.1)
4646

4747
# cubic spline interpolation
48-
interp_cubic = CubicSplineInterpolation((xs, ys), A)
48+
interp_cubic = cubic_spline_interpolation((xs, ys), A)
4949
interp_cubic(3, 2) # exactly log(3 + 2)
5050
interp_cubic(3.1, 2.1) # approximately log(3.1 + 2.1)
5151
```
@@ -57,25 +57,25 @@ xs = 1:0.2:5
5757
A = [f(x) for x in xs]
5858

5959
# extrapolation with linear boundary conditions
60-
extrap = LinearInterpolation(xs, A, extrapolation_bc = Line())
60+
extrap = linear_interpolation(xs, A, extrapolation_bc = Line())
6161

6262
@test extrap(1 - 0.2) # ≈ f(1) - (f(1.2) - f(1))
6363
@test extrap(5 + 0.2) # ≈ f(5) + (f(5) - f(4.8))
6464
```
6565
You can also use a "fill" value, which gets returned whenever you ask for out-of-range values:
6666

6767
```julia
68-
extrap = LinearInterpolation(xs, A, extrapolation_bc = NaN)
68+
extrap = linear_interpolation(xs, A, extrapolation_bc = NaN)
6969
@test isnan(extrap(5.2))
7070
```
7171

72-
Irregular grids are supported as well; note that presently only `ConstantInterpolation` and `LinearInterpolation` supports irregular grids.
72+
Irregular grids are supported as well; note that presently only `constant_interpolation` and `linear_interpolation` supports irregular grids.
7373
```julia
7474
xs = [x^2 for x = 1:0.2:5]
7575
A = [f(x) for x in xs]
7676

7777
# linear interpolation
78-
interp_linear = LinearInterpolation(xs, A)
78+
interp_linear = linear_interpolation(xs, A)
7979
interp_linear(1) # exactly log(1)
8080
interp_linear(1.05) # approximately log(1.05)
8181
```
@@ -96,8 +96,8 @@ x = a:1.0:b
9696
# length(x) == length(y)
9797
y = @. cos(x^2 / 9.0) # Function application by broadcasting
9898
# Interpolations
99-
itp_linear = LinearInterpolation(x, y)
100-
itp_cubic = CubicSplineInterpolation(x, y)
99+
itp_linear = linear_interpolation(x, y)
100+
itp_cubic = cubic_spline_interpolation(x, y)
101101
# Interpolation functions
102102
f_linear(x) = itp_linear(x)
103103
f_cubic(x) = itp_cubic(x)

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ A = log.(xs)
4444
```
4545
Create linear interpolation object without extrapolation
4646
```julia
47-
interp_linear = LinearInterpolation(xs, A)
47+
interp_linear = linear_interpolation(xs, A)
4848
interp_linear(3) # exactly log(3)
4949
interp_linear(3.1) # approximately log(3.1)
5050
interp_linear(0.9) # outside grid: error
5151
```
5252
Create linear interpolation object with extrapolation
5353
```julia
54-
interp_linear_extrap = LinearInterpolation(xs, A, extrapolation_bc=Line())
54+
interp_linear_extrap = linear_interpolation(xs, A,extrapolation_bc=Line())
5555
interp_linear_extrap(0.9) # outside grid: linear extrapolation
5656
```
5757

docs/src/iterate.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ last knot being co-located. (ie. in the example below `etp(2.0) = 1.0` not
5959
```jldoctest periodic-demo; setup = :(using Interpolations)
6060
julia> x = [1.0, 1.5, 1.75, 2.0];
6161
62-
julia> etp = LinearInterpolation(x, x.^2, extrapolation_bc=Periodic());
62+
julia> etp = linear_interpolation(x, x.^2, extrapolation_bc=Periodic());
6363
6464
julia> kiter = knots(etp);
6565
@@ -101,7 +101,7 @@ k[1], k[2], ..., k[end-1], k[end], k[end+1], ... k[2], k[1], k[2], ...
101101
```jldoctest reflect-demo; setup = :(using Interpolations)
102102
julia> x = [1.0, 1.5, 1.75, 2.0];
103103
104-
julia> etp = LinearInterpolation(x, x.^2, extrapolation_bc=Reflect());
104+
julia> etp = linear_interpolation(x, x.^2, extrapolation_bc=Reflect());
105105
106106
julia> kiter = knots(etp);
107107
@@ -139,7 +139,7 @@ multi-dimensional extrapolation also supported.
139139
```jldoctest; setup = :(using Interpolations)
140140
julia> x = [1.0, 1.5, 1.75, 2.0];
141141
142-
julia> etp = LinearInterpolation((x, x), x.*x');
142+
julia> etp = linear_interpolation((x, x), x.*x');
143143
144144
julia> knots(etp) |> collect
145145
4×4 Matrix{Tuple{Float64, Float64}}:
@@ -156,7 +156,7 @@ iteration over knots can end up "stuck" iterating along a single axis:
156156
```jldoctest; setup = :(using Interpolations)
157157
julia> x = [1.0, 1.5, 1.75, 2.0];
158158
159-
julia> etp = LinearInterpolation((x, x), x.*x', extrapolation_bc=(Periodic(), Throw()));
159+
julia> etp = linear_interpolation((x, x), x.*x', extrapolation_bc=(Periodic(), Throw()));
160160
161161
julia> knots(etp) |> k -> Iterators.take(k, 6) |> collect
162162
6-element Vector{Tuple{Float64, Float64}}:
@@ -174,7 +174,7 @@ Rearranging the axes so non-repeating knots are first can address this issue:
174174
```jldoctest; setup = :(using Interpolations)
175175
julia> x = [1.0, 1.5, 1.75, 2.0];
176176
177-
julia> etp = LinearInterpolation((x, x), x.*x', extrapolation_bc=(Throw(), Periodic()));
177+
julia> etp = linear_interpolation((x, x), x.*x', extrapolation_bc=(Throw(), Periodic()));
178178
179179
julia> knots(etp) |> k -> Iterators.take(k, 6) |> collect
180180
6-element Vector{Tuple{Float64, Float64}}:
@@ -199,7 +199,7 @@ result, the iterator will generate an infinite sequence of knots starting at `1.
199199
```jldoctest iterate-directional-unbounded; setup = :(using Interpolations)
200200
julia> x = [1.0, 1.2, 1.3, 2.0];
201201
202-
julia> etp = LinearInterpolation(x, x.^2, extrapolation_bc=((Throw(), Periodic()),));
202+
julia> etp = linear_interpolation(x, x.^2, extrapolation_bc=((Throw(), Periodic()),));
203203
204204
julia> kiter = knots(etp);
205205
@@ -227,7 +227,7 @@ Swapping the boundary conditions, results in a finite sequence of knots from
227227
```jldoctest iterate-directional-bounded; setup = :(using Interpolations)
228228
julia> x = [1.0, 1.2, 1.3, 2.0];
229229
230-
julia> etp = LinearInterpolation(x, x.^2, extrapolation_bc=((Periodic(), Throw()),));
230+
julia> etp = linear_interpolation(x, x.^2, extrapolation_bc=((Periodic(), Throw()),));
231231
232232
julia> kiter = knots(etp);
233233
@@ -272,7 +272,7 @@ We can iterate over all knots greater than `start` by omitting `stop`
272272
```jldoctest knotsbetween-usage; setup = :(using Interpolations)
273273
julia> x = [1.0, 1.5, 1.75, 2.0];
274274
275-
julia> etp = LinearInterpolation(x, x.^2, extrapolation_bc=Periodic());
275+
julia> etp = linear_interpolation(x, x.^2, extrapolation_bc=Periodic());
276276
277277
julia> krange = knotsbetween(etp; start=4.0);
278278
@@ -322,7 +322,7 @@ dimensions.
322322
```jldoctest; setup = :(using Interpolations)
323323
julia> x = [1.0, 1.5, 1.75, 2.0];
324324
325-
julia> etp = LinearInterpolation((x, x), x.*x');
325+
julia> etp = linear_interpolation((x, x), x.*x');
326326
327327
julia> knotsbetween(etp; start=(1.2, 1.5), stop=(1.8, 3.0)) |> collect
328328
2×2 Matrix{Tuple{Float64, Float64}}:

src/Interpolations.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ export
2323
InPlaceQ,
2424
Throw,
2525

26-
ConstantInterpolation,
27-
LinearInterpolation,
28-
CubicSplineInterpolation,
26+
constant_interpolation,
27+
linear_interpolation,
28+
cubic_spline_interpolation,
2929

3030
knots,
3131
knotsbetween

src/convenience-constructors.jl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
# convenience copnstructors for constant / linear / cubic spline interpolations
22
# 1D version
3-
ConstantInterpolation(range::AbstractRange, vs::AbstractVector; extrapolation_bc = Throw()) =
3+
constant_interpolation(range::AbstractRange, vs::AbstractVector; extrapolation_bc = Throw()) =
44
extrapolate(scale(interpolate(vs, BSpline(Constant())), range), extrapolation_bc)
5-
ConstantInterpolation(range::AbstractVector, vs::AbstractVector; extrapolation_bc = Throw()) =
5+
constant_interpolation(range::AbstractVector, vs::AbstractVector; extrapolation_bc = Throw()) =
66
extrapolate(interpolate((range, ), vs, Gridded(Constant())), extrapolation_bc)
7-
LinearInterpolation(range::AbstractRange, vs::AbstractVector; extrapolation_bc = Throw()) =
7+
linear_interpolation(range::AbstractRange, vs::AbstractVector; extrapolation_bc = Throw()) =
88
extrapolate(scale(interpolate(vs, BSpline(Linear())), range), extrapolation_bc)
9-
LinearInterpolation(range::AbstractVector, vs::AbstractVector; extrapolation_bc = Throw()) =
9+
linear_interpolation(range::AbstractVector, vs::AbstractVector; extrapolation_bc = Throw()) =
1010
extrapolate(interpolate((range, ), vs, Gridded(Linear())), extrapolation_bc)
11-
CubicSplineInterpolation(range::AbstractRange, vs::AbstractVector;
11+
cubic_spline_interpolation(range::AbstractRange, vs::AbstractVector;
1212
bc = Line(OnGrid()), extrapolation_bc = Throw()) =
1313
extrapolate(scale(interpolate(vs, BSpline(Cubic(bc))), range), extrapolation_bc)
1414

1515
# multivariate versions
16-
ConstantInterpolation(ranges::NTuple{N,AbstractRange}, vs::AbstractArray{T,N};
16+
constant_interpolation(ranges::NTuple{N,AbstractRange}, vs::AbstractArray{T,N};
1717
extrapolation_bc = Throw()) where {N,T} =
1818
extrapolate(scale(interpolate(vs, BSpline(Constant())), ranges...), extrapolation_bc)
19-
ConstantInterpolation(ranges::NTuple{N,AbstractVector}, vs::AbstractArray{T,N};
19+
constant_interpolation(ranges::NTuple{N,AbstractVector}, vs::AbstractArray{T,N};
2020
extrapolation_bc = Throw()) where {N,T} =
2121
extrapolate(interpolate(ranges, vs, Gridded(Constant())), extrapolation_bc)
22-
LinearInterpolation(ranges::NTuple{N,AbstractRange}, vs::AbstractArray{T,N};
22+
linear_interpolation(ranges::NTuple{N,AbstractRange}, vs::AbstractArray{T,N};
2323
extrapolation_bc = Throw()) where {N,T} =
2424
extrapolate(scale(interpolate(vs, BSpline(Linear())), ranges...), extrapolation_bc)
25-
LinearInterpolation(ranges::NTuple{N,AbstractVector}, vs::AbstractArray{T,N};
25+
linear_interpolation(ranges::NTuple{N,AbstractVector}, vs::AbstractArray{T,N};
2626
extrapolation_bc = Throw()) where {N,T} =
2727
extrapolate(interpolate(ranges, vs, Gridded(Linear())), extrapolation_bc)
28-
CubicSplineInterpolation(ranges::NTuple{N,AbstractRange}, vs::AbstractArray{T,N};
28+
cubic_spline_interpolation(ranges::NTuple{N,AbstractRange}, vs::AbstractArray{T,N};
2929
bc = Line(OnGrid()), extrapolation_bc = Throw()) where {N,T} =
3030
extrapolate(scale(interpolate(vs, BSpline(Cubic(bc))), ranges...), extrapolation_bc)
3131

3232
"""
33-
etp = LinearInterpolation(knots, A; extrapolation_bc=Throw())
33+
etp = linear_interpolation(knots, A; extrapolation_bc=Throw())
3434
3535
A shorthand for one of the following.
3636
* `extrapolate(scale(interpolate(A, BSpline(Linear())), knots), extrapolation_bc)`
@@ -41,10 +41,10 @@ Consider using `interpolate`, `scale`, or `extrapolate` explicitly as needed
4141
rather than using this convenience constructor. Performance will improve
4242
without scaling or extrapolation.
4343
"""
44-
LinearInterpolation
44+
linear_interpolation
4545

4646
"""
47-
etp = ConstantInterpolation(knots, A; extrapolation_bc=Throw())
47+
etp = constant_interpolation(knots, A; extrapolation_bc=Throw())
4848
4949
A shorthand for `extrapolate(interpolate(knots, A, scheme), extrapolation_bc)`,
5050
where `scheme` is either `BSpline(Constant())` or `Gridded(Constant())` depending on whether
@@ -54,15 +54,15 @@ Consider using `interpolate` or `extrapolate` explicitly as needed
5454
rather than using this convenience constructor. Performance will improve
5555
without extrapolation.
5656
"""
57-
ConstantInterpolation
57+
constant_interpolation
5858

5959
"""
60-
etp = CubicSplineInterpolation(knots, A; bc=Line(OnGrid()), extrapolation_bc=Throw())
60+
etp = cubic_spline_interpolation(knots, A; bc=Line(OnGrid()), extrapolation_bc=Throw())
6161
6262
A shorthand for `extrapolate(scale(interpolate(A, BSpline(Cubic(bc))),knots), extrapolation_bc)`.
6363
6464
Consider using `interpolate`, `scale`, or `extrapolate` explicitly as needed
6565
rather than using this convenience constructor. Performance will improve
6666
without scaling or extrapolation.
6767
"""
68-
CubicSplineInterpolation
68+
cubic_spline_interpolation

src/deprecations.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ create_bcs(it::Flag, gt::Tuple) = map(t->it(t), gt)
6262
replace_linear_line(::Linear) = Line()
6363
replace_linear_line(bc::BoundaryCondition) = bc
6464
replace_linear_line(etpflag::Tuple) = replace_linear_line.(etpflag)
65+
66+
# Old convenience constructors
67+
@deprecate LinearInterpolation linear_interpolation
68+
@deprecate ConstantInterpolation constant_interpolation
69+
@deprecate CubicSplineInterpolation cubic_spline_interpolation

src/iterate.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ multiple KnotIterator within `Iterators.product`.
5151
```jldoctest
5252
julia> using Interpolations;
5353
54-
julia> etp = LinearInterpolation([1.0, 1.2, 2.3, 3.0], rand(4); extrapolation_bc=Periodic());
54+
julia> etp = linear_interpolation([1.0, 1.2, 2.3, 3.0], rand(4); extrapolation_bc=Periodic());
5555
5656
julia> kiter = knots(etp);
5757
@@ -121,7 +121,7 @@ infinite sequence of knots.
121121
```jldoctest
122122
julia> using Interpolations;
123123
124-
julia> etp = LinearInterpolation([1.0, 1.2, 2.3, 3.0], rand(4); extrapolation_bc=Periodic());
124+
julia> etp = linear_interpolation([1.0, 1.2, 2.3, 3.0], rand(4); extrapolation_bc=Periodic());
125125
126126
julia> Iterators.take(knots(etp), 5) |> collect
127127
5-element $(Array{typeof(1.0),1}):
@@ -424,7 +424,7 @@ If no such knots exists will return a KnotIterator with length 0
424424
```jldoctest
425425
julia> using Interpolations;
426426
427-
julia> etp = LinearInterpolation([1.0, 1.2, 2.3, 3.0], rand(4); extrapolation_bc=Periodic());
427+
julia> etp = linear_interpolation([1.0, 1.2, 2.3, 3.0], rand(4); extrapolation_bc=Periodic());
428428
429429
julia> knotsbetween(etp; start=38, stop=42) |> collect
430430
6-element $(Array{typeof(1.0),1}):

0 commit comments

Comments
 (0)