Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.

Commit c8a0a31

Browse files
committed
SciML style formatting
1 parent 55954f7 commit c8a0a31

28 files changed

Lines changed: 1125 additions & 624 deletions

.github/workflows/FormatCheck.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: format-check
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'release-'
8+
tags: '*'
9+
pull_request:
10+
11+
jobs:
12+
build:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
julia-version: [1]
17+
julia-arch: [x86]
18+
os: [ubuntu-latest]
19+
steps:
20+
- uses: julia-actions/setup-julia@latest
21+
with:
22+
version: ${{ matrix.julia-version }}
23+
24+
- uses: actions/checkout@v1
25+
- name: Install JuliaFormatter and format
26+
# This will use the latest version by default but you can set the version like so:
27+
#
28+
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
29+
run: |
30+
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
31+
julia -e 'using JuliaFormatter; format(".", verbose=true)'
32+
- name: Format check
33+
run: |
34+
julia -e '
35+
out = Cmd(`git diff --name-only`) |> read |> String
36+
if out == ""
37+
exit(0)
38+
else
39+
@error "Some files have not been formatted !!!"
40+
write(stdout, out)
41+
exit(1)
42+
end'

docs/make.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ makedocs(
1515
pages = pages,
1616
)
1717

18-
deploydocs(repo = "https://github.com/JuliaDiff/SparseDiffTools.jl.git"; push_preview = true)
18+
deploydocs(
19+
repo = "https://github.com/JuliaDiff/SparseDiffTools.jl.git";
20+
push_preview = true,
21+
)

src/SparseDiffTools.jl

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,40 @@ using DataStructures: DisjointSets, find_root!, union!
1919

2020
using ArrayInterfaceCore: matrix_colors
2121

22-
export contract_color,
23-
greedy_d1,
24-
greedy_star1_coloring,
25-
greedy_star2_coloring,
26-
matrix2graph,
27-
matrix_colors,
28-
forwarddiff_color_jacobian!,
29-
forwarddiff_color_jacobian,
30-
ForwardColorJacCache,
31-
numauto_color_hessian!,
32-
numauto_color_hessian,
33-
autoauto_color_hessian!,
34-
autoauto_color_hessian,
35-
ForwardColorHesCache,
36-
ForwardAutoColorHesCache,
37-
auto_jacvec,auto_jacvec!,
38-
num_jacvec,num_jacvec!,
39-
num_vecjac,num_vecjac!,
40-
num_hesvec,num_hesvec!,
41-
numauto_hesvec,numauto_hesvec!,
42-
autonum_hesvec,autonum_hesvec!,
43-
num_hesvecgrad,num_hesvecgrad!,
44-
auto_hesvecgrad,auto_hesvecgrad!,
45-
JacVec,HesVec,HesVecGrad
22+
export contract_color,
23+
greedy_d1,
24+
greedy_star1_coloring,
25+
greedy_star2_coloring,
26+
matrix2graph,
27+
matrix_colors,
28+
forwarddiff_color_jacobian!,
29+
forwarddiff_color_jacobian,
30+
ForwardColorJacCache,
31+
numauto_color_hessian!,
32+
numauto_color_hessian,
33+
autoauto_color_hessian!,
34+
autoauto_color_hessian,
35+
ForwardColorHesCache,
36+
ForwardAutoColorHesCache,
37+
auto_jacvec,
38+
auto_jacvec!,
39+
num_jacvec,
40+
num_jacvec!,
41+
num_vecjac,
42+
num_vecjac!,
43+
num_hesvec,
44+
num_hesvec!,
45+
numauto_hesvec,
46+
numauto_hesvec!,
47+
autonum_hesvec,
48+
autonum_hesvec!,
49+
num_hesvecgrad,
50+
num_hesvecgrad!,
51+
auto_hesvecgrad,
52+
auto_hesvecgrad!,
53+
JacVec,
54+
HesVec,
55+
HesVecGrad
4656

4757

4858
include("coloring/high_level.jl")
@@ -64,7 +74,8 @@ parameterless_type(x::Type) = __parameterless_type(x)
6474

6575
function __init__()
6676
@require Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" begin
67-
export numback_hesvec, numback_hesvec!, autoback_hesvec, autoback_hesvec!, auto_vecjac, auto_vecjac!
77+
export numback_hesvec,
78+
numback_hesvec!, autoback_hesvec, autoback_hesvec!, auto_vecjac, auto_vecjac!
6879

6980
include("differentiation/vecjac_products_zygote.jl")
7081
include("differentiation/jaches_products_zygote.jl")

src/coloring/acyclic_coloring.jl

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
1313
color = zeros(Int, nv(g))
1414
two_colored_forest = DisjointSets{Int}(())
1515

16-
first_visit_to_tree = fill((0,0), ne(g))
17-
first_neighbor = fill((0,0), ne(g))
16+
first_visit_to_tree = fill((0, 0), ne(g))
17+
first_neighbor = fill((0, 0), ne(g))
1818

1919
forbidden_colors = zeros(Int, nv(g))
2020

@@ -30,7 +30,16 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
3030
for x in outneighbors(g, w)
3131
if color[x] != 0
3232
if forbidden_colors[color[x]] != v
33-
prevent_cycle!(first_visit_to_tree,forbidden_colors,v, w, x, g, two_colored_forest,color)
33+
prevent_cycle!(
34+
first_visit_to_tree,
35+
forbidden_colors,
36+
v,
37+
w,
38+
x,
39+
g,
40+
two_colored_forest,
41+
color,
42+
)
3443
end
3544
end
3645
end
@@ -41,7 +50,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
4150

