Skip to content

Commit c8c61bf

Browse files
committed
Run formatter
1 parent 9d68481 commit c8c61bf

15 files changed

+107
-107
lines changed

ext/SparseDiffToolsSymbolicsExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using SparseDiffTools, Symbolics
44
import SparseDiffTools: AbstractSparseADType
55

66
function (alg::SymbolicsSparsityDetection)(ad::AbstractSparseADType, f, x; fx = nothing,
7-
kwargs...)
7+
kwargs...)
88
fx = fx === nothing ? similar(f(x)) : dx
99
f!(y, x) = (y .= f(x))
1010
J = Symbolics.jacobian_sparsity(f!, fx, x)

ext/SparseDiffToolsZygoteExt.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ end
7575
end
7676

7777
function autoback_hesvec!(dy, f, x, v, cache1 = _default_autoback_hesvec_cache(x, v),
78-
cache2 = _default_autoback_hesvec_cache(x, v))
78+
cache2 = _default_autoback_hesvec_cache(x, v))
7979
g = let f = f
8080
(dx, x) -> dx .= first(Zygote.gradient(f, x))
8181
end
@@ -140,7 +140,7 @@ end
140140

141141
# prefer non in-place method
142142
function (L::AutoDiffVJP{<:AutoZygote, IIP, true})(dv, v, p, t;
143-
VJP_input = nothing) where {IIP}
143+
VJP_input = nothing) where {IIP}
144144
# ignore VJP_input as pullback was computed in update_coefficients!(...)
145145

146146
_dv = L(v, p, t; VJP_input = VJP_input)

src/coloring/acyclic_coloring.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ the induced 2-colored subgraphs/trees where the id of set is an integer
7373
representing an edge of graph 'g'
7474
"""
7575
function prevent_cycle!(first_visit_to_tree::AbstractVector{<:Tuple{Integer, Integer}},
76-
forbidden_colors::AbstractVector{<:Integer}, v::Integer, w::Integer, x::Integer,
77-
g::Graphs.AbstractGraph, two_colored_forest::DisjointSets{<:Integer},
78-
color::AbstractVector{<:Integer})
76+
forbidden_colors::AbstractVector{<:Integer}, v::Integer, w::Integer, x::Integer,
77+
g::Graphs.AbstractGraph, two_colored_forest::DisjointSets{<:Integer},
78+
color::AbstractVector{<:Integer})
7979
e = find(w, x, g, two_colored_forest)
8080
p, q = first_visit_to_tree[e]
8181

@@ -97,8 +97,8 @@ Disjoint set is used to store stars in sets, which are identified through key
9797
edges present in g.
9898
"""
9999
function grow_star!(two_colored_forest::DisjointSets{<:Integer},
100-
first_neighbor::AbstractVector{<:Tuple{Integer, Integer}}, v::Integer, w::Integer,
101-
g::Graphs.AbstractGraph, color::AbstractVector{<:Integer})
100+
first_neighbor::AbstractVector{<:Tuple{Integer, Integer}}, v::Integer, w::Integer,
101+
g::Graphs.AbstractGraph, color::AbstractVector{<:Integer})
102102
insert_new_tree!(two_colored_forest, v, w, g)
103103
p, q = first_neighbor[color[w]]
104104

