Skip to content
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

Add sneaky invoke example (from Slack) #38

Merged
merged 3 commits into from
Jan 22, 2020

Conversation

phipsgabler
Copy link
Contributor

I cleaned it up a bit as well.


concrete(::Type{Type{T}}) where {T} = T

function _sneaky_transform(f::Type, Types::Type{<:Tuple})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to split this out? I can see this being useful for development but for show it off we should probably make it as simple as possible.

Copy link
Contributor Author

@phipsgabler phipsgabler Jan 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all. But accessing parameters[1] just felt kind of ugly to me. OTOH, for a show off, it shows the semantics much more clearly: that we need to get rid of a level of Type here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that you need concrete but I don't see that it needs _sneaky_transform to be split out, because that's not doing any unwrapping, it just passes through arguments without modification.

It could work well to just do @dynamo function sneakyinvoke(f, Type{T}, ...) where T<:Tuple. The dynamo type signature refers to the unwrapped parameters so that might be a cleaner way to unwrap that avoids the utility functions.

Copy link
Member

@MikeInnes MikeInnes Jan 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong above due to #41, but I've pushed a fix which makes the following work:

@dynamo function sneakyinvoke(f, ::Type{T}, args...) where T<:Tuple
    ir = IR(f, T.parameters...)
    argument!(ir, at = 2)
    return ir
end

I think this is a slightly more idiomatic way to do the unwrapping.

Copy link
Contributor

@MasonProtter MasonProtter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also give this example:

println("Get around overly restrictive type annotations")
@show sneakyinvoke((x::Float64) -> x + 1, Tuple{Float64}, 1)

@MikeInnes
Copy link
Member

Hope you don't mind that I made those small tweaks. Thanks a lot for working out this example!

@MikeInnes MikeInnes merged commit 287448f into FluxML:master Jan 22, 2020
@phipsgabler
Copy link
Contributor Author

Sure I don't mind. And about #41: of course that's exactly why I wrote it that way :) In fact, I have just always accepted this limitation and never considered it a missing feature.

@phipsgabler phipsgabler deleted the sneakyinvoke branch January 22, 2020 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants