34 const auto &f = functions.
functions.at(
"f");
35 wrap(
"f", [&] { f_eval::validate_num_args(f); });
36 auto n = f.size1_in(0);
37 auto p = f.size1_in(1);
38 wrap(
"f", [&] { f_eval::validate_dimensions(f,
dims(n, p),
dims(1)); });
41 auto x = casadi::SX::sym(
"x", n);
42 auto param = casadi::SX::sym(
"param", p);
43 auto fx = f(std::vector{x, param})[0];
44 auto grad_f = casadi::SX::gradient(
fx, x);
46 casadi::Function(
"f_grad_f", {x, param}, {
fx, grad_f});
51 wrap(
"g", [&] { g_eval::validate_num_args(g); });
52 auto m = g.size1_out(0);
53 wrap(
"g", [&] { g_eval::validate_dimensions(g,
dims(n, p),
dims(m)); });
58 auto y = casadi::SX::sym(
"y", m);
59 auto gx = g(std::vector{x, param})[0];
60 auto grad_g_prod = casadi::SX::jtimes(
gx, x, y,
true);
62 casadi::Function(
"grad_g_prod", {x, param, y}, {grad_g_prod});
65 auto grad_L = grad_f + grad_g_prod;
67 casadi::Function(
"grad_L", {x, param, y}, {grad_L});