Skip to content

Commit

Permalink
Revert "Get rid of union! (#42)"
Browse files Browse the repository at this point in the history
This reverts commit ae7199d.
  • Loading branch information
gdalle authored May 3, 2024
1 parent ae7199d commit a078d4b
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/tracers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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}`.
"""
Expand Down Expand Up @@ -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
Expand All @@ -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

#===========#
Expand Down

0 comments on commit a078d4b

Please sign in to comment.