Skip to content

Commit

Permalink
comment on rng copy
Browse files Browse the repository at this point in the history
  • Loading branch information
hexaeder committed Oct 7, 2024
1 parent 5c5427f commit 2be5b80
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/sfdp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ function Base.iterate(iter::LayoutIterator{<:SFDP}, state)
end
end
if any(isnan, force)
# if two points are at the exact same location
# use random force in any direction
rng = copy(algo.rng)
force += randn(rng, Ftype)
# if two points are at the exact same location use random force in any direction
# copy rng from alg struct to not advance the "initial" rng state
# otherwise algo(g)==algo(g) might be broken
force += randn(copy(algo.rng), Ftype)
end
mask = (!).(pin[i]) # where pin=true mask will multiply with 0
locs[i] = locs[i] .+ (step .* (force ./ norm(force))) .* mask
Expand Down
5 changes: 3 additions & 2 deletions src/spring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ function Base.iterate(iter::LayoutIterator{<:Spring}, state)
else
# if two points are at the exact same location
# use random force in any direction
rng = copy(algo.rng)
force_vec += randn(rng, Ftype)
# copy rng from alg struct to not advance the "initial" rng state
# otherwise algo(g)==algo(g) might be broken
force_vec += randn(copy(algo.rng), Ftype)
end

end
Expand Down

0 comments on commit 2be5b80

Please sign in to comment.