@@ -20,9 +20,9 @@ function make_hessian_buffers(colorvec, x)
20
20
end
21
21
22
22
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))
26
26
ncolors, D, buffer, G, G2 = make_hessian_buffers (colorvec, x)
27
27
grad_config = ForwardDiff. GradientConfig (f, x)
28
28
@@ -46,7 +46,7 @@ function ForwardColorHesCache(f, x::AbstractVector{<:Number},
46
46
end
47
47
48
48
function numauto_color_hessian! (H:: AbstractMatrix{<:Number} , f, x:: AbstractArray{<:Number} ,
49
- hes_cache:: ForwardColorHesCache ; safe = true )
49
+ hes_cache:: ForwardColorHesCache ; safe = true )
50
50
ϵ = cbrt (eps (eltype (x)))
51
51
for j in 1 : (hes_cache. ncolors)
52
52
x .+ = ϵ .* @view hes_cache. D[:, j]
@@ -67,23 +67,23 @@ function numauto_color_hessian!(H::AbstractMatrix{<:Number}, f, x::AbstractArray
67
67
end
68
68
69
69
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 )
72
72
hes_cache = ForwardColorHesCache (f, x, colorvec, sparsity)
73
73
numauto_color_hessian! (H, f, x, hes_cache)
74
74
return H
75
75
end
76
76
77
77
function numauto_color_hessian (f, x:: AbstractArray{<:Number} ,
78
- hes_cache:: ForwardColorHesCache )
78
+ hes_cache:: ForwardColorHesCache )
79
79
H = convert .(eltype (x), hes_cache. sparsity)
80
80
numauto_color_hessian! (H, f, x, hes_cache)
81
81
return H
82
82
end
83
83
84
84
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 )
87
87
hes_cache = ForwardColorHesCache (f, x, colorvec, sparsity)
88
88
H = convert .(eltype (x), hes_cache. sparsity)
89
89
numauto_color_hessian! (H, f, x, hes_cache)
102
102
struct AutoAutoTag end
103
103
104
104
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}
108
108
if sparsity === nothing
109
109
sparsity = sparse (ones (length (x), length (x)))
110
110
end
@@ -124,28 +124,28 @@ function ForwardAutoColorHesCache(f, x::AbstractVector{V},
124
124
end
125
125
126
126
function autoauto_color_hessian! (H:: AbstractMatrix{<:Number} , f, x:: AbstractArray{<:Number} ,
127
- hes_cache:: ForwardAutoColorHesCache )
127
+ hes_cache:: ForwardAutoColorHesCache )
128
128
forwarddiff_color_jacobian! (H, hes_cache. grad!, x, hes_cache. jac_cache)
129
129
end
130
130
131
131
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 )
134
134
hes_cache = ForwardAutoColorHesCache (f, x, colorvec, sparsity)
135
135
autoauto_color_hessian! (H, f, x, hes_cache)
136
136
return H
137
137
end
138
138
139
139
function autoauto_color_hessian (f, x:: AbstractArray{<:Number} ,
140
- hes_cache:: ForwardAutoColorHesCache )
140
+ hes_cache:: ForwardAutoColorHesCache )
141
141
H = convert .(eltype (x), hes_cache. sparsity)
142
142
autoauto_color_hessian! (H, f, x, hes_cache)
143
143
return H
144
144
end
145
145
146
146
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 )
149
149
hes_cache = ForwardAutoColorHesCache (f, x, colorvec, sparsity)
150
150
H = convert .(eltype (x), hes_cache. sparsity)
151
151
autoauto_color_hessian! (H, f, x, hes_cache)
0 commit comments