Merge pull request #485 from dhairyagandhi96/master

Add call back
This commit is contained in:
Mike J Innes 2018-11-08 13:18:17 +00:00 committed by GitHub
commit 5e572df557
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -11,6 +11,7 @@ function update!(opt, xs)
end
# Callback niceties
call(f, xs...) = f(xs...)
runall(f) = f
runall(fs::AbstractVector) = () -> foreach(call, fs)

View File

@ -1,4 +1,5 @@
using Flux.Optimise
using Flux.Optimise: runall
using Flux.Tracker
using Test
@testset "Optimise" begin
@ -50,4 +51,11 @@ end
cb = Flux.throttle(() -> (i > 3 && Flux.stop()), 1))
@test 3 < i < 50
# Test multiple callbacks
x = 0
fs = [() -> (), () -> x = 1]
cbs = runall(fs)
cbs()
@test x == 1
end