Skip to content

Commit

Permalink
improve error handling for arrays in nonlinear expressions (#1373)
Browse files Browse the repository at this point in the history
* improve error handling for arrays in nonlinear expressions

* improve coverage
  • Loading branch information
mlubin committed Jul 24, 2018
1 parent e88ddaa commit eb7acc6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parsenlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ function parseNLExpr_runtime(m::Model, x::NonlinearParameter, tape, parent, valu
nothing
end

function parseNLExpr_runtime(m::Model, x::Vector, tape, parent, values)
error("Unexpected vector $x in nonlinear expression. Nonlinear expressions may contain only scalar expressions.")
function parseNLExpr_runtime(m::Model, x::AbstractArray, tape, parent, values)
error("Unexpected array $x in nonlinear expression. Nonlinear expressions may contain only scalar expressions.")
end

function expression_complexity(ex::Expr)
Expand Down
6 changes: 6 additions & 0 deletions test/nlp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@
@test_throws ErrorException @NLexpression(m, sum(x))
end

@testset "Error on non-scalar expressions" begin
m = Model()
x = [1,2,3]
@test_throws ErrorException @NLexpression(m, x + 1)
end

# Converts the lower-triangular sparse Hessian in MOI format into a dense
# matrix.
function dense_hessian(hessian_sparsity, V, n)
Expand Down

0 comments on commit eb7acc6

Please sign in to comment.