Skip to content

Commit 6f626c7

Browse files
committed
collect all imports to top-level file
1 parent 279063c commit 6f626c7

File tree

16 files changed

+42
-81
lines changed

16 files changed

+42
-81
lines changed

src/ProximalAlgorithms.jl

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ module ProximalAlgorithms
33
using ADTypes: ADTypes
44
using DifferentiationInterface: DifferentiationInterface
55
using ProximalCore
6-
using ProximalCore: prox, prox!, is_smooth, is_locally_smooth, is_convex, is_strongly_convex, is_proximable
7-
using OperatorCore: is_linear
6+
using ProximalCore: Zero, IndZero, convex_conjugate, prox, prox!, is_smooth, is_locally_smooth, is_convex, is_strongly_convex, is_proximable
7+
using OperatorCore: is_linear, is_symmetric, is_positive_definite
8+
using LinearAlgebra
9+
using Base.Iterators
10+
using Printf
11+
812
import Base: show
13+
import Base: *
14+
import LinearAlgebra: mul!
915

1016
const RealOrComplex{R} = Union{R,Complex{R}}
1117
const Maybe{T} = Union{T,Nothing}
@@ -113,8 +119,39 @@ IterativeAlgorithm(T; maxit, stop, solution, verbose, freq, display, kwargs...)
113119
kwargs,
114120
)
115121

122+
"""
123+
get_iterator(alg::IterativeAlgorithm{IteratorType}) where {IteratorType}
124+
125+
Return an iterator of type `IteratorType` constructed from the algorithm `alg`.
126+
This is a convenience function to allow for easy access to the iterator type
127+
associated with an `IterativeAlgorithm`.
128+
129+
# Example
130+
```julia
131+
julia> using ProximalAlgorithms: CG, get_iterator
132+
133+
julia> alg = CG(maxit=3, tol=1e-8);
134+
135+
julia> iter = get_iterator(alg, A=reshape(collect(1:25)), b=collect(1:5));
136+
137+
julia> for (k, state) in enumerate(iter)
138+
if k >= alg.maxit || alg.stop(iter, state)
139+
alg.verbose && alg.display(k, iter, state)
140+
return (alg.solution(iter, state), k)
141+
end
142+
alg.verbose && mod(k, alg.freq) == 0 && alg.display(k, iter, state)
143+
end
144+
1 | 7.416e+00
145+
2 | 2.742e+00
146+
3 | 2.300e+01
147+
([0.5581699346405239, 0.31633986928104635, 0.07450980392156867, -0.16732026143790907, -0.4091503267973867], 3)
148+
```
149+
"""
150+
get_iterator(alg::IterativeAlgorithm{IteratorType}; kwargs...) where {IteratorType} =
151+
IteratorType(; alg.kwargs..., kwargs...)
152+
116153
function (alg::IterativeAlgorithm{IteratorType})(; kwargs...) where {IteratorType}
117-
iter = IteratorType(; alg.kwargs..., kwargs...)
154+
iter = get_iterator(alg; kwargs...)
118155
for (k, state) in enumerate(iter)
119156
if k >= alg.maxit || alg.stop(iter, state)
120157
alg.verbose && alg.display(k, iter, state)

src/accel/anderson.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
using LinearAlgebra
2-
import Base: *
3-
import LinearAlgebra: mul!
4-
51
mutable struct AndersonAccelerationOperator{M,I,T}
62
currmem::I
73
curridx::I

src/accel/broyden.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
using LinearAlgebra
2-
import Base: *
3-
import LinearAlgebra: mul!
4-
51
struct BroydenOperator{R,TH}
62
H::TH
73
theta_bar::R

src/accel/lbfgs.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
using LinearAlgebra
2-
import Base: *
3-
import LinearAlgebra: mul!
4-
51
mutable struct LBFGSOperator{M,R,I,T}
62
currmem::I
73
curridx::I

src/algorithms/davis_yin.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
# Applications", Set-Valued and Variational Analysis, vol. 25, no. 4,
33
# pp. 829–858 (2017).
44

5-
using Printf
6-
using ProximalCore: Zero
7-
using LinearAlgebra
8-
using Printf
9-
105
"""
116
DavisYinIteration(; <keyword-arguments>)
127

src/algorithms/douglas_rachford.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
# Proximal Point Algorithm for Maximal Monotone Operators",
33
# Mathematical Programming, vol. 55, no. 1, pp. 293-318 (1989).
44

5-
using Base.Iterators
6-
using ProximalCore: Zero
7-
using LinearAlgebra
8-
using Printf
9-
105
"""
116
DouglasRachfordIteration(; <keyword-arguments>)
127

src/algorithms/drls.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
# nonconvex optimization: Accelerated and Newton-type linesearch algorithms",
33
# Computational Optimization and Applications, vol. 82, no. 2, pp. 395-440 (2022).
44

5-
using Base.Iterators
6-
using ProximalAlgorithms.IterationTools
7-
using ProximalCore: Zero
8-
using LinearAlgebra
9-
using Printf
10-
115
function drls_default_gamma(f::Tf, mf, Lf, alpha, lambda) where {Tf}
126
if mf !== nothing && mf > 0
137
return 1 / (alpha * mf)

src/algorithms/fast_forward_backward.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55
# for Linear Inverse Problems", SIAM Journal on Imaging Sciences, vol. 2,
66
# no. 1, pp. 183-202 (2009).
77

8-
using Base.Iterators
9-
using ProximalAlgorithms.IterationTools
10-
using ProximalCore: Zero
11-
using LinearAlgebra
12-
using Printf
13-
148
"""
159
FastForwardBackwardIteration(; <keyword-arguments>)
1610
@@ -151,7 +145,7 @@ default_stopping_criterion(
151145
) = norm(state.res, Inf) / state.gamma <= tol
152146
default_solution(::FastForwardBackwardIteration, state::FastForwardBackwardState) = state.z
153147
default_display(it, ::FastForwardBackwardIteration, state::FastForwardBackwardState) =
154-
@printf("%5d | %.3e | %.3e\n", it, state.gamma, norm(state.res, Inf) / state.gamma)
148+
@printf("%5d | %.3e | %.3e | %.3e | %.3e\n", it, state.gamma, state.f_x, state.g_z, norm(state.res, Inf) / state.gamma)
155149

156150
"""
157151
FastForwardBackward(; <keyword-arguments>)

src/algorithms/forward_backward.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# Lions, Mercier, “Splitting algorithms for the sum of two nonlinear
22
# operators,” SIAM Journal on Numerical Analysis, vol. 16, pp. 964–979 (1979).
33

4-
using Base.Iterators
5-
using ProximalAlgorithms.IterationTools
6-
using ProximalCore: Zero
7-
using LinearAlgebra
8-
using Printf
9-
104
"""
115
ForwardBackwardIteration(; <keyword-arguments>)
126

src/algorithms/li_lin.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
# Li, Lin, "Accelerated Proximal Gradient Methods for Nonconvex Programming",
22
# Proceedings of NIPS 2015 (2015).
33

4-
using Base.Iterators
5-
using ProximalAlgorithms.IterationTools
6-
using ProximalCore: Zero
7-
using LinearAlgebra
8-
using Printf
9-
104
"""
115
LiLinIteration(; <keyword-arguments>)
126

0 commit comments

Comments
 (0)