Skip to content

Commit a14c06b

Browse files
committed
🤖 Format .jl files
1 parent e33a43d commit a14c06b

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

src/lbfgs.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ function LBFGSData(
4646
inverse ? Vector{T}(undef, 0) : [zeros(T, n) for _ = 1:mem],
4747
1,
4848
Vector{T}(undef, n),
49-
Array{T}(undef, (n, 2*mem)),
50-
Vector{T}(undef, 2*mem),
51-
Vector{T}(undef, n)
49+
Array{T}(undef, (n, 2 * mem)),
50+
Vector{T}(undef, 2 * mem),
51+
Vector{T}(undef, n),
5252
)
5353
end
5454

src/utilities.jl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export check_ctranspose, check_hermitian, check_positive_definite, normest, solve_shifted_system!, ldiv!
1+
export check_ctranspose,
2+
check_hermitian, check_positive_definite, normest, solve_shifted_system!, ldiv!
23
import LinearAlgebra.ldiv!
34

45
"""
@@ -147,8 +148,7 @@ end
147148
check_positive_definite(M::AbstractMatrix; kwargs...) =
148149
check_positive_definite(LinearOperator(M); kwargs...)
149150

150-
151-
"""
151+
"""
152152
solve_shifted_system!(x, B, b, σ)
153153
154154
Solve linear system (B + σI) x = b, where B is a forward L-BFGS operator and σ ≥ 0.
@@ -209,14 +209,13 @@ function solve_shifted_system!(
209209
B::LBFGSOperator{T, I, F1, F2, F3},
210210
b::AbstractVector{T},
211211
σ::T,
212-
) where {T, I, F1, F2, F3}
213-
212+
) where {T, I, F1, F2, F3}
214213
if σ < 0
215214
throw(ArgumentError("σ must be nonnegative"))
216215
end
217216
data = B.data
218217
insert = data.insert
219-
218+
220219
γ_inv = 1 / data.scaling_factor
221220
x_0 = 1 / (γ_inv + σ)
222221
@. x = x_0 * b
@@ -234,20 +233,20 @@ function solve_shifted_system!(
234233
sign_t = 1
235234
for t = 1:(i - 1)
236235
c0 = dot(view(data.shifted_p, :, t), data.shifted_u)
237-
c1= sign_t .*data.shifted_v[t]
236+
c1 = sign_t .* data.shifted_v[t]
238237
c2 = c1 * c0
239238
view(data.shifted_p, :, i) .+= c2 .* view(data.shifted_p, :, t)
240239
sign_t = -sign_t
241240
end
242241

243242
data.shifted_v[i] = 1 / (1 - sign_i * dot(data.shifted_u, view(data.shifted_p, :, i)))
244-
x .+= sign_i *data.shifted_v[i] * (view(data.shifted_p, :, i)' * b) .* view(data.shifted_p, :, i)
243+
x .+=
244+
sign_i * data.shifted_v[i] * (view(data.shifted_p, :, i)' * b) .* view(data.shifted_p, :, i)
245245
sign_i = -sign_i
246246
end
247247
return x
248248
end
249249

250-
251250
"""
252251
ldiv!(x, B, b)
253252
@@ -279,8 +278,12 @@ ldiv!(x, B, b)
279278
# The vector `x` now contains the solution
280279
"""
281280

282-
function ldiv!(x::AbstractVector{T}, B::LBFGSOperator{T, I, F1, F2, F3}, b::AbstractVector{T}) where {T, I, F1, F2, F3}
281+
function ldiv!(
282+
x::AbstractVector{T},
283+
B::LBFGSOperator{T, I, F1, F2, F3},
284+
b::AbstractVector{T},
285+
) where {T, I, F1, F2, F3}
283286
# Call solve_shifted_system! with σ = 0
284287
solve_shifted_system!(x, B, b, T(0.0))
285288
return x
286-
end
289+
end

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ include("test_deprecated.jl")
1515
include("test_normest.jl")
1616
include("test_diag.jl")
1717
include("test_chainrules.jl")
18-
include("test_solve_shifted_system.jl")
18+
include("test_solve_shifted_system.jl")

test/test_solve_shifted_system.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ function setup_test_val(; M = 5, n = 100, scaling = false, σ = 0.1)
1616
x = randn(n)
1717
b = B * x + σ .* x # so we know the true answer is x
1818

19-
return B, H , b, σ, zeros(n), x
19+
return B, H, b, σ, zeros(n), x
2020
end
2121

2222
function test_solve_shifted_system()
2323
@testset "solve_shifted_system! Default setup test" begin
2424
# Setup Test Case 1: Default setup from setup_test_val
25-
B,_, b, σ, x_sol, x_true = setup_test_val(n = 100, M = 5)
25+
B, _, b, σ, x_sol, x_true = setup_test_val(n = 100, M = 5)
2626

2727
result = solve_shifted_system!(x_sol, B, b, σ)
2828

@@ -40,7 +40,7 @@ function test_solve_shifted_system()
4040
end
4141
@testset "solve_shifted_system! Negative σ test" begin
4242
# Setup Test Case 2: Negative σ
43-
B,_, b, _, x_sol, _ = setup_test_val(n = 100, M = 5)
43+
B, _, b, _, x_sol, _ = setup_test_val(n = 100, M = 5)
4444
σ = -0.1
4545

4646
# Expect an ArgumentError to be thrown

0 commit comments

Comments
 (0)