Skip to content

Commit

Permalink
Refactor and use foreach more
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Milsted committed Jul 9, 2024
1 parent f9bc9f8 commit 81a6601
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/time_dependent_operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ operators.
function master_h_dynamic_function(H::AbstractTimeDependentOperator, Js)
Htup = _tuplify(H)
Js_tup = ((_tuplify(J) for J in Js)...,)

Jdags_tup = _tdopdagger.(Js_tup)
function _getfunc(Hop, Jops, Jdops)
return (@inline _tdop_master_wrapper_1(t, _) = (set_time!(Hop, t), set_time!.(Jops, t), set_time!.(Jdops, t)))

return let Hop = Htup, Jops = Js_tup, Jdops = Jdags_tup
@inline function _tdop_master_wrapper_1(t, _)
f = (o -> set_time!(o, t))
foreach(f, Jops)
foreach(f, Jdops)
set_time!(Hop, t)
return Hop, Jops, Jdops
end
end
return _getfunc(Htup, Js_tup, Jdags_tup)
end

"""
Expand All @@ -82,8 +87,15 @@ function master_nh_dynamic_function(Hnh::AbstractTimeDependentOperator, Js)
Jdags_tup = _tdopdagger.(Js_tup)
Htdagup = _tdopdagger(Hnhtup)

function _getfunc(Hop, Hdop, Jops, Jdops)
return (@inline _tdop_master_wrapper_2(t, _) = (set_time!(Hop, t), set_time!(Hdop, t), set_time!.(Jops, t), set_time!.(Jdops, t)))
return let Hop = Htup, Hdop = Htdagup, Jops = Js_tup, Jdops = Jdags_tup
@inline function _tdop_master_wrapper_2(t, _)
f = (o -> set_time!(o, t))
foreach(f, Jops)
foreach(f, Jdops)
set_time!(Hop, t)
set_time!(Hdop, t)
return Hop, Hdop, Jops, Jdops
end
end
return _getfunc(Hnhtup, Htdagup, Js_tup, Jdags_tup)
end
Expand Down

0 comments on commit 81a6601

Please sign in to comment.