Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Utilities/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,14 @@ end

# Arithmetic

function Base.zero(::Type{MOI.ScalarAffineFunction{T}}) where T
return MOI.ScalarAffineFunction(MOI.ScalarAffineTerm{T}[], zero(T))
end
function Base.zero(::Type{MOI.ScalarQuadraticFunction{T}}) where T
return MOI.ScalarQuadraticFunction(MOI.ScalarAffineTerm{T}[],
MOI.ScalarQuadraticTerm{T}[], zero(T))
end

"""
operate(op::Function, ::Type{T},
args::Union{T, MOI.AbstractFunction}...)::MOI.AbstractFunction where T
Expand Down
8 changes: 8 additions & 0 deletions test/Utilities/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
end
@testset "Scalar" begin
@testset "Affine" begin
@testset "zero" begin
f = @inferred MOIU.zero(MOI.ScalarAffineFunction{Float64})
@test MOIU.isapprox_zero(f, 1e-16)
end
@testset "promote_operation" begin
@test MOIU.promote_operation(+, Float64, MOI.SingleVariable,
MOI.SingleVariable) == MOI.ScalarAffineFunction{Float64}
Expand Down Expand Up @@ -225,6 +229,10 @@
end
end
@testset "Quadratic" begin
@testset "zero" begin
f = @inferred MOIU.zero(MOI.ScalarQuadraticFunction{Float64})
@test MOIU.isapprox_zero(f, 1e-16)
end
@testset "promote_operation" begin
@test MOIU.promote_operation(+, Int,
MOI.ScalarQuadraticFunction{Int},
Expand Down