@@ -438,11 +438,6 @@ function rrule(
438
438
return z, mapfoldl_pullback_tuple
439
439
end
440
440
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
-
446
441
# ####
447
442
# #### `foldl(f, ::Tuple)`
448
443
# ####
@@ -491,6 +486,10 @@ function rrule(
491
486
init,
492
487
x:: Tuple ;
493
488
) 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
+
494
493
# Treat `init` by simply appending it to the `x`:
495
494
y, back = rrule (config, Base. mapfoldl_impl, identity, op, Base. _InitialValue (), (init, x... ))
496
495
project_x = ProjectTo (x)
@@ -502,12 +501,6 @@ function rrule(
502
501
return y, foldl_pullback_tuple_init
503
502
end
504
503
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
-
511
504
# ####
512
505
# #### `foldl(f, ::Array)`
513
506
# ####
0 commit comments