Skip to content

Commit 94d7cca

Browse files
🤖 Format .jl files
1 parent 68a375d commit 94d7cca

3 files changed

Lines changed: 32 additions & 11 deletions

File tree

src/compositeNormL2.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,20 @@ mutable struct CompositeNormL2{
4545
J!::Function,
4646
A::AbstractMatrix{T},
4747
b::AbstractVector{T};
48-
store_previous_jacobian::Bool = false
48+
store_previous_jacobian::Bool = false,
4949
) where {T <: Real}
5050
λ > 0 || error("CompositeNormL2: λ should be positive")
5151
length(b) == size(A, 1) || error(
5252
"Composite Norm L2: Wrong input dimensions, the length of c(x) should be the same as the number of rows of J(x)",
5353
)
54-
new{T, typeof(c!), typeof(J!), typeof(A), typeof(b)}(NormL2(λ), c!, J!, A, b, store_previous_jacobian)
54+
new{T, typeof(c!), typeof(J!), typeof(A), typeof(b)}(
55+
NormL2(λ),
56+
c!,
57+
J!,
58+
A,
59+
b,
60+
store_previous_jacobian,
61+
)
5562
end
5663
end
5764

src/shiftedCompositeNormL2.jl

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mutable struct ShiftedCompositeNormL2{
5353
J!::Function,
5454
A::AbstractMatrix{T},
5555
b::AbstractVector{T};
56-
store_previous_jacobian::Bool = false
56+
store_previous_jacobian::Bool = false,
5757
) where {T <: Real}
5858
p = similar(b, A.n + A.m)
5959
dp = similar(b, A.n + A.m)
@@ -86,7 +86,7 @@ mutable struct ShiftedCompositeNormL2{
8686
dq,
8787
p,
8888
dp,
89-
false
89+
false,
9090
)
9191
end
9292
end
@@ -105,7 +105,14 @@ shifted(
105105
ψ.c!(b, xk)
106106
A = similar.A)
107107
ψ.J!(A, xk)
108-
ShiftedCompositeNormL2.h.lambda, ψ.c!, ψ.J!, A, b, store_previous_jacobian = ψ.store_previous_jacobian)
108+
ShiftedCompositeNormL2(
109+
ψ.h.lambda,
110+
ψ.c!,
111+
ψ.J!,
112+
A,
113+
b,
114+
store_previous_jacobian = ψ.store_previous_jacobian,
115+
)
109116
end
110117

111118
fun_name::ShiftedCompositeNormL2) = "shifted `ℓ₂` norm"
@@ -120,7 +127,14 @@ function prox!(
120127
max_iter = 10,
121128
atol = eps(T)^0.3,
122129
max_time = 180.0,
123-
) where {T <: Real, F0 <: Function, F1 <: Function, M <: AbstractMatrix{T}, N <: Union{Nothing, M}, V <: AbstractVector{T}}
130+
) where {
131+
T <: Real,
132+
F0 <: Function,
133+
F1 <: Function,
134+
M <: AbstractMatrix{T},
135+
N <: Union{Nothing, M},
136+
V <: AbstractVector{T},
137+
}
124138
@assert ν > zero(T)
125139
start_time = time()
126140
θ = T(0.8)

test/runtests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ for (op, composite_op, shifted_op) ∈
4949
ν = 0.1056
5050
prox!(y, ϕ, x, ν)
5151
@test ϕ.full_row_rank == true
52-
52+
5353
if "$op" == "NormL2"
5454
y_true = [0.24545429, 0.75250248, -0.66619752, 1.19372286]
5555
norm = Op(1.0)
@@ -64,17 +64,18 @@ for (op, composite_op, shifted_op) ∈
6464
@test ϕ.A == SparseMatrixCOO(Float64[2 0 0 -1; 0 1 1 0])
6565
@test ϕ(ones(Float64, 4)) ==
6666
h([1.0, 2.0] + SparseMatrixCOO(Float64[2 0 0 -1; 0 1 1 0])*ones(Float64, 4))
67-
67+
6868
# test store previous Jacobian option
6969

7070
function c_store_prev!(z, x)
7171
z[1] = 2*x[1]^2 - x[4]
7272
z[2] = x[2] + x[3]
7373
end
7474
function J_store_prev!(z, x)
75-
z.vals .= Float64[4.0*x[1], 1.0, 1.0, -1.0]
75+
z.vals .= Float64[4.0 * x[1], 1.0, 1.0, -1.0]
7676
end
77-
ψ_store_prev = CompositeOp(λ, c_store_prev!, J_store_prev!, A, b, store_previous_jacobian = true)
77+
ψ_store_prev =
78+
CompositeOp(λ, c_store_prev!, J_store_prev!, A, b, store_previous_jacobian = true)
7879
@test ψ_store_prev.store_previous_jacobian == true
7980

8081
xk = [1.0, 0.0, 0.0, 0.0]
@@ -95,7 +96,6 @@ for (op, composite_op, shifted_op) ∈
9596
@test all(ϕ_store_prev.A_prev .== SparseMatrixCOO([8.0 0.0 0.0 -1.0; 0.0 1.0 1.0 0.0]))
9697
@test all(ϕ_store_prev.A .== SparseMatrixCOO([2.0 0.0 0.0 -1.0; 0.0 1.0 1.0 0.0]))
9798

98-
9999
# test different types
100100
h = Op(Float32(λ))
101101
function c2!(z, x)

0 commit comments

Comments
 (0)