Skip to content

Commit

Permalink
Merge 297fa17 into 3f62885
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 4, 2018
2 parents 3f62885 + 297fa17 commit 3e00e21
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 41 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
language: julia
julia:
- 0.6
# - 0.7
- nightly
matrix:
allow_failures:
- julia: nightly
# matrix:
# allow_failures:
# - julia: nightly
notifications:
email: false
sudo: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'include(joinpath(JULIA_HOME, Base.DATAROOTDIR, "julia", "build_sysimg.jl")); build_sysimg(force=true)';
- julia -e 'Pkg.clone(pwd()); Pkg.build("ForwardDiff"); Pkg.test("ForwardDiff"; coverage=true)';
- julia -O3 -e 'include(joinpath(Pkg.dir("ForwardDiff"), "test/SIMDTest.jl"))';
- julia -O3 -e 'Pkg.add("Compat"); include(joinpath(Pkg.dir("ForwardDiff"), "test/SIMDTest.jl"))';
after_success:
- julia -e 'cd(Pkg.dir("ForwardDiff")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'Pkg.add("Documenter")'
Expand Down
4 changes: 4 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
# - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.7/julia-0.7-latest-win32.exe"
# - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.7/julia-0.7-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
Expand Down
6 changes: 5 additions & 1 deletion test/ConfusionTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ using Compat
using Compat.Test
using ForwardDiff

using Compat.LinearAlgebra: norm, dot
const cholesky = isdefined(Compat.LinearAlgebra, :cholesky) ?
Compat.LinearAlgebra.cholesky : Compat.LinearAlgebra.cholfact

# Perturbation Confusion (Issue #83) #
#------------------------------------#

Expand Down Expand Up @@ -44,7 +48,7 @@ function Legendre_transformation(F, w)
z = fill(0.0, size(w))
M = ForwardDiff.hessian(F, z)
b = ForwardDiff.gradient(F, z)
v = cholfact(M)\(w-b)
v = cholesky(M)\(w-b)
dot(w,v) - F(v)
end
function Lagrangian2Hamiltonian(Lagrangian, t, q, p)
Expand Down
1 change: 1 addition & 0 deletions test/DerivativeTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Calculus

using Compat
using Compat.Test
using Compat.Random
using ForwardDiff
using DiffTests

Expand Down
1 change: 1 addition & 0 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module DualTest

using Compat
using Compat.Test
using Compat.Random
using ForwardDiff
using ForwardDiff: Partials, Dual, value, partials

Expand Down
4 changes: 2 additions & 2 deletions test/GradientTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ v = f(x)
g = [-9.4, 15.6, 52.0]

for c in (1, 2, 3), tag in (nothing, Tag(f, eltype(x)))
println(" ...running hardcoded test with chunk size = $c and tag = $tag")
println(" ...running hardcoded test with chunk size = $c and tag = $(repr(tag))")
cfg = ForwardDiff.GradientConfig(f, x, ForwardDiff.Chunk{c}(), tag)

@test eltype(cfg) == Dual{typeof(tag), eltype(x), c}
Expand Down Expand Up @@ -61,7 +61,7 @@ for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
g = ForwardDiff.gradient(f, X)
@test isapprox(g, Calculus.gradient(f, X), atol=FINITEDIFF_ERROR)
for c in CHUNK_SIZES, tag in (nothing, Tag(f, eltype(x)))
println(" ...testing $f with chunk size = $c and tag = $tag")
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
cfg = ForwardDiff.GradientConfig(f, X, ForwardDiff.Chunk{c}(), tag)

out = ForwardDiff.gradient(f, X, cfg)
Expand Down
8 changes: 4 additions & 4 deletions test/HessianTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ h = [-66.0 -40.0 0.0;
-40.0 130.0 -80.0;
0.0 -80.0 200.0]

