Skip to content

Commit

Permalink
moved
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay-sanjay authored and amontoison committed Sep 27, 2023
1 parent e593555 commit b0fd2cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/auxiliary/bounds.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Auxiliary function related to bound-constrainted problems

export active, active!, breakpoints, compute_Hs_slope_qs!, project!, project_step!
export active, active!, breakpoints, compute_Hs_slope_qs!, compute_As_slope_qs!, project!, project_step!

"""
active(x, ℓ, u; rtol = 1e-8, atol = 1e-8)
Expand Down Expand Up @@ -110,6 +110,23 @@ function compute_Hs_slope_qs!(
return slope, qs
end

"""
slope, qs = compute_As_slope_qs!(As, A, s, Fx)
Compute `slope = dot(As, Fx)` and `qs = dot(As, As) / 2 + slope`. Use `As` to store `A * s`.
"""
function compute_As_slope_qs!(
As::AbstractVector{T},
A::Union{AbstractMatrix, AbstractLinearOperator},
s::AbstractVector{T},
Fx::AbstractVector{T},
) where {T <: Real}
mul!(As, A, s)
slope = dot(As, Fx)
qs = dot(As, As) / 2 + slope
return slope, qs
end

"""
project!(y, x, ℓ, u)
Expand Down
10 changes: 10 additions & 0 deletions test/test_auxiliary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ function test_auxiliary()
a = @allocated compute_Hs_slope_qs!(Hx, H, x, g)
@test a == 0

x1 = [10.0; 11.0; 12.0; 13.0; 14.0; 15.0; 16.0]
A = diagm(0 => 2 * ones(7), -1 => -ones(6), 1 => -ones(6))
As = zeros(7)
Fx = rand(7)
slope, qx = compute_As_slope_qs!(As, A, x1, Fx)
@test slope == dot(As, Fx)
@test qx == dot(As, As) / 2 + slope
b = @allocated compute_As_slope_qs!(As, A, x1, Fx)
@test b == 0

z = [ℓ[1:2] - rand(2); x[3]; u[4:5] + rand(2)]
y = rand(5)
project!(y, z, ℓ, u)
Expand Down

0 comments on commit b0fd2cf

Please sign in to comment.