Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Mar 18, 2024
1 parent bb90b58 commit 54fb88e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/nl_to_polynomial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ function _checked_div(
b::DynamicPolynomials.Variable,
)
divisor, remainder = Base.divrem(a, b)
if iszero(remainder)
return divisor
if !iszero(remainder)
throw(
InvalidNLExpression("Cannot convert `$(a) / $b` into a polynomial"),
)
end
return a / b
return divisor
end

function _to_polynomial(expr, ::Type{T}) where {T}
Expand Down
16 changes: 14 additions & 2 deletions test/qcqp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,21 @@ function test_scalar_nonlinear_function_div_rem_zero(x, y, T)
return
end

test_scalar_nonlinear_function_div_rem_one(x, y, ::Type{Int}) = nothing
function test_scalar_nonlinear_function_div_rem_err(x, y, T)
inner = Model{T}()
model = PolyJuMP.JuMP.GenericModel{T}() do
return PolyJuMP.QCQP.Optimizer{T}(MOI.Utilities.MockOptimizer(inner))
end
PolyJuMP.@variable(model, x)
PolyJuMP.@variable(model, y)
PolyJuMP.@objective(model, Min, x^3 / y)
@test_throws PolyJuMP.InvalidNLExpression PolyJuMP.optimize!(model)
return
end

test_scalar_nonlinear_function_div_rem_number(x, y, ::Type{Int}) = nothing

function test_scalar_nonlinear_function_div_rem_one(x, y, T)
function test_scalar_nonlinear_function_div_rem_number(x, y, T)
inner = Model{T}()
model = PolyJuMP.JuMP.GenericModel{T}() do
return PolyJuMP.QCQP.Optimizer{T}(MOI.Utilities.MockOptimizer(inner))
Expand Down

0 comments on commit 54fb88e

Please sign in to comment.