for c in (1, 2, 3), tag in (nothing, Tag((f,gradient), eltype(x)))
println(" ...running hardcoded test with chunk size = $c and tag = $tag")
for c in (1, 2, 3), tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
println(" ...running hardcoded test with chunk size = $c and tag = $(repr(tag))")
cfg = ForwardDiff.HessianConfig(f, x, ForwardDiff.Chunk{c}(), tag)
resultcfg = ForwardDiff.HessianConfig(f, DiffResults.HessianResult(x), x, ForwardDiff.Chunk{c}(), tag)

Expand Down Expand Up @@ -69,8 +69,8 @@ for f in DiffTests.VECTOR_TO_NUMBER_FUNCS
h = ForwardDiff.hessian(f, X)
# finite difference approximation error is really bad for Hessians...
@test isapprox(h, Calculus.hessian(f, X), atol=0.02)
for c in CHUNK_SIZES, tag in (nothing, Tag((f,gradient), eltype(x)))
println(" ...testing $f with chunk size = $c and tag = $tag")
for c in CHUNK_SIZES, tag in (nothing, Tag((f,ForwardDiff.gradient), eltype(x)))
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
cfg = ForwardDiff.HessianConfig(f, X, ForwardDiff.Chunk{c}(), tag)
resultcfg = ForwardDiff.HessianConfig(f, DiffResults.HessianResult(X), X, ForwardDiff.Chunk{c}(), tag)

