Skip to content

Commit 0729fff

Browse files
committed
Use zero and oneunit in place of one
In Julia 0.6, a distinction is made between one(T) (multiplicative identity) and oneunit(T) ("1" of type T). In essentially every place we mean oneunit rather than one. However, packages like StaticArrays (for multivalued interpolation) don't define either, but `zero` will work for us. Also deletes Interpolations-old.jl, which I don't think has a purpose.
1 parent 94240ba commit 0729fff

File tree

8 files changed

+24
-283
lines changed

8 files changed

+24
-283
lines changed

src/Interpolations-old.jl

Lines changed: 0 additions & 261 deletions
This file was deleted.

src/Interpolations.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ import Base: convert, size, indices, getindex, gradient, promote_rule,
4343
# Julia v0.5 compatibility
4444
if isdefined(:scaling) import Base.scaling end
4545
if isdefined(:scale) import Base.scale end
46+
if !isdefined(Base, :oneunit)
47+
const oneunit = one
48+
end
4649

4750
@compat abstract type Flag end
4851
@compat abstract type InterpolationType <: Flag end

src/b-splines/b-splines.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ function BSplineInterpolation{N,Tel,TWeights<:Real,IT<:DimSpec{BSpline},GT<:DimS
2121
isleaftype(IT) || error("The b-spline type must be a leaf type (was $IT)")
2222
isleaftype(typeof(A)) || warn("For performance reasons, consider using an array of a concrete type (typeof(A) == $(typeof(A)))")
2323

24-
c = one(TWeights)
24+
c = zero(TWeights)
2525
for _ in 2:N
2626
c *= c
2727
end
28-
T = typeof(c * one(Tel))
28+
T = typeof(c * zero(Tel))
2929

3030
BSplineInterpolation{T,N,typeof(A),IT,GT,pad}(A)
3131
end

src/b-splines/cubic.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ Applying this condition yields
187187
function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
188188
::Type{Cubic{Flat}}, ::Type{OnGrid})
189189
dl, d, du = inner_system_diags(T, n, Cubic{Flat})
190-
d[1] = d[end] = -one(T)
190+
d[1] = d[end] = -oneunit(T)
191191
du[1] = dl[end] = zero(T)
192192

193193
# Now Woodbury correction to set `[1, 3], [n, n-2] ==> 1`
194-
specs = WoodburyMatrices.sparse_factors(T, n, (1, 3, one(T)), (n, n-2, one(T)))
194+
specs = WoodburyMatrices.sparse_factors(T, n, (1, 3, oneunit(T)), (n, n-2, oneunit(T)))
195195

196196
Woodbury(lufact!(Tridiagonal(dl, d, du), Val{false}), specs...), zeros(TC, n)
197197
end
@@ -222,8 +222,8 @@ function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
222222
specs = WoodburyMatrices.sparse_factors(T, n,
223223
(1, 3, T(-3)),
224224
(n, n-2, T(-3)),
225-
(1, 4, one(T)),
226-
(n, n-3, one(T))
225+
(1, 4, oneunit(T)),
226+
(n, n-3, oneunit(T))
227227
)
228228

229229
Woodbury(lufact!(Tridiagonal(dl, d, du), Val{false}), specs...), zeros(TC, n)
@@ -251,8 +251,8 @@ function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
251251
specs = WoodburyMatrices.sparse_factors(T, n,
252252
(1, 3, T(5)),
253253
(n, n-2, T(5)),
254-
(1, 4, -one(T)),
255-
(n, n-3, -one(T))
254+
(1, 4, -oneunit(T)),
255+
(n, n-3, -oneunit(T))
256256
)
257257

