From df315d98c1b43b479a52a7123b6e5cd906310c24 Mon Sep 17 00:00:00 2001 From: jonschumacher Date: Mon, 29 Apr 2024 10:22:08 +0200 Subject: [PATCH 1/3] Fix warnings due to removed parameters --- src/LeastSquares.jl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/LeastSquares.jl b/src/LeastSquares.jl index 1ad1dee..ec62ed3 100644 --- a/src/LeastSquares.jl +++ b/src/LeastSquares.jl @@ -3,13 +3,12 @@ export LeastSquaresParameters abstract type AbstractSolverParameters <: AbstractMPIRecoParameters end export LeastSquaresParameters -Base.@kwdef struct LeastSquaresParameters{L<:AbstractLinearSolver, O, M, R<:AbstractRegularization, P<:AbstractSolverParameters, W} <: AbstractMPIRecoParameters +Base.@kwdef struct LeastSquaresParameters{L<:AbstractLinearSolver, O, M, R<:AbstractRegularization, P<:AbstractSolverParameters} <: AbstractMPIRecoParameters solver::Type{L} = Kaczmarz op::O = nothing S::M reg::Vector{R} solverParams::P - weights::W = nothing end # TODO place weights and more @@ -35,11 +34,10 @@ function process(t::Type{<:AbstractMPIRecoAlgorithm}, params::LeastSquaresParame u = reshape(u, M, L) c = zeros(N, L) - args = toKwargs(params.solverParams) - reg = prepareRegularization(params.reg, params) + reg, args = prepareRegularization(params.reg, params) args[:reg] = reg - args[:sparseTrafo] = params.op - solv = createLinearSolver(params.solver, params.S; args..., weights = params.weights) + + solv = createLinearSolver(params.solver, params.S; args...) for l=1:L d = solve!(solv, u[:, l]) @@ -54,6 +52,7 @@ function process(t::Type{<:AbstractMPIRecoAlgorithm}, params::LeastSquaresParame end function prepareRegularization(reg::Vector{R}, regLS::LeastSquaresParameters) where R<:AbstractRegularization + args = toKwargs(regLS.solverParams) params = regLS.solverParams result = AbstractRegularization[] @@ -66,11 +65,15 @@ function prepareRegularization(reg::Vector{R}, regLS::LeastSquaresParameters) wh push!(result, RealRegularization()) end + pop!(args, :enforceReal) + pop!(args, :enforcePositive) + # Add sparsity op if !isnothing(regLS.op) result = map(r -> TransformedRegularization(r, regLS.op), result) end - return result + + return result, args end #= function process(t::Type{<:AbstractMPIRecoAlgorithm}, params::LeastSquaresParameters, threadInput::MultiThreadedInput) From 320930f6f2d49faa20ca52ac2803c1c3b3b05248 Mon Sep 17 00:00:00 2001 From: jonschumacher Date: Mon, 29 Apr 2024 10:31:30 +0200 Subject: [PATCH 2/3] Do not douply push constraints when already in `reg` --- src/LeastSquares.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/LeastSquares.jl b/src/LeastSquares.jl index ec62ed3..2a31d4a 100644 --- a/src/LeastSquares.jl +++ b/src/LeastSquares.jl @@ -60,9 +60,15 @@ function prepareRegularization(reg::Vector{R}, regLS::LeastSquaresParameters) wh # Add further constraints if params.enforceReal && params.enforcePositive - push!(result, PositiveRegularization()) + if !any([item isa PositiveRegularization for item ∈ reg]) + push!(result, PositiveRegularization()) + end + + filter!(x -> !(x isa RealRegularization), reg) elseif params.enforceReal - push!(result, RealRegularization()) + if !any([item isa RealRegularization for item ∈ reg]) + push!(result, RealRegularization()) + end end pop!(args, :enforceReal) From 2394eccb7e7ef4ea23e66d213820395605446a34 Mon Sep 17 00:00:00 2001 From: jonschumacher Date: Mon, 29 Apr 2024 17:20:00 +0200 Subject: [PATCH 3/3] Re-add weights --- src/LeastSquares.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/LeastSquares.jl b/src/LeastSquares.jl index 2a31d4a..f7150f0 100644 --- a/src/LeastSquares.jl +++ b/src/LeastSquares.jl @@ -3,12 +3,13 @@ export LeastSquaresParameters abstract type AbstractSolverParameters <: AbstractMPIRecoParameters end export LeastSquaresParameters -Base.@kwdef struct LeastSquaresParameters{L<:AbstractLinearSolver, O, M, R<:AbstractRegularization, P<:AbstractSolverParameters} <: AbstractMPIRecoParameters +Base.@kwdef struct LeastSquaresParameters{L<:AbstractLinearSolver, O, M, R<:AbstractRegularization, P<:AbstractSolverParameters, W} <: AbstractMPIRecoParameters solver::Type{L} = Kaczmarz op::O = nothing S::M reg::Vector{R} solverParams::P + weights::W = nothing end # TODO place weights and more @@ -37,7 +38,7 @@ function process(t::Type{<:AbstractMPIRecoAlgorithm}, params::LeastSquaresParame reg, args = prepareRegularization(params.reg, params) args[:reg] = reg - solv = createLinearSolver(params.solver, params.S; args...) + solv = createLinearSolver(params.solver, params.S; args..., weights = params.weights) for l=1:L d = solve!(solv, u[:, l])