From ed08ee98f5d7ad65bbd1f5414f5b448e0d2dc78c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 18 Jul 2019 20:24:29 -0600 Subject: [PATCH 1/2] Fix broadcast for scalar sets --- src/sets.jl | 2 ++ test/sets.jl | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/sets.jl b/src/sets.jl index 61e2b73681..9ff4b316ea 100644 --- a/src/sets.jl +++ b/src/sets.jl @@ -37,6 +37,8 @@ Abstract supertype for subsets of ``\\mathbb{R}``. """ abstract type AbstractScalarSet <: AbstractSet end +Base.broadcastable(set::AbstractScalarSet) = Ref(set) + dimension(s::AbstractScalarSet) = 1 """ diff --git a/test/sets.jl b/test/sets.jl index deb82310e8..8d8ff60bc7 100644 --- a/test/sets.jl +++ b/test/sets.jl @@ -1,3 +1,10 @@ +using Test + +using MathOptInterface +const MOI = MathOptInterface + +include("dummy.jl") + """ MutLessThan{T<:Real} <: MOI.AbstractScalarSet @@ -32,7 +39,17 @@ Base.copy(mlt::MutLessThan) = MutLessThan(Base.copy(mlt.upper)) @test s3.set.upper ≈ 4.0 s3_copy.set.upper = 5.0 @test s3.set.upper ≈ 4.0 - @test s3_copy.set.upper ≈ 5.0 + @test s3_copy.set.upper ≈ 5.0 + end + end + @testset "Broadcast" begin + model = DummyModelWithAdd() + x = MOI.add_variables(model, 3) + cis = MOI.add_constraint.(model, x, MOI.EqualTo(0.0)) + @test length(cis) == 3 + for i in 1:3 + @test cis[i] == MOI.ConstraintIndex{MOI.SingleVariable, + MOI.EqualTo{Float64}}(0) end end end From 9a830682c5693087405e2e233d0f6f53060f164d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Thu, 18 Jul 2019 21:23:34 -0600 Subject: [PATCH 2/2] Address comments --- test/sets.jl | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/test/sets.jl b/test/sets.jl index 8d8ff60bc7..6e7a2613bd 100644 --- a/test/sets.jl +++ b/test/sets.jl @@ -46,10 +46,8 @@ Base.copy(mlt::MutLessThan) = MutLessThan(Base.copy(mlt.upper)) model = DummyModelWithAdd() x = MOI.add_variables(model, 3) cis = MOI.add_constraint.(model, x, MOI.EqualTo(0.0)) + @test cis isa Vector{MOI.ConstraintIndex{MOI.SingleVariable, + MOI.EqualTo{Float64}}} @test length(cis) == 3 - for i in 1:3 - @test cis[i] == MOI.ConstraintIndex{MOI.SingleVariable, - MOI.EqualTo{Float64}}(0) - end end end