Skip to content

Commit

Permalink
fix L-BFGS memory
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Dec 28, 2023
1 parent 4ef1dd7 commit 7fcf166
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Manopt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import ManifoldsBase: embed!
using ColorSchemes
using ColorTypes
using Colors
using DataStructures: CircularBuffer, capacity, length, push!, size
using DataStructures: CircularBuffer, capacity, length, push!, size, isfull
using Dates: Millisecond, Nanosecond, Period, canonicalize, value
using LinearAlgebra:
Diagonal, I, eigen, eigvals, tril, Symmetric, dot, cholesky, eigmin, opnorm
Expand Down
17 changes: 15 additions & 2 deletions src/solvers/quasi_Newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,21 @@ function update_hessian!(
end

# add newest
push!(d.memory_s, copy(M, st.sk))
push!(d.memory_y, copy(M, st.yk))
# reuse old memory if buffer is full or allocate a copy if it is not
if isfull(d.memory_s)
old_sk = popfirst!(d.memory_s)
copyto!(M, old_sk, st.sk)
push!(d.memory_s, old_sk)
else
push!(d.memory_s, copy(M, st.sk))
end
if isfull(d.memory_y)
old_yk = popfirst!(d.memory_y)
copyto!(M, old_yk, st.yk)
push!(d.memory_y, old_yk)
else
push!(d.memory_y, copy(M, st.yk))
end
return d
end

Expand Down

0 comments on commit 7fcf166

Please sign in to comment.