Skip to content

Commit a070be2

Browse files
committed
Protect users against mixing vectors and scalars
1 parent 68707b8 commit a070be2

1 file changed

Lines changed: 25 additions & 9 deletions

File tree

src/jump_wrapper.jl

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,12 @@ Set the function to be used for forward mode differentiation of a constraint.
210210
"""
211211
function set_forward_constraint_function(
212212
model::JuMP.Model,
213-
con_ref::JuMP.ConstraintRef,
213+
con_ref::JuMP.ConstraintRef{
214+
M,
215+
<:MOI.ConstraintIndex{<:MOI.AbstractScalarFunction},
216+
},
214217
func::JuMP.AbstractJuMPScalar,
215-
)
218+
) where {M}
216219
JuMP.check_belongs_to_model(con_ref, model)
217220
JuMP.check_belongs_to_model(func, model)
218221
return MOI.set(
@@ -225,9 +228,12 @@ end
225228

226229
function set_forward_constraint_function(
227230
model::JuMP.Model,
228-
con_ref::JuMP.ConstraintRef,
231+
con_ref::JuMP.ConstraintRef{
232+
M,
233+
<:MOI.ConstraintIndex{<:MOI.AbstractScalarFunction},
234+
},
229235
value::Number,
230-
)
236+
) where {M}
231237
JuMP.check_belongs_to_model(con_ref, model)
232238
return MOI.set(
233239
JuMP.backend(model),
@@ -239,9 +245,12 @@ end
239245

240246
function set_forward_constraint_function(
241247
model::JuMP.Model,
242-
con_ref::JuMP.ConstraintRef,
248+
con_ref::JuMP.ConstraintRef{
249+
M,
250+
<:MOI.ConstraintIndex{<:MOI.AbstractVectorFunction},
251+
},
243252
value::AbstractArray{<:JuMP.AbstractJuMPScalar},
244-
)
253+
) where {M}
245254
JuMP.check_belongs_to_model(con_ref, model)
246255
JuMP.check_belongs_to_model.(value, model)
247256
return MOI.set(
@@ -254,9 +263,12 @@ end
254263

255264
function set_forward_constraint_function(
256265
model::JuMP.Model,
257-
con_ref::JuMP.ConstraintRef,
266+
con_ref::JuMP.ConstraintRef{
267+
M,
268+
<:MOI.ConstraintIndex{<:MOI.AbstractVectorFunction},
269+
},
258270
value::AbstractArray{<:Number},
259-
)
271+
) where {M}
260272
JuMP.check_belongs_to_model(con_ref, model)
261273
return MOI.set(
262274
JuMP.backend(model),
@@ -268,7 +280,11 @@ end
268280

269281
function set_forward_constraint_function(
270282
model::JuMP.Model,
271-
con_ref::JuMP.ConstraintRef{<:JuMP.AbstractModel,<:MOI.ConstraintIndex,S},
283+
con_ref::JuMP.ConstraintRef{
284+
<:JuMP.AbstractModel,
285+
<:MOI.ConstraintIndex{<:MOI.AbstractVectorFunction},
286+
S,
287+
},
272288
value::AbstractMatrix{<:Number},
273289
) where {S<:Union{JuMP.SquareMatrixShape,JuMP.SymmetricMatrixShape}}
274290
if !LinearAlgebra.issymmetric(value)

0 commit comments

Comments
 (0)