Skip to content

Commit

Permalink
fix up checks
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Jan 23, 2020
1 parent 186d038 commit 7c635d1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Project.toml
Expand Up @@ -39,9 +39,8 @@ julia = "1"
CUDAapi = "3895d2a7-ec45-59b8-82bb-cfc6a382f9b3"
CuArrays = "3a865a2d-5b23-5a0f-bc46-62713ec82fae"
Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
FiniteDifferences = "25cc04aa-876d-5657-8c51-4c34ba976000"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Distances", "FiniteDifferences", "StatsFuns", "CUDAapi", "CuArrays"]
test = ["Test", "Distances", "StatsFuns", "CUDAapi", "CuArrays"]
9 changes: 6 additions & 3 deletions test/gradcheck.jl
Expand Up @@ -6,15 +6,18 @@ using FiniteDifferences: FiniteDifferences

function ngradient(f, xs::AbstractArray...)
fdm = FiniteDifferences.central_fdm(5,1)
return FiniteDifferences.grad(fdm, xs...)
return FiniteDifferences.grad(fdm, f, xs...)
end

gradcheck(f, xs...) =
all(isapprox.(ngradient(f, xs...),
gradient(f, xs...), rtol = 1e-5, atol = 1e-5))

gradtest(f, xs::AbstractArray...) = gradcheck((xs...) -> sum(sin.(f(xs...))), xs...)
gradtest(f, dims...) = gradtest(f, rand.(Float64, dims)...)
# We generate random matrix with elements between 0.2 and -.7 so we are not close to any
# nondefined areas for common functions
rand27(args...) = 0.2 .+ 0.5.*rand(args...)
gradtest(f, dims...) = gradtest(f, rand27.(Float64, dims)...)

# utilities for using gradcheck with complex matrices
_splitreim(A) = (real(A),)
Expand Down Expand Up @@ -68,7 +71,7 @@ Random.seed!(0)
@test gradtest(x -> x', rand(5))

@test gradtest(det, (4, 4))
@test gradtest(logdet, map(x -> x*x', (rand(4, 4),))[1])
@test gradtest(logdet, map(x -> x*x', (rand27(4, 4),))[1])
@test gradtest(x -> logabsdet(x)[1], (4, 4))

@testset "getindex" begin
Expand Down

0 comments on commit 7c635d1

Please sign in to comment.