Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
fix whitespace issues throughout codebase (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbromberger authored Jul 12, 2017
1 parent b623300 commit 6642481
Show file tree
Hide file tree
Showing 110 changed files with 1,300 additions and 1,314 deletions.
6 changes: 3 additions & 3 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using PkgBenchmark
using LightGraphs


testdatadir = joinpath(dirname(@__FILE__), "..","test","testdata")
testdatadir = joinpath(dirname(@__FILE__), "..", "test", "testdata")
benchdatadir = joinpath(dirname(@__FILE__), "data")
paramsfile = joinpath(benchdatadir, "params.jld")

Expand All @@ -11,13 +11,13 @@ println("paramsfile = $paramsfile")

dg1fn = joinpath(testdatadir, "graph-5k-50k.jgz")

DIGRAPHS = Dict{String, DiGraph}(
DIGRAPHS = Dict{String,DiGraph}(
"complete100" => CompleteDiGraph(100),
"5000-50000" => LightGraphs.load(dg1fn)["graph-5000-50000"],
"path500" => PathDiGraph(500)
)

GRAPHS = Dict{String, Graph}(
GRAPHS = Dict{String,Graph}(
"complete100" => CompleteGraph(100),
"tutte" => smallgraph(:tutte),
"path500" => PathGraph(500),
Expand Down
8 changes: 4 additions & 4 deletions benchmark/edges.jl
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import Base: convert

const P = Pair{Int, Int}
const P = Pair{Int,Int}

convert(::Type{Tuple}, e::Pair) = (e.first, e.second)

function fille(n)
t = Array{LightGraphs.Edge,1}(n)
for i in 1:n
t[i] = LightGraphs.Edge(i, i+1)
t[i] = LightGraphs.Edge(i, i + 1)
end
return t
end

function fillp(n)
t = Array{P,1}(n)
for i in 1:n
t[i] = P(i, i+1)
t[i] = P(i, i + 1)
end
return t
end

function tsum(t)
x = 0
for i in 1:length(t)
u,v = Tuple(t[i])
u, v = Tuple(t[i])
x += u
x += v
end
Expand Down
2 changes: 1 addition & 1 deletion benchmark/insertions.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@benchgroup "insertions" begin
n = 10000
@bench "ER Generation" g = Graph($n, 16*$n)
@bench "ER Generation" g = Graph($n, 16 * $n)
end
4 changes: 2 additions & 2 deletions benchmark/max-flow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
for n in 9:5:29
srand(1)
p = 8.0 / n
A = sprand(n,n,p)
A = sprand(n, n, p)
g = DiGraph(A)
cap = round.(A*100)
cap = round.(A * 100)
@bench "n = $n" LightGraphs.maximum_flow($g, 1, $n, $cap)
end
end # max-flow
4 changes: 2 additions & 2 deletions benchmark/parallel/egonets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using BenchmarkTools
a = 0
for u in neighbors(g, i)
for v in neighbors(g, u)
a += degree(g,v)
a += degree(g, v)
end
end
return a
Expand Down Expand Up @@ -53,7 +53,7 @@ using BenchmarkTools
end

nv_ = 10000
g = Graph(nv_, 64*nv_)
g = Graph(nv_, 64 * nv_)
f = vertex_function
println(g)

Expand Down
3 changes: 0 additions & 3 deletions src/LightGraphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,6 @@ CombinatorialAdjacency, non_backtracking_matrix, incidence_matrix,
nonbacktrack_embedding, Nonbacktracking,
contract,

# astar
a_star,

# persistence
loadgraph, loadgraphs, savegraph, LGFormat,

Expand Down
2 changes: 1 addition & 1 deletion src/biconnectivity/biconnect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function visit!(g::AbstractGraph, state::Biconnections, u::Integer, v::Integer)
if (u == v && children > 1) || (u != v && state.low[w] >= state.depth[v])
e = Edge(0, 0) #Invalid Edge, used for comparison only
st = Vector{Edge}()
while e != Edge(min(v, w),max(v, w))
while e != Edge(min(v, w), max(v, w))
e = pop!(state.stack)
push!(st, e)
end
Expand Down
2 changes: 1 addition & 1 deletion src/centrality/betweenness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function betweenness_centrality(

betweenness = zeros(n_v)
for s in vs
if degree(g,s) > 0 # this might be 1?
if degree(g, s) > 0 # this might be 1?
state = dijkstra_shortest_paths(g, s; allpaths=true, trackvertices=true)
if endpoints
_accumulate_endpoints!(betweenness, state, g, s)
Expand Down
12 changes: 6 additions & 6 deletions src/centrality/closeness.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ function closeness_centrality(
if degree(g, u) == 0 # no need to do Dijkstra here
closeness[u] = 0.0
else
d = dijkstra_shortest_paths(g,u,distmx).dists
δ = filter(x->x != typemax(x), d)
d = dijkstra_shortest_paths(g, u, distmx).dists
δ = filter(x -> x != typemax(x), d)
σ = sum(δ)
l = length(δ) - 1
if σ > 0
closeness[u] = l / σ
if normalize
n = l / (n_v-1)
n = l / (n_v - 1)
closeness[u] *= n
end
end
Expand All @@ -50,14 +50,14 @@ function parallel_closeness_centrality(
if degree(g, u) == 0 # no need to do Dijkstra here
closeness[u] = 0.0
else
d = dijkstra_shortest_paths(g,u,distmx).dists
δ = filter(x->x != typemax(x), d)
d = dijkstra_shortest_paths(g, u, distmx).dists
δ = filter(x -> x != typemax(x), d)
σ = sum(δ)
l = length(δ) - 1
if σ > 0
closeness[u] = l / σ
if normalize
n = l * 1.0 / (n_v-1)
n = l * 1.0 / (n_v - 1)
closeness[u] *= n
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/centrality/degree.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ function _degree_centrality(g::AbstractGraph, gtype::Integer; normalize=true)
c = zeros(n_v)
for v in vertices(g)
if gtype == 0 # count both in and out degree if appropriate
deg = is_directed(g)? outdegree(g, v) + indegree(g, v) : outdegree(g, v)
deg = is_directed(g) ? outdegree(g, v) + indegree(g, v) : outdegree(g, v)
elseif gtype == 1 # count only in degree
deg = indegree(g, v)
else # count only out degree
deg = outdegree(g, v)
end
s = normalize? (1.0 / (n_v - 1.0)) : 1.0
c[v] = deg*s
s = normalize ? (1.0 / (n_v - 1.0)) : 1.0
c[v] = deg * s
end
return c
end
Expand Down
2 changes: 1 addition & 1 deletion src/centrality/katz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function katz_centrality(g::AbstractGraph, α::Real=0.3)
v = ones(Float64, nvg)
spI = speye(Float64, nvg)
A = adjacency_matrix(g, :in, Bool)
v = (spI - α*A)\v
v = (spI - α * A) \ v
v /= norm(v)
return v
end
14 changes: 7 additions & 7 deletions src/centrality/pagerank.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ is not reached within `n` iterations.
function pagerank end

@traitfn function pagerank(g::::IsDirected, α=0.85, n=100::Integer, ϵ=1.0e-6)
A = adjacency_matrix(g,:in,Float64)
S = vec(sum(A,1))
S = 1./S
S[find(S .== Inf)]=0.0
M = A' # need a separate line due to bug #17456 in julia
A = adjacency_matrix(g, :in, Float64)
S = vec(sum(A, 1))
S = 1 ./ S
S[find(S .== Inf)] = 0.0
M = A' # need a separate line due to bug #17456 in julia
# scaling the adjmat to stochastic adjacency matrix
M = (Diagonal(S) * M)'
N = Int(nv(g))
# solution vector
x = fill(1.0/N, N)
x = fill(1.0 / N, N)
# personalization vector
p = fill(1.0/N, N)
p = fill(1.0 / N, N)
# temporary to hold the results of SpMV
y = zeros(Float64, N)
# adjustment for leaf nodes in digraph
Expand Down
2 changes: 1 addition & 1 deletion src/community/cliques.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function maximal_cliques end
# union!(cand, keys(nnbrs))
smallcand = setdiff(cand, pivotnbrs)
done = Set{T}()
stack = Vector{Tuple{Set{T}, Set{T}, Set{T}}}()
stack = Vector{Tuple{Set{T},Set{T},Set{T}}}()
clique_so_far = Vector{T}()
cliques = Vector{Array{T}}()

Expand Down
6 changes: 3 additions & 3 deletions src/community/clustering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end

function local_clustering_coefficient(g::AbstractGraph, vs = vertices(g))
ntriang, nalltriang = local_clustering(g, vs)
return map(p->p[2]==0? 0. : p[1]*1.0/p[2], zip(ntriang, nalltriang))
return map(p -> p[2] == 0 ? 0. : p[1] * 1.0 / p[2], zip(ntriang, nalltriang))
end

function local_clustering!(storage::AbstractVector{Bool}, g::AbstractGraph, v::Integer)
Expand All @@ -30,7 +30,7 @@ function local_clustering!(storage::AbstractVector{Bool}, g::AbstractGraph, v::I
end
end
end
return is_directed(g) ? (tcount , k*(k-1)) : (div(tcount,2) , div(k*(k-1),2))
return is_directed(g) ? (tcount, k * (k - 1)) : (div(tcount, 2), div(k * (k - 1), 2))
end

function local_clustering!(storage::AbstractVector{Bool},
Expand Down Expand Up @@ -101,7 +101,7 @@ function global_clustering_coefficient(g::AbstractGraph)
end
end
k = degree(g, v)
ntriangles += k*(k-1)
ntriangles += k * (k - 1)
end
ntriangles == 0 && return 1.
return c / ntriangles
Expand Down
4 changes: 2 additions & 2 deletions src/community/core-periphery.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function core_periphery_deg end
s = sum(degs) / 2.
sbest = +Inf
kbest = 0
for k = 1:nv(g)-1
s = s + k - 1 - degree(g, p[k])
for k = 1:nv(g) - 1
s = s + k - 1 - degree(g, p[k])
if s < sbest
sbest = s
kbest = k
Expand Down
18 changes: 9 additions & 9 deletions src/community/label_propagation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function label_propagation(g::AbstractGraph, maxiter=1000)
n = nv(g)
label = collect(one(T):n)
active_vs = IntSet(vertices(g))
c = NeighComm(collect(one(T):n), fill(-1,n), one(T))
c = NeighComm(collect(one(T):n), fill(-1, n), one(T))
convergence_hist = Vector{Int}()
random_order = Vector{T}(n)
i = 0
Expand All @@ -24,11 +24,11 @@ function label_propagation(g::AbstractGraph, maxiter=1000)
i += 1

# processing vertices in random order
for (j,node) in enumerate(active_vs)
for (j, node) in enumerate(active_vs)
random_order[j] = node
end
range_shuffle!(1:num_active, random_order)
@inbounds for j=1:num_active
@inbounds for j = 1:num_active
u = random_order[j]
old_comm = label[u]
label[u] = vote!(g, label, c, u)
Expand Down Expand Up @@ -64,11 +64,11 @@ Fast shuffle Array `a` in UnitRange `r`.
"""
function range_shuffle!(r::UnitRange, a::AbstractVector)
(r.start > 0 && r.stop <= length(a)) || error("out of bounds")
@inbounds for i=length(r):-1:2
@inbounds for i = length(r):-1:2
j = rand(1:i)
ii = i + r.start - 1
jj = j + r.start - 1
a[ii],a[jj] = a[jj],a[ii]
a[ii], a[jj] = a[jj], a[ii]
end
end

Expand All @@ -78,15 +78,15 @@ end
Return the label with greatest frequency.
"""
function vote!(g::AbstractGraph, m::Vector, c::NeighComm, u::Integer)
@inbounds for i=1:c.neigh_last-1
@inbounds for i = 1:c.neigh_last - 1
c.neigh_cnt[c.neigh_pos[i]] = -1
end
c.neigh_last = 1
c.neigh_pos[1] = m[u]
c.neigh_cnt[c.neigh_pos[1]] = 0
c.neigh_last = 2
max_cnt = 0
for neigh in out_neighbors(g,u)
for neigh in out_neighbors(g, u)
neigh_comm = m[neigh]
if c.neigh_cnt[neigh_comm] < 0
c.neigh_cnt[neigh_comm] = 0
Expand All @@ -99,7 +99,7 @@ function vote!(g::AbstractGraph, m::Vector, c::NeighComm, u::Integer)
end
end
# ties breaking randomly
range_shuffle!(1:c.neigh_last-1, c.neigh_pos)
range_shuffle!(1:c.neigh_last - 1, c.neigh_pos)
for lbl in c.neigh_pos
if c.neigh_cnt[lbl] == max_cnt
return lbl
Expand All @@ -111,7 +111,7 @@ function renumber_labels!(membership::Vector, label_counters::Vector{Int})
N = length(membership)
(maximum(membership) > N || minimum(membership) < 1) && error("Label must between 1 and |V|")
j = 1
@inbounds for i=1:length(membership)
@inbounds for i = 1:length(membership)
k = membership[i]
if k >= 1
if label_counters[k] == 0
Expand Down
14 changes: 7 additions & 7 deletions src/community/modularity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ Return a value representing Newman's modularity `Q` for the undirected graph
"""
function modularity end
@traitfn function modularity(g::::(!IsDirected), c::Vector)
m = 2*ne(g)
m = 2 * ne(g)
m == 0 && return 0.
nc = maximum(c)
a = zeros(Int,nc)
a = zeros(Int, nc)
Q = 0
for u in vertices(g)
for v in neighbors(g,u)
for v in neighbors(g, u)
if u <= v
c1 = c[u]
c2 = c[v]
Expand All @@ -24,9 +24,9 @@ function modularity end
end
end
end
Q = Q*m
@inbounds for i=1:nc
Q -= a[i]*a[i]
Q = Q * m
@inbounds for i = 1:nc
Q -= a[i] * a[i]
end
return Q/m/m
return Q / m / m
end
Loading

0 comments on commit 6642481

Please sign in to comment.