Skip to content

add varargs nondiff rules #339

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

Merged
merged 7 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ChainRules"
uuid = "082447d4-558c-5d27-93f4-14fc19e9eca2"
version = "0.7.42"
version = "0.7.43"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
101 changes: 21 additions & 80 deletions src/rulesets/Base/nondiff.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
@non_differentiable !(::Any)
@non_differentiable *(::Union{Regex, AbstractChar, AbstractString})
@non_differentiable *(
::Union{Regex, AbstractChar, AbstractString},
::Union{Regex, AbstractChar, AbstractString},
)
@non_differentiable *(
::Union{Regex, AbstractChar, AbstractString},
::Union{Regex, AbstractChar, AbstractString},
::Union{Regex, AbstractChar, AbstractString},
)
@non_differentiable *(::Union{Regex, AbstractChar, AbstractString}...)
@non_differentiable -(::AbstractChar, ::AbstractChar)
@non_differentiable <=(::Any)
@non_differentiable <=(::Any, ::Any)
Expand Down Expand Up @@ -85,8 +76,7 @@
@non_differentiable Array(::AbstractArray{Bool})
@non_differentiable IndexStyle(::AbstractArray{Bool})

@non_differentiable abspath(::AbstractString)
@non_differentiable abspath(::AbstractString, ::AbstractString)
@non_differentiable abspath(::AbstractString...)
@non_differentiable all(::Any)
@non_differentiable all(::Any, ::Any)
@non_differentiable any(::Any)
Expand Down Expand Up @@ -122,9 +112,7 @@
@non_differentiable download(::AbstractString)
@non_differentiable download(::AbstractString, ::AbstractString)

@non_differentiable eachindex(::Any)
@non_differentiable eachindex(::Any, ::Any)
@non_differentiable eachindex(::Any, ::Any, ::Any)
@non_differentiable eachindex(::Any...)
@non_differentiable eachline(::AbstractString)
@non_differentiable eachline(::IO)
@non_differentiable eachmatch(::Regex, ::AbstractString)
Expand Down Expand Up @@ -162,9 +150,7 @@ VERSION >= v"1.1" && @non_differentiable fieldtypes(T)
@non_differentiable flush(::Any)

@non_differentiable gensym(::Symbol)
@non_differentiable gensym(::String)
@non_differentiable gensym(::String, ::String)
@non_differentiable gensym(::String, ::String, ::String)
@non_differentiable gensym(::String...)
@non_differentiable getindex(::AbstractChar)
@non_differentiable getindex(::AbstractString, ::Colon)
@non_differentiable getindex(::Base.TTY, ::Symbol)
Expand All @@ -186,62 +172,44 @@ VERSION >= v"1.1" && @non_differentiable fieldtypes(T)
@non_differentiable isapprox(::Any, ::Any)
@non_differentiable isascii(::AbstractChar)
@non_differentiable isascii(::AbstractString)
@non_differentiable isassigned(::Any)
@non_differentiable isassigned(::Any, ::Any)
@non_differentiable isassigned(::Any, ::Any, ::Any)
@non_differentiable isassigned(::Any...)
@non_differentiable isbits(::Any)
@non_differentiable isbitstype(::Any)
@non_differentiable isblockdev(::Any)
@non_differentiable isblockdev(::Any, ::Any)
@non_differentiable isblockdev(::Any, ::Any, ::Any)
@non_differentiable ischardev(::Any)
@non_differentiable ischardev(::Any, ::Any)
@non_differentiable ischardev(::Any, ::Any, ::Any)
@non_differentiable isblockdev(::Any...)
@non_differentiable ischardev(::Any...)
@non_differentiable iscntrl(::AbstractChar)
@non_differentiable isconcretetype(::Any)
@non_differentiable isconst(::Module, ::Symbol)
@non_differentiable isdigit(::AbstractChar)
@non_differentiable isdir(::Any)
@non_differentiable isdir(::Any, ::Any)
@non_differentiable isdir(::Any, ::Any, ::Any)
@non_differentiable isdir(::Any...)
@non_differentiable isdirpath(::AbstractString)
VERSION >= v"1.5" && @non_differentiable isdisjoint(::Any, ::Any)
@non_differentiable isdispatchtuple(::Any)
@non_differentiable isempty(::Any)
@non_differentiable isequal(::Any)
@non_differentiable isequal(::Any, ::Any)
@non_differentiable iseven(::Any)
@non_differentiable isfifo(::Any)
@non_differentiable isfifo(::Any, ::Any)
@non_differentiable isfifo(::Any, ::Any, ::Any)
@non_differentiable isfile(::Any)
@non_differentiable isfile(::Any, ::Any)
@non_differentiable isfile(::Any, ::Any, ::Any)
@non_differentiable isfifo(::Any...)
@non_differentiable isfile(::Any...)
@non_differentiable isfinite(::Any)
@non_differentiable isimmutable(::Any)
@non_differentiable isinf(::Any)
@non_differentiable isinteger(::Any)
@non_differentiable isless(::Any, ::Any)
@non_differentiable isletter(::AbstractChar)
@non_differentiable islink(::Any)
@non_differentiable islink(::Any, ::Any)
@non_differentiable islink(::Any, ::Any, ::Any)
@non_differentiable islink(::Any...)
@non_differentiable islowercase(::AbstractChar)
@non_differentiable ismarked(::IO)
@non_differentiable ismissing(::Any)
@non_differentiable ismount(::Any)
@non_differentiable ismount(::Any, ::Any)
@non_differentiable ismount(::Any, ::Any, ::Any)
@non_differentiable ismount(::Any...)
VERSION >= v"1.5" && @non_differentiable ismutable(::Any)
@non_differentiable isnan(::Any)
VERSION >= v"1.1" && @non_differentiable isnothing(::Any)
@non_differentiable isnumeric(::AbstractChar)
@non_differentiable isodd(::Any)
@non_differentiable isone(::Any)
@non_differentiable isopen(::Any)
@non_differentiable ispath(::Any)
@non_differentiable ispath(::Any, ::Any)
@non_differentiable ispath(::Any, ::Any, ::Any)
@non_differentiable ispath(::Any...)
@non_differentiable isperm(::Any)
@non_differentiable ispow2(::Any)
@non_differentiable isprimitivetype(::Any)
Expand Down Expand Up @@ -282,9 +250,7 @@ VERSION >= v"1.3" && @non_differentiable istaskfailed(::Task)
@non_differentiable join(::Any, ::Any)
@non_differentiable join(::Any, ::Any, ::Any)
@non_differentiable join(::IO, ::Any, ::Any, ::Any)
@non_differentiable joinpath(::AbstractString)
@non_differentiable joinpath(::AbstractString, ::AbstractString)
@non_differentiable joinpath(::AbstractString, ::AbstractString, ::AbstractString)
@non_differentiable joinpath(::AbstractString, ::AbstractString...)

