Skip to content

Commit

Permalink
boundschecks, cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoolen committed Feb 16, 2018
1 parent 3c534e4 commit 5663f27
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/MathOptInterfaceOSQP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ end

function Base.setindex!(cache::MatrixModificationCache, x, row::Integer, col::Integer)
I = CartesianIndex(row, col)
I cache.cartesian_indices_set || throw(ArgumentError("Changing the sparsity pattern is not allowed."))
@boundscheck I cache.cartesian_indices_set || throw(ArgumentError("Changing the sparsity pattern is not allowed."))
cache.modifications[I] = x
end

function Base.setindex!(cache::MatrixModificationCache, x::Real, ::Colon)
x == 0 || throw(ArgumentError("Changing the sparsity pattern is not allowed."))
@boundscheck x == 0 || throw(ArgumentError("Changing the sparsity pattern is not allowed."))
for I in cache.cartesian_indices
cache.modifications[I] = 0
end
Expand Down Expand Up @@ -367,6 +367,7 @@ MOI.get(optimizer::OSQPOptimizer, ::MOI.NumberOfVariables) = OSQP.dimensions(opt
MOI.canget(optimizer::OSQPOptimizer, ::MOI.ListOfVariableIndices) = MOI.canget(optimizer, MOI.NumberOfVariables())
MOI.get(optimizer::OSQPOptimizer, ::MOI.ListOfVariableIndices) = [VI(i) for i = 1 : get(optimizer, MOI.NumberOfVariables())] # TODO: support for UnitRange would be nice


## Solver-specific optimizer attributes:
module OSQPSettings

Expand Down Expand Up @@ -399,6 +400,7 @@ function MOI.set!(optimizer::OSQPOptimizer, a::OSQPAttribute, value)
end
end


## Optimizer methods:
function MOI.optimize!(optimizer::OSQPOptimizer)
processupdates!(optimizer.inner, optimizer.modcache)
Expand All @@ -415,7 +417,6 @@ MOI.get(optimizer::OSQPOptimizer, ::MOI.RawSolver) = optimizer.inner
MOI.canget(optimizer::OSQPOptimizer, ::MOI.ResultCount) = hasresults(optimizer) # TODO: or true?
MOI.get(optimizer::OSQPOptimizer, ::MOI.ResultCount) = 1

# TODO: could be even more selective when updating P by taking non-structural zeros into account
MOI.canset(optimizer::OSQPOptimizer, ::MOI.ObjectiveFunction{SingleVariable}) = !MOI.isempty(optimizer)
function MOI.set!(optimizer::OSQPOptimizer, ::MOI.ObjectiveFunction{SingleVariable}, obj::SingleVariable)
optimizer.modcache.Pcache[:] = 0
Expand Down

0 comments on commit 5663f27

Please sign in to comment.