From 258a74a0fa058a6bf5665f62a01861edd12ee62d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20W=C3=BCrfel?= Date: Wed, 23 Sep 2026 10:13:43 +0200 Subject: [PATCH 1/2] fix full iteration return value --- src/NetworkLayout.jl | 10 +++------- test/runtests.jl | 3 +++ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/NetworkLayout.jl b/src/NetworkLayout.jl index 257fb88..8b8c6f7 100644 --- a/src/NetworkLayout.jl +++ b/src/NetworkLayout.jl @@ -79,13 +79,9 @@ end function layout(alg::IterativeLayout, adj_matrix::AbstractMatrix) assertsquare(adj_matrix) - iter = LayoutIterator(alg, adj_matrix) - next = Base.iterate(iter) - pos = next[1] - while next !== nothing - (item, state) = next - next = Base.iterate(iter, state) - pos = next !== nothing ? item : pos + local pos + for item in LayoutIterator(alg, adj_matrix) + pos = item end return pos end diff --git a/test/runtests.jl b/test/runtests.jl index bfe74c0..59c3824 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -47,6 +47,7 @@ jagmesh_adj = jagmesh() push!(vec, p) end @test length(vec) == l + @test it.algorithm(adj_matrix) == last(vec) @test length(unique!(vec)) == l end end @@ -104,6 +105,7 @@ jagmesh_adj = jagmesh() push!(vec, p) end @test length(vec) == l + @test it.algorithm(adj_matrix) == last(vec) @test length(unique!(vec)) == l end end @@ -212,6 +214,7 @@ jagmesh_adj = jagmesh() push!(vec, p) end @test length(vec) == l + @test it.algorithm(adj_matrix) == last(vec) @test length(unique!(vec)) == l end end From 3813d705515e1ef0051fed21c12773a66e900f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20W=C3=BCrfel?= Date: Wed, 23 Sep 2026 10:38:53 +0200 Subject: [PATCH 2/2] fix iterations kw argument iterations now fixes number of iterations not including the initial positions --- NEWS.md | 6 ++++++ src/sfdp.jl | 2 +- src/spring.jl | 2 +- src/stress.jl | 2 +- test/runtests.jl | 14 +++++++------- 5 files changed, 16 insertions(+), 10 deletions(-) create mode 100644 NEWS.md diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..9dbd460 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,6 @@ +# NetworkLayout Release Notes + +## v0.4.11 Changelog +- Fixes two bugs in the iteration scheme: + - The layout iterator returned the second-to-last layout; now it returns the final positions after full iteration. + - Iterative layouts computed `iterations` layouts, including the initial guess. Now `iterations` describes the number of actual *iterations*, and the layout iterator returns at most `iterations + 1` layouts. diff --git a/src/sfdp.jl b/src/sfdp.jl index b9a9379..f214245 100644 --- a/src/sfdp.jl +++ b/src/sfdp.jl @@ -85,7 +85,7 @@ function Base.iterate(iter::LayoutIterator{<:SFDP}, state) K, C, tol = algo.K, algo.C, algo.tol # stop if stopflag (tol reached) or nr of iterations reached - if iter >= algo.iterations || stopflag + if iter > algo.iterations || stopflag return nothing end diff --git a/src/spring.jl b/src/spring.jl index b0b26d0..7f932a9 100644 --- a/src/spring.jl +++ b/src/spring.jl @@ -81,7 +81,7 @@ end function Base.iterate(iter::LayoutIterator{<:Spring}, state) algo, adj_matrix = iter.algorithm, iter.adj_matrix iteration, old_pos, pin, rng = state - iteration >= algo.iterations && return nothing + iteration > algo.iterations && return nothing # The optimal distance bewteen vertices N = size(adj_matrix, 1) diff --git a/src/stress.jl b/src/stress.jl index 73579d5..412e2b7 100644 --- a/src/stress.jl +++ b/src/stress.jl @@ -153,7 +153,7 @@ function Base.iterate(iter::LayoutIterator{<:Stress{Dim,Ptype}}, state) where {D algo, δ = iter.algorithm, iter.adj_matrix i, oldstress, oldpos, weights, distances, pinvLw, maxiter, pin, stopflag = state - if i >= maxiter || stopflag + if i > maxiter || stopflag return nothing end diff --git a/test/runtests.jl b/test/runtests.jl index 59c3824..78ea45d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -46,9 +46,9 @@ jagmesh_adj = jagmesh() for p in it push!(vec, p) end - @test length(vec) == l + @test length(vec) == l + 1 @test it.algorithm(adj_matrix) == last(vec) - @test length(unique!(vec)) == l + @test length(unique!(vec)) == l + 1 end end @@ -104,9 +104,9 @@ jagmesh_adj = jagmesh() for p in it push!(vec, p) end - @test length(vec) == l + @test length(vec) == l + 1 @test it.algorithm(adj_matrix) == last(vec) - @test length(unique!(vec)) == l + @test length(unique!(vec)) == l + 1 end end @@ -213,9 +213,9 @@ jagmesh_adj = jagmesh() for p in it push!(vec, p) end - @test length(vec) == l + @test length(vec) == l + 1 @test it.algorithm(adj_matrix) == last(vec) - @test length(unique!(vec)) == l + @test length(unique!(vec)) == l + 1 end end @@ -475,7 +475,7 @@ jagmesh_adj = jagmesh() positions :: Vector{Point{Dim, Ptype}} end NetworkLayout.layout(algo::Manual, ::AbstractMatrix) = copy(algo.positions) - + g = Graph(2); add_edge!(g, 1, 2) pos = Align(Manual([Point2f(1, 2), Point2f(2, 3)]), 0.0)(g) @test all(r->abs(r[2])<1e-12, pos)