Skip to content

Commit c53d3ab

Browse files
committed
Implement MOI.Utilities.scalar_type for (Matrix|Sparse)VectorAffineFunction
1 parent 07478f8 commit c53d3ab

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/utils.jl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ struct MatrixVectorAffineFunction{AT,VT} <: MOI.AbstractVectorFunction
239239
terms::AT
240240
constants::VT
241241
end
242+
242243
MOI.constant(func::MatrixVectorAffineFunction) = func.constants
243244
function Base.convert(
244245
::Type{MOI.VectorAffineFunction{T}},
@@ -269,14 +270,23 @@ function MOIU.isapprox_zero(
269270
return MOIU.isapprox_zero(standard_form(func), tol)
270271
end
271272

272-
_scalar(::Type{<:MatrixVectorAffineFunction}) = VectorScalarAffineFunction
273-
_scalar(::Type{<:SparseVectorAffineFunction}) = SparseScalarAffineFunction
273+
function MOI.Utilities.scalar_type(::Type{<:MatrixVectorAffineFunction})
274+
return VectorScalarAffineFunction
275+
end
276+
277+
function MOI.Utilities.scalar_type(::Type{<:SparseVectorAffineFunction})
278+
return SparseScalarAffineFunction
279+
end
280+
274281

275282
function Base.getindex(
276283
it::MOI.Utilities.ScalarFunctionIterator{F},
277284
output_index::Integer,
278285
) where {F<:Union{MatrixVectorAffineFunction,SparseVectorAffineFunction}}
279-
return _scalar(F)(it.f.terms[output_index, :], it.f.constants[output_index])
286+
return MOI.Utilities.scalar_type(F)(
287+
it.f.terms[output_index, :],
288+
it.f.constants[output_index],
289+
)
280290
end
281291

282292
function _index_map_to_oneto!(index_map, v::MOI.VariableIndex)

0 commit comments

Comments
 (0)