Expand Down
43 changes: 23 additions & 20 deletions test/JacobianTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ j = [0.8242369704835132 0.4121184852417566 -10.933563142616123

for c in (1, 2, 3), tags in ((nothing, nothing),
(Tag(f, eltype(x)), Tag(f!, eltype(x))))
println(" ...running hardcoded test with chunk size = $c and tag = $tags")
println(" ...running hardcoded test with chunk size = $c and tag = $(repr(tags))")
cfg = JacobianConfig(f, x, ForwardDiff.Chunk{c}(), tags[1])
ycfg = JacobianConfig(f!, fill(0.0, 4), x, ForwardDiff.Chunk{c}(), tags[2])

Expand Down Expand Up @@ -108,7 +108,7 @@ for f in DiffTests.ARRAY_TO_ARRAY_FUNCS
if tag == Tag
tag = Tag(f, eltype(X))
end
println(" ...testing $f with chunk size = $c and tag = $tag")
println(" ...testing $f with chunk size = $c and tag = $(repr(tag))")
cfg = JacobianConfig(f, X, ForwardDiff.Chunk{c}(), tag)

out = ForwardDiff.jacobian(f, X, cfg)
Expand All @@ -131,7 +131,7 @@ for f! in DiffTests.INPLACE_ARRAY_TO_ARRAY_FUNCS
j = ForwardDiff.jacobian(f!, fill!(similar(Y), 0.0), X)
@test isapprox(j, Calculus.jacobian(x -> (y = fill!(similar(Y), 0.0); f!(y, x); vec(y)), X, :forward), atol=FINITEDIFF_ERROR)
for c in CHUNK_SIZES, tag in (nothing, Tag(f!, eltype(X)))
println(" ...testing $(f!) with chunk size = $c and tag = $tag")
println(" ...testing $(f!) with chunk size = $c and tag = $(repr(tag))")
ycfg = JacobianConfig(f!, fill!(similar(Y), 0.0), X, ForwardDiff.Chunk{c}(), tag)

y = fill!(similar(Y), 0.0)
Expand Down Expand Up @@ -173,35 +173,38 @@ sx = StaticArrays.SArray{Tuple{3,3}}(x)
cfg = ForwardDiff.JacobianConfig(nothing, x)
scfg = ForwardDiff.JacobianConfig(nothing, sx)

actual = ForwardDiff.jacobian(diff, x)
@test ForwardDiff.jacobian(diff, sx) == actual
@test ForwardDiff.jacobian(diff, sx, cfg) == actual
@test ForwardDiff.jacobian(diff, sx, scfg) == actual
@test ForwardDiff.jacobian(diff, sx, scfg) isa StaticArray
@test ForwardDiff.jacobian(diff, sx, scfg, Val{false}()) == actual
@test ForwardDiff.jacobian(diff, sx, scfg, Val{false}()) isa StaticArray
_diff(A) = VERSION < v"0.7.0-DEV.4861" ? diff(A, 1) : diff(A; dims=1)
_diff(A::StaticArray) = diff(A) # StaticArray's don't use dims kwarg (yet)

actual = ForwardDiff.jacobian(_diff, x)
@test ForwardDiff.jacobian(_diff, sx) == actual
@test ForwardDiff.jacobian(_diff, sx, cfg) == actual
@test ForwardDiff.jacobian(_diff, sx, scfg) == actual
@test ForwardDiff.jacobian(_diff, sx, scfg) isa StaticArray
@test ForwardDiff.jacobian(_diff, sx, scfg, Val{false}()) == actual
@test ForwardDiff.jacobian(_diff, sx, scfg, Val{false}()) isa StaticArray

out = similar(x, 6, 9)
ForwardDiff.jacobian!(out, diff, sx)
ForwardDiff.jacobian!(out, _diff, sx)
@test out == actual

out = similar(x, 6, 9)
ForwardDiff.jacobian!(out, diff, sx, cfg)
ForwardDiff.jacobian!(out, _diff, sx, cfg)
@test out == actual

out = similar(x, 6, 9)
ForwardDiff.jacobian!(out, diff, sx, scfg)
ForwardDiff.jacobian!(out, _diff, sx, scfg)
@test out == actual

result = DiffResults.JacobianResult(similar(x, 6), x)
result = ForwardDiff.jacobian!(result, diff, x)
result = ForwardDiff.jacobian!(result, _diff, x)

result1 = DiffResults.JacobianResult(similar(sx, 6), sx)
result2 = DiffResults.JacobianResult(similar(sx, 6), sx)
result3 = DiffResults.JacobianResult(similar(sx, 6), sx)
result1 = ForwardDiff.jacobian!(result1, diff, sx)
result2 = ForwardDiff.jacobian!(result2, diff, sx, cfg)
result3 = ForwardDiff.jacobian!(result3, diff, sx, scfg)
result1 = ForwardDiff.jacobian!(result1, _diff, sx)
result2 = ForwardDiff.jacobian!(result2, _diff, sx, cfg)
result3 = ForwardDiff.jacobian!(result3, _diff, sx, scfg)
@test DiffResults.value(result1) == DiffResults.value(result)
@test DiffResults.value(result2) == DiffResults.value(result)
@test DiffResults.value(result3) == DiffResults.value(result)
Expand All @@ -213,9 +216,9 @@ sy = @SVector fill(zero(eltype(sx)), 6)
sresult1 = DiffResults.JacobianResult(sy, sx)
sresult2 = DiffResults.JacobianResult(sy, sx)
sresult3 = DiffResults.JacobianResult(sy, sx)
sresult1 = ForwardDiff.jacobian!(sresult1, diff, sx)
sresult2 = ForwardDiff.jacobian!(sresult2, diff, sx, cfg)
sresult3 = ForwardDiff.jacobian!(sresult3, diff, sx, scfg)
sresult1 = ForwardDiff.jacobian!(sresult1, _diff, sx)
sresult2 = ForwardDiff.jacobian!(sresult2, _diff, sx, cfg)
sresult3 = ForwardDiff.jacobian!(sresult3, _diff, sx, scfg)
@test DiffResults.value(sresult1) == DiffResults.value(result)
@test DiffResults.value(sresult2) == DiffResults.value(result)
@test DiffResults.value(sresult3) == DiffResults.value(result)
Expand Down
3 changes: 2 additions & 1 deletion test/MiscTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Compat
using Compat.Test
using ForwardDiff
using DiffTests
using Compat.SparseArrays: sparse

include(joinpath(dirname(@__FILE__), "utils.jl"))

Expand Down Expand Up @@ -114,7 +115,7 @@ N = 4
a = fill(1.0, N)
jac0 = reshape(vcat([[fill(0.0, N*(i-1)); a; fill(0.0, N^2-N*i)] for i = 1:N]...), N^2, N)

for op in (:-, :+, :.-, :.+, :./, :.*)
for op in (:.-, :.+, :./, :.*)
f = @eval x -> [$op(x[1], a); $op(x[2], a); $op(x[3], a); $op(x[4], a)]
jac = @eval ForwardDiff.jacobian(f, a)
@test isapprox(jac0, jac)
Expand Down
1 change: 1 addition & 0 deletions test/PartialsTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module PartialsTest

using Compat
using Compat.Test
using Compat.Random
using ForwardDiff
using ForwardDiff: Partials

Expand Down
19 changes: 10 additions & 9 deletions test/SIMDTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module SIMDTest
using Compat
using Compat.Test
using ForwardDiff: Dual, valtype
using Compat.InteractiveUtils

const DUALS = (Dual(1., 2., 3., 4.),
Dual(1., 2., 3., 4., 5.),
Expand All @@ -19,28 +20,28 @@ end

for D in map(typeof, DUALS)
plus_bitcode = sprint(io -> code_llvm(io, +, (D, D)))
@test contains(plus_bitcode, "fadd <4 x double>")
@test Compat.occursin("fadd <4 x double>", plus_bitcode)

minus_bitcode = sprint(io -> code_llvm(io, -, (D, D)))
@test contains(minus_bitcode, "fsub <4 x double>")
@test Compat.occursin("fsub <4 x double>", minus_bitcode)

times_bitcode = sprint(io -> code_llvm(io, *, (D, D)))
@test ismatch(r"fadd \<.*?x double\>", times_bitcode)
@test ismatch(r"fmul \<.*?x double\>", times_bitcode)
@test Compat.occursin(r"fadd \<.*?x double\>", times_bitcode)
@test Compat.occursin(r"fmul \<.*?x double\>", times_bitcode)

div_bitcode = sprint(io -> code_llvm(io, /, (D, D)))
@test ismatch(r"fadd \<.*?x double\>", div_bitcode)
@test ismatch(r"fmul \<.*?x double\>", div_bitcode)
@test Compat.occursin(r"fadd \<.*?x double\>", div_bitcode)
@test Compat.occursin(r"fmul \<.*?x double\>", div_bitcode)

exp_bitcode = sprint(io -> code_llvm(io, ^, (D, D)))
@test ismatch(r"fadd \<.*?x double\>", exp_bitcode)
@test Compat.occursin(r"fadd \<.*?x double\>", exp_bitcode)
if !(valtype(D) <: Dual)
# see https://github.com/JuliaDiff/ForwardDiff.jl/issues/167
@test ismatch(r"fmul \<.*?x double\>", exp_bitcode)
@test Compat.occursin(r"fmul \<.*?x double\>", exp_bitcode)

# see https://github.com/JuliaDiff/ForwardDiff.jl/pull/201
sum_bitcode = sprint(io -> code_llvm(io, simd_sum, (Vector{D},)))
@test ismatch(r"fadd \<.*?x double\>", sum_bitcode)
@test Compat.occursin(r"fadd (fast |)\<.*?x double\>", sum_bitcode)
end
end

Expand Down
1 change: 1 addition & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ForwardDiff
using ForwardDiff: DEFAULT_CHUNK_THRESHOLD
using Compat
using Compat.Test
using Compat.Random

# seed RNG, thus making result inaccuracies deterministic
# so we don't have to retune EPS for arbitrary inputs
Expand Down

0 comments on commit 3e00e21

Please sign in to comment.