Skip to content

Commit dbb9d6c

Browse files
committed
Only use hand-rolled fold workaround on Julia < 1.6
foldl over tuples infers fine from Julia 1.6 onward (verified on 1.6.7, 1.9.4, 1.10, 1.12, 1.13); only Julia 1.0.x needs the recursive workaround, so keep using foldl on newer versions. Created by generative AI.
1 parent 86da231 commit dbb9d6c

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

src/with_ladj.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,20 @@ 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...)
146+
@static if VERSION >= v"1.6"
147+
function _with_ladj_on_mapped(y_with_ladj::Tuple{Tuple{Any,Real}, Vararg{Union{NoLogAbsDetJacobian, Tuple{Any,Real}}}})
148+
a, bs = first(y_with_ladj), Base.tail(y_with_ladj)
149+
return foldl(_combine_y_ladj, bs, init = ((a[1],), a[2]))
150+
end
151+
else
152+
# Hand-rolled foldl, foldl over tuples is not inferrable on Julia < 1.6:
153+
_foldl_combine_y_ladj(acc) = acc
154+
_foldl_combine_y_ladj(acc, b, bs...) = _foldl_combine_y_ladj(_combine_y_ladj(acc, b), bs...)
149155

150-
function _with_ladj_on_mapped(y_with_ladj::Tuple{Tuple{Any,Real}, Vararg{Union{NoLogAbsDetJacobian, Tuple{Any,Real}}}})
151-
a = first(y_with_ladj)
152-
return _foldl_combine_y_ladj(((a[1],), a[2]), Base.tail(y_with_ladj)...)
156+
function _with_ladj_on_mapped(y_with_ladj::Tuple{Tuple{Any,Real}, Vararg{Union{NoLogAbsDetJacobian, Tuple{Any,Real}}}})
157+
a = first(y_with_ladj)
158+
return _foldl_combine_y_ladj(((a[1],), a[2]), Base.tail(y_with_ladj)...)
159+
end
153160
end
154161

155162
@static if VERSION >= v"1.6"

0 commit comments

Comments
 (0)