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

support varargs in @non_differentiable #212

Closed
oxinabox opened this issue Aug 28, 2020 · 5 comments · Fixed by #254
Closed

support varargs in @non_differentiable #212

oxinabox opened this issue Aug 28, 2020 · 5 comments · Fixed by #254
Labels
enhancement New feature or request rule definition helper relating to helpers for declaring rules

Comments

@oxinabox
Copy link
Member

follow up to #207
it would be useful to support varargs.

@gxyd
Copy link
Contributor

gxyd commented Nov 24, 2020

Currently when I do:

jl> using ChainRules
jl> function h(a, x::Vararg{Any}; kwargs...)
        return a
    end
jl> @non_differentiable h(::Vararg{Any})
jl> rrule(h, 1, 2)[2](1)
(Zero(), DoesNotExist(), DoesNotExist())

Doesn't it mean that it does support Vararg's? Or am I missing something?

@mzgubic
Copy link
Member

mzgubic commented Nov 26, 2020

I can't reproduce your results, for me it errors:

julia> @non_differentiable h(::Vararg{Any})
ERROR: LoadError: @non_differentiable does not support Varargs like: ::Vararg{Any}
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] @non_differentiable(::LineNumberNode, ::Module, ::Any) at /Users/mzgubic/Projects/ChainRules.jl/dev/ChainRulesCore/src/rule_definition_tools.jl:291
in expression starting at REPL[4]:1

What version of ChainRules and julia were you using?

Have you defined other methods of h in the REPL before?

@gxyd
Copy link
Contributor

gxyd commented Nov 26, 2020

Sorry, you'll have to uncomment this block of code: https://github.com/JuliaDiff/ChainRulesCore.jl/blob/master/src/rule_definition_tools.jl#L290-L292

Have you defined other methods of h in the REPL before?

No, that's probably not the case.

@mzgubic
Copy link
Member

mzgubic commented Nov 26, 2020

Have you made any other changes?

I get:

julia> rrule(h, 1, 2)[2](1)
(Zero(), DoesNotExist())

And that is regardless of how many arguments I pass. Which I think makes sense, because it just treats the Vararg as if it was a normal argument (since it is not supported at present).

@gxyd
Copy link
Contributor

gxyd commented Nov 28, 2020

Sorry, I think I made a few changes to the code at that point of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request rule definition helper relating to helpers for declaring rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants