diff --git a/src/Utilities/operate.jl b/src/Utilities/operate.jl index de4afa1f6a..9656a1875b 100644 --- a/src/Utilities/operate.jl +++ b/src/Utilities/operate.jl @@ -323,7 +323,12 @@ end ### 1c: operate(+, T, args...) function operate(::typeof(+), ::Type{T}, f, g, h, args...) where {T<:Number} - return operate!(+, T, operate(+, T, f, g), h, args...) + ret = operate(+, T, f, g) + ret = operate!(+, T, ret, h) + for a in args + ret = operate!(+, T, ret, a) + end + return ret end ### 2a: operate(::typeof(-), ::Type{T}, ::F) @@ -1167,8 +1172,13 @@ end ### 1c: operate!(+, T, args...) -function operate!(op::typeof(+), ::Type{T}, f, g, h, args...) where {T<:Number} - return operate!(+, T, operate!(op, T, f, g), h, args...) +function operate!(::typeof(+), ::Type{T}, f, g, h, args...) where {T<:Number} + ret = operate!(+, T, f, g) + ret = operate!(+, T, ret, h) + for a in args + ret = operate!(+, T, ret, a) + end + return ret end ### 2a: operate!(::typeof(-), ::Type{T}, ::F) diff --git a/test/Utilities/test_operate!.jl b/test/Utilities/test_operate!.jl index 4a82333729..3c22ff900e 100644 --- a/test/Utilities/test_operate!.jl +++ b/test/Utilities/test_operate!.jl @@ -170,6 +170,20 @@ function test_operate_1c() return end +function test_operate_1c_many_arguments() + x = [i + i * MOI.VariableIndex(i) for i in 1:1_000] + y = MOI.Utilities.operate(+, Int, x...) + f = MOI.ScalarAffineFunction( + [MOI.ScalarAffineTerm(i, MOI.VariableIndex(i)) for i in 1:1_000], + sum(i for i in 1:1_000), + ) + @test ≈(y, f) + z = zero(MOI.ScalarAffineFunction{Int}) + z = MOI.Utilities.operate!(+, Int, z, x...) + @test ≈(z, f) + return +end + function test_operate_2a() T = Int for (f, g) in (