Skip to content

Commit d698d19

Browse files
committed
use JuliaFormatter
1 parent f07f22c commit d698d19

File tree

9 files changed

+111
-138
lines changed

9 files changed

+111
-138
lines changed

.JuliaFormatter.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
always_for_in = true
2+
always_use_return = true
3+
import_to_using = true
4+
margin = 110
5+
pipe_to_function_call = true
6+
remove_extra_newlines = true
7+
short_to_long_function_def = true
8+
style = "yas"
9+
whitespace_in_kwargs = false
10+
whitespace_ops_in_indices = true
11+
whitespace_typedefs = false

src/buchheim.jl

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function Tree(tree::AbstractVector, nodesize)
4141
end
4242

4343
function layout(t::AbstractVector; nodesize=ones(length(t)))
44-
layout!(t, nodesize)
44+
return layout!(t, nodesize)
4545
end
4646

4747
function layout!(t::AbstractVector, nodesize)
@@ -54,7 +54,7 @@ end
5454
function parent(v, t::Tree)
5555
tree = t.nodes
5656
for i in 1:length(tree)
57-
y = findall(x -> (x==v), tree[i])
57+
y = findall(x -> (x == v), tree[i])
5858
if length(y) != 0
5959
return i
6060
end
@@ -67,28 +67,28 @@ function first_walk(v, t::Tree)
6767
mod = t.mod
6868
tree = t.nodes
6969
nodesize = t.nodesize
70-
p = parent(v,t)
70+
p = parent(v, t)
7171
if p != nothing
72-
index = findall(x -> (x==v), tree[p])[1]
72+
index = findall(x -> (x == v), tree[p])[1]
7373
else
7474
index = 1
7575
end
7676
if length(tree[v]) == 0
7777
if v != tree[p][1]
78-
prelim[v] = prelim[tree[p][index-1]] + (nodesize[tree[p][index-1]])
78+
prelim[v] = prelim[tree[p][index - 1]] + (nodesize[tree[p][index - 1]])
7979
else
80-
prelim[v] = 0
80+
prelim[v] = 0
8181
end
8282
else
8383
defaultAncestor = tree[v][1]
8484
for w in tree[v]
85-
first_walk(w,t)
85+
first_walk(w, t)
8686
defaultAncestor = apportion(w, defaultAncestor, t)
8787
end
8888
execute_shifts(v, t)
8989
midpoint = (prelim[tree[v][1]] + prelim[tree[v][end]]) / 2
9090
if index > 1
91-
w = tree[p][index-1]
91+
w = tree[p][index - 1]
9292
prelim[v] = prelim[w] + (nodesize[w] + 1.0)
9393
mod[v] = prelim[v] - midpoint
9494
else
@@ -106,28 +106,29 @@ function apportion(v::T, defaultAncestor::T, t::Tree) where {T}
106106
p = parent(v, t)
107107
nodesize = t.nodesize
108108
if p != nothing
109-
index = findall(x-> (x==v), tree[p])[1]
109+
index = findall(x -> (x == v), tree[p])[1]
110110
else
111111
index = 1
112112
end
113113
if index > 1
114-
w = tree[p][index-1]
114+
w = tree[p][index - 1]
115115
v_in_right = v_out_right = v
116116
v_in_left = w
117117
v_out_left = tree[parent(v_in_right, t)][1]
118118
s_in_right = mod[v_in_right]
119119
s_out_right = mod[v_out_right]
120120
s_in_left = mod[v_in_left]
121121
s_out_left = mod[v_out_left]
122-
while next_right(v_in_left, t)!=0 && next_left(v_in_right, t)!=0
122+
while next_right(v_in_left, t) != 0 && next_left(v_in_right, t) != 0
123123
v_in_left = next_right(v_in_left, t)
124124
v_in_right = next_left(v_in_right, t)
125125
v_out_left = next_left(v_out_left, t)
126126
v_out_right = next_right(v_out_right, t)
127127
ancestor[v_out_right] = v
128-
shift = (prelim[v_in_left] + s_in_left) - (prelim[v_in_right] + s_in_right) + (nodesize[v_in_left])
128+
shift = (prelim[v_in_left] + s_in_left) - (prelim[v_in_right] + s_in_right) +
129+
(nodesize[v_in_left])
129130
if shift > 0
130-
move_subtree(find_ancestor(v_in_left, v, defaultAncestor,t), v,shift, t)
131+
move_subtree(find_ancestor(v_in_left, v, defaultAncestor, t), v, shift, t)
131132
s_in_right += shift
132133
s_out_right += shift
133134
end
@@ -140,7 +141,7 @@ function apportion(v::T, defaultAncestor::T, t::Tree) where {T}
140141
thread[v_out_right] = next_right(v_in_left, t)
141142
mod[v_out_right] += s_in_left - s_out_right
142143
else
143-
if next_left(v_in_right,t) != 0 && next_left(v_out_left,t) == 0
144+
if next_left(v_in_right, t) != 0 && next_left(v_out_left, t) == 0
144145
thread[v_out_left] = next_left(v_in_right, t)
145146
mod[v_out_left] += s_in_right - s_out_left
146147
defaultAncestor = v
@@ -152,7 +153,7 @@ end
152153

