From a078d4b0a065c8b1d343387ca3a243c5e5554460 Mon Sep 17 00:00:00 2001 From: Guillaume Dalle <22795598+gdalle@users.noreply.github.com> Date: Fri, 3 May 2024 18:29:48 +0200 Subject: [PATCH] Revert "Get rid of union! (#42)" This reverts commit ae7199dbea5f337bd1232c9e3f7a06a602082d93. --- src/tracers.jl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/tracers.jl b/src/tracers.jl index 4ba824b4..8a3fa9e8 100644 --- a/src/tracers.jl +++ b/src/tracers.jl @@ -11,7 +11,7 @@ const SET_TYPE_MESSAGE = """ The provided index set type `S` has to satisfy the following conditions: - it is an iterable with `<:Integer` element type -- it implements `union` +- it implements methods `union`, `union!` and `push!` Subtypes of `AbstractSet{<:Integer}` are a natural choice, like `BitSet` or `Set{UInt64}`. """ @@ -152,8 +152,9 @@ HessianTracer(t::HessianTracer) = t # Turn first-order interactions into second-order interactions function promote_order(t::HessianTracer) d = deepcopy(t.inputs) - for (k, v) in pairs(d) - d[k] = reduce(union, keys(d); init=v) + ks = keys(d) + for v in values(d) + union!(v, ks) end return HessianTracer(d) end @@ -167,14 +168,15 @@ end function distributive_merge(a::HessianTracer, b::HessianTracer) da = deepcopy(a.inputs) db = deepcopy(b.inputs) - # add second-order interaction term - for (ka, va) in pairs(da) - da[ka] = reduce(union, keys(db); init=va) + for ka in keys(da) + for kb in keys(db) + # add second-order interaction term + union!(da[ka], kb) + union!(db[kb], ka) + end end - for (kb, vb) in pairs(db) - db[kb] = reduce(union, keys(da); init=vb) - end - return HessianTracer(merge(da, db)) + merge!(da, db) + return HessianTracer(da) end #===========#