Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SparseArrays dependency #253

Merged
merged 1 commit into from
Mar 25, 2024
Merged
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
2 changes: 0 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ version = "0.16.2"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
Downloads = "<0.0.1, 1"
Libdl = "<0.0.1, 1.6"
MathOptInterface = "1"
Random = "<0.0.1, 1.6"
SparseArrays = "<0.0.1, 1.6"
Test = "<0.0.1, 1.6"
julia = "1.6"

Expand Down
55 changes: 16 additions & 39 deletions src/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2744,25 +2744,14 @@ function _get_sparse_sos(model)
nnz = @_invoke(
Lib.XPRSgetintattrib(model.inner, Lib.XPRS_ORIGINALSETMEMBERS, _)::Int
)
nsos = @_invoke Lib.XPRSgetintattrib(
model.inner,
Lib.XPRS_ORIGINALSETS,
_,
)::Int
n = @_invoke Lib.XPRSgetintattrib(
model.inner,
Lib.XPRS_ORIGINALCOLS,
_,
)::Int

nsos = @_invoke(
Lib.XPRSgetintattrib(model.inner, Lib.XPRS_ORIGINALSETS, _)::Int
)
settypes = Array{Cchar}(undef, nsos)
setstart = Array{Cint}(undef, nsos + 1)
setcols = Array{Cint}(undef, nnz)
setvals = Array{Float64}(undef, nnz)

intents = Ref{Cint}(0)
nsets = Ref{Cint}(0)

setstart = zeros(Cint, nsos + 1)
setcols = zeros(Cint, nnz)
setvals = zeros(Float64, nnz)
intents, nsets = Ref{Cint}(), Ref{Cint}()
@checked Lib.XPRSgetglobal(
model.inner,
intents,
Expand All @@ -2775,41 +2764,29 @@ function _get_sparse_sos(model)
setcols,
setvals,
)

setstart[end] = nnz

I = Array{Cint}(undef, nnz)
J = Array{Cint}(undef, nnz)
V = Array{Float64}(undef, nnz)
for i in 1:length(setstart)-1
for j in (setstart[i]+1):setstart[i+1]
I[j] = i
J[j] = setcols[j] + 1
V[j] = setvals[j]
end
end
return SparseArrays.sparse(I, J, V, nsets[], n)
return setstart, setcols, setvals
end

function MOI.get(
model::Optimizer,
::MOI.ConstraintSet,
c::MOI.ConstraintIndex{MOI.VectorOfVariables,S},
) where {S<:SOS}
A = _get_sparse_sos(model)
return S(A[_info(model, c).row, :].nzval)
setstart, setcols, setvals = _get_sparse_sos(model)
row = _info(model, c).row
return S(setvals[(setstart[row]+1):setstart[row+1]])
end

function MOI.get(
model::Optimizer,
::MOI.ConstraintFunction,
c::MOI.ConstraintIndex{MOI.VectorOfVariables,S},
) where {S<:SOS}
A = _get_sparse_sos(model)
indices = SparseArrays.nonzeroinds(A[_info(model, c).row, :])
return MOI.VectorOfVariables([
model.variable_info[CleverDicts.LinearIndex(i)].index for i in indices
])
setstart, setcols, setvals = _get_sparse_sos(model)
row = _info(model, c).row
indices = (setstart[row]+1):setstart[row+1]
cols = CleverDicts.LinearIndex.(setcols[indices] .+ 1)
return MOI.VectorOfVariables([model.variable_info[c].index for c in cols])
end

###
Expand Down
1 change: 0 additions & 1 deletion src/Xpress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Xpress

import Libdl
import MathOptInterface as MOI
import SparseArrays

# Load in `deps.jl`, complaining if it does not exist
const depsjl_path = joinpath(@__DIR__, "..", "deps", "deps.jl")
Expand Down
Loading