258258
Woodbury(lufact!(Tridiagonal(dl, d, du), Val{false}), specs...), zeros(TC, n)
@@ -273,8 +273,8 @@ function prefiltering_system{T,TC}(::Type{T}, ::Type{TC}, n::Int,
273273
# now need Woodbury correction to set :
274274
# - [1, 3] and [n, n-2] ==> 1
275275
specs = WoodburyMatrices.sparse_factors(T, n,
276-
(1, 3, one(T)),
277-
(n, n-2, one(T)),
276+
(1, 3, oneunit(T)),
277+
(n, n-2, oneunit(T)),
278278
)
279279

280280
Woodbury(lufact!(Tridiagonal(dl, d, du), Val{false}), specs...), zeros(TC, n)

src/b-splines/quadratic.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ function prefiltering_system{T,TC,BC<:Union{Flat,Reflect}}(::Type{T}, ::Type{TC}
198198
du[1] = dl[end] = 0
199199

200200
specs = WoodburyMatrices.sparse_factors(T, n,
201-
(1, 3, one(T)),
202-
(n, n-2, one(T))
201+
(1, 3, oneunit(T)),
202+
(n, n-2, oneunit(T))
203203
)
204204

205205
Woodbury(lufact!(Tridiagonal(dl, d, du), Val{false}), specs...), zeros(TC, n)
@@ -218,8 +218,8 @@ function prefiltering_system{T,TC,GT<:GridType}(::Type{T}, ::Type{TC}, n::Int, :
218218
du[1] = dl[end] = -2
219219

220220
specs = WoodburyMatrices.sparse_factors(T, n,
221-
(1, 3, one(T)),
222-
(n, n-2, one(T)),
221+
(1, 3, oneunit(T)),
222+
(n, n-2, oneunit(T)),
223223
)
224224

225225
Woodbury(lufact!(Tridiagonal(dl, d, du), Val{false}), specs...), zeros(TC, n)

src/gridded/gridded.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ function GriddedInterpolation{N,TCoefs,TWeights<:Real,IT<:DimSpec{Gridded},pad}(
2424
issorted(k) || error("knot-vectors must be sorted in increasing order")
2525
iextract(IT, d) != NoInterp || k == collect(1:size(A, d)) || error("knot-vector should be the range 1:$(size(A,d)) for the method Gridded{NoInterp}")
2626
end
27-
c = one(TWeights)
27+
c = zero(TWeights)
2828
for _ in 2:N
2929
c *= c
3030
end
31-
T = typeof(c * one(TCoefs))
31+
T = typeof(c * zero(TCoefs))
3232

3333
GriddedInterpolation{T,N,TCoefs,IT,typeof(knts),pad}(knts, A)
3434
end

src/scaling/scaling.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ Returns *half* the width of one step of the range.
6868
This function is used to calculate the upper and lower bounds of `OnCell` interpolation objects.
6969
""" boundstep
7070

71-
coordlookup(r::UnitRange, x) = x - r.start + one(eltype(r))
71+
coordlookup(r::UnitRange, x) = x - r.start + oneunit(eltype(r))
7272
coordlookup(i::Bool, r::Range, x) = i ? coordlookup(r, x) : convert(typeof(coordlookup(r,x)), x)
73-
coordlookup(r::StepRange, x) = (x - r.start) / r.step + one(eltype(r))
73+
coordlookup(r::StepRange, x) = (x - r.start) / r.step + oneunit(eltype(r))
7474

7575
@static if isdefined(:StepRangeLen)
76-
coordlookup(r::StepRangeLen, x) = (x - first(r)) / step(r) + one(eltype(r))
76+
coordlookup(r::StepRangeLen, x) = (x - first(r)) / step(r) + oneunit(eltype(r))
7777
boundstep(r::StepRangeLen) = 0.5*step(r)
7878
rescale_gradient(r::StepRangeLen, g) = g / step(r)
7979
end
@@ -113,7 +113,7 @@ rescale_gradient(r::UnitRange, g) = g
113113
rescale_gradient(r::LinSpace, g) = g * r.divisor / (r.stop - r.start)
114114
rescale_gradient(r::FloatRange, g) = g * r.divisor / r.step
115115
coordlookup(r::LinSpace, x) = (r.divisor * x + r.stop - r.len * r.start) / (r.stop - r.start)
116-
coordlookup(r::FloatRange, x) = (r.divisor * x - r.start) / r.step + one(eltype(r))
116+
coordlookup(r::FloatRange, x) = (r.divisor * x - r.start) / r.step + oneunit(eltype(r))
117117
boundstep(r::LinSpace) = ((r.stop - r.start) / r.divisor) / 2
118118
boundstep(r::FloatRange) = r.step / 2
119119
end

0 commit comments

Comments
 (0)