@non_differentiable keys(::AbstractString)
@non_differentiable keys(::Cmd)
Expand Down Expand Up @@ -316,9 +282,7 @@ VERSION >= v"1.3" && @non_differentiable istaskfailed(::Task)
@non_differentiable ncodeunits(::AbstractString)
@non_differentiable ndims(::AbstractChar)
@non_differentiable nfields(::Any)
@non_differentiable normpath(::AbstractString)
@non_differentiable normpath(::AbstractString, ::AbstractString)
@non_differentiable normpath(::AbstractString, ::AbstractString, ::AbstractString)
@non_differentiable normpath(::AbstractString...)

@non_differentiable occursin(::Regex, ::AbstractString)
@non_differentiable occursin(::Union{AbstractChar, AbstractString}, ::AbstractString)
Expand All @@ -331,16 +295,8 @@ VERSION >= v"1.4" && @non_differentiable only(::Char)
@non_differentiable position(::Base.GenericIOBuffer)
@non_differentiable position(::Base.SecretBuffer)
@non_differentiable position(::IOStream)
@non_differentiable print(::Any)
@non_differentiable print(::Any, ::Any)
@non_differentiable print(::Any, ::Any, ::Any)
@non_differentiable print(::Any, ::Any, ::Any, ::Any)
@non_differentiable print(::Any, ::Any, ::Any, ::Any, ::Any)
@non_differentiable println(::Any)
@non_differentiable println(::Any, ::Any)
@non_differentiable println(::Any, ::Any, ::Any)
@non_differentiable println(::Any, ::Any, ::Any, ::Any)
@non_differentiable println(::Any, ::Any, ::Any, ::Any, ::Any)
@non_differentiable print(::Any...)
@non_differentiable println(::Any...)
@non_differentiable process_exited(::Any)
@non_differentiable process_running(::Any)
@non_differentiable pushdisplay(::AbstractDisplay)
Expand Down Expand Up @@ -394,11 +350,7 @@ VERSION >= v"1.1" && @non_differentiable splitpath(::AbstractString)
@non_differentiable stat(::Base.Filesystem.File)
@non_differentiable stat(::IOStream)
@non_differentiable stat(::RawFD)
@non_differentiable string(::Any)
@non_differentiable string(::Any, ::Any)
@non_differentiable string(::Any, ::Any, ::Any)
@non_differentiable string(::Any, ::Any, ::Any, ::Any)
@non_differentiable string(::Any, ::Any, ::Any, ::Any, ::Any)
@non_differentiable string(::Any...)
@non_differentiable strip(::AbstractString)
@non_differentiable success(::Array{Base.Process,1})
@non_differentiable success(::Base.Process)
Expand Down Expand Up @@ -427,27 +379,16 @@ VERSION >= v"1.1" && @non_differentiable splitpath(::AbstractString)
@non_differentiable wait(::Base.Process)
@non_differentiable wait(::Base.ProcessChain)
@non_differentiable wait(::RawFD)
@non_differentiable write(::IO, ::Any)
@non_differentiable write(::IO, ::Any, ::Any,)
@non_differentiable write(::IO, ::Any, ::Any, ::Any)
@non_differentiable write(::IO, ::Any, ::Any, ::Any, ::Any)
@non_differentiable write(::IO, ::Any...)

