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

Fix performance issue building large sparse linear operators #122

Merged
merged 1 commit into from
Oct 6, 2024
Merged
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
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
Loading