Skip to content

Commit 7ef0d25

Browse files
MaxenceGollieramontoison
authored andcommitted
lbfgs: optimize memory accesses in multiply
1 parent 8de69f4 commit 7ef0d25

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/lbfgs.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,12 @@ function LBFGSOperator(T::Type, n::I; kwargs...) where {I <: Integer}
187187
data.scaling && (q ./= data.scaling_factor)
188188

189189
# B = B₀ + Σᵢ (bᵢbᵢ' - aᵢaᵢ').
190-
for i = 1:(data.mem)
190+
@inbounds for i = 1:(data.mem)
191191
k = mod(data.insert + i - 2, data.mem) + 1
192192
if data.ys[k] != 0
193193
ax = dot(data.a[k], x)
194194
bx = dot(data.b[k], x)
195-
for j eachindex(q)
196-
q[j] += bx * data.b[k][j] - ax * data.a[k][j]
197-
end
195+
@. q += bx .* data.b[k] - ax .* data.a[k]
198196
end
199197
end
200198
if β == zero(T2)

0 commit comments

Comments
 (0)