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

Commit 7f00964

Browse files
Merge pull request #208 from ArnoStrouwen/master
SciML style formatting
2 parents 55954f7 + 3d6e463 commit 7f00964

31 files changed

+1095
-994
lines changed

.JuliaFormatter.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style = "sciml"

.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: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ using Documenter, SparseDiffTools
22

33
include("pages.jl")
44

5-
makedocs(
6-
sitename = "SparseDiffTools.jl",
7-
authors = "Chris Rackauckas",
8-
modules = [SparseDiffTools],
9-
clean = true,
10-
doctest = false,
11-
format = Documenter.HTML(
12-
assets = ["assets/favicon.ico"],
13-
canonical = "https://docs.sciml.ai/SparseDiffTools/stable/",
14-
),
15-
pages = pages,
16-
)
5+
makedocs(sitename = "SparseDiffTools.jl",
6+
authors = "Chris Rackauckas",
7+
modules = [SparseDiffTools],
8+
clean = true,
9+
doctest = false,
10+
format = Documenter.HTML(assets = ["assets/favicon.ico"],
11+
canonical = "https://docs.sciml.ai/SparseDiffTools/stable/"),
12+
pages = pages)
1713

18-
deploydocs(repo = "https://github.com/JuliaDiff/SparseDiffTools.jl.git"; push_preview = true)
14+
deploydocs(repo = "https://github.com/JuliaDiff/SparseDiffTools.jl.git";
15+
push_preview = true)

src/SparseDiffTools.jl

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,30 @@ 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
46-
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
4746

4847
include("coloring/high_level.jl")
4948
include("coloring/backtracking_coloring.jl")
@@ -63,8 +62,9 @@ parameterless_type(x) = parameterless_type(typeof(x))
6362
parameterless_type(x::Type) = __parameterless_type(x)
6463

6564
function __init__()
66-
@require Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" begin
67-
export numback_hesvec, numback_hesvec!, autoback_hesvec, autoback_hesvec!, auto_vecjac, auto_vecjac!
65+
@require Zygote="e88e6eb3-aa80-5325-afca-941959d7151f" begin
66+
export numback_hesvec, numback_hesvec!, autoback_hesvec, autoback_hesvec!,
67+
auto_vecjac, auto_vecjac!
6868

6969
include("differentiation/vecjac_products_zygote.jl")
7070
include("differentiation/jaches_products_zygote.jl")

src/coloring/acyclic_coloring.jl

Lines changed: 17 additions & 24 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,8 @@ 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!(first_visit_to_tree, forbidden_colors, v, w, x,
34+
g, two_colored_forest, color)
3435
end
3536
end
3637
end
@@ -41,7 +42,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
4142

4243
for w in outneighbors(g, v)
4344
if color[w] != 0
44-
grow_star!(two_colored_forest,first_neighbor,v, w, g, color)
45+
grow_star!(two_colored_forest, first_neighbor, v, w, g, color)
4546
end
4647
end
4748

@@ -50,7 +51,7 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
5051
for x in outneighbors(g, w)
5152
if color[x] != 0 && x != v
5253
if color[x] == color[v]
53-
merge_trees!(two_colored_forest,v,w,x,g)
54+
merge_trees!(two_colored_forest, v, w, x, g)
5455
end
5556
end
5657
end
@@ -60,7 +61,6 @@ function color_graph(g::Graphs.AbstractGraph, ::AcyclicColoring)
6061
return color
6162
end
6263

63-
6464
"""
6565
prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Integer}},
6666
forbidden_colors::AbstractVector{<:Integer},
@@ -76,7 +76,7 @@ which is adjacent to vertices w and x in graph g. Disjoint set is used to store
7676
the induced 2-colored subgraphs/trees where the id of set is an integer
7777
representing an edge of graph 'g'
7878
"""
79-
function prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Integer}},
79+
function prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer, Integer}},
8080
forbidden_colors::AbstractVector{<:Integer},
8181
v::Integer,
8282
w::Integer,
@@ -88,13 +88,12 @@ function prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer,Inte
8888
p, q = first_visit_to_tree[e]
8989