@@ -119,7 +119,7 @@ Subroutine to merge trees present in the disjoint set which have a
119119
common edge.
120120
"""
121121
function merge_trees!(two_colored_forest::DisjointSets{<:Integer}, v::Integer, w::Integer,
122-
x::Integer, g::Graphs.AbstractGraph)
122+
x::Integer, g::Graphs.AbstractGraph)
123123
e1 = find(v, w, g, two_colored_forest)
124124
e2 = find(w, x, g, two_colored_forest)
125125
if e1 != e2
@@ -135,7 +135,7 @@ creates a new singleton set in the disjoint set 'two_colored_forest' consisting
135135
of the edge connecting v and w in the graph g
136136
"""
137137
function insert_new_tree!(two_colored_forest::DisjointSets{<:Integer}, v::Integer,
138-
w::Integer, g::Graphs.AbstractGraph)
138+
w::Integer, g::Graphs.AbstractGraph)
139139
edge_index = find_edge_index(v, w, g)
140140
push!(two_colored_forest, edge_index)
141141
end
@@ -157,7 +157,7 @@ Returns the root of the disjoint set to which the edge connecting vertices w and
157157
in the graph g belongs to
158158
"""
159159
function find(w::Integer, x::Integer, g::Graphs.AbstractGraph,
160-
two_colored_forest::DisjointSets{<:Integer})
160+
two_colored_forest::DisjointSets{<:Integer})
161161
edge_index = find_edge_index(w, x, g)
162162
return find_root!(two_colored_forest, edge_index)
163163
end

src/coloring/backtracking_coloring.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Returns an uncolored vertex from the partially
115115
colored graph which has the highest degree
116116
"""
117117
function uncolored_vertex_of_maximal_degree(A::AbstractVector{<:Integer},
118-
F::AbstractVector{<:Integer})
118+
F::AbstractVector{<:Integer})
119119
for v in A
120120
if F[v] == 0
121121
return v
@@ -145,8 +145,8 @@ g: Graph to be colored
145145
opt: Current optimal number of colors to be used in the coloring of graph g
146146
"""
147147
function free_colors(x::Integer, A::AbstractVector{<:Integer},
148-
colors::AbstractVector{<:Integer}, F::Vector{Integer}, g::Graphs.AbstractGraph,
149-
opt::Integer)
148+
colors::AbstractVector{<:Integer}, F::Vector{Integer}, g::Graphs.AbstractGraph,
149+
opt::Integer)
150150
index = -1
151151

152152
freecolors = zeros(Int, 0)
@@ -187,7 +187,7 @@ Returns least index i such that color of vertex
187187
A[i] is equal to `opt` (optimal chromatic number)
188188
"""
189189
function least_index(F::AbstractVector{<:Integer}, A::AbstractVector{<:Integer},
190-
opt::Integer)
190+
opt::Integer)
191191
for i in eachindex(A)
192192
if F[A[i]] == opt
193193
return i
@@ -202,7 +202,7 @@ Uncolors all vertices A[i] where i is
202202
greater than or equal to start
203203
"""
204204
function uncolor_all!(F::AbstractVector{<:Integer}, A::AbstractVector{<:Integer},
205-
start::Integer)
205+
start::Integer)
206206
for i in start:length(A)
207207
F[A[i]] = 0
208208
end

src/coloring/high_level.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ If `ArrayInterface.fast_matrix_colors(A)` is true, then uses
2121
`ArrayInterface.matrix_colors(A)` to compute the matrix colors.
2222
"""
2323
function ArrayInterface.matrix_colors(A::AbstractMatrix,
24-
alg::SparseDiffToolsColoringAlgorithm = GreedyD1Color();
25-
partition_by_rows::Bool = false)
24+
alg::SparseDiffToolsColoringAlgorithm = GreedyD1Color();
25+
partition_by_rows::Bool = false)
2626

2727
# If fast algorithm for matrix coloring exists use that
2828
if !partition_by_rows

