Skip to content

Commit 86da231

Browse files
committed
Make _with_ladj_on_mapped for tuples inferrable on older Julia versions
foldl over a tuple is not fully inferrable on Julia v1.0, resulting in tuple-length information getting lost. Use hand-rolled recursion instead. Created by generative AI.
1 parent 393df8d commit 86da231

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/with_ladj.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ function _with_ladj_on_mapped(y_with_ladj::Tuple{NoLogAbsDetJacobian, Vararg{Uni
143143
return first(y_with_ladj)
144144
end
145145

146+
# Hand-rolled foldl, foldl over tuples is not inferrable on older Julia versions:
147+
_foldl_combine_y_ladj(acc) = acc
148+
_foldl_combine_y_ladj(acc, b, bs...) = _foldl_combine_y_ladj(_combine_y_ladj(acc, b), bs...)
149+
146150
function _with_ladj_on_mapped(y_with_ladj::Tuple{Tuple{Any,Real}, Vararg{Union{NoLogAbsDetJacobian, Tuple{Any,Real}}}})
147-
a, bs = first(y_with_ladj), Base.tail(y_with_ladj)
148-
return foldl(_combine_y_ladj, bs, init = ((a[1],), a[2]))
151+
a = first(y_with_ladj)
152+
return _foldl_combine_y_ladj(((a[1],), a[2]), Base.tail(y_with_ladj)...)
149153
end
150154

151155
@static if VERSION >= v"1.6"

0 commit comments

Comments
 (0)