Skip to content

Commit e722173

Browse files
authored
Implement MOI.Utilities.scalar_type for (Matrix|Sparse)VectorAffineFunction (#264)
1 parent 07478f8 commit e722173

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/utils.jl

Lines changed: 12 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,22 @@ 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
274280

275281
function Base.getindex(
276282
it::MOI.Utilities.ScalarFunctionIterator{F},
277283
output_index::Integer,
278284
) where {F<:Union{MatrixVectorAffineFunction,SparseVectorAffineFunction}}
279-
return _scalar(F)(it.f.terms[output_index, :], it.f.constants[output_index])
285+
return MOI.Utilities.scalar_type(F)(
286+
it.f.terms[output_index, :],
287+
it.f.constants[output_index],
288+
)
280289
end
281290

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

0 commit comments

Comments
 (0)