153154
function number(v, t::Tree)
154155
p = parent(v, t)
155-
index = findall(x -> (x==v), t.nodes[p])[1]
156+
index = findall(x -> (x == v), t.nodes[p])[1]
156157
return index
157158
end
158159

@@ -169,22 +170,22 @@ function move_subtree(w_left::T, w_right::T, shift::Float64, t::Tree) where {T}
169170
shifttree[w_right] += shift
170171
change[w_left] += shift / subtrees
171172
prelim[w_right] += shift
172-
mod[w_right] += shift
173+
return mod[w_right] += shift
173174
end
174175

175176
function second_walk(v, m::Float64, depth::Float64, t::Tree)
176177
prelim = t.prelim
177178
mod = t.mod
178179
positions = t.positions
179180
nodesize = t.nodesize
180-
positions[v] = Point(prelim[v]+m, -depth)
181+
positions[v] = Point(prelim[v] + m, -depth)
181182
if length(t.nodes[v]) != 0
182183
maxdist = maximum([nodesize[i] for i in t.nodes[v]])
183184
else
184185
maxdist = 0
185186
end
186187
for w in t.nodes[v]
187-
second_walk(w, m+mod[v], Float64(depth + 1 + maxdist), t)
188+
second_walk(w, m + mod[v], Float64(depth + 1 + maxdist), t)
188189
end
189190
end
190191

src/circular.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ module Circular
1919
using GeometryBasics
2020

2121
function layout(adj_matrix::AbstractMatrix)
22-
layout!(adj_matrix)
22+
return layout!(adj_matrix)
2323
end
2424

2525
function layout!(adj_matrix::AbstractMatrix)
2626
if size(adj_matrix, 1) == 1
2727
return Point{2,Float64}[Point(0.0, 0.0)]
2828
else
2929
# Discard the extra angle since it matches 0 radians.
30-
θ = range(0, stop=2pi, length=size(adj_matrix, 1) + 1)[1:end - 1]
30+
θ = range(0, stop=2pi, length=size(adj_matrix, 1) + 1)[1:(end - 1)]
3131
return Point{2,Float64}[(cos(o), sin(o)) for o in θ]
3232
end
3333
end

src/sfdp.jl

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module SFDP
1616
using GeometryBasics
1717
using LinearAlgebra: norm
1818

19-
struct Layout{M <: AbstractMatrix,P <: AbstractVector,T <: AbstractFloat}
19+
struct Layout{M<:AbstractMatrix,P<:AbstractVector,T<:AbstractFloat}
2020
adj_matrix::M
2121
positions::P
2222
tol::T
@@ -25,28 +25,20 @@ struct Layout{M <: AbstractMatrix,P <: AbstractVector,T <: AbstractFloat}
2525
iterations::Int
2626
end
2727

28-
function Layout(
29-
adj_matrix, PT::Type{Point{N,T}}=Point{2,Float64};
30-
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)),
31-
tol=1.0, C=0.2, K=1.0, iterations=100
32-
) where {N,T}
33-
Layout(adj_matrix, startpositions, T(tol), T(C), T(K), Int(iterations))
28+
function Layout(adj_matrix, PT::Type{Point{N,T}}=Point{2,Float64};
29+
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)), tol=1.0, C=0.2, K=1.0,
30+
iterations=100) where {N,T}
31+
return Layout(adj_matrix, startpositions, T(tol), T(C), T(K), Int(iterations))
3432
end
3533

3634
layout(adj_matrix, dim::Int; kw_args...) = layout(adj_matrix, Point{dim,Float64}; kw_args...)
3735

38-
function layout(
39-
adj_matrix, PT::Type{Point{N,T}}=Point{2,Float64};
40-
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)),
41-
kw_args...
42-
) where {N,T}
43-
layout!(adj_matrix, startpositions; kw_args...)
36+
function layout(adj_matrix, PT::Type{Point{N,T}}=Point{2,Float64};
37+
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)), kw_args...) where {N,T}
38+
return layout!(adj_matrix, startpositions; kw_args...)
4439
end
4540

