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 in _canonical_quadratic_reduction #296

Merged
merged 3 commits into from
Jul 22, 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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ version = "0.14.2"
[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
Libdl = "<0.0.1, 1.6"
Expand All @@ -18,7 +17,8 @@ julia = "1.6"

[extras]
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Printf"]
test = ["Printf", "SparseArrays", "Test"]
1 change: 0 additions & 1 deletion src/KNITRO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module KNITRO

import Libdl
import MathOptInterface as MOI
import SparseArrays

const _DEPS_FILE = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl")
if isfile(_DEPS_FILE)
Expand Down
10 changes: 5 additions & 5 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ const _SETS = Union{
}

function _canonical_quadratic_reduction(f::MOI.ScalarQuadraticFunction)
I = Cint[term.variable_1.value for term in f.quadratic_terms]
J = Cint[term.variable_2.value for term in f.quadratic_terms]
if !MOI.Utilities.is_canonical(f)
f = MOI.Utilities.canonicalize!(copy(f))
end
I = Cint[_c_column(term.variable_1) for term in f.quadratic_terms]
J = Cint[_c_column(term.variable_2) for term in f.quadratic_terms]
V = Cdouble[term.coefficient for term in f.quadratic_terms]
for i in 1:length(V)
if I[i] == J[i]
Expand All @@ -28,9 +31,6 @@ function _canonical_quadratic_reduction(f::MOI.ScalarQuadraticFunction)
I[i], J[i] = J[i], I[i]
end
end
I, J, V = SparseArrays.findnz(SparseArrays.sparse(I, J, V))
I .-= Cint(1)
J .-= Cint(1)
return return length(I), I, J, V
end

Expand Down
Loading