Skip to content

Commit

Permalink
preallocate storage for LSR1 operator
Browse files Browse the repository at this point in the history
  • Loading branch information
dpo committed Sep 8, 2024
1 parent ed65e59 commit 4c92b94
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lsr1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mutable struct LSR1Data{T, I <: Integer}
as::Vector{T}
insert::I
Ax::Vector{T}
tmp::Vector{T}
end

function LSR1Data(
Expand All @@ -33,6 +34,7 @@ function LSR1Data(
zeros(T, mem),
1,
Vector{T}(undef, n),
Vector{T}(undef, n),
)
end

Expand Down Expand Up @@ -127,8 +129,9 @@ function push!(op::LSR1Operator, s::AbstractVector, y::AbstractVector)

# op.counters.updates += 1
data = op.data
Bs = op * s
ymBs = y - Bs
ymBs = data.tmp
ymBs .= y
mul!(ymBs, op, s, -1, 1) # ymBs = y - B * s
ys = dot(y, s)
sNorm = norm(s)
yy = dot(y, y)
Expand All @@ -143,7 +146,8 @@ function push!(op::LSR1Operator, s::AbstractVector, y::AbstractVector)
sufficient_curvature = abs(ys) ϵ * yNorm * sNorm
if sufficient_curvature
scaling_factor = ys / yy
scaling_condition = norm(y - s / scaling_factor) >= ϵ * yNorm * sNorm
@. data.tmp = y - s / scaling_factor
scaling_condition = norm(data.tmp) >= ϵ * yNorm * sNorm
end
end

Expand Down

0 comments on commit 4c92b94

Please sign in to comment.