{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/668","repository_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl","labels_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/668/labels{/name}","comments_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/668/comments","events_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/668/events","html_url":"https://github.com/JuliaOpt/JuMP.jl/pull/668","id":132583639,"number":668,"title":"RFC: support for user-defined nonlinear functions","user":{"login":"mlubin","id":1733683,"avatar_url":"https://avatars.githubusercontent.com/u/1733683?v=3","gravatar_id":"","url":"https://api.github.com/users/mlubin","html_url":"https://github.com/mlubin","followers_url":"https://api.github.com/users/mlubin/followers","following_url":"https://api.github.com/users/mlubin/following{/other_user}","gists_url":"https://api.github.com/users/mlubin/gists{/gist_id}","starred_url":"https://api.github.com/users/mlubin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlubin/subscriptions","organizations_url":"https://api.github.com/users/mlubin/orgs","repos_url":"https://api.github.com/users/mlubin/repos","events_url":"https://api.github.com/users/mlubin/events{/privacy}","received_events_url":"https://api.github.com/users/mlubin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2016-02-10T01:18:24Z","updated_at":"2016-02-10T17:29:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/pulls/668","html_url":"https://github.com/JuliaOpt/JuMP.jl/pull/668","diff_url":"https://github.com/JuliaOpt/JuMP.jl/pull/668.diff","patch_url":"https://github.com/JuliaOpt/JuMP.jl/pull/668.patch"},"body":"``autodiff=true`` makes a beautiful comeback: \r\n\r\n```julia\r\nmysquare(x) = x^2\r\nmyf(x,y) = (x-1)^2+(y-2)^2\r\n\r\nregisterNLFunction(:myf, 2, myf, autodiff=true)\r\nregisterNLFunction(:mysquare, 1, mysquare, autodiff=true)\r\n\r\nm = Model()\r\n\r\n@defVar(m, x[1:2] >= 0.5)\r\n@setNLObjective(m, Min, myf(x[1],mysquare(x[2])))\r\n\r\nstatus = solve(m)\r\n@show getValue(x)\r\n```\r\n\r\nCurrently requires master of ReverseDiffSparse and ForwardDiff.\r\n\r\nOnly major caveat at the moment is that we don't yet support hessians for multivariate functions. Mostly looking to get feedback on the syntax. Interesting usage examples would also be appreciated for the documentation.\r\n\r\nCC @jrevels @davidanthoff @anriseth @tkelman @dpo"},"comment":{"url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/comments/182493542","html_url":"https://github.com/JuliaOpt/JuMP.jl/pull/668#issuecomment-182493542","issue_url":"https://api.github.com/repos/JuliaOpt/JuMP.jl/issues/668","id":182493542,"user":{"login":"mlubin","id":1733683,"avatar_url":"https://avatars.githubusercontent.com/u/1733683?v=3","gravatar_id":"","url":"https://api.github.com/users/mlubin","html_url":"https://github.com/mlubin","followers_url":"https://api.github.com/users/mlubin/followers","following_url":"https://api.github.com/users/mlubin/following{/other_user}","gists_url":"https://api.github.com/users/mlubin/gists{/gist_id}","starred_url":"https://api.github.com/users/mlubin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlubin/subscriptions","organizations_url":"https://api.github.com/users/mlubin/orgs","repos_url":"https://api.github.com/users/mlubin/repos","events_url":"https://api.github.com/users/mlubin/events{/privacy}","received_events_url":"https://api.github.com/users/mlubin/received_events","type":"User","site_admin":false},"created_at":"2016-02-10T17:29:51Z","updated_at":"2016-02-10T17:29:51Z","body":"The feature requests start piling up :)\r\n\r\n> Isn't splatting still kind of slow for large vectors?\r\n\r\nYes, in the first pass I'm aiming to support the low-dimensional use cases.\r\n\r\n> I'd want to express functions of separate vectors, say state, control, parameters etc so something more general than a single vector input and less verbose than listing every scalar input would be ideal.\r\n\r\nI could imagine something like:\r\n```\r\nfunction foo(x,y)\r\n ...\r\nend\r\nregisterNLFunction(:foo, (2,2), foo, autodiff=true)\r\n```\r\n\r\nwhich will pass two vectors of length 2. The trouble is that JuMP's syntax doesn't allow vector-valued nodes in the nonlinear expression graph, so you wouldn't be able to call it like ``foo(x,y)`` in the JuMP nonlinear expression where x and y are vectors of variables. It's worth thinking about but there's no way I can spend time on making this work anytime soon."}}