From 6d7bb40064543b44dd3576c41abfc8534352e595 Mon Sep 17 00:00:00 2001 From: Niklas Schmitz Date: Wed, 6 Jan 2021 00:49:42 +0100 Subject: [PATCH 1/7] add varargs nondiff rules --- src/rulesets/Base/nondiff.jl | 101 ++++++++--------------------------- src/rulesets/Core/core.jl | 13 +---- 2 files changed, 23 insertions(+), 91 deletions(-) diff --git a/src/rulesets/Base/nondiff.jl b/src/rulesets/Base/nondiff.jl index 6404d720e..14b7a4aa5 100644 --- a/src/rulesets/Base/nondiff.jl +++ b/src/rulesets/Base/nondiff.jl @@ -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) @@ -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) @@ -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) @@ -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) @@ -186,24 +172,16 @@ 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) @@ -211,27 +189,19 @@ VERSION >= v"1.5" && @non_differentiable isdisjoint(::Any, ::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) @@ -239,9 +209,7 @@ VERSION >= v"1.1" && @non_differentiable isnothing(::Any) @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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/src/rulesets/Core/core.jl b/src/rulesets/Core/core.jl index 5f056cfe6..047b3da4f 100644 --- a/src/rulesets/Core/core.jl +++ b/src/rulesets/Core/core.jl @@ -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) From ea38e7f4d1fdc1c23d243fe224e8661f0bb382ff Mon Sep 17 00:00:00 2001 From: Niklas Schmitz Date: Wed, 6 Jan 2021 12:25:35 +0100 Subject: [PATCH 2/7] add Integer varargs to rand --- src/rulesets/Random/random.jl | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/rulesets/Random/random.jl b/src/rulesets/Random/random.jl index 1afa2466c..2d51b29c7 100644 --- a/src/rulesets/Random/random.jl +++ b/src/rulesets/Random/random.jl @@ -15,24 +15,11 @@ end @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 @non_differentiable rand!(::Any) From 591dee36bccc5f61938cdb5f2d1e6a2c2ae1da06 Mon Sep 17 00:00:00 2001 From: Niklas Schmitz Date: Wed, 6 Jan 2021 12:27:59 +0100 Subject: [PATCH 3/7] add varargs for randn --- src/rulesets/Random/random.jl | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/rulesets/Random/random.jl b/src/rulesets/Random/random.jl index 2d51b29c7..0953cd55c 100644 --- a/src/rulesets/Random/random.jl +++ b/src/rulesets/Random/random.jl @@ -35,18 +35,11 @@ end @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) @non_differentiable copy(::AbstractRNG) @non_differentiable copy!(::AbstractRNG, ::AbstractRNG) From 2b6281df5966e59e2fa9f05ecb1528ce1e027a20 Mon Sep 17 00:00:00 2001 From: Niklas Schmitz Date: Wed, 6 Jan 2021 12:35:45 +0100 Subject: [PATCH 4/7] add varargs for randexp --- src/rulesets/Random/random.jl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/rulesets/Random/random.jl b/src/rulesets/Random/random.jl index 0953cd55c..2e8fcaaf4 100644 --- a/src/rulesets/Random/random.jl +++ b/src/rulesets/Random/random.jl @@ -26,11 +26,7 @@ end @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...) @non_differentiable randexp!(::AbstractArray) @non_differentiable randexp!(::AbstractRNG, ::AbstractArray) From 02ba3ed1a79bed2ee7160755666a8ffe408ab705 Mon Sep 17 00:00:00 2001 From: Niklas Schmitz Date: Wed, 6 Jan 2021 12:39:43 +0100 Subject: [PATCH 5/7] bump version number --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 8663964a5..96005171f 100644 --- a/Project.toml +++ b/Project.toml @@ -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" From 0d2ba5757e69c151b902e6a026e3b3c190051031 Mon Sep 17 00:00:00 2001 From: Niklas Schmitz Date: Wed, 6 Jan 2021 13:10:35 +0100 Subject: [PATCH 6/7] remove rand() rule covered by rand(::Integer...) Co-authored-by: Miha Zgubic --- src/rulesets/Random/random.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rulesets/Random/random.jl b/src/rulesets/Random/random.jl index 2e8fcaaf4..c0524c66b 100644 --- a/src/rulesets/Random/random.jl +++ b/src/rulesets/Random/random.jl @@ -12,7 +12,6 @@ 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...) From b74e3f7ea1f0b9867a9a8e80a7c10e68d9bd3c67 Mon Sep 17 00:00:00 2001 From: Niklas Schmitz Date: Wed, 6 Jan 2021 13:11:33 +0100 Subject: [PATCH 7/7] remove rand(::AbstractRNG) rule covered by rand(::AbstractRNG, ::Integer...) Co-authored-by: Miha Zgubic --- src/rulesets/Random/random.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rulesets/Random/random.jl b/src/rulesets/Random/random.jl index c0524c66b..8da0b1f22 100644 --- a/src/rulesets/Random/random.jl +++ b/src/rulesets/Random/random.jl @@ -12,7 +12,6 @@ end @non_differentiable Random.randexp(::AbstractRNG) @non_differentiable Random.randstring(::AbstractRNG) -@non_differentiable rand(::AbstractRNG) @non_differentiable rand(::AbstractRNG, ::Random.Sampler) @non_differentiable rand(::AbstractRNG, ::Integer...) @non_differentiable rand(::Type{<:Real})