Skip to content

Commit a2f0fb1

Browse files
authored
Merge pull request #32 from JuliaGraphs/hw/fixspring
fix Spring for single node graph
2 parents e80e36a + 240a24e commit a2f0fb1

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/spring.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function Base.iterate(iter::LayoutIterator{<:Spring}, state)
106106
# Now apply them, but limit to temperature
107107
for i in 1:N
108108
force_mag = norm(force[i])
109+
iszero(force_mag) && continue
109110
scale = min(force_mag, temp) ./ force_mag
110111
locs[i] += force[i] .* scale
111112
end

test/runtests.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ jagmesh_adj = jagmesh()
153153
@test positions ==
154154
spring(adj_matrix; C=2.0, iterations=100, initialtemp=2.0, Ptype=Float32, dim=3)
155155
end
156+
157+
@testset "test single node graph" begin
158+
g = SimpleGraph(1)
159+
pos = Spring()(g)
160+
@test length(pos) == 1
161+
@test !isnan(pos[1])
162+
end
156163
end
157164

158165
@testset "Testing Spectral Algorithm" begin

0 commit comments

Comments
 (0)