9#include <casadi/core/function.hpp>
10#include <casadi/mem.h>
16template <Config Conf,
size_t N_in,
size_t N_out>
20 static_assert(std::is_same_v<real_t, casadi_real>);
28 using namespace std::literals::string_literals;
29 if (N_in !=
fun.n_in())
30 throw std::invalid_argument(
31 "Invalid number of input arguments: got "s +
32 std::to_string(
fun.n_in()) +
", should be " +
33 std::to_string(N_in) +
".");
34 if (N_out !=
fun.n_out())
35 throw std::invalid_argument(
36 "Invalid number of output arguments: got "s +
37 std::to_string(
fun.n_out()) +
", should be " +
38 std::to_string(N_out) +
".");
43 const std::array<casadi_dim, N_in> &dim_in,
44 const std::array<casadi_dim, N_out> &dim_out)
52 const std::array<casadi_dim, N_out> &dim_out = {}) {
53 using namespace std::literals::string_literals;
54 static constexpr std::array count{
"first",
"second",
"third",
55 "fourth",
"fifth",
"sixth",
57 static_assert(N_in <= count.size());
58 static_assert(N_out <= count.size());
60 return "(" + std::to_string(d.first) +
", " +
61 std::to_string(d.second) +
")";
63 for (
size_t n = 0; n < N_in; ++n) {
64 auto cs_n =
static_cast<casadi_int
>(n);
65 if (dim_in[n].first != 0 && dim_in[n] !=
fun.size_in(cs_n))
66 throw std::invalid_argument(
67 "Invalid dimension of "s + count[n] +
68 " input argument: got " + to_string(
fun.size_in(cs_n)) +
69 ", should be " + to_string(dim_in[n]) +
".");
71 for (
size_t n = 0; n < N_out; ++n) {
72 auto cs_n =
static_cast<casadi_int
>(n);
73 if (dim_out[n].first != 0 && dim_out[n] !=
fun.size_out(cs_n))
74 throw std::invalid_argument(
75 "Invalid dimension of "s + count[n] +
76 " output argument: got " + to_string(
fun.size_out(cs_n)) +
77 ", should be " + to_string(dim_out[n]) +
".");
82 void operator()(
const double *
const *in,
double *
const *out)
const {
83 std::copy_n(in, N_in,
arg_work.begin());
84 std::copy_n(out, N_out,
res_work.begin());
90 double *
const (&out)[N_out])
const {
98 mutable std::vector<casadi_int>
iwork;
99 mutable std::vector<double>
dwork;
Class for evaluating CasADi functions, allocating the necessary workspace storage in advance for allo...
CasADiFunctionEvaluator(casadi::Function &&f, const std::array< casadi_dim, N_in > &dim_in, const std::array< casadi_dim, N_out > &dim_out)
CasADiFunctionEvaluator(casadi::Function &&f)
void validate_dimensions(const std::array< casadi_dim, N_in > &dim_in={}, const std::array< casadi_dim, N_out > &dim_out={})
void operator()(const double *const *in, double *const *out) const
std::vector< double * > res_work
void operator()(const double *const (&in)[N_in], double *const (&out)[N_out]) const
std::pair< casadi_int, casadi_int > casadi_dim
std::vector< double > dwork
std::vector< const double * > arg_work
std::vector< casadi_int > iwork
#define USING_ALPAQA_CONFIG(Conf)