New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Functors.functor
#162
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff!
I have one comment about the testing; it seems like we currently only test a couple of the bijectors?
function test_functor(x, xs) | ||
_xs, re = Functors.functor(x) | ||
@test x == re(_xs) | ||
@test _xs == xs | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this being used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the norm_flows
tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, missed that 👍
Yes, indeed, so far only |
That's correct, but the idea is to start using that approach for all bijectors. So feel free to add it there for now :) |
Actually, I guess it's somewhat non-trivial to add this to |
I assume one would have to specify the parameters explicitly, similar to |
E.g. function test_bijector(
b::Bijector,
xs_true,
ys_true,
logjacs_true
params = nothing;
kwargs...
)
!isnothing(params) && test_functor(b, params)
return test_bijector(b, xs_true, ys_true, logjacs_true; kwargs...)
end ? |
This will lead to a stackoverflow error. But in principle this is the idea. |
Oh yeah, rather: function test_bijector(
b::Bijector,
xs_true,
ys_true,
logjacs_true
params;
kwargs...
)
test_functor(b, params)
return test_bijector(b, xs_true, ys_true, logjacs_true; kwargs...)
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy for now, and we can make it testing the functor functionality part of the tests once we unify testing a bit.
Ah sorry, I forgot about the PR. OK, let's update the tests separately then! |
This PR is an alternative to #161. As mentioned there,
Flux.@treelike
does not exist anymore. Instead, Flux relies onFunctors.functor
and reexportsFlux.@functor
.This PR implements
Functors.functor
for bijectors and normalizing flows. Thus users can just callFlux.params
without implementing@functor
for the different layers.A dependency on the lightweight package Functors.jl is added and the optional dependency on Flux is dropped.