Skip to content

Commit 3904a2b

Browse files
VSCode warnings (#423)
Changed a bunch of iterations from `for i in 1:length(vec)` to `for i in eachindex(vec)`. I substituted a loop with a list comprehension because it seemed faster and clearer to read. I correct some spelling typos in comments in the code. I replaced comparisons of the type `a == nothing` with `isnothing(a)`.
1 parent 6130332 commit 3904a2b

File tree

8 files changed

+18
-22
lines changed

8 files changed

+18
-22
lines changed

benchmark/serial/edges.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ const P = Pair{Int,Int}
55
convert(::Type{Tuple}, e::Pair) = (e.first, e.second)
66

77
function fille(n)
8-
t = Vector{Graphs.Edge}(undef, n)
9-
for i in 1:n
10-
t[i] = Graphs.Edge(i, i + 1)
11-
end
12-
return t
8+
return [Graphs.Edge(i, i + 1) for i in 1:n]
139
end
1410

1511
function fillp(n)
@@ -22,8 +18,8 @@ end
2218

2319
function tsum(t)
2420
x = 0
25-
for i in 1:length(t)
26-
u, v = Tuple(t[i])
21+
for item in t
22+
u, v = Tuple(item)
2723
x += u
2824
x += v
2925
end

src/Experimental/vf2.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ function vf2check_feasibility(
278278
vf2rule_self_loops(u, v, state, problemtype)
279279
syntactic_feasability || return false
280280

281-
if vertex_relation != nothing
281+
if !isnothing(vertex_relation)
282282
vertex_relation(u, v) || return false
283283
end
284-
if edge_relation != nothing
284+
if !isnothing(edge_relation)
285285
E1 = edgetype(state.g1)
286286
E2 = edgetype(state.g2)
287287
for u2 in outneighbors(state.g1, u)

src/SimpleGraphs/simpledigraph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ function _SimpleDiGraphFromIterator(iter)::SimpleDiGraph
335335
fadjlist = Vector{Vector{T}}()
336336
badjlist = Vector{Vector{T}}()
337337

338-
while next != nothing
338+
while !isnothing(next)
339339
(e, state) = next
340340

341341
if !(e isa E)

src/SimpleGraphs/simplegraph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ function _SimpleGraphFromIterator(iter)::SimpleGraph
316316
g = SimpleGraph{T}()
317317
fadjlist = Vector{Vector{T}}()
318318

319-
while next != nothing
319+
while !isnothing(next)
320320
(e, state) = next
321321

322322
if !(e isa E)

src/cycles/basis.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function cycle_basis(g::AbstractGraph, root=nothing)
3636
nv(g) == 0 && return cycles
3737

3838
gnodes = Set(vertices(g))
39-
r::T = (root == nothing) ? pop!(gnodes) : T(root)
39+
r::T = isnothing(root) ? pop!(gnodes) : T(root)
4040
while true
4141
stack = [r]
4242
pred = Dict(r => r)

src/dominatingset/minimal_dom_set.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function dominating_set(
4242
# Check if any vertex is depending on v to be dominated
4343
dependent = findfirst(u -> !in_dom_set[u] && dom_degree[u] <= 1, neighbors(g, v))
4444

45-
(dependent != nothing) && continue
45+
!isnothing(dependent) && continue
4646
in_dom_set[v] = false
4747
length_ds -= 1
4848
dom_degree[neighbors(g, v)] .-= 1

test/experimental/isomorphism.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,32 +84,32 @@ cubic_graphs = [
8484
cubic_graphs_perm = []
8585

8686
rng = StableRNG(1)
87-
for i in 1:length(cubic_graphs)
88-
push!(cubic_graphs_perm, shuffle_vertices(cubic_graphs[i], randperm(rng, 8)))
87+
for graph in cubic_graphs
88+
push!(cubic_graphs_perm, shuffle_vertices(graph, randperm(rng, 8)))
8989
end
9090

9191
@testset "Isomorphism" begin
9292
@test has_isomorph(grid([2, 3]), grid([3, 2]))
9393

94-
# the cubic graphs should only be isomorph to themself
94+
# the cubic graphs should only be isomorphic to themselves
9595
# the same holds for subgraph isomorphism and induced subgraph isomorphism
96-
for i in 1:length(cubic_graphs), j in 1:length(cubic_graphs)
96+
for i in eachindex(cubic_graphs), j in eachindex(cubic_graphs)
9797
@test (i == j) == has_isomorph(cubic_graphs[i], cubic_graphs[j])
9898
@test (i == j) == has_subgraphisomorph(cubic_graphs[i], cubic_graphs[j])
9999
@test (i == j) == has_induced_subgraphisomorph(cubic_graphs[i], cubic_graphs[j])
100100
end
101101

102-
# the cubic graphs should only be isomorph a permutation of themself
102+
# the cubic graphs should only be isomorphic to a permutation of themselves
103103
# the same holds for subgraph isomorphism and induced subgraph isomorphism
104-
for i in 1:length(cubic_graphs), j in 1:length(cubic_graphs_perm)
104+
for i in eachindex(cubic_graphs), j in eachindex(cubic_graphs_perm)
105105
@test (i == j) == has_isomorph(cubic_graphs[i], cubic_graphs_perm[j])
106106
@test (i == j) == has_subgraphisomorph(cubic_graphs[i], cubic_graphs_perm[j])
107107
@test (i == j) ==
108108
has_induced_subgraphisomorph(cubic_graphs[i], cubic_graphs_perm[j])
109109
end
110110

111111
# count_isomorph, count_subgraphisomorph and count_induced_subgraphisomorph are commutative
112-
for i in 1:length(cubic_graphs)
112+
for i in eachindex(cubic_graphs)
113113
g1 = cubic_graphs[i]
114114
g2 = cubic_graphs_perm[i]
115115
@test count_isomorph(g1, g1) ==
@@ -126,7 +126,7 @@ end
126126
count_subgraphisomorph(g2, g2)
127127
end
128128

129-
for i in 1:length(cubic_graphs)
129+
for i in eachindex(cubic_graphs)
130130
g1 = cubic_graphs[i]
131131
g2 = cubic_graphs_perm[i]
132132
length(collect(all_isomorph(g1, g1))) == count_isomorph(g1, g2)

test/linalg/graphmatrices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ using ArnoldiMethod: LM, SR, LR, partialschur, partialeigen
200200
abs(l1 - 1) < 1e-8 || error("failed to compute stationary distribution") # TODO 0.7: should we change the error type to InexactError?
201201
p = real(er[2][:, 1])
202202
if p[1] < 0
203-
for i in 1:length(p)
203+
for i in eachindex(p)
204204
p[i] = -p[i]
205205
end
206206
end

0 commit comments

Comments
 (0)