Skip to content

Commit 6333879

Browse files
committed
avoid ambiguities
1 parent c0a1aeb commit 6333879

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

src/rulesets/Base/mapreduce.jl

+4-11
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,6 @@ function rrule(
438438
return z, mapfoldl_pullback_tuple
439439
end
440440

441-
function rrule(::RuleConfig{>:HasReverseMode}, ::typeof(mapfoldl_impl), f, op, init, x::Tuple{})
442-
foldl_pullback_empty(dy) = (NoTangent(), NoTangent(), NoTangent(), dy, NoTangent())
443-
return init, foldl_pullback_empty
444-
end
445-
446441
#####
447442
##### `foldl(f, ::Tuple)`
448443
#####
@@ -491,6 +486,10 @@ function rrule(
491486
init,
492487
x::Tuple;
493488
) where {G}
489+
# Trivial case handled here to avoid ambiguities (and necc. because of Base.tail below)
490+
foldl_pullback_empty(dy) = (NoTangent(), NoTangent(), NoTangent(), dy, NoTangent())
491+
isempty(x) && return init, foldl_pullback_empty
492+
494493
# Treat `init` by simply appending it to the `x`:
495494
y, back = rrule(config, Base.mapfoldl_impl, identity, op, Base._InitialValue(), (init, x...))
496495
project_x = ProjectTo(x)
@@ -502,12 +501,6 @@ function rrule(
502501
return y, foldl_pullback_tuple_init
503502
end
504503

505-
# Base.tail doesn't work on (), trivial case:
506-
function rrule(::RuleConfig{>:HasReverseMode}, ::typeof(mapfoldl_impl), ::typeof(identity), op, init, x::Tuple{})
507-
foldl_pullback_empty(dy) = (NoTangent(), NoTangent(), NoTangent(), dy, NoTangent())
508-
return init, foldl_pullback_empty
509-
end
510-
511504
#####
512505
##### `foldl(f, ::Array)`
513506
#####

test/rulesets/Base/mapreduce.jl

-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ const _INIT = Base._InitialValue()
306306

307307
# Trivial case
308308
test_rrule(mapfoldl_impl, identity, /, 2pi, ())
309-
test_rrule(mapfoldl_impl, sqrt, /, 2pi, ())
310309
end
311310
@testset "mapfoldl(f, g, ::Tuple)" begin
312311
test_rrule(mapfoldl_impl, cbrt, /, _INIT, Tuple(1 .+ rand(5)), check_inferred=false)

0 commit comments

Comments
 (0)