Skip to content

Commit

Permalink
Fix deprecation warnings in test (#22)
Browse files Browse the repository at this point in the history
* Add seed in landscape plot

* Update README.md

* Remove deprecation warnings with the latest version of Flux
  • Loading branch information
mBarreau committed Mar 16, 2023
1 parent da0dcce commit bb94989
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/FluxOptTools.jl
Expand Up @@ -27,13 +27,13 @@ function optfuns(loss, pars::Union{Flux.Params, Zygote.Params})
end
fg! = function (F,G,w)
copy!(pars, w)
if G != nothing
if !isnothing(G)
l, back = Zygote.pullback(loss, pars)
grads = back(1)
copy!(G, grads)
return l
end
if F != nothing
if !isnothing(F)
return loss()
end
end
Expand Down
14 changes: 7 additions & 7 deletions test/runtests.jl
Expand Up @@ -11,7 +11,7 @@ using FluxOptTools, Optim, Zygote, Flux, Plots, Test, Statistics, Random
@info "Testing copy"

m = Chain(Dense(1,5,tanh), Dense(5,5,tanh) , Dense(5,1))
x = collect(LinRange(-pi,pi,100)')
x = collect(LinRange{Float32}(-pi,pi,100)')
y = sin.(x)
sp = sortperm(x[:])

Expand Down Expand Up @@ -50,7 +50,7 @@ end
# NOTE: tests below fail if they are in a testset, probably Zygote's fault

m = Chain(Dense(1,5,tanh), Dense(5,5,tanh) , Dense(5,1))
x = collect(LinRange(-pi,pi,100)')
x = collect(LinRange{Float32}(-pi,pi,100)')
y = sin.(x)
sp = sortperm(x[:])

Expand All @@ -59,7 +59,7 @@ loss() = mean(abs2, m(x) .- y)
Zygote.refresh()
pars = Flux.params(m)

opt = ADAM(0.01)
opt = Flux.Adam(0.01)
@show loss()
for i = 1:500
grads = Zygote.gradient(loss, pars)
Expand All @@ -84,12 +84,12 @@ losses_adam = map(1:10) do i
@show i
Random.seed!(i)
m = Chain(Dense(1,5,tanh), Dense(5,5,tanh) , Dense(5,1))
x = collect(LinRange(-pi,pi,100)')
x = collect(LinRange{Float32}(-pi,pi,100)')
y = sin.(x)
loss() = mean(abs2, m(x) .- y)
Zygote.refresh()
pars = Flux.params(m)
opt = Flux.ADAM(0.2)
opt = Flux.Adam(0.2)
trace = [loss()]
for i = 1:500
l,back = Zygote.pullback(loss, pars)
Expand All @@ -104,7 +104,7 @@ res_lbfgs = map(1:10) do i
@show i
Random.seed!(i)
m = Chain(Dense(1,5,tanh), Dense(5,5,tanh) , Dense(5,1))
x = LinRange(-pi,pi,100)'
x = LinRange{Float32}(-pi,pi,100)'
y = sin.(x)
loss() = mean(abs2, m(x) .- y)
Zygote.refresh()
Expand All @@ -118,7 +118,7 @@ losses_SLBFGS = map(1:10) do i
@show i
Random.seed!(i)
m = Chain(Dense(1,5,tanh), Dense(5,5,tanh) , Dense(5,1))
x = LinRange(-pi,pi,100)'
x = LinRange{Float32}(-pi,pi,100)'
y = sin.(x)
loss() = mean(abs2, m(x) .- y)
Zygote.refresh()
Expand Down

0 comments on commit bb94989

Please sign in to comment.