Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions src/functions/indPolyhedralOSQP.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# IndPolyhedral: OSQP implementation

using OSQP

struct IndPolyhedralOSQP{R} <: IndPolyhedral
struct IndPolyhedralOSQP{R,M} <: IndPolyhedral
l::AbstractVector{R}
A::AbstractMatrix{R}
u::AbstractVector{R}
mod::OSQP.Model
function IndPolyhedralOSQP{R}(
mod::M
function IndPolyhedralOSQP(
l::AbstractVector{R}, A::AbstractMatrix{R}, u::AbstractVector{R}
) where R
m, n = size(A)
mod = OSQP.Model()
if !all(l .<= u)
error("function is improper (are some bounds inverted?)")
mod = Base.invokelatest(Base.require(@__MODULE__, :OSQP)) do OSQP
mod = OSQP.Model()
if !all(l .<= u)
error("function is improper (are some bounds inverted?)")
end
OSQP.setup!(mod; P=SparseMatrixCSC{R}(I, n, n), l=l, A=sparse(A), u=u, verbose=false,
eps_abs=eps(R), eps_rel=eps(R),
eps_prim_inf=eps(R), eps_dual_inf=eps(R))
mod
end
OSQP.setup!(mod; P=SparseMatrixCSC{R}(I, n, n), l=l, A=sparse(A), u=u, verbose=false,
eps_abs=eps(R), eps_rel=eps(R),
eps_prim_inf=eps(R), eps_dual_inf=eps(R))
new(l, A, u, mod)
new{R,typeof(mod)}(l, A, u, mod)
end
end

Expand All @@ -28,11 +29,6 @@ is_proximable(::Type{<:IndPolyhedralOSQP}) = false

# constructors

IndPolyhedralOSQP(
l::AbstractVector{R}, A::AbstractMatrix{R}, u::AbstractVector{R}
) where R =
IndPolyhedralOSQP{R}(l, A, u)

IndPolyhedralOSQP(
l::AbstractVector{R}, A::AbstractMatrix{R}, u::AbstractVector{R},
xmin::AbstractVector{R}, xmax::AbstractVector{R}
Expand Down Expand Up @@ -65,8 +61,10 @@ end

function prox!(y, f::IndPolyhedralOSQP, x, gamma)
R = eltype(x)
OSQP.update!(f.mod; q=-x)
results = OSQP.solve!(f.mod)
results = Base.invokelatest(Base.require(@__MODULE__, :OSQP)) do OSQP
OSQP.update!(f.mod; q=-x)
OSQP.solve!(f.mod)
end
y .= results.x
return R(0)
end
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ function predicates_test(f)
end

@testset "Aqua" begin
Aqua.test_all(ProximalOperators; ambiguities=false)
Aqua.test_all(ProximalOperators; ambiguities=false, stale_deps=false, persistent_tasks=false)
Aqua.test_stale_deps(ProximalOperators, ignore=[:OSQP])
end

@testset "Documentation" begin
Expand Down
Loading