JuliaSmoothOptimizers / QuadraticModels.jl

Data structures for linear and quadratic optimization problems based on NLPModels.jl
Other
16 stars 10 forks source link

QuadraticModels with unit range #71

Open tmigot opened 2 years ago

tmigot commented 2 years ago

The idea would be to define the rows and cols using UnitRange. I am wondering whether this would be a desirable feature or not, because it looks so natural.


julia> QuadraticModel(zeros(3), 1:3, 1:3, ones(3))
ERROR: MethodError: no method matching SparseMatricesCOO.SparseMatrixCOO(::Int64, ::Int64, ::UnitRange{Int64}, ::UnitRange{Int64}, ::Vector{Float64})
Closest candidates are:
  SparseMatricesCOO.SparseMatrixCOO(::Integer, ::Integer, ::Vector, ::Vector, ::Vector) at .julia\packages\SparseMatricesCOO\z5uST\src\coo_types.jl:51
Stacktrace:
 [1] QuadraticModel(c::Vector{Float64}, Hrows::UnitRange{Int64}, Hcols::UnitRange{Int64}, Hvals::Vector{Float64}; Arows::Vector{Int64}, Acols::Vector{Int64}, Avals::Vector{Float64}, lcon::Vector{Float64}, ucon::Vector{Float64}, lvar::Vector{Float64}, uvar::Vector{Float64}, c0::Float64, sortcols::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
   @ QuadraticModels .julia\packages\QuadraticModels\etxWq\src\qpmodel.jl:123
 [2] QuadraticModel(c::Vector{Float64}, Hrows::UnitRange{Int64}, Hcols::UnitRange{Int64}, Hvals::Vector{Float64})
   @ QuadraticModels .julia\packages\QuadraticModels\etxWq\src\qpmodel.jl:97
 [3] top-level scope
   @ REPL[5]:1
``
dpo commented 2 years ago

It would be easy to achieve using collect(), but do you mean that the internal storage should also use UnitRange?

tmigot commented 2 years ago

We would save some memory with UnitRange then.

But, a temporary solution could be to do a collect internally.