Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of union! #42

Merged
merged 2 commits into from
May 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 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 methods `union`, `union!` and `push!`
- it implements `union`
Subtypes of `AbstractSet{<:Integer}` are a natural choice, like `BitSet` or `Set{UInt64}`.
"""
Expand Down Expand Up @@ -152,9 +152,8 @@ HessianTracer(t::HessianTracer) = t
# Turn first-order interactions into second-order interactions
function promote_order(t::HessianTracer)
d = deepcopy(t.inputs)
ks = keys(d)
for v in values(d)
union!(v, ks)
for (k, v) in pairs(d)
d[k] = reduce(union, keys(d); init=v)
end
return HessianTracer(d)
end
Expand All @@ -168,15 +167,14 @@ end
function distributive_merge(a::HessianTracer, b::HessianTracer)
da = deepcopy(a.inputs)
db = deepcopy(b.inputs)
for ka in keys(da)
for kb in keys(db)
# add second-order interaction term
union!(da[ka], kb)
union!(db[kb], ka)
end
# add second-order interaction term
for (ka, va) in pairs(da)
da[ka] = reduce(union, keys(db); init=va)
end
merge!(da, db)
return HessianTracer(da)
for (kb, vb) in pairs(db)
db[kb] = reduce(union, keys(da); init=vb)
end
return HessianTracer(merge(da, db))
end

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