src/coloring/matrix2graph.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Note that the sparsity pattern is defined by structural nonzeroes, ie includes e
3333
stored zeros.
3434
"""
3535
function matrix2graph(sparse_matrix::AbstractSparseMatrix{<:Number},
36-
partition_by_rows::Bool = true)
36+
partition_by_rows::Bool = true)
3737
(rows_index, cols_index, _) = findnz(sparse_matrix)
3838

3939
ncols = size(sparse_matrix, 2)

src/differentiation/compute_hessian_ad.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function make_hessian_buffers(colorvec, x)
2020
end
2121

2222
function ForwardColorHesCache(f, x::AbstractVector{<:Number},
23-
colorvec::AbstractVector{<:Integer} = eachindex(x),
24-
sparsity::Union{AbstractMatrix, Nothing} = nothing,
25-
g! = (G, x, grad_config) -> ForwardDiff.gradient!(G, f, x, grad_config))
23+
colorvec::AbstractVector{<:Integer} = eachindex(x),
24+
sparsity::Union{AbstractMatrix, Nothing} = nothing,
25+
g! = (G, x, grad_config) -> ForwardDiff.gradient!(G, f, x, grad_config))
2626
ncolors, D, buffer, G, G2 = make_hessian_buffers(colorvec, x)
2727
grad_config = ForwardDiff.GradientConfig(f, x)
2828

@@ -46,7 +46,7 @@ function ForwardColorHesCache(f, x::AbstractVector{<:Number},
4646
end
4747

4848
function numauto_color_hessian!(H::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number},
49-
hes_cache::ForwardColorHesCache; safe = true)
49+
hes_cache::ForwardColorHesCache; safe = true)
5050
ϵ = cbrt(eps(eltype(x)))
5151
for j in 1:(hes_cache.ncolors)
5252
x .+= ϵ .* @view hes_cache.D[:, j]
@@ -67,23 +67,23 @@ function numauto_color_hessian!(H::AbstractMatrix{<:Number}, f, x::AbstractArray
6767
end
6868

6969
function numauto_color_hessian!(H::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number},
70-
colorvec::AbstractVector{<:Integer} = eachindex(x),
71-
sparsity::Union{AbstractMatrix, Nothing} = nothing)
70+
colorvec::AbstractVector{<:Integer} = eachindex(x),
71+
sparsity::Union{AbstractMatrix, Nothing} = nothing)
7272
hes_cache = ForwardColorHesCache(f, x, colorvec, sparsity)
7373
numauto_color_hessian!(H, f, x, hes_cache)
7474
return H
7575
end
7676

7777
function numauto_color_hessian(f, x::AbstractArray{<:Number},
78-
hes_cache::ForwardColorHesCache)
78+
hes_cache::ForwardColorHesCache)
7979
H = convert.(eltype(x), hes_cache.sparsity)
8080
numauto_color_hessian!(H, f, x, hes_cache)
8181
return H
8282
end
8383

8484
function numauto_color_hessian(f, x::AbstractArray{<:Number},
85-
colorvec::AbstractVector{<:Integer} = eachindex(x),
86-
sparsity::Union{AbstractMatrix, Nothing} = nothing)
85+
colorvec::AbstractVector{<:Integer} = eachindex(x),
86+
sparsity::Union{AbstractMatrix, Nothing} = nothing)
8787
hes_cache = ForwardColorHesCache(f, x, colorvec, sparsity)
8888
H = convert.(eltype(x), hes_cache.sparsity)
8989
numauto_color_hessian!(H, f, x, hes_cache)
@@ -102,9 +102,9 @@ end
102102
struct AutoAutoTag end
103103

104104
function ForwardAutoColorHesCache(f, x::AbstractVector{V},
105-
colorvec::AbstractVector{<:Integer} = eachindex(x),
106-
sparsity::Union{AbstractMatrix, Nothing} = nothing,
107-
tag::ForwardDiff.Tag = ForwardDiff.Tag(AutoAutoTag(), V)) where {V}
105+
colorvec::AbstractVector{<:Integer} = eachindex(x),
106+
sparsity::Union{AbstractMatrix, Nothing} = nothing,
107+
tag::ForwardDiff.Tag = ForwardDiff.Tag(AutoAutoTag(), V)) where {V}
108108
if sparsity === nothing
109109
sparsity = sparse(ones(length(x), length(x)))
110110
end
@@ -124,28 +124,28 @@ function ForwardAutoColorHesCache(f, x::AbstractVector{V},
124124
end
125125

126126
function autoauto_color_hessian!(H::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number},
127-
hes_cache::ForwardAutoColorHesCache)
127+
hes_cache::ForwardAutoColorHesCache)
128128
forwarddiff_color_jacobian!(H, hes_cache.grad!, x, hes_cache.jac_cache)
129129
end
130130

131131
function autoauto_color_hessian!(H::AbstractMatrix{<:Number}, f, x::AbstractArray{<:Number},
132-
colorvec::AbstractVector{<:Integer} = eachindex(x),
133-
sparsity::Union{AbstractMatrix, Nothing} = nothing)
132+
colorvec::AbstractVector{<:Integer} = eachindex(x),
133+
sparsity::Union{AbstractMatrix, Nothing} = nothing)
134134
hes_cache = ForwardAutoColorHesCache(f, x, colorvec, sparsity)
135135
autoauto_color_hessian!(H, f, x, hes_cache)
136136
return H
137137
end
138138

139139
function autoauto_color_hessian(f, x::AbstractArray{<:Number},
140-
hes_cache::ForwardAutoColorHesCache)
140+
hes_cache::ForwardAutoColorHesCache)
141141
H = convert.(eltype(x), hes_cache.sparsity)
142142
autoauto_color_hessian!(H, f, x, hes_cache)
143143
return H
144144
end
145145

146146
function autoauto_color_hessian(f, x::AbstractArray{<:Number},
147-
colorvec::AbstractVector{<:Integer} = eachindex(x),
148-
sparsity::Union{AbstractMatrix, Nothing} = nothing)
147+
colorvec::AbstractVector{<:Integer} = eachindex(x),
148+
sparsity::Union{AbstractMatrix, Nothing} = nothing)
149149
hes_cache = ForwardAutoColorHesCache(f, x, colorvec, sparsity)
150150
H = convert.(eltype(x), hes_cache.sparsity)
151151
autoauto_color_hessian!(H, f, x, hes_cache)

src/differentiation/compute_jacobian_ad.jl

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const default_chunk_size = ForwardDiff.pickchunksize
2020
const SMALLTAG = typeof(ForwardDiff.Tag(missing, Float64))
2121

2222
function ForwardColorJacCache(f::F, x, _chunksize = nothing; dx = nothing, tag = nothing,
23-
colorvec = 1:length(x), sparsity::Union{AbstractArray, Nothing} = nothing) where {F}
23+
colorvec = 1:length(x), sparsity::Union{AbstractArray, Nothing} = nothing) where {F}
2424
if _chunksize isa Nothing
2525
chunksize = ForwardDiff.pickchunksize(maximum(colorvec))
2626
else
@@ -105,13 +105,13 @@ end
105105
end
106106

107107
function forwarddiff_color_jacobian(f::F,
108-
x::AbstractArray{<:Number};
109-
colorvec = 1:length(x),
110-
sparsity = nothing,
111-
jac_prototype = nothing,
112-
chunksize = nothing,
113-
dx = sparsity === nothing && jac_prototype === nothing ?
114-
nothing : copy(x)) where {F} #if dx is nothing, we will estimate dx at the cost of a function call
108+
x::AbstractArray{<:Number};
109+
colorvec = 1:length(x),
110+
sparsity = nothing,
111+
jac_prototype = nothing,
112+
chunksize = nothing,
113+
dx = sparsity === nothing && jac_prototype === nothing ?
114+
nothing : copy(x)) where {F} #if dx is nothing, we will estimate dx at the cost of a function call
115115
if sparsity === nothing && jac_prototype === nothing
116116
cfg = if chunksize === nothing
117117
if typeof(x) <: StaticArrays.StaticArray
@@ -136,12 +136,12 @@ function forwarddiff_color_jacobian(f::F,
136136
end
137137

138138
function forwarddiff_color_jacobian(J::AbstractArray{<:Number}, f::F,
139-
x::AbstractArray{<:Number};
140-
colorvec = 1:length(x),
141-
sparsity = nothing,
142-
jac_prototype = nothing,
143-
chunksize = nothing,
144-
dx = similar(x, size(J, 1))) where {F} #dx kwarg can be used to avoid re-allocating dx every time
139+
x::AbstractArray{<:Number};
140+
colorvec = 1:length(x),
141+
sparsity = nothing,
142+
jac_prototype = nothing,
143+
chunksize = nothing,
144+
dx = similar(x, size(J, 1))) where {F} #dx kwarg can be used to avoid re-allocating dx every time
145145
if sparsity === nothing && jac_prototype === nothing
146146
cfg = chunksize === nothing ? ForwardDiff.JacobianConfig(f, x) :
147147
ForwardDiff.JacobianConfig(f, x, ForwardDiff.Chunk(getsize(chunksize)))
@@ -154,8 +154,8 @@ function forwarddiff_color_jacobian(J::AbstractArray{<:Number}, f::F,
154154
end
155155

156156
function forwarddiff_color_jacobian(f::F, x::AbstractArray{<:Number},
157-
jac_cache::ForwardColorJacCache,
158-
jac_prototype = nothing) where {F}
157+
jac_cache::ForwardColorJacCache,
158+
jac_prototype = nothing) where {F}
159159
if jac_prototype isa Nothing ? ArrayInterface.ismutable(x) :
160160
ArrayInterface.ismutable(jac_prototype)
161161
# Whenever J is mutable, we mutate it to avoid allocations
@@ -174,8 +174,8 @@ end
174174

175175
# When J is mutable, this version of forwarddiff_color_jacobian will mutate J to avoid allocations
176176
function forwarddiff_color_jacobian(J::AbstractMatrix{<:Number}, f::F,
177-
x::AbstractArray{<:Number},
178-
jac_cache::ForwardColorJacCache) where {F}
177+
x::AbstractArray{<:Number},
178+
jac_cache::ForwardColorJacCache) where {F}
179179
t = jac_cache.t
180180
dx = jac_cache.dx
181181
p = jac_cache.p
@@ -248,8 +248,8 @@ end
248248

249249
# When J is immutable, this version of forwarddiff_color_jacobian will avoid mutating J
250250
function forwarddiff_color_jacobian_immutable(f, x::AbstractArray{<:Number},
251-
jac_cache::ForwardColorJacCache,
252-
jac_prototype = nothing)
251+
jac_cache::ForwardColorJacCache,
252+
jac_prototype = nothing)
253253
t = jac_cache.t
254254
dx = jac_cache.dx
255255
p = jac_cache.p
@@ -313,15 +313,15 @@ function forwarddiff_color_jacobian_immutable(f, x::AbstractArray{<:Number},
313313
end
314314

315315
function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number}, f,
316-
x::AbstractArray{<:Number}; dx = similar(x, size(J, 1)), colorvec = 1:length(x),
317-
sparsity = ArrayInterface.has_sparsestruct(J) ? J : nothing)
316+
x::AbstractArray{<:Number}; dx = similar(x, size(J, 1)), colorvec = 1:length(x),
317+
sparsity = ArrayInterface.has_sparsestruct(J) ? J : nothing)
318318
forwarddiff_color_jacobian!(J, f, x, ForwardColorJacCache(f, x; dx, colorvec, sparsity))
319319
end
320320

321321
function forwarddiff_color_jacobian!(J::AbstractMatrix{<:Number},
322-
f,
323-
x::AbstractArray{<:Number},
324-
jac_cache::ForwardColorJacCache)
322+
f,
323+
x::AbstractArray{<:Number},
324+
jac_cache::ForwardColorJacCache)
325325
t = jac_cache.t
326326
fx = jac_cache.fx
327327
dx = jac_cache.dx

0 commit comments

Comments
 (0)