9090
if p != v
91-
first_visit_to_tree[e] = (v,w)
91+
first_visit_to_tree[e] = (v, w)
9292
elseif q != w
9393
forbidden_colors[color[x]] = v
9494
end
9595
end
9696

97-
9897
"""
9998
grow_star!(two_colored_forest::DisjointSets{<:Integer},
10099
first_neighbor::AbstractVector{<: Tuple{Integer,Integer}},
@@ -109,24 +108,23 @@ Disjoint set is used to store stars in sets, which are identified through key
109108
edges present in g.
110109
"""
111110
function grow_star!(two_colored_forest::DisjointSets{<:Integer},
112-
first_neighbor::AbstractVector{<: Tuple{Integer,Integer}},
111+
first_neighbor::AbstractVector{<:Tuple{Integer, Integer}},
113112
v::Integer,
114113
w::Integer,
115114
g::Graphs.AbstractGraph,
116115
color::AbstractVector{<:Integer})
117-
insert_new_tree!(two_colored_forest,v,w,g)
116+
insert_new_tree!(two_colored_forest, v, w, g)
118117
p, q = first_neighbor[color[w]]
119118

120119
if p != v
121-
first_neighbor[color[w]] = (v,w)
120+
first_neighbor[color[w]] = (v, w)
122121
else
123-
e1 = find(v,w,g,two_colored_forest)
124-
e2 = find(p,q,g,two_colored_forest)
122+
e1 = find(v, w, g, two_colored_forest)
123+
e2 = find(p, q, g, two_colored_forest)
125124
union!(two_colored_forest, e1, e2)
126125
end
127126
end
128127

129-
130128
"""
131129
merge_trees!(two_colored_forest::DisjointSets{<:Integer},
132130
v::Integer,
@@ -142,14 +140,13 @@ function merge_trees!(two_colored_forest::DisjointSets{<:Integer},
142140
w::Integer,
143141
x::Integer,
144142
g::Graphs.AbstractGraph)
145-
e1 = find(v,w,g,two_colored_forest)
146-
e2 = find(w,x,g,two_colored_forest)
143+
e1 = find(v, w, g, two_colored_forest)
144+
e2 = find(w, x, g, two_colored_forest)
147145
if e1 != e2
148146
union!(two_colored_forest, e1, e2)
149147
end
150148
end
151149

152-
153150
"""
154151
insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
155152
v::Integer,
@@ -163,11 +160,10 @@ function insert_new_tree!(two_colored_forest::DisjointSets{<:Integer},
163160
v::Integer,
164161
w::Integer,
165162
g::Graphs.AbstractGraph)
166-
edge_index = find_edge_index(v,w,g)
167-
push!(two_colored_forest,edge_index)
163+
edge_index = find_edge_index(v, w, g)
164+
push!(two_colored_forest, edge_index)
168165
end
169166

170-
171167
"""
172168
min_index(forbidden_colors::AbstractVector{<:Integer}, v::Integer)
173169
@@ -177,7 +173,6 @@ function min_index(forbidden_colors::AbstractVector{<:Integer}, v::Integer)
177173
return findfirst(!isequal(v), forbidden_colors)
178174
end
179175

180-
181176
"""
182177
find(w::Integer,
183178
x::Integer,
@@ -195,7 +190,6 @@ function find(w::Integer,
195190
return find_root!(two_colored_forest, edge_index)
196191
end
197192

198-
199193
"""
200194
find_edge(g::Graphs.AbstractGraph, v::Integer, w::Integer)
201195
@@ -205,7 +199,6 @@ v and w in the graph g
205199
function find_edge_index(v::Integer, w::Integer, g::Graphs.AbstractGraph)
206200
pos = 1
207201
for i in edges(g)
208-
209202
if (src(i) == v && dst(i) == w) || (src(i) == w && dst(i) == v)
210203
return pos
211204
end

0 commit comments

Comments
 (0)