Hi @xuqingyu,
There’s no explicit support for this, but you have a couple of options.
Assuming A and B have the same dimensions, then you can use broadcasting:
add_to_expression!.(A, B)
This will call add_to_expression! on each element pair of A and B.
Second, although I see your p.p.s., just use a loop! It won’t be any slower.
Third, if your problem is small enough, just use +=. It’s a warning, not an error. So if it’s fast enough for you, don’t worry about the “best” thing to do.
You might also be able to restructure your code to avoid constructing expressions outside the macros. Here’s an explanation in the docs for why we warn that += is less efficient: Performance tips · JuMP