@non_differentiable xor(::Any)
@non_differentiable xor(::Any, ::Any,)
@non_differentiable xor(::Any, ::Any, ::Any)
@non_differentiable xor(::Any, ::Any, ::Any, ::Any)
@non_differentiable xor(::Any, ::Any, ::Any, ::Any, ::Any)
@non_differentiable xor(::Any...)

# Non-public Base
@non_differentiable Base.gc_num()
@non_differentiable Base.time_ns()
@non_differentiable Base.typename(::Any)

@non_differentiable Broadcast.combine_styles(::Any)
@non_differentiable Broadcast.combine_styles(::Any, ::Any)
@non_differentiable Broadcast.combine_styles(::Any, ::Any, ::Any)
@non_differentiable Broadcast.combine_styles(::Any, ::Any, ::Any, ::Any)
@non_differentiable Broadcast.combine_styles(::Any, ::Any, ::Any, ::Any, ::Any)
@non_differentiable Broadcast.combine_styles(::Any...)
@non_differentiable Broadcast.result_style(::Any)
@non_differentiable Broadcast.result_style(::Any, ::Any)

Expand Down
13 changes: 2 additions & 11 deletions src/rulesets/Core/core.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
@non_differentiable Core.print(::Any)
@non_differentiable Core.print(::Any, ::Any)
@non_differentiable Core.print(::Any, ::Any, ::Any)
@non_differentiable Core.print(::Any, ::Any, ::Any, ::Any)
@non_differentiable Core.print(::Any, ::Any, ::Any, ::Any, ::Any)

@non_differentiable Core.println(::Any)
@non_differentiable Core.println(::Any, ::Any)
@non_differentiable Core.println(::Any, ::Any, ::Any)
@non_differentiable Core.println(::Any, ::Any, ::Any, ::Any)
@non_differentiable Core.println(::Any, ::Any, ::Any, ::Any, ::Any)
@non_differentiable Core.print(::Any...)
@non_differentiable Core.println(::Any...)

@non_differentiable Core.show(::Any)
@non_differentiable Core.show(::Any, ::Any)
Expand Down
36 changes: 5 additions & 31 deletions src/rulesets/Random/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,54 +12,28 @@ end
@non_differentiable Random.randexp(::AbstractRNG)
@non_differentiable Random.randstring(::AbstractRNG)

@non_differentiable rand()
@non_differentiable rand(::AbstractRNG)
@non_differentiable rand(::AbstractRNG, ::Random.Sampler)
@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)
@non_differentiable rand(::AbstractRNG, ::Integer...)
@non_differentiable rand(::Type{<:Real})
@non_differentiable rand(::Type{<:Real}, ::Tuple)
@non_differentiable rand(::Type{<:Real}, ::Integer)
@non_differentiable rand(::Type{<:Real}, ::Integer, ::Integer)
@non_differentiable rand(::Type{<:Real}, ::Integer, ::Integer, ::Integer)
@non_differentiable rand(::Type{<:Real}, ::Integer, ::Integer, ::Integer, ::Integer)
@non_differentiable rand(::Type{<:Real}, ::Integer, ::Integer, ::Integer, ::Integer, ::Integer)
@non_differentiable rand(::Integer)
@non_differentiable rand(::Integer, ::Integer)
@non_differentiable rand(::Integer, ::Integer, ::Integer)
@non_differentiable rand(::Integer, ::Integer, ::Integer, ::Integer)
@non_differentiable rand(::Integer, ::Integer, ::Integer, ::Integer, ::Integer)

@non_differentiable rand(::Type{<:Real}, ::Integer...)
@non_differentiable rand(::Integer...)

# There are many different 1-3 arg methods, but not varargs
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm unsure about what this comment means, so I didn't replace it by rand!(::Any...)

Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now I see, thank you!

@non_differentiable rand!(::Any)
@non_differentiable rand!(::Any, ::Any)
@non_differentiable rand!(::Any, ::Any, ::Any)

@non_differentiable randexp(::Any)
@non_differentiable randexp(::Any, ::Any)
@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...)
Copy link
Member

Choose a reason for hiding this comment

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

Great, this was actually missing a randexp() before, which is now covered.


@non_differentiable randexp!(::AbstractArray)
@non_differentiable randexp!(::AbstractRNG, ::AbstractArray)

@non_differentiable randn()
@non_differentiable randn(::Any)
@non_differentiable randn(::Any, ::Any)
@non_differentiable randn(::Any, ::Any, ::Any)
@non_differentiable randn(::Any, ::Any, ::Any, ::Any)
@non_differentiable randn(::Any, ::Any, ::Any, ::Any, ::Any)
@non_differentiable randn(::Any...)

@non_differentiable randn!(::AbstractArray)
@non_differentiable randn!(::AbstractRNG, ::AbstractArray)


@non_differentiable randn(::AbstractRNG)
Copy link
Member

Choose a reason for hiding this comment

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

Was this line removed by accident, or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is covered already by randn(::Any...) above

@non_differentiable copy(::AbstractRNG)
@non_differentiable copy!(::AbstractRNG, ::AbstractRNG)

Expand Down