@@ -36,6 +36,12 @@ abstract type AbstractConstraintAttribute end
36
36
37
37
const AnyAttribute = Union{AbstractOptimizerAttribute, AbstractModelAttribute, AbstractVariableAttribute, AbstractConstraintAttribute}
38
38
39
+ @static if VERSION >= v " 0.7-"
40
+ # This allows to use attributes in broadcast calls without the need to
41
+ # embed it in a `Ref`
42
+ Base. broadcastable (attribute:: AnyAttribute ) = Ref (attribute)
43
+ end
44
+
39
45
"""
40
46
struct UnsupportedAttribute{AttrType} <: UnsupportedError
41
47
attr::AttrType
@@ -183,7 +189,7 @@ function get end
183
189
# We want to avoid being too specific in the type arguments to avoid method ambiguity.
184
190
# For model, get(::ModelLike, ::AbstractVariableAttribute, ::Vector{VariableIndex}) would not allow
185
191
# to define get(::SomeModel, ::AnyAttribute, ::Vector)
186
- get (model:: ModelLike , attr:: AnyAttribute , idxs:: Vector ) = get .(model, Ref ( attr) , idxs)
192
+ get (model:: ModelLike , attr:: AnyAttribute , idxs:: Vector ) = get .(model, attr, idxs)
187
193
188
194
function get (model:: ModelLike , attr:: AnyAttribute , args... )
189
195
throw (ArgumentError (" ModelLike of type $(typeof (model)) does not support accessing the attribute $attr " ))
@@ -264,7 +270,12 @@ set(model, ConstraintFunction(), c, SingleVariable(v1)) # Error
264
270
"""
265
271
function set end
266
272
# See note with get
267
- set (model:: ModelLike , attr:: Union{AbstractVariableAttribute, AbstractConstraintAttribute} , idxs:: Vector , vector_of_values:: Vector ) = set .(model, Ref (attr), idxs, vector_of_values)
273
+ function set (model:: ModelLike ,
274
+ attr:: Union {AbstractVariableAttribute,
275
+ AbstractConstraintAttribute},
276
+ idxs:: Vector , vector_of_values:: Vector )
277
+ return set .(model, attr, idxs, vector_of_values)
278
+ end
268
279
269
280
function set (model:: ModelLike , attr:: AnyAttribute , args... )
270
281
set_fallback_error (model, attr, args... )
0 commit comments