4251
for w in outneighbors(g, v)
4352
if color[w] != 0
44-
grow_star!(two_colored_forest,first_neighbor,v, w, g, color)
53+
grow_star!(two_colored_forest, first_neighbor, v, w, g, color)
4554
end
4655
end
4756

@@ -50,7 +59,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
5059
for x in outneighbors(g, w)
5160
if color[x] != 0 && x != v
5261
if color[x] == color[v]
53-
merge_trees!(two_colored_forest,v,w,x,g)
62+
merge_trees!(two_colored_forest, v, w, x, g)
5463
end
5564
end
5665
end
@@ -76,19 +85,21 @@ which is adjacent to vertices w and x in graph g. Disjoint set is used to store
7685
the induced 2-colored subgraphs/trees where the id of set is an integer
7786
representing an edge of graph 'g'
7887
"""
79-
function prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Integer}},
80-
forbidden_colors::AbstractVector{<:Integer},
81-
v::Integer,
82-
w::Integer,
83-
x::Integer,
84-
g::Graphs.AbstractGraph,
85-
two_colored_forest::DisjointSets{<:Integer},
86-
color::AbstractVector{<:Integer})
88+
function prevent_cycle!(
89+
first_visit_to_tree::AbstractVector{<:Tuple{Integer,Integer}},
90+
forbidden_colors::AbstractVector{<:Integer},
91+
v::Integer,
92+
w::Integer,
93+
x::Integer,
94+
g::Graphs.AbstractGraph,
95+
two_colored_forest::DisjointSets{<:Integer},
96+
color::AbstractVector{<:Integer},
97+
)
8798
e = find(w, x, g, two_colored_forest)
8899
p, q = first_visit_to_tree[e]
89100

90101
if p != v
91-
first_visit_to_tree[e] = (v,w)
102+
first_visit_to_tree[e] = (v, w)
92103
elseif q != w
93104
forbidden_colors[color[x]] = v
94105
end
@@ -108,20 +119,22 @@ previously uncolored vertex v, by comparing it with the adjacent vertex w.
108119
Disjoint set is used to store stars in sets, which are identified through key
109120
edges present in g.
110121
"""
111-
function grow_star!(two_colored_forest::DisjointSets{<:Integer},
112-
first_neighbor::AbstractVector{<: Tuple{Integer,Integer}},
113-
v::Integer,
114-
w::Integer,
115-
g::Graphs.AbstractGraph,
116-
color::AbstractVector{<:Integer})
117-
insert_new_tree!(two_colored_forest,v,w,g)
122+
function grow_star!(
123+
two_colored_forest::DisjointSets{<:Integer},
124+
first_neighbor::AbstractVector{<:Tuple{Integer,Integer}},
125+
v::Integer,
126+
w::Integer,
127+
g::Graphs.AbstractGraph,
128+
color::AbstractVector{<:Integer},
129+
)
130+
insert_new_tree!(two_colored_forest, v, w, g)
118131
p, q = first_neighbor[color[w]]
119132

120133
if p != v
121-
first_neighbor[color[w]] = (v,w)
134+
first_neighbor[color[w]] = (v, w)
122135
else
123-
e1 = find(v,w,g,two_colored_forest)
124-
e2 = find(p,q,g,two_colored_forest)
136+
e1 = find(v, w, g, two_colored_forest)
137+
e2 = find(p, q, g, two_colored_forest)
125138
union!(two_colored_forest, e1, e2)
126139
end
127140
end
@@ -137,13 +150,15 @@ end
137150
Subroutine to merge trees present in the disjoint set which have a
138151
common edge.
139152
"""
140-
function merge_trees!(two_colored_forest::DisjointSets{<:Integer},
141-
v::Integer,
142-
w::Integer,
143-
x::Integer,
144-
g::Graphs.AbstractGraph)
145-
e1 = find(v,w,g,two_colored_forest)
146-
e2 = find(w,x,g,two_colored_forest)
153+
function merge_trees!(
154+
two_colored_forest::DisjointSets{<:Integer},
155+
v::Integer,
156+
w::Integer,
157+
x::Integer,
158+
g::Graphs.AbstractGraph,
159+
)
160+
e1 = find(v, w, g, two_colored_forest)
161+
e2 = find(w, x, g, two_colored_forest)
147162
if e1 != e2
148163
union!(two_colored_forest, e1, e2)
149164
end
@@ -159,12 +174,14 @@ end
159174
creates a new singleton set in the disjoint set 'two_colored_forest' consisting
160175
of the edge connecting v and w in the graph g
161176
"""
162-
function insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
163-
v::Integer,
164-
w::Integer,
165-
g::Graphs.AbstractGraph)
166-
edge_index = find_edge_index(v,w,g)
167-
push!(two_colored_forest,edge_index)
177+
function insert_new_tree!(
178+
two_colored_forest::DisjointSets{<:Integer},
179+
v::Integer,
180+
w::Integer,
181+
g::Graphs.AbstractGraph,
182+
)
183+
edge_index = find_edge_index(v, w, g)
184+
push!(two_colored_forest, edge_index)
168185
end
169186

170187

@@ -187,10 +204,12 @@ end
187204
Returns the root of the disjoint set to which the edge connecting vertices w and x
188205
in the graph g belongs to
189206
"""
190-
function find(w::Integer,
191-
x::Integer,
192-
g::Graphs.AbstractGraph,
193-
two_colored_forest::DisjointSets{<:Integer})
207+
function find(
208+
w::Integer,
209+
x::Integer,
210+
g::Graphs.AbstractGraph,
211+
two_colored_forest::DisjointSets{<:Integer},
212+
)
194213
edge_index = find_edge_index(w, x, g)
195214
return find_root!(two_colored_forest, edge_index)
196215
end

0 commit comments

Comments
 (0)