3#include <casadi/core/function.hpp>
16template <
size_t N_in,
size_t N_out>
26 if (N_in !=
fun.n_in())
27 throw std::invalid_argument(
"Invalid number of input arguments.");
28 if (N_out !=
fun.n_out())
29 throw std::invalid_argument(
"Invalid number of output arguments.");
36 using std::operator
""s;
37 constexpr static const char *count[]{
"first",
"second",
"third",
39 static_assert(N_in <= 4);
40 static_assert(N_out <= 4);
42 return "(" + std::to_string(
d.first) +
", " +
43 std::to_string(
d.second) +
")";
45 for (
size_t n = 0;
n < N_in; ++
n)
46 if (dim_in[
n].first != 0 && dim_in[
n] !=
fun.size_in(
n))
47 throw std::invalid_argument(
48 "Invalid dimension of "s + count[
n] +
49 " input argument: got " + to_string(
fun.size_in(
n)) +
50 ", should be " + to_string(dim_in[
n]) +
".");
51 for (
size_t n = 0;
n < N_out; ++
n)
52 if (dim_out[
n].first != 0 && dim_out[
n] !=
fun.size_out(
n))
53 throw std::invalid_argument(
54 "Invalid dimension of "s + count[
n] +
55 " output argument: got " + to_string(
fun.size_out(
n)) +
56 ", should be " + to_string(dim_out[
n]) +
".");
61 fun(
const_cast<const double **
>(in),
const_cast<double **
>(
out),
67 double *
const (&
out)[N_out])
const {
75 mutable std::vector<casadi_int>
iwork;
76 mutable std::vector<double>
dwork;
83 :
fun(std::move(
f), {{dim_in, 1}}, {{1, 1}}) {}
99 const std::array<casadi_int, 2> &dim_in = {})
100 :
fun(std::move(
f), {{dim_in[0], 1}, {dim_in[1], 1}}, {{1, 1}}) {}
118 casadi_int dim_out = 0)
119 :
fun(std::move(
f), {{dim_in, 1}}, {{dim_out, 1}}) {}
122 fun({in.data()}, {
out.data()});
135 const std::array<casadi_int, 2> &dim_in = {},
136 casadi_int dim_out = 0)
137 :
fun(std::move(
f), {{dim_in[0], 1}, {dim_in[1], 1}}, {{dim_out, 1}}) {}
140 fun({in1.data(), in2.data()}, {
out.data()});
151 const std::array<casadi_int, 2> &dim_in = {},
153 :
fun(std::move(
f), {{dim_in[0], 1}, {dim_in[1], 1}}, {dim_out}) {}
156 fun({in1.data(), in2.data()}, {
out.data()});
167 const std::array<casadi_int, 3> &dim_in = {},
179 fun({in1.data(), in2.data(), in3.data()}, {
out.data()});
190 const std::array<casadi_int, 3> &dim_in = {},
191 casadi_int dim_out = 0)
202 fun({in1.data(), in2.data(), in3.data()}, {
out.data()});
213 const std::array<casadi_int, 4> &dim_in = {},
214 casadi_int dim_out = 0)
226 fun({in1.data(), in2.data(), in3.data(), in4.data()}, {
out.data()});
Wrapper for CasADiFunctionEvaluator with 1 vector input, scalar output.
CasADiFunctionEvaluator< 1, 1 > fun
CasADiFun_1Vi1So(casadi::Function &&f, casadi_int dim_in=0)
double operator()(alpaqa::crvec x) const
Wrapper for CasADiFunctionEvaluator with 1 vector input, 1 vector output.
CasADiFun_1Vi1Vo(CasADiFunctionEvaluator< 1, 1 > &&fun)
CasADiFun_1Vi1Vo(casadi::Function &&f, casadi_int dim_in=0, casadi_int dim_out=0)
void operator()(alpaqa::crvec in, alpaqa::rvec out) const
CasADiFunctionEvaluator< 1, 1 > fun
Wrapper for CasADiFunctionEvaluator with 2 vector inputs, 1 matrix output.
CasADiFun_2Vi1Mo(casadi::Function &&f, const std::array< casadi_int, 2 > &dim_in={}, CasADiFunctionEvaluator< 2, 1 >::casadi_dim dim_out={0, 0})
void operator()(alpaqa::crvec in1, alpaqa::crvec in2, alpaqa::rmat out) const
CasADiFunctionEvaluator< 2, 1 > fun
Wrapper for CasADiFunctionEvaluator with 2 vector inputs, scalar output.
CasADiFun_2Vi1So(casadi::Function &&f, const std::array< casadi_int, 2 > &dim_in={})
double operator()(alpaqa::crvec x, alpaqa::crvec p) const
CasADiFunctionEvaluator< 2, 1 > fun
Wrapper for CasADiFunctionEvaluator with 2 vector inputs, 1 vector output.
CasADiFun_2Vi1Vo(CasADiFunctionEvaluator< 2, 1 > &&fun)
CasADiFun_2Vi1Vo(casadi::Function &&f, const std::array< casadi_int, 2 > &dim_in={}, casadi_int dim_out=0)
void operator()(alpaqa::crvec in1, alpaqa::crvec in2, alpaqa::rvec out) const
CasADiFunctionEvaluator< 2, 1 > fun
Wrapper for CasADiFunctionEvaluator with 3 vector inputs, 1 matrix output.
void operator()(alpaqa::crvec in1, alpaqa::crvec in2, alpaqa::crvec in3, alpaqa::rmat out) const
CasADiFun_3Vi1Mo(casadi::Function &&f, const std::array< casadi_int, 3 > &dim_in={}, CasADiFunctionEvaluator< 3, 1 >::casadi_dim dim_out={0, 0})
CasADiFunctionEvaluator< 3, 1 > fun
Wrapper for CasADiFunctionEvaluator with 3 vector inputs, 1 vector output.
void operator()(alpaqa::crvec in1, alpaqa::crvec in2, alpaqa::crvec in3, alpaqa::rvec out) const
CasADiFunctionEvaluator< 3, 1 > fun
CasADiFun_3Vi1Vo(casadi::Function &&f, const std::array< casadi_int, 3 > &dim_in={}, casadi_int dim_out=0)
Wrapper for CasADiFunctionEvaluator with 4 vector inputs, 1 vector output.
CasADiFunctionEvaluator< 4, 1 > fun
CasADiFun_4Vi1Vo(casadi::Function &&f, const std::array< casadi_int, 4 > &dim_in={}, casadi_int dim_out=0)
void operator()(alpaqa::crvec in1, alpaqa::crvec in2, alpaqa::crvec in3, alpaqa::crvec in4, alpaqa::rvec out) const
Class for evaluating CasADi functions, allocating the necessary workspace storage in advance for allo...
void operator()(const double *const *in, double *const *out) const
CasADiFunctionEvaluator(casadi::Function &&f, const casadi_dim(&dim_in)[N_in]={}, const casadi_dim(&dim_out)[N_out]={})
void operator()(const double *const (&in)[N_in], double *const (&out)[N_out]) const
void validate_dimensions(const casadi_dim(&dim_in)[N_in], const casadi_dim(&dim_out)[N_out])
std::pair< casadi_int, casadi_int > casadi_dim
std::vector< double > dwork
std::vector< casadi_int > iwork
Eigen::Ref< const vec > crvec
Default type for immutable references to vectors.
Eigen::Ref< mat > rmat
Default type for mutable references to matrices.
Eigen::Ref< vec > rvec
Default type for mutable references to vectors.