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

repeat rrule ambiguity for Bool arrays #654

Closed
ToucheSir opened this issue Aug 1, 2022 · 2 comments · Fixed by #668
Closed

repeat rrule ambiguity for Bool arrays #654

ToucheSir opened this issue Aug 1, 2022 · 2 comments · Fixed by #668
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ToucheSir
Copy link
Contributor

julia> rrule(repeat, falses(1), 1)
ERROR: MethodError: rrule(::typeof(repeat), ::BitVector, ::Int64) is ambiguous. Candidates:
  rrule(::typeof(repeat), xs::AbstractArray, counts::Integer...) in ChainRules at /home/brianc/.julia/packages/ChainRules/o1vND/src/rulesets/Base/array.jl:191
  rrule(::typeof(repeat), var"543"::AbstractArray{Bool}, var"544"...; repeat_pullback) in ChainRules at /home/brianc/.julia/packages/ChainRules/o1vND/src/rulesets/Base/nondiff.jl:65
Possible fix, define
  rrule(::typeof(repeat), ::AbstractArray{Bool}, ::Vararg{Integer})
Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

Found while working on FluxML/Zygote.jl#1234. Is there a way to constrain the vararg type in

@non_differentiable repeat(::AbstractArray{Bool}, ::Any...)
to remove this ambiguity?

@mzgubic
Copy link
Member

mzgubic commented Aug 2, 2022

Can we just do

@non_differentiable repeat(::AbstractArray{Bool}, ::Integer...)

It's just integers that are expected as the counts right?

@mcabbott
Copy link
Member

mcabbott commented Aug 2, 2022

Might be worth trying to be systematic about these... at least to track progress. Not sure what to make of the frule ambiguities, but for rrule there appear to be 8, including this one:

julia> filter(Test.detect_ambiguities(ChainRules, ChainRulesCore)) do t
         (t[1].name in [:frule, Symbol("frule##kw")])
       end |> length
1242

julia> filter(Test.detect_ambiguities(ChainRules, ChainRulesCore)) do t
         (t[1].name in [:rrule, Symbol("rrule##kw")])
       end
8-element Vector{Tuple{Method, Method}}:
 (rrule(::typeof(findfirst), var"776"::Union{Regex, AbstractChar, AbstractString, Function}, var"777"::AbstractString; findfirst_pullback)
     @ ChainRules ~/.julia/packages/ChainRules/BbzFc/src/rulesets/Base/nondiff.jl:175, rrule(::typeof(findfirst), var"780"::Function, var"781"; findfirst_pullback)
     @ ChainRules ~/.julia/packages/ChainRules/BbzFc/src/rulesets/Base/nondiff.jl:176)
 ((::ChainRulesCore.var"#rrule##kw")(kwargs, ::typeof(rrule), ::typeof(findfirst), var"780"::Function, var"781")
     @ ChainRules none:0, (::ChainRulesCore.var"#rrule##kw")(kwargs, ::typeof(rrule), ::typeof(findfirst), var"776"::Union{Regex, AbstractChar, AbstractString, Function}, var"777"::AbstractString)
     @ ChainRules none:0)
 ((::ChainRulesCore.var"#rrule##kw")(kwargs, ::typeof(rrule), ::typeof(findfirst), var"776"::Union{Regex, AbstractChar, AbstractString, Function}, var"777"::AbstractString)
     @ ChainRules none:0, (::ChainRulesCore.var"#rrule##kw")(kwargs, ::typeof(rrule), ::typeof(findfirst), var"780"::Function, var"781")
     @ ChainRules none:0)
 ((::ChainRulesCore.var"#rrule##kw")(kwargs, ::typeof(rrule), ::typeof(findlast), var"791"::Function, var"792")
     @ ChainRules none:0, (::ChainRulesCore.var"#rrule##kw")(kwargs, ::typeof(rrule), ::typeof(findlast), var"787"::Union{AbstractChar, AbstractString, Function}, var"788"::AbstractString)
     @ ChainRules none:0)
 (rrule(::typeof(findlast), var"787"::Union{AbstractChar, AbstractString, Function}, var"788"::AbstractString; findlast_pullback)
     @ ChainRules ~/.julia/packages/ChainRules/BbzFc/src/rulesets/Base/nondiff.jl:178, rrule(::typeof(findlast), var"791"::Function, var"792"; findlast_pullback)
     @ ChainRules ~/.julia/packages/ChainRules/BbzFc/src/rulesets/Base/nondiff.jl:179)
 ((::ChainRulesCore.var"#rrule##kw")(kwargs, ::typeof(rrule), ::typeof(findlast), var"787"::Union{AbstractChar, AbstractString, Function}, var"788"::AbstractString)
     @ ChainRules none:0, (::ChainRulesCore.var"#rrule##kw")(kwargs, ::typeof(rrule), ::typeof(findlast), var"791"::Function, var"792")
     @ ChainRules none:0)
 (rrule(::Type{Matrix}, var"427"::AbstractArray{Bool}; Matrix_pullback)
     @ ChainRules ~/.julia/packages/ChainRules/BbzFc/src/rulesets/Base/nondiff.jl:57, rrule(TM::Type{<:Matrix}, A::Union{LinearAlgebra.Hermitian{T, S}, LinearAlgebra.Symmetric{T, S}} where {T, S})
     @ ChainRules ~/.julia/packages/ChainRules/BbzFc/src/rulesets/LinearAlgebra/symmetric.jl:25)
 (rrule(::typeof(repeat), xs::AbstractArray, counts::Integer...)
     @ ChainRules ~/.julia/packages/ChainRules/BbzFc/src/rulesets/Base/array.jl:191, rrule(::typeof(repeat), var"454"::AbstractArray{Bool}, var"455"...; repeat_pullback)
     @ ChainRules ~/.julia/packages/ChainRules/BbzFc/src/rulesets/Base/nondiff.jl:65)

@mcabbott mcabbott added bug Something isn't working good first issue Good for newcomers labels Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants