File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 396396# get(::ModelLike, ::AbstractVariableAttribute, ::Vector{VariableIndex})
397397# would not allow us to define get(::SomeModel, ::AnyAttribute, ::Vector).
398398function get (model:: ModelLike , attr:: AnyAttribute , idxs:: Vector )
399+ if isempty (idxs)
400+ return Vector {attribute_value_type(attr)} ()
401+ end
399402 return get .(model, attr, idxs)
400403end
401404
Original file line number Diff line number Diff line change @@ -316,6 +316,23 @@ function test_attributes_AutomaticDifferentiationBackend()
316316 return
317317end
318318
319+ function test_empty_vector_attribute ()
320+ model = MOI. Utilities. Model {Float64} ()
321+ x = MOI. get (model, MOI. ListOfVariableIndices ())
322+ @test typeof (x) == Vector{MOI. VariableIndex}
323+ ret = MOI. get (model, MOI. VariablePrimalStart (), x)
324+ @test typeof (ret) == Vector{Any}
325+ ret = MOI. get (model, MOI. VariableName (), x)
326+ @test typeof (ret) == Vector{String}
327+ F, S = MOI. ScalarAffineFunction{Float64}, MOI. EqualTo{Float64}
328+ c = MOI. get (model, MOI. ListOfConstraintIndices {F,S} ())
329+ ret = MOI. get (model, MOI. ConstraintPrimalStart (), c)
330+ @test typeof (ret) == Vector{Any}
331+ ret = MOI. get (model, MOI. ConstraintName (), c)
332+ @test typeof (ret) == Vector{String}
333+ return
334+ end
335+
319336function runtests ()
320337 for name in names (@__MODULE__ ; all = true )
321338 if startswith (" $name " , " test_" )
You can’t perform that action at this time.
0 commit comments