Skip to content

Commit

Permalink
Merge 9abfe5c into 3f62885
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Jul 15, 2018
2 parents 3f62885 + 9abfe5c commit e4df3c5
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 73 deletions.
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: julia
julia:
- 0.6
- 0.7
- nightly
matrix:
allow_failures:
Expand All @@ -10,10 +10,9 @@ notifications:
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 'include("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("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia -e 'Pkg.add("Documenter")'
- julia -e 'cd(Pkg.dir("ForwardDiff")); include(joinpath("docs", "make.jl"))'
- julia -e 'include("docs/make.jl")'
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
julia 0.6.0
Compat 0.47.0
julia 0.7-beta2
StaticArrays 0.5.0
DiffResults 0.0.1
DiffRules 0.0.4
Expand Down
11 changes: 9 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
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"

matrix:
allow_failures:
- 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
2 changes: 1 addition & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ makedocs(modules=[ForwardDiff],

deploydocs(repo = "github.com/JuliaDiff/ForwardDiff.jl.git",
osname = "linux",
julia = "0.6",
julia = "0.7",
target = "build",
deps = nothing,
make = nothing)
3 changes: 1 addition & 2 deletions src/ForwardDiff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ module ForwardDiff
using DiffRules, DiffResults
using DiffResults: DiffResult, MutableDiffResult, ImmutableDiffResult
using StaticArrays
using Compat
using Compat.Random
using Random

import NaNMath
import SpecialFunctions
Expand Down
7 changes: 4 additions & 3 deletions test/ConfusionTest.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module ConfusionTest

using Compat
using Compat.Test
using Test
using ForwardDiff

using LinearAlgebra

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

Expand Down Expand Up @@ -44,7 +45,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
7 changes: 3 additions & 4 deletions test/DeprecatedTest.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module DeprecatedTest

using Compat
using Compat.Test
using Test
using ForwardDiff, DiffResults

using ForwardDiff: AbstractConfig, GradientConfig,
Expand Down Expand Up @@ -31,7 +30,7 @@ out = DiffResults.HessianResult(x)
N = 1
chunk = ForwardDiff.Chunk{N}()

info("The following tests print lots of deprecation warnings on purpose.")
@info("The following tests print lots of deprecation warnings on purpose.")

@test similar_config(GradientConfig{N}(x), GradientConfig(nothing, x, chunk))
@test similar_config(JacobianConfig{N}(x), JacobianConfig(nothing, x, chunk))
Expand All @@ -40,6 +39,6 @@ info("The following tests print lots of deprecation warnings on purpose.")
@test similar_config(HessianConfig{N}(out, x), HessianConfig(nothing, out, x, chunk))
@test similar_config(MultithreadConfig(GradientConfig(nothing, x, chunk)), GradientConfig(nothing, x, chunk))

info("Deprecation testing is now complete, so any further deprecation warnings are real.")
@info("Deprecation testing is now complete, so any further deprecation warnings are real.")

end # module
4 changes: 2 additions & 2 deletions test/DerivativeTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module DerivativeTest

import Calculus

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

Expand Down
4 changes: 2 additions & 2 deletions test/DualTest.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module DualTest

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

Expand Down
7 changes: 3 additions & 4 deletions test/GradientTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module GradientTest

import Calculus

using Compat
using Compat.Test
using Test
using ForwardDiff
using ForwardDiff: Dual, Tag
using StaticArrays
Expand All @@ -21,7 +20,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 +60,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
11 changes: 5 additions & 6 deletions test/HessianTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module HessianTest

import Calculus

using Compat
using Compat.Test
using Test
using ForwardDiff
using ForwardDiff: Dual, Tag
using StaticArrays
Expand All @@ -23,8 +22,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 +68,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
46 changes: 24 additions & 22 deletions test/JacobianTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ module JacobianTest

import Calculus

using Compat
using Compat.Test
using Test
using ForwardDiff
using ForwardDiff: Dual, Tag, JacobianConfig
using StaticArrays
Expand Down Expand Up @@ -33,7 +32,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 +107,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 +130,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 +172,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) = 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 +215,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
6 changes: 3 additions & 3 deletions test/MiscTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module MiscTest

import NaNMath

using Compat
using Compat.Test
using Test
using ForwardDiff
using DiffTests
using SparseArrays: sparse

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

Expand Down Expand Up @@ -114,7 +114,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
4 changes: 2 additions & 2 deletions test/PartialsTest.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module PartialsTest

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

Expand Down
22 changes: 11 additions & 11 deletions test/SIMDTest.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module SIMDTest

using Compat
using Compat.Test
using Test
using ForwardDiff: Dual, valtype
using InteractiveUtils: code_llvm

const DUALS = (Dual(1., 2., 3., 4.),
Dual(1., 2., 3., 4., 5.),
Expand All @@ -19,28 +19,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 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 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 occursin(r"fadd \<.*?x double\>", times_bitcode)
@test 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 occursin(r"fadd \<.*?x double\>", div_bitcode)
@test 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 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 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 occursin(r"fadd (fast |)\<.*?x double\>", sum_bitcode)
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/utils.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ForwardDiff
using ForwardDiff: DEFAULT_CHUNK_THRESHOLD
using Compat
using Compat.Test
using Test
using 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 e4df3c5

Please sign in to comment.