Skip to content

Commit

Permalink
Fix performance issue building large sparse linear operators (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 6, 2024
1 parent 9529cce commit a94619d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ end

function _F_linear_operator(model::Optimizer)
n = MOI.get(model, MOI.NumberOfVariables())
M = SparseArrays.sparse(Int32[], Int32[], Float64[], n, n)
I, J, V = Int32[], Int32[], Float64[]
q = zeros(n)
has_term = fill(false, n)
names = fill("", n)
Expand Down Expand Up @@ -231,7 +231,9 @@ function _F_linear_operator(model::Optimizer)
"$(div(Si.dimension, 2) + term.output_index).",
)
end
M[row_i, s_term.variable.value] += s_term.coefficient
push!(I, row_i)
push!(J, s_term.variable.value)
push!(V, s_term.coefficient)
end
c_name = MOI.get(model, MOI.ConstraintName(), index)
if length(rows) == 2
Expand All @@ -242,6 +244,7 @@ function _F_linear_operator(model::Optimizer)
end
end
end
M = SparseArrays.sparse(I, J, V, n, n)
return M, q, SparseArrays.nnz(M), names
end

Expand Down

0 comments on commit a94619d

Please sign in to comment.