diff --git a/benchmark/serial/edges.jl b/benchmark/serial/edges.jl index cf2f1d7aa..101821446 100644 --- a/benchmark/serial/edges.jl +++ b/benchmark/serial/edges.jl @@ -5,11 +5,7 @@ const P = Pair{Int,Int} convert(::Type{Tuple}, e::Pair) = (e.first, e.second) function fille(n) - t = Vector{Graphs.Edge}(undef, n) - for i in 1:n - t[i] = Graphs.Edge(i, i + 1) - end - return t + return [Graphs.Edge(i, i + 1) for i in 1:n] end function fillp(n) @@ -22,8 +18,8 @@ end function tsum(t) x = 0 - for i in 1:length(t) - u, v = Tuple(t[i]) + for item in t + u, v = Tuple(item) x += u x += v end diff --git a/src/Experimental/vf2.jl b/src/Experimental/vf2.jl index 8b66f7126..d4286fe4b 100644 --- a/src/Experimental/vf2.jl +++ b/src/Experimental/vf2.jl @@ -278,10 +278,10 @@ function vf2check_feasibility( vf2rule_self_loops(u, v, state, problemtype) syntactic_feasability || return false - if vertex_relation != nothing + if !isnothing(vertex_relation) vertex_relation(u, v) || return false end - if edge_relation != nothing + if !isnothing(edge_relation) E1 = edgetype(state.g1) E2 = edgetype(state.g2) for u2 in outneighbors(state.g1, u) diff --git a/src/SimpleGraphs/simpledigraph.jl b/src/SimpleGraphs/simpledigraph.jl index 56f9e3653..598ed976b 100644 --- a/src/SimpleGraphs/simpledigraph.jl +++ b/src/SimpleGraphs/simpledigraph.jl @@ -335,7 +335,7 @@ function _SimpleDiGraphFromIterator(iter)::SimpleDiGraph fadjlist = Vector{Vector{T}}() badjlist = Vector{Vector{T}}() - while next != nothing + while !isnothing(next) (e, state) = next if !(e isa E) diff --git a/src/SimpleGraphs/simplegraph.jl b/src/SimpleGraphs/simplegraph.jl index b896c33ae..c97806548 100644 --- a/src/SimpleGraphs/simplegraph.jl +++ b/src/SimpleGraphs/simplegraph.jl @@ -316,7 +316,7 @@ function _SimpleGraphFromIterator(iter)::SimpleGraph g = SimpleGraph{T}() fadjlist = Vector{Vector{T}}() - while next != nothing + while !isnothing(next) (e, state) = next if !(e isa E) diff --git a/src/cycles/basis.jl b/src/cycles/basis.jl index e26692384..9ff04cd5e 100644 --- a/src/cycles/basis.jl +++ b/src/cycles/basis.jl @@ -36,7 +36,7 @@ function cycle_basis(g::AbstractGraph, root=nothing) nv(g) == 0 && return cycles gnodes = Set(vertices(g)) - r::T = (root == nothing) ? pop!(gnodes) : T(root) + r::T = isnothing(root) ? pop!(gnodes) : T(root) while true stack = [r] pred = Dict(r => r) diff --git a/src/dominatingset/minimal_dom_set.jl b/src/dominatingset/minimal_dom_set.jl index a91837de0..554ac5f34 100644 --- a/src/dominatingset/minimal_dom_set.jl +++ b/src/dominatingset/minimal_dom_set.jl @@ -42,7 +42,7 @@ function dominating_set( # Check if any vertex is depending on v to be dominated dependent = findfirst(u -> !in_dom_set[u] && dom_degree[u] <= 1, neighbors(g, v)) - (dependent != nothing) && continue + !isnothing(dependent) && continue in_dom_set[v] = false length_ds -= 1 dom_degree[neighbors(g, v)] .-= 1 diff --git a/test/experimental/isomorphism.jl b/test/experimental/isomorphism.jl index 658ca60d5..dc4551d50 100644 --- a/test/experimental/isomorphism.jl +++ b/test/experimental/isomorphism.jl @@ -84,24 +84,24 @@ cubic_graphs = [ cubic_graphs_perm = [] rng = StableRNG(1) -for i in 1:length(cubic_graphs) - push!(cubic_graphs_perm, shuffle_vertices(cubic_graphs[i], randperm(rng, 8))) +for graph in cubic_graphs + push!(cubic_graphs_perm, shuffle_vertices(graph, randperm(rng, 8))) end @testset "Isomorphism" begin @test has_isomorph(grid([2, 3]), grid([3, 2])) - # the cubic graphs should only be isomorph to themself + # the cubic graphs should only be isomorphic to themselves # the same holds for subgraph isomorphism and induced subgraph isomorphism - for i in 1:length(cubic_graphs), j in 1:length(cubic_graphs) + for i in eachindex(cubic_graphs), j in eachindex(cubic_graphs) @test (i == j) == has_isomorph(cubic_graphs[i], cubic_graphs[j]) @test (i == j) == has_subgraphisomorph(cubic_graphs[i], cubic_graphs[j]) @test (i == j) == has_induced_subgraphisomorph(cubic_graphs[i], cubic_graphs[j]) end - # the cubic graphs should only be isomorph a permutation of themself + # the cubic graphs should only be isomorphic to a permutation of themselves # the same holds for subgraph isomorphism and induced subgraph isomorphism - for i in 1:length(cubic_graphs), j in 1:length(cubic_graphs_perm) + for i in eachindex(cubic_graphs), j in eachindex(cubic_graphs_perm) @test (i == j) == has_isomorph(cubic_graphs[i], cubic_graphs_perm[j]) @test (i == j) == has_subgraphisomorph(cubic_graphs[i], cubic_graphs_perm[j]) @test (i == j) == @@ -109,7 +109,7 @@ end end # count_isomorph, count_subgraphisomorph and count_induced_subgraphisomorph are commutative - for i in 1:length(cubic_graphs) + for i in eachindex(cubic_graphs) g1 = cubic_graphs[i] g2 = cubic_graphs_perm[i] @test count_isomorph(g1, g1) == @@ -126,7 +126,7 @@ end count_subgraphisomorph(g2, g2) end - for i in 1:length(cubic_graphs) + for i in eachindex(cubic_graphs) g1 = cubic_graphs[i] g2 = cubic_graphs_perm[i] length(collect(all_isomorph(g1, g1))) == count_isomorph(g1, g2) diff --git a/test/linalg/graphmatrices.jl b/test/linalg/graphmatrices.jl index e667124ad..9cc73ea70 100644 --- a/test/linalg/graphmatrices.jl +++ b/test/linalg/graphmatrices.jl @@ -200,7 +200,7 @@ using ArnoldiMethod: LM, SR, LR, partialschur, partialeigen abs(l1 - 1) < 1e-8 || error("failed to compute stationary distribution") # TODO 0.7: should we change the error type to InexactError? p = real(er[2][:, 1]) if p[1] < 0 - for i in 1:length(p) + for i in eachindex(p) p[i] = -p[i] end end