33 const auto &f = functions.
functions.at(
"f");
34 wrap(
"f", [&] { f_eval::validate_num_args(f); });
35 auto n = f.size1_in(0);
36 auto p = f.size1_in(1);
37 wrap(
"f", [&] { f_eval::validate_dimensions(f,
dims(n, p),
dims(1)); });
40 auto x = casadi::SX::sym(
"x", n);
41 auto param = casadi::SX::sym(
"param", p);
42 auto fx = f(std::vector{x, param})[0];
43 auto grad_f = casadi::SX::gradient(
fx, x);
45 casadi::Function(
"f_grad_f", {x, param}, {
fx, grad_f});
50 wrap(
"g", [&] { g_eval::validate_num_args(g); });
51 auto m = g.size1_out(0);
52 wrap(
"g", [&] { g_eval::validate_dimensions(g,
dims(n, p),
dims(m)); });
57 auto y = casadi::SX::sym(
"y", m);
58 auto gx = g(std::vector{x, param})[0];
59 auto grad_g_prod = casadi::SX::jtimes(
gx, x, y,
true);
61 casadi::Function(
"grad_g_prod", {x, param, y}, {grad_g_prod});
64 auto grad_L = grad_f + grad_g_prod;
66 casadi::Function(
"grad_L", {x, param, y}, {grad_L});