46-
function layout!(adj_matrix,
47-
startpositions::AbstractVector{Point{N,T}};
48-
kw_args...
49-
) where {N,T}
41+
function layout!(adj_matrix, startpositions::AbstractVector{Point{N,T}}; kw_args...) where {N,T}
5042
network = Layout(adj_matrix, Point{N,T}; startpositions=startpositions, kw_args...)
5143
next = iterate(network)
5244
while next != nothing
@@ -67,19 +59,23 @@ end
6759
function iterate(network::Layout, state)
6860
step, energy, progress, start, iter, locs0 = state
6961
K, C, tol, adj_matrix = network.K, network.C, network.tol, network.adj_matrix
70-
locs = network.positions; locs0 = copy(locs)
71-
energy0 = energy; energy = zero(energy)
72-
F = eltype(locs); N = size(adj_matrix, 1)
62+
locs = network.positions
63+
locs0 = copy(locs)
64+
energy0 = energy
65+
energy = zero(energy)
66+
F = eltype(locs)
67+
N = size(adj_matrix, 1)
7368
for i in 1:N
7469
force = F(0)
7570
for j in 1:N
7671
i == j && continue
77-
if adj_matrix[i,j] == 1
78-
# Attractive forces for adjacent nodes
72+
if adj_matrix[i, j] == 1
73+
# Attractive forces for adjacent nodes
7974
force += F(f_attr(locs[i], locs[j], K) .* ((locs[j] .- locs[i]) / norm(locs[j] .- locs[i])))
8075
else
81-
# Repulsive forces
82-
force += F(f_repln(locs[i], locs[j], C, K) .* ((locs[j] .- locs[i]) / norm(locs[j] .- locs[i])))
76+
# Repulsive forces
77+
force += F(f_repln(locs[i], locs[j], C, K) .*
78+
((locs[j] .- locs[i]) / norm(locs[j] .- locs[i])))
8379
end
8480
end
8581
locs[i] = locs[i] .+ step .* (force ./ norm(force))
@@ -96,7 +92,7 @@ function iterate(network::Layout, state)
9692
end
9793

9894
# Calculate Attractive force
99-
f_attr(a, b, K) = (norm(a .- b).^2) ./ K
95+
f_attr(a, b, K) = (norm(a .- b) .^ 2) ./ K
10096
# Calculate Repulsive force
10197
f_repln(a, b, C, K) = -C .* (K^2) / norm(a .- b)
10298

src/shell.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module Shell
2020
using GeometryBasics
2121

2222
function layout(adj_matrix::AbstractMatrix; nlist::Union{Nothing,Vector{Vector{Int}}}=nothing)
23-
layout!(adj_matrix, nlist)
23+
return layout!(adj_matrix, nlist)
2424
end
2525

