-
Notifications
You must be signed in to change notification settings - Fork 94
Description
The functions currently enforces the list of terms to be a Vector
, e.g.
mutable struct ScalarAffineFunction{T} <: AbstractScalarFunction
terms::Vector{ScalarAffineTerm{T}}
constant::T
end
However, the fact that it is a Vector
and not any AbstractVector
does not help the solver wrappers in any way. Before we add the term types and we had different field for the coefficients and variables, we could have solver wrappers that pass directly the coefficient vector by pointer to the C-interface but won't do that anymore. It will need to iterate through the vector to do some transformation anyway so I suspect that if we change this to AbstractVector, it won't require any change from the solver wrappers.
The tricky point to discuss is how to update the MOIU model. We have a few choices:
- Store only function with
Vector
terms and collect the terms if a function is passed with AbstractVector - Store a vector of an non-concrete type not specifying which type of vector is it allowing to store function using different types of vectors
- Allow either 1) and 2) or even more by simply taking what is in the macro call. For instance if we have
ScalarAffineFunction{T, VT <: AbstractVector{T}}
, we could defineconst StandardScalarAffineFunction{T} = ScalarAffineFunction{T, Vector{T}}
and use@model ... (StandardScalarAffineFunction, ...) ...
to do 1) and do@model ... (ScalarAffineFunction, ...) ...
to do 2).
What do you think ?
The advantages of using AbstractVector instead of Vector are numerous:
- GPU support ScalarFunctionIterator has quadratic complexity #418 (comment)
- Use views in function iterators ScalarFunctionIterator has quadratic complexity #418 (comment)
- Use StructOfArrays ScalarFunctionIterator has quadratic complexity #418 (comment)
- Implement lazy_operate lazy_operate #526