Skip to content

Remove if VERSION ≥ v"1.4" etc. #616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/ForwardDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ module ForwardDiff
using DiffRules, DiffResults
using DiffResults: DiffResult, MutableDiffResult, ImmutableDiffResult
using StaticArrays
if VERSION >= v"1.6"
using Preferences
end
using Preferences
using Random
using LinearAlgebra

Expand Down
19 changes: 6 additions & 13 deletions src/dual.jl
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,7 @@ Base.cld(x::Dual, y::Dual) = cld(value(x), value(y))

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

if VERSION ≥ v"1.4"
Base.div(x::Dual, y::Dual, r::RoundingMode) = div(value(x), value(y), r)
else
Base.div(x::Dual, y::Dual) = div(value(x), value(y))
end
Base.div(x::Dual, y::Dual, r::RoundingMode) = div(value(x), value(y), r)

Base.hash(d::Dual) = hash(value(d))
Base.hash(d::Dual, hsh::UInt) = hash(value(d), hsh)
Expand Down Expand Up @@ -697,6 +693,7 @@ end

# sin/cos #
#--------#

function Base.sin(d::Dual{T}) where T
s, c = sincos(value(d))
return Dual{T}(s, c * partials(d))
Expand All @@ -715,11 +712,9 @@ end
# sincospi #
#----------#

if VERSION >= v"1.6.0-DEV.292"
@inline function Base.sincospi(d::Dual{T}) where T
sd, cd = sincospi(value(d))
return (Dual{T}(sd, cd * π * partials(d)), Dual{T}(cd, -sd * π * partials(d)))
end
@inline function Base.sincospi(d::Dual{T}) where T
sd, cd = sincospi(value(d))
return (Dual{T}(sd, cd * π * partials(d)), Dual{T}(cd, -sd * π * partials(d)))
end

# Symmetric eigvals #
Expand Down Expand Up @@ -816,6 +811,4 @@ for op in (:(Base.typemin), :(Base.typemax), :(Base.floatmin), :(Base.floatmax))
end
end

if VERSION >= v"1.6.0-rc1"
Printf.tofloat(d::Dual) = Printf.tofloat(value(d))
end
Printf.tofloat(d::Dual) = Printf.tofloat(value(d))
9 changes: 2 additions & 7 deletions src/prelude.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
@static if VERSION >= v"1.6"
const NANSAFE_MODE_ENABLED = @load_preference("nansafe_mode", false)
const DEFAULT_CHUNK_THRESHOLD = @load_preference("default_chunk_threshold", 12)
else
const NANSAFE_MODE_ENABLED = false
const DEFAULT_CHUNK_THRESHOLD = 12
end
const NANSAFE_MODE_ENABLED = @load_preference("nansafe_mode", false)
const DEFAULT_CHUNK_THRESHOLD = @load_preference("default_chunk_threshold", 12)

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

Expand Down
24 changes: 9 additions & 15 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,8 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
@test div(NESTED_FDNUM, PRIMAL2) === div(PRIMAL, PRIMAL2)
@test div(PRIMAL, NESTED_FDNUM2) === div(PRIMAL, PRIMAL2)

if VERSION ≥ v"1.4"
@test div(FDNUM, FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
@test div(NESTED_FDNUM, NESTED_FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
end
@test div(FDNUM, FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)
@test div(NESTED_FDNUM, NESTED_FDNUM2, RoundUp) === div(PRIMAL, PRIMAL2, RoundUp)

@test Base.rtoldefault(typeof(FDNUM)) ≡ Base.rtoldefault(typeof(PRIMAL))
@test Dual{TestTag()}(PRIMAL-eps(V), PARTIALS) ≈ FDNUM
Expand Down Expand Up @@ -554,9 +552,7 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false

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

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

if V === Float32
@test typeof(sqrt(FDNUM)) === typeof(FDNUM)
Expand Down Expand Up @@ -589,7 +585,7 @@ ForwardDiff.:≺(::Type{OuterTestTag}, ::Type{TestTag}) = false
@test pq isa Tuple{Dual{TestTag()},Dual{TestTag()}}
# We have to adjust tolerances if lower accuracy is requested
# Therefore we don't use `dual_isapprox`
tol = V === Float32 ? 5f-4 : 1e-6
tol = V === Float32 ? 5f-4 : 1e-5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tol = tol^(one(tol) / 2^(isempty(ind) ? 0 : first(ind)))
for i in 1:2
@test value(pq[i]) ≈ gamma_inc(a, 1 + PRIMAL, ind...)[i] rtol=tol
Expand Down Expand Up @@ -648,13 +644,11 @@ end
@test length(UnitRange(Dual(1.5,1), Dual(3.5,3))) == 3
end

if VERSION >= v"1.6.0-rc1"
@testset "@printf" begin
for T in (Float16, Float32, Float64, BigFloat)
d1 = Dual(one(T))
@test_nowarn @printf("Testing @printf: %.2e\n", d1)
@test @sprintf("Testing @sprintf: %.2e\n", d1) == "Testing @sprintf: 1.00e+00\n"
end
@testset "@printf" begin
for T in (Float16, Float32, Float64, BigFloat)
d1 = Dual(one(T))
@test_nowarn @printf("Testing @printf: %.2e\n", d1)
@test @sprintf("Testing @sprintf: %.2e\n", d1) == "Testing @sprintf: 1.00e+00\n"
end
end

Expand Down
14 changes: 6 additions & 8 deletions test/GradientTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,13 @@ end
# Issue 536, version with 3-arg *, Julia 1.7:
@test ForwardDiff.derivative(x -> sum(x*a*b), 0.0) ≈ sum(a * b)

if VERSION >= v"1.3"
# version with just mul!
dx = ForwardDiff.derivative(0.0) do x
c = similar(a, typeof(x))
mul!(c, a, b, x, false)
sum(c)
end
@test dx ≈ sum(a * b)
# version with just mul!
dx = ForwardDiff.derivative(0.0) do x
c = similar(a, typeof(x))
mul!(c, a, b, x, false)
sum(c)
end
@test dx ≈ sum(a * b)
end

end # module
12 changes: 5 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,10 @@ Random.seed!(SEED)
t = @elapsed include("MiscTest.jl")
println("##### done (took $t seconds).")
end
if VERSION >= v"1.5-"
@testset "Allocations" begin
println("##### Testing allocations...")
t = @elapsed include("AllocationsTest.jl")
println("##### done (took $t seconds).")
end
@testset "Allocations" begin
println("##### Testing allocations...")
t = @elapsed include("AllocationsTest.jl")
println("##### done (took $t seconds).")
end
println("##### Running all ForwardDiff tests took $(time() - t0) seconds.")
end
end