add varargs nondiff rules - #339
Conversation
Codecov Report
@@ Coverage Diff @@
## master #339 +/- ##
=======================================
Coverage 97.64% 97.64%
=======================================
Files 18 18
Lines 1018 1018
=======================================
Hits 994 994
Misses 24 24
Continue to review full report at Codecov.
|
mzgubic
left a comment
There was a problem hiding this comment.
Hey, thanks for taking this on, we appreciate it! The changes look great, thanks for going through the all rules.
With regard to #263: The issue was that the rand function arguments were not constrained at all (i.e. were Any), meaning that the @non_differentiable macro would apply to all the methods, even those that were differentiable in some arguments. It is still possible to reduce the number of lines by replacing, for example:
@non_differentiable rand(::AbstractRNG, ::Integer)
@non_differentiable rand(::AbstractRNG, ::Integer, ::Integer)
@non_differentiable rand(::AbstractRNG, ::Integer, ::Integer, ::Integer)
@non_differentiable rand(::AbstractRNG, ::Integer, ::Integer, ::Integer, ::Integer)
@non_differentiable rand(::AbstractRNG, ::Integer, ::Integer, ::Integer, ::Integer, ::Integer)
with
@non_differentiable rand(::AbstractRNG, ::Integer...)
If you can bump the version number as well this PR is ready to merge.
| @non_differentiable rand(::Type{<:Real}, ::Integer...) | ||
| @non_differentiable rand(::Integer...) | ||
|
|
||
| # There are many different 1-3 arg methods, but not varargs |
There was a problem hiding this comment.
I'm unsure about what this comment means, so I didn't replace it by rand!(::Any...)
There was a problem hiding this comment.
The comment means that the function rand! has many different method definitions, which you can see by typing methods(rand!) in the REPL. However, if you look closely, none of them have a Vararg (or ...) in the arguments. So, it is correct not to replace it, as it would lead to incorrect results in case someone defined a differentiable rand! method with four arguments.
There was a problem hiding this comment.
Now I see, thank you!
mzgubic
left a comment
There was a problem hiding this comment.
Great, thanks! Just a couple of minor things left
| @non_differentiable rand(::Type{<:Real}, ::Integer...) | ||
| @non_differentiable rand(::Integer...) | ||
|
|
||
| # There are many different 1-3 arg methods, but not varargs |
There was a problem hiding this comment.
The comment means that the function rand! has many different method definitions, which you can see by typing methods(rand!) in the REPL. However, if you look closely, none of them have a Vararg (or ...) in the arguments. So, it is correct not to replace it, as it would lead to incorrect results in case someone defined a differentiable rand! method with four arguments.
| @non_differentiable randn!(::AbstractRNG, ::AbstractArray) | ||
|
|
||
|
|
||
| @non_differentiable randn(::AbstractRNG) |
There was a problem hiding this comment.
Was this line removed by accident, or am I missing something?
There was a problem hiding this comment.
I think it is covered already by randn(::Any...) above
| @non_differentiable randexp(::Any, ::Any, ::Any) | ||
| @non_differentiable randexp(::Any, ::Any, ::Any, ::Any) | ||
| @non_differentiable randexp(::Any, ::Any, ::Any, ::Any, ::Any) | ||
| @non_differentiable randexp(::Any...) |
There was a problem hiding this comment.
Great, this was actually missing a randexp() before, which is now covered.
Co-authored-by: Miha Zgubic <mzgubic@users.noreply.github.com>
…ger...) Co-authored-by: Miha Zgubic <mzgubic@users.noreply.github.com>
|
Thanks @mzgubic ! |
Addresses #253, following @oxinabox.
I left out the last three rand definitions in light of #263 (?)