2626
function layout!(adj_matrix::AbstractMatrix, nlist::Union{Nothing,Vector{Vector{Int}}})
@@ -39,12 +39,12 @@ function layout!(adj_matrix::AbstractMatrix, nlist::Union{Nothing,Vector{Vector{
3939
locs = T[]
4040
for nodes in nlist
4141
# Discard the extra angle since it matches 0 radians.
42-
θ = range(0, stop=2pi, length=length(nodes) + 1)[1:end - 1]
42+
θ = range(0, stop=2pi, length=length(nodes) + 1)[1:(end - 1)]
4343
x = T[(radius * cos(o), radius * sin(o)) for o in θ]
4444
append!(locs, x)
4545
radius += 1.0
4646
end
47-
locs
47+
return locs
4848
end
4949

5050
end # end of module

src/spectral.jl

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ using LinearAlgebra: diag, eigen, Diagonal
1515

1616
function make_symmetric(adj_matrix::AbstractMatrix)
1717
adj_matrix = copy(adj_matrix)
18-
for i in 1:size(adj_matrix, 1), j in i + 1:size(adj_matrix, 2)
19-
adj_matrix[i,j] = adj_matrix[j,i] = adj_matrix[i,j] + adj_matrix[j,i]
18+
for i in 1:size(adj_matrix, 1), j in (i + 1):size(adj_matrix, 2)
19+
adj_matrix[i, j] = adj_matrix[j, i] = adj_matrix[i, j] + adj_matrix[j, i]
2020
end
21-
adj_matrix
21+
return adj_matrix
2222
end
2323

2424
function compute_laplacian(adj_matrix, node_weights)
@@ -35,24 +35,18 @@ function compute_laplacian(adj_matrix, node_weights)
3535
D = Matrix(Diagonal(deg))
3636
T = eltype(node_weights)
3737
# Laplacian (L = D - adj_matrix)
38-
L = T[i == j ? deg[i] : -adj_matrix[i,j] for i = 1:n,j = 1:n]
39-
38+
L = T[i == j ? deg[i] : -adj_matrix[i, j] for i in 1:n, j in 1:n]
4039
return L, D
4140
end
4241

43-
function layout(
44-
adj_matrix::M;
45-
node_weights=ones(eltype(M),
46-
size(adj_matrix, 1)),
47-
kw_args...
48-
) where {M <: AbstractMatrix}
49-
layout!(adj_matrix, node_weights, kw_args...)
42+
function layout(adj_matrix::M; node_weights=ones(eltype(M), size(adj_matrix, 1)),
43+
kw_args...) where {M<:AbstractMatrix}
44+
return layout!(adj_matrix, node_weights, kw_args...)
5045
end
5146

5247
function layout!(adj_matrix, node_weights, kw_args...)
5348
adj_matrix = make_symmetric(adj_matrix)
5449
L, D = compute_laplacian(adj_matrix, node_weights)
55-
5650
# get the matrix of eigenvectors
5751
v = eigen(L, D).vectors
5852
# x, y, and z are the 2nd through 4th eigenvectors of the solution to the

src/spring.jl

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,38 +19,28 @@ module Spring
1919
using GeometryBasics
2020
using LinearAlgebra: norm
2121

22-
struct Layout{M <: AbstractMatrix,P <: AbstractVector,T <: AbstractFloat}
22+
struct Layout{M<:AbstractMatrix,P<:AbstractVector,T<:AbstractFloat}
2323
adj_matrix::M
2424
positions::P
2525
C::T
2626
iterations::Int
2727
initialtemp::T
2828
end
2929

30-
function Layout(
31-
adj_matrix,
32-
PT::Type{Point{N,T}}=Point{2,Float64};
33-
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)),
34-
C=2.0, iterations=100, initialtemp=2.0
35-
) where {N,T}
36-
Layout(adj_matrix, startpositions, T(C), Int(iterations), T(initialtemp))
30+
function Layout(adj_matrix, PT::Type{Point{N,T}}=Point{2,Float64};
31+
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)), C=2.0, iterations=100,
32+
initialtemp=2.0) where {N,T}
33+
return Layout(adj_matrix, startpositions, T(C), Int(iterations), T(initialtemp))
3734
end
3835

3936
layout(adj_matrix, dim::Int; kw_args...) = layout(adj_matrix, Point{dim,Float64}; kw_args...)
4037

41-
function layout(
42-
adj_matrix, PT::Type{Point{N,T}}=Point{2,Float64};
43-
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)),
44-
kw_args...
45-
) where {N,T}
46-
layout!(adj_matrix, startpositions;kw_args...)
38+
function layout(adj_matrix, PT::Type{Point{N,T}}=Point{2,Float64};
39+
startpositions=map(x -> 2 .* rand(PT) .- 1, 1:size(adj_matrix, 1)), kw_args...) where {N,T}
40+
return layout!(adj_matrix, startpositions; kw_args...)
4741
end
4842

49-
function layout!(
50-
adj_matrix,
51-
startpositions::AbstractVector{Point{N,T}};
52-
kw_args...
53-
) where {N,T}
43+
function layout!(adj_matrix, startpositions::AbstractVector{Point{N,T}}; kw_args...) where {N,T}
5444
size(adj_matrix, 1) != size(adj_matrix, 2) && error("Adj. matrix must be square.")
5545
# Layout object for the graph
5646
network = Layout(adj_matrix, Point{N,T}; startpositions=startpositions, kw_args...)
@@ -81,12 +71,12 @@ function iterate(network::Layout{M,P,T}, state) where {M,P,T}
8171
K = C * sqrt(4.0 / N)
8272

8373
# Calculate forces
84-
for i = 1:N
74+
for i in 1:N
8575
force_vec = Ftype(0)
86-
for j = 1:N
76+
for j in 1:N
8777
i == j && continue
8878
d = norm(locs[j] .- locs[i])
89-
if adj_matrix[i,j] != zero(eltype(adj_matrix)) || adj_matrix[j,i] != zero(eltype(adj_matrix))
79+
if adj_matrix[i, j] != zero(eltype(adj_matrix)) || adj_matrix[j, i] != zero(eltype(adj_matrix))
9080
# F = d^2 / K - K^2 / d
9181
F_d = d / K - K^2 / d^2
9282
else
@@ -106,7 +96,7 @@ function iterate(network::Layout{M,P,T}, state) where {M,P,T}
10696
# Cool down
10797
temp = initialtemp / state
10898
# Now apply them, but limit to temperature
109-
for i = 1:N
99+
for i in 1:N
110100
force_mag = norm(force[i])
111101
scale = min(force_mag, temp) ./ force_mag
112102
locs[i] += force[i] .* scale

0 commit comments

Comments
 (0)