JuMP vector input in Nonlinear expressions

foo = x -> x[1]^2+x[1]*x[2]
m = Model(solver=IpoptSolver())
@variable(m,a[1:2])
JuMP.register(m, :f, 1, foo, autodiff=true)
@NLobjective(m,Min,f(a))

throws an error stating that nonlinear expressions may only contain scalar expressions.

foo2 = (x1,x2) -> x1^2+x1*x2
JuMP.register(m, :f2, 2, foo2, autodiff=true)
@NLobjective(m,Min,f2(a...))

Shouldn’t that be working with the “…”-expression? Or how to handle otherwise array inputs (in my case the size of the variable ‘a’ is changing)?

I am aware that

@NLobjective(m,Min,f2(a[1],a[2]))

is working.

You also need the splatting operator in the argument of foo2:

function foo2(x...)
    x[1]^2 + x[1]*x[2]
end

m = Model(solver=IpoptSolver())

@variable(m,a[1:2])

JuMP.register(m, :f2, 2, foo2, autodiff=true)
@NLobjective(m,Min,f2(a...))