Skip to content

Commit

Permalink
Fix broadcasting over NonlinearExpr objects (#3881)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Nov 14, 2024
1 parent 5f07ea2 commit 7111683
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/nlp_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ struct GenericNonlinearExpr{V<:AbstractVariableRef} <: AbstractJuMPScalar
end
end

Base.broadcastable(f::GenericNonlinearExpr) = Ref(f)

variable_ref_type(::Type{GenericNonlinearExpr}, ::Any) = nothing

function variable_ref_type(::Type{GenericNonlinearExpr}, x::AbstractJuMPScalar)
Expand Down
10 changes: 10 additions & 0 deletions test/test_nlp_expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1134,4 +1134,14 @@ function test_promote_type()
return
end

function test_broadcastable()
model = Model()
@variable(model, x, start = 2)
f = sin(x)^2
@test Base.broadcastable(f) isa Base.RefValue{NonlinearExpr}
@test value(start_value, f) sin(2)^2
@test value.(start_value, f) sin(2)^2
return
end

end # module

0 comments on commit 7111683

Please sign in to comment.