Skip to content

Commit d315336

Browse files
MohamedLaghdafHABIBOULLAHdpo
authored andcommitted
Remove allocation from DBFGS update
1 parent ee92de2 commit d315336

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/DiagonalHessianApproximation.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,16 @@ end
245245
# y = ∇f(x_{k+1}) - ∇f(x_k)
246246
function push!(
247247
B::DiagonalBFGS{T, I, V, F},
248-
s0::V,
249-
y0::V,
248+
s::V,
249+
y::V,
250250
) where {T <: Real, I <: Integer, V <: AbstractVector{T}, F}
251-
s0Norm = norm(s0, 2)
252-
if s0Norm == 0
251+
sNorm = norm(s, 2)
252+
if sNorm == 0
253253
error("Cannot update DiagonalQN operator with s=0")
254254
end
255-
# sᵀBs = sᵀy can be scaled by ||s||² without changing the update
256-
s = (si / s0Norm for si s0)
257-
y = (yi / s0Norm for yi y0)
258-
sT_y = dot(s, y)
259-
B.d .= sum(abs.(y)) / sT_y .* abs.(y)
255+
sNorm2 = sNorm^2
256+
sT_y = dot(s, y) / sNorm2
257+
B.d .= abs.(y)
258+
B.d .*= sum(B.d) / sT_y
260259
return B
261260
end

0 commit comments

Comments
 (0)