Skip to content

Commit 60a6230

Browse files
authored
Remove if VERSION ≥ v"1.4" etc. (#616)
* Update dual.jl * Update prelude.jl * Update ForwardDiff.jl * Update GradientTest.jl * Update DualTest.jl * adjust tolerance for gamma_inc test * Update runtests.jl
1 parent 5e0c94d commit 60a6230

File tree

6 files changed

+29
-53
lines changed

6 files changed

+29
-53
lines changed

src/ForwardDiff.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ module ForwardDiff
33
using DiffRules, DiffResults
44
using DiffResults: DiffResult, MutableDiffResult, ImmutableDiffResult
55
using StaticArrays
6-
if VERSION >= v"1.6"
7-
using Preferences
8-
end
6+
using Preferences
97
using Random
108
using LinearAlgebra
119

src/dual.jl

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,7 @@ Base.cld(x::Dual, y::Dual) = cld(value(x), value(y))
334334

335335
Base.exponent(x::Dual) = exponent(value(x))
336336

337-
if VERSION v"1.4"
338-
Base.div(x::Dual, y::Dual, r::RoundingMode) = div(value(x), value(y), r)
339-
else
340-
Base.div(x::Dual, y::Dual) = div(value(x), value(y))
341-
end
337+
Base.div(x::Dual, y::Dual, r::RoundingMode) = div(value(x), value(y), r)
342338

343339
Base.hash(d::Dual) = hash(value(d))
344340
Base.hash(d::Dual, hsh::UInt) = hash(value(d), hsh)
@@ -697,6 +693,7 @@ end
697693

698694
# sin/cos #
699695
#--------#
696+
700697
function Base.sin(d::Dual{T}) where T
701698
s, c = sincos(value(d))
702699
return Dual{T}(s, c * partials(d))
@@ -715,11 +712,9 @@ end
715712
# sincospi #
716713
#----------#
717714

718-
if VERSION >= v"1.6.0-DEV.292"
719-
@inline function Base.sincospi(d::Dual{T}) where T
720-
sd, cd = sincospi(value(d))
721-
return (Dual{T}(sd, cd * π * partials(d)), Dual{T}(cd, -sd * π * partials(d)))
722-
end
715+
@inline function Base.sincospi(d::Dual{T}) where T
716+
sd, cd = sincospi(value(d))
717+
return (Dual{T}(sd, cd * π * partials(d)), Dual{T}(cd, -sd * π * partials(d)))
723718
end
724719

725720
# Symmetric eigvals #
@@ -816,6 +811,4 @@ for op in (:(Base.typemin), :(Base.typemax), :(Base.floatmin), :(Base.floatmax))
816811
end
817812
end
818813

819-
if VERSION >= v"1.6.0-rc1"
820-
Printf.tofloat(d::Dual) = Printf.tofloat(value(d))
821-
end
814+
Printf.tofloat(d::Dual) = Printf.tofloat(value(d))

src/prelude.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
@static if VERSION >= v"1.6"
2-
const NANSAFE_MODE_ENABLED = @load_preference("nansafe_mode", false)
3-
const DEFAULT_CHUNK_THRESHOLD = @load_preference("default_chunk_threshold", 12)
4-
else
5-
const NANSAFE_MODE_ENABLED = false
6-
const DEFAULT_CHUNK_THRESHOLD = 12
7-
end
1+
const NANSAFE_MODE_ENABLED = @load_preference("nansafe_mode", false)
2+
const DEFAULT_CHUNK_THRESHOLD = @load_preference("default_chunk_threshold", 12)
83

94
const AMBIGUOUS_TYPES = (AbstractFloat, Irrational, Integer, Rational, Real, RoundingMode)
105

test/DualTest.jl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,8 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
178178
@test div(NESTED_FDNUM, PRIMAL2) === div(PRIMAL, PRIMAL2)
179179
@test div(PRIMAL, NESTED_FDNUM2) === div(PRIMAL, PRIMAL2)
180180

181-
if VERSION v"1.4"
182-
@test div(FDNUM, FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
183-
@test div(NESTED_FDNUM, NESTED_FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
184-
end
181+
@test div(FDNUM, FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
182+
@test div(NESTED_FDNUM, NESTED_FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
185183

186184
@test Base.rtoldefault(typeof(FDNUM)) Base.rtoldefault(typeof(PRIMAL))
187185
@test Dual{TestTag()}(PRIMAL-eps(V), PARTIALS) FDNUM
@@ -554,9 +552,7 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
554552

555553
@test all(map(dual_isapprox, ForwardDiff.sincos(FDNUM), (sin(FDNUM), cos(FDNUM))))
556554

557-
if VERSION >= v"1.6.0-DEV.292"
558-
@test all(map(dual_isapprox, sincospi(FDNUM), (sinpi(FDNUM), cospi(FDNUM))))
559-
end
555+
@test all(map(dual_isapprox, sincospi(FDNUM), (sinpi(FDNUM), cospi(FDNUM))))
560556

561557
if V === Float32
562558
@test typeof(sqrt(FDNUM)) === typeof(FDNUM)
@@ -589,7 +585,7 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
589585
@test pq isa Tuple{Dual{TestTag()},Dual{TestTag()}}
590586
# We have to adjust tolerances if lower accuracy is requested
591587
# Therefore we don't use `dual_isapprox`
592-
tol = V === Float32 ? 5f-4 : 1e-6
588+
tol = V === Float32 ? 5f-4 : 1e-5
593589
tol = tol^(one(tol) / 2^(isempty(ind) ? 0 : first(ind)))
594590
for i in 1:2
595591
@test value(pq[i]) gamma_inc(a, 1 + PRIMAL, ind...)[i] rtol=tol
@@ -648,13 +644,11 @@ end
648644
@test length(UnitRange(Dual(1.5,1), Dual(3.5,3))) == 3
649645
end
650646

651-
if VERSION >= v"1.6.0-rc1"
652-
@testset "@printf" begin
653-
for T in (Float16, Float32, Float64, BigFloat)
654-
d1 = Dual(one(T))
655-
@test_nowarn @printf("Testing @printf: %.2e\n", d1)
656-
@test @sprintf("Testing @sprintf: %.2e\n", d1) == "Testing @sprintf: 1.00e+00\n"
657-
end
647+
@testset "@printf" begin
648+
for T in (Float16, Float32, Float64, BigFloat)
649+
d1 = Dual(one(T))
650+
@test_nowarn @printf("Testing @printf: %.2e\n", d1)
651+
@test @sprintf("Testing @sprintf: %.2e\n", d1) == "Testing @sprintf: 1.00e+00\n"
658652
end
659653
end
660654

test/GradientTest.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,13 @@ end
207207
# Issue 536, version with 3-arg *, Julia 1.7:
208208
@test ForwardDiff.derivative(x -> sum(x*a*b), 0.0) sum(a * b)
209209

210-
if VERSION >= v"1.3"
211-
# version with just mul!
212-
dx = ForwardDiff.derivative(0.0) do x
213-
c = similar(a, typeof(x))
214-
mul!(c, a, b, x, false)
215-
sum(c)
216-
end
217-
@test dx sum(a * b)
210+
# version with just mul!
211+
dx = ForwardDiff.derivative(0.0) do x
212+
c = similar(a, typeof(x))
213+
mul!(c, a, b, x, false)
214+
sum(c)
218215
end
216+
@test dx sum(a * b)
219217
end
220218

221219
end # module

test/runtests.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ Random.seed!(SEED)
4646
t = @elapsed include("MiscTest.jl")
4747
println("##### done (took $t seconds).")
4848
end
49-
if VERSION >= v"1.5-"
50-
@testset "Allocations" begin
51-
println("##### Testing allocations...")
52-
t = @elapsed include("AllocationsTest.jl")
53-
println("##### done (took $t seconds).")
54-
end
49+
@testset "Allocations" begin
50+
println("##### Testing allocations...")
51+
t = @elapsed include("AllocationsTest.jl")
52+
println("##### done (took $t seconds).")
5553
end
5654
println("##### Running all ForwardDiff tests took $(time() - t0) seconds.")
57-
end
55+
end

0 commit comments

Comments
 (0)