Flux.jl
Flux.jl copied to clipboard
Add a macro `@throttle`
trafficstars
We're discussing removing callbacks in favour of just writing a loop.
One nice thing you can do with callbacks is cb = throttle(mysave, 60) to save roughly once a minute, etc. This PR adds a macro that lets you write @throttle 60 mysave() inside your for-loop. It should accept an arbitrary block of code, which may depend on local variables, e.g.:
for i in 1:100
g = ...
@throttle 0.5 begin # macro creates fun(save, m, g, i) = begin ...
save("file", m, g, i)
end
...
(It re-uses the function throttle, and has to eval some things to happen before the loop it's in.)
PR Checklist
- [ ] Tests are added
- [ ] Entry in NEWS.md
- [ ] Documentation, if applicable