25 #ifndef CASADI_FUNCTION_HPP
26 #define CASADI_FUNCTION_HPP
28 #include "sx_elem.hpp"
30 #include "printable.hpp"
38 class FunctionInternal;
39 class SerializingStream;
40 class DeserializingStream;
60 public SWIG_IF_ELSE(PrintableCommon, Printable<Function>) {
82 const std::vector<SX>& ex_in,
83 const std::vector<SX>& ex_out,
86 const std::vector<SX>& ex_in,
87 const std::vector<SX>& ex_out,
88 const std::vector<std::string>& name_in,
89 const std::vector<std::string>& name_out,
91 Function(
const std::string& name,
const std::map<std::string, SX>& dict,
92 const std::vector<std::string>& name_in,
93 const std::vector<std::string>& name_out,
102 const std::vector<MX>& ex_in,
103 const std::vector<MX>& ex_out,
106 const std::vector<MX>& ex_in,
107 const std::vector<MX>& ex_out,
108 const std::vector<std::string>& name_in,
109 const std::vector<std::string>& name_out,
111 Function(
const std::string& name,
const std::map<std::string, MX>& dict,
112 const std::vector<std::string>& name_in,
113 const std::vector<std::string>& name_out,
129 const StringVector& name_in,
const StringVector& name_out,
132 const StringVector& name_in,
const StringVector& name_out,
135 const StringVector& name_in,
const StringVector& name_out,
144 const StringVector& name_in,
const StringVector& name_out,
147 const StringVector& name_in,
const StringVector& name_out,
150 const StringVector& name_in,
const StringVector& name_out,
185 static Function jit(
const std::string& name,
const std::string& body,
186 const std::vector<std::string>& name_in,
187 const std::vector<std::string>& name_out,
189 static Function jit(
const std::string& name,
const std::string& body,
190 const std::vector<std::string>& name_in,
191 const std::vector<std::string>& name_out,
192 const std::vector<Sparsity>& sparsity_in,
193 const std::vector<Sparsity>& sparsity_out,
216 static Function create(FunctionInternal* node);
221 static Function create(FunctionInternal* node,
const Dict& opts);
243 std::pair<casadi_int, casadi_int>
size_in(casadi_int ind)
const;
244 std::pair<casadi_int, casadi_int>
size_in(
const std::string& iname)
const {
245 return size_in(index_in(iname));
257 std::pair<casadi_int, casadi_int>
size_out(casadi_int ind)
const;
258 std::pair<casadi_int, casadi_int>
size_out(
const std::string& oname)
const {
259 return size_out(index_out(oname));
271 casadi_int
nnz_in(
const std::string& iname)
const {
return nnz_in(index_in(iname));}
282 casadi_int
nnz_out(
const std::string& oname)
const {
return nnz_out(index_out(oname));}
310 const std::vector<std::string>&
name_in()
const;
320 const std::string&
name_in(casadi_int ind)
const;
333 casadi_int
index_in(
const std::string &name)
const;
395 typedef std::map<std::string, std::vector<std::string> >
AuxOut;
399 const std::vector<std::string>& s_in,
400 const std::vector<std::string>& s_out,
426 const std::vector<std::string>& s_out,
427 casadi_int order=1,
bool tr=
false)
const;
462 #ifdef WITH_DEPRECATED_FEATURES
476 bool compact=
false,
bool symmetric=
false)
const;
478 bool compact=
false,
bool symmetric=
false)
const {
479 return sparsity_jac(index_in(iind), oind, compact, symmetric);
482 bool compact=
false,
bool symmetric=
false)
const {
483 return sparsity_jac(iind, index_out(oind), compact, symmetric);
486 bool compact=
false,
bool symmetric=
false)
const {
487 return sparsity_jac(index_in(iind), index_out(oind), compact, symmetric);
514 void call(
const std::vector<DM> &arg, std::vector<DM>& SWIG_OUTPUT(res),
515 bool always_inline=
false,
bool never_inline=
false)
const;
516 void call(
const std::vector<SX> &arg, std::vector<SX>& SWIG_OUTPUT(res),
517 bool always_inline=
false,
bool never_inline=
false)
const;
518 void call(
const std::vector<MX> &arg, std::vector<MX>& SWIG_OUTPUT(res),
519 bool always_inline=
false,
bool never_inline=
false)
const;
521 bool always_inline=
false,
bool never_inline=
false)
const;
523 bool always_inline=
false,
bool never_inline=
false)
const;
525 bool always_inline=
false,
bool never_inline=
false)
const;
530 bool operator==(
const Function& f)
const;
534 std::vector<DM> operator()(
const std::vector<DM>& arg)
const;
535 std::vector<SX> operator()(
const std::vector<SX>& arg)
const;
536 std::vector<MX> operator()(
const std::vector<MX>& arg)
const;
546 void operator()(std::vector<const double*> arg, std::vector<double*> res)
const;
547 void operator()(std::vector<const bvec_t*> arg, std::vector<bvec_t*> res)
const;
548 void operator()(std::vector<const SXElem*> arg, std::vector<SXElem*> res)
const;
549 template<
typename D>
void call_gen(std::vector<const D*> arg, std::vector<D*> res)
const;
556 typedef const std::vector<std::vector<double>>& VecArg;
557 std::vector<const double*> buf_in(VecArg arg)
const;
558 typedef std::vector<std::vector<double>>& VecRes;
559 std::vector<double*> buf_out(VecRes res)
const;
560 typedef std::vector<std::vector<double>*> VPrRes;
561 std::vector<double*> buf_out(VPrRes res)
const;
563 typedef const std::map<std::string, std::vector<double>>& MapArg;
564 std::vector<const double*> buf_in(MapArg arg)
const;
565 typedef std::map<std::string, std::vector<double>>& MapRes;
566 std::vector<double*> buf_out(MapRes res)
const;
567 typedef std::map<std::string, std::vector<double>*> MPrRes;
568 std::vector<double*> buf_out(MPrRes res)
const;
575 void operator()(VecArg arg, VecRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
576 void operator()(VecArg arg, MapRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
577 void operator()(VecArg arg, VPrRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
578 void operator()(VecArg arg, MPrRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
580 void operator()(MapArg arg, VecRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
581 void operator()(MapArg arg, MapRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
582 void operator()(MapArg arg, VPrRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
583 void operator()(MapArg arg, MPrRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
588 std::vector<DM> operator()(
const DM& arg0)
const {
589 return operator()(std::vector<DM>{arg0});
591 std::vector<SX> operator()(
const SX& arg0)
const {
592 return operator()(std::vector<SX>{arg0});
594 std::vector<MX> operator()(
const MX& arg0)
const {
595 return operator()(std::vector<MX>{arg0});
602 int operator()(
const double** arg,
double** res,
603 casadi_int* iw,
double* w,
int mem)
const;
608 int operator()(
const double** arg,
double** res,
609 casadi_int* iw,
double* w)
const;
616 int operator()(
const SXElem** arg, SXElem** res,
617 casadi_int* iw, SXElem* w,
int mem=0)
const;
622 int operator()(
const bvec_t** arg, bvec_t** res,
623 casadi_int* iw, bvec_t* w,
int mem=0)
const;
628 int rev(bvec_t** arg, bvec_t** res, casadi_int* iw, bvec_t* w,
int mem=0)
const;
633 int rev(std::vector<bvec_t*> arg, std::vector<bvec_t*> res)
const;
642 std::vector<MX>
mapsum(
const std::vector<MX > &x,
643 const std::string& parallelization=
"serial")
const;
690 const std::vector<casadi_int>& accum_in,
691 const std::vector<casadi_int>& accum_out,
694 const std::vector<std::string>& accum_in,
695 const std::vector<std::string>& accum_out,
726 Function map(casadi_int n,
const std::string& parallelization=
"serial")
const;
728 casadi_int max_num_threads)
const;
737 Function map(
const std::string& name,
const std::string& parallelization, casadi_int n,
738 const std::vector<casadi_int>& reduce_in,
739 const std::vector<casadi_int>& reduce_out,
741 Function map(
const std::string& name,
const std::string& parallelization, casadi_int n,
742 const std::vector<std::string>& reduce_in,
743 const std::vector<std::string>& reduce_out,
746 const std::vector<bool>& reduce_in,
747 const std::vector<bool>& reduce_out=std::vector<bool>(),
754 Function slice(
const std::string& name,
const std::vector<casadi_int>& order_in,
755 const std::vector<casadi_int>& order_out,
const Dict& opts=
Dict())
const;
775 const std::vector< std::vector<double> >& knots,
const std::vector<double>& coeffs,
776 const std::vector<casadi_int>& degree, casadi_int m=1,
const Dict& opts=
Dict());
854 void generate_in(
const std::string& fname,
const std::vector<DM>& arg);
865 void generate_out(
const std::string& fname,
const std::vector<DM>& arg);
876 const std::string &fname,
const Dict& options=
Dict())
const;
882 void serialize(std::ostream &stream,
const Dict& opts=
Dict())
const;
904 void export_code(
const std::string& lang,
905 std::ostream &stream,
const Dict& options=
Dict())
const;
911 FunctionInternal* get()
const;
916 T* ret =
dynamic_cast<T*
>(get());
917 casadi_assert_dev(ret!=
nullptr);
924 FunctionInternal* operator->()
const;
927 static bool test_cast(
const SharedObjectInternal* ptr);
941 const SX sx_in(
const std::string& iname)
const {
942 return sx_in(index_in(iname));
944 const std::vector<SX>
sx_in()
const;
946 const MX mx_in(
const std::string & iname)
const {
947 return mx_in(index_in(iname));
949 const std::vector<MX>
mx_in()
const;
960 return sx_out(index_out(oname));
965 return mx_out(index_out(oname));
974 std::vector<double>
nz_from_in(
const std::vector<DM>& arg)
const;
975 std::vector<double>
nz_from_out(
const std::vector<DM>& arg)
const;
976 std::vector<DM>
nz_to_in(
const std::vector<double>& arg)
const;
977 std::vector<DM>
nz_to_out(
const std::vector<double>& arg)
const;
1025 Function& SWIG_OUTPUT(vinit_fcn))
const;
1106 void sz_work(
size_t& sz_arg,
size_t& sz_res,
size_t& sz_iw,
size_t& sz_w)
const;
1111 void set_work(
const double**& arg,
double**& res,
1112 casadi_int*& iw,
double*& w,
int mem=0)
const;
1117 void set_temp(
const double** arg,
double** res,
1118 casadi_int* iw,
double* w,
int mem=0)
const;
1123 void setup(
const double** arg,
double** res, casadi_int* iw,
double* w,
int mem=0)
const;
1128 template<
typename M>
1129 void call_gen(
const std::map<std::string, M>& arg, std::map<std::string, M>& res,
1130 bool always_inline,
bool never_inline)
const;
1144 bool is_a(
const std::string& type,
bool recursive=
true)
const;
1196 casadi_int n = 1,
bool allow_all_zero_sparse =
true)
const;
1206 void* memory(
int ind)
const;
1253 void construct(
const std::string& name,
1254 const std::vector<SX>& ex_in,
const std::vector<SX>& ex_out,
1255 const std::vector<std::string>& name_in,
1256 const std::vector<std::string>& name_out,
1258 void construct(
const std::string& name,
1259 const std::vector<MX>& ex_in,
const std::vector<MX>& ex_out,
1260 const std::vector<std::string>& name_in,
1261 const std::vector<std::string>& name_out,
1263 template<
typename M>
1264 void construct(
const std::string& name,
const std::map<std::string, M>& dict,
1265 const std::vector<std::string>& name_in,
1266 const std::vector<std::string>& name_out,
1271 static bool proceed_to(std::istream& file,
const std::string& str);
1274 Function mapaccum(
const std::string& name,
const std::vector<Function>& chain,
1275 casadi_int n_accum=1,
const Dict& opts =
Dict())
const;
1277 #ifdef WITH_EXTRA_CHECKS
1281 static thread_local casadi_int call_depth_;
1297 std::vector<double> w_;
1298 std::vector<casadi_int> iw_;
1299 std::vector<const double*> arg_;
1300 std::vector<double*> res_;
1301 FunctionInternal* f_node_;
1303 void *mem_internal_;
1323 void set_arg(casadi_int i,
const double* a, casadi_int size);
1332 void set_res(casadi_int i,
double* a, casadi_int size);
1344 #include "casadi_interrupt.hpp"
1345 #include "runtime/shared.hpp"
Helper class for Serialization.
Class to achieve minimal overhead function evaluations.
void set_res(casadi_int i, double *a, casadi_int size)
Set output buffer for ouput i.
void set_arg(casadi_int i, const double *a, casadi_int size)
Set input buffer for input i.
FunctionBuffer(const Function &f)
Main constructor.
int ret()
Get last return value.
const MX mx_in(const std::string &iname) const
Get symbolic primitives equivalent to the input expressions.
bool has_sprev() const
Is the class able to propagate seeds through the algorithm?
casadi_int numel_in() const
Get number of input elements.
Function map(casadi_int n, const std::vector< bool > &reduce_in, const std::vector< bool > &reduce_out=std::vector< bool >(), const Dict &opts=Dict()) const
Map with reduction.
std::vector< bool > is_diff_in() const
Get differentiability of inputs/output.
Function forward(casadi_int nfwd) const
Get a function that calculates nfwd forward derivatives.
casadi_int nnz_out() const
Get number of output nonzeros.
const std::vector< std::string > & name_in() const
Get input scheme.
Function(const std::string &fname)
Construct from a file.
void print_options(std::ostream &stream=casadi::uout()) const
Print options to a stream.
casadi_int n_instructions() const
Number of instruction in the algorithm (SXFunction/MXFunction)
std::string export_code(const std::string &lang, const Dict &options=Dict()) const
Export function in specific language.
size_t sz_res() const
Get required length of res field.
void generate_in(const std::string &fname, const std::vector< DM > &arg)
Export an input file that can be passed to generate C code with a main.
void call(const std::vector< SX > &arg, std::vector< SX > &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
void print_option(const std::string &name, std::ostream &stream=casadi::uout()) const
Print all information there is to know about a certain option.
std::pair< casadi_int, casadi_int > size_out(const std::string &oname) const
Get output dimension.
std::string generate_dependencies(const std::string &fname, const Dict &opts=Dict()) const
Export / Generate C code for the dependency function.
std::vector< double > nz_from_out(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
void save(const std::string &fname, const Dict &opts=Dict()) const
Save Function to a file.
const std::string & name() const
Name of the function.
void call(const std::vector< MX > &arg, std::vector< MX > &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
void assert_size_in(casadi_int i, casadi_int nrow, casadi_int ncol) const
Assert that an input dimension is equal so some given value.
casadi_int size2_out(casadi_int ind) const
Get output dimension.
std::vector< bool > which_depends(const std::string &s_in, const std::vector< std::string > &s_out, casadi_int order=1, bool tr=false) const
Which variables enter with some order.
void call(const MXDict &arg, MXDict &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
const Sparsity & sparsity_out(casadi_int ind) const
Get sparsity of a given output.
Function map(const std::string &name, const std::string ¶llelization, casadi_int n, const std::vector< casadi_int > &reduce_in, const std::vector< casadi_int > &reduce_out, const Dict &opts=Dict()) const
Map with reduction.
const MX mx_in(casadi_int ind) const
Get symbolic primitives equivalent to the input expressions.
Function(const std::string &name, const std::vector< MX > &ex_in, const std::vector< MX > &ex_out, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts=Dict())
Construct an MX function.
bool has_spfwd() const
Is the class able to propagate seeds through the algorithm?
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Get output dimension.
std::vector< DM > generate_out(const std::string &fname)
Export an output file that can be checked with generated C code output.
double max_in(casadi_int ind) const
Get largest input value.
std::vector< DM > convert_out(const DMDict &arg) const
Convert from/to input/output lists/map.
const Sparsity sparsity_jac(const std::string &iind, casadi_int oind=0, bool compact=false, bool symmetric=false) const
Function(const std::string &name, const std::vector< MX > &ex_in, const std::vector< MX > &ex_out, const Dict &opts=Dict())
Construct an MX function.
casadi_int nnz_out(const std::string &oname) const
Get number of output nonzeros.
casadi_int size1_in(casadi_int ind) const
Get input dimension.
Function fold(casadi_int N, const Dict &opts=Dict()) const
Create a mapaccumulated version of this function.
casadi_int nnz_in(casadi_int ind) const
Get number of input nonzeros.
std::vector< SX > convert_out(const SXDict &arg) const
Convert from/to input/output lists/map.
Function mapaccum(const std::string &name, casadi_int N, const Dict &opts=Dict()) const
Create a mapaccumulated version of this function.
Function expand() const
Expand a function to SX.
MXDict convert_in(const std::vector< MX > &arg) const
Convert from/to input/output lists/map.
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Get input dimension.
casadi_int nnz_out(casadi_int ind) const
Get number of output nonzeros.
static bool check_name(const std::string &name)
Check if a string is a valid function name.
Dict cache() const
Get all functions in the cache.
static Function conditional(const std::string &name, const std::vector< Function > &f, const Function &f_def, const Dict &opts=Dict())
Constuct a switch function.
std::vector< casadi_int > instruction_input(casadi_int k) const
Locations in the work vector for the inputs of the instruction.
const std::vector< Sparsity > & jac_sparsity(bool compact=false) const
Get, if necessary generate, the sparsity of all Jacobian blocks.
casadi_int numel_out() const
Get number of output elements.
casadi_int size2_in(const std::string &iname) const
Get input dimension.
std::vector< MX > convert_in(const MXDict &arg) const
Convert from/to input/output lists/map.
std::vector< SX > convert_in(const SXDict &arg) const
Convert from/to input/output lists/map.
Function wrap() const
Wrap in an Function instance consisting of only one MX call.
std::vector< double > nominal_in(casadi_int ind) const
Get nominal input value.
casadi_int numel_in(const std::string &iname) const
Get number of input elements.
casadi_int nnz_in(const std::string &iname) const
Get number of input nonzeros.
const MX mx_out(casadi_int ind) const
Get symbolic primitives equivalent to the output expressions.
Function reverse(casadi_int nadj) const
Get a function that calculates nadj adjoint derivatives.
std::vector< DM > nz_to_in(const std::vector< double > &arg) const
Convert from/to flat vector of input/output nonzeros.
casadi_int size1_out(const std::string &oname) const
Get output dimension.
static Function deserialize(const std::string &s)
Build function from serialization.
Function oracle() const
Get oracle.
std::vector< MX > convert_out(const MXDict &arg) const
Convert from/to input/output lists/map.
const Sparsity sparsity_jac(const std::string &iind, const std::string &oind, bool compact=false, bool symmetric=false) const
Function jacobian() const
Calculate all Jacobian blocks.
casadi_int numel_in(casadi_int ind) const
Get number of input elements.
const std::vector< MX > mx_in() const
Get symbolic primitives equivalent to the input expressions.
void release(int mem) const
Release a memory object.
casadi_int index_in(const std::string &name) const
Find the index for a string describing a particular entry of an input scheme.
Function expand(const std::string &name, const Dict &opts=Dict()) const
Expand a function to SX.
std::vector< std::string > get_function() const
Get a list of all functions.
const MX mx_out(const std::string &oname) const
Get symbolic primitives equivalent to the output expressions.
std::vector< Function > find_functions(casadi_int max_depth=-1) const
Get all functions embedded in the expression graphs.
std::vector< DM > nz_to_out(const std::vector< double > &arg) const
Convert from/to flat vector of input/output nonzeros.
const SX sx_out(const std::string &oname) const
Get symbolic primitives equivalent to the output expressions.
static Function deserialize(std::istream &stream)
Build function from serialization.
static std::string fix_name(const std::string &name)
Turn a string into a valid function name as defined by "check_name".
std::vector< bool > is_diff_out() const
Get differentiability of inputs/output.
casadi_int checkout() const
Checkout a memory object.
bool is_diff_out(casadi_int ind) const
Get differentiability of inputs/output.
Function hessian_old(casadi_int iind, casadi_int oind) const
[DEPRECATED] Replaced by Function::factory.
std::vector< DM > convert_in(const DMDict &arg) const
Convert from/to input/output lists/map.
Function mapaccum(const std::string &name, casadi_int n, const std::vector< std::string > &accum_in, const std::vector< std::string > &accum_out, const Dict &opts=Dict()) const
Create a mapaccumulated version of this function.
casadi_int n_nodes() const
Number of nodes in the algorithm.
const Sparsity sparsity_jac(casadi_int iind, casadi_int oind, bool compact=false, bool symmetric=false) const
Function(const std::string &name, const std::vector< SX > &ex_in, const std::vector< SX > &ex_out, const Dict &opts=Dict())
Construct an SX function.
const std::string & name_in(casadi_int ind) const
Get input scheme name by index.
Function find_function(const std::string &name, casadi_int max_depth=-1) const
Get a specific function embedded in the expression graphs.
Function get_function(const std::string &name) const
Get a dependency function.
SX instructions_sx() const
Get the SX node corresponding to all instructions (SXFunction)
void assert_sparsity_out(casadi_int i, const Sparsity &sp, casadi_int n=1, bool allow_all_zero_sparse=true) const
Assert that an output sparsity is a multiple of some given sparsity.
MX instruction_MX(casadi_int k) const
Get the MX node corresponding to an instruction (MXFunction)
const SX sx_in(casadi_int iind) const
Get symbolic primitives equivalent to the input expressions.
Function mapaccum(casadi_int N, const Dict &opts=Dict()) const
Create a mapaccumulated version of this function.
const std::vector< SX > sx_out() const
Get symbolic primitives equivalent to the output expressions.
casadi_int numel_out(casadi_int ind) const
Get number of output elements.
size_t sz_iw() const
Get required length of iw field.
void call(const DMDict &arg, DMDict &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
casadi_int n_out() const
Get the number of function outputs.
std::vector< casadi_int > instruction_output(casadi_int k) const
Location in the work vector for the output of the instruction.
const Sparsity & sparsity_in(const std::string &iname) const
Get sparsity of a given input.
std::string serialize(const Dict &opts=Dict()) const
Serialize.
static Function conditional(const std::string &name, const Function &f, const Dict &opts=Dict())
Conditional call to a function.
casadi_int n_in() const
Get the number of function inputs.
Function(const std::string &name, const std::map< std::string, SX > &dict, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts=Dict())
Construct an SX function.
static Function load(const std::string &filename)
Build function from serialization.
casadi_int size1_in(const std::string &iname) const
Get input dimension.
bool is_diff_in(casadi_int ind) const
Get differentiability of inputs/output.
DMDict convert_in(const std::vector< DM > &arg) const
Convert from/to input/output lists/map.
Function(const std::string &name, const std::vector< SX > &ex_in, const std::vector< SX > &ex_out, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts=Dict())
Construct an SX function.
Function map(const std::string &name, const std::string ¶llelization, casadi_int n, const std::vector< std::string > &reduce_in, const std::vector< std::string > &reduce_out, const Dict &opts=Dict()) const
Map with reduction.
const std::string & name_out(casadi_int ind) const
Get output scheme name by index.
Function map(casadi_int n, const std::string ¶llelization="serial") const
Create a mapped version of this function.
DMDict convert_out(const std::vector< DM > &arg) const
Convert from/to input/output lists/map.
static Function deserialize(DeserializingStream &s)
Build function from serialization.
casadi_int size2_out(const std::string &oname) const
Get output dimension.
size_t sz_w() const
Get required length of w field.
casadi_int numel_out(const std::string &oname) const
Get number of output elements.
Function mapaccum(const std::string &name, casadi_int N, casadi_int n_accum, const Dict &opts=Dict()) const
Create a mapaccumulated version of this function.
Function(const std::string &name, const std::map< std::string, MX > &dict, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts=Dict())
Construct an MX function.
SXDict convert_out(const std::vector< SX > &arg) const
Convert from/to input/output lists/map.
size_t sz_arg() const
Get required length of arg field.
void generate_out(const std::string &fname, const std::vector< DM > &arg)
Export an output file that can be checked with generated C code output.
std::string generate(const std::string &fname, const Dict &opts=Dict()) const
Export / Generate C code for the function.
bool is_a(const std::string &type, bool recursive=true) const
Check if the function is of a particular type.
double min_in(casadi_int ind) const
Get smallest input value.
static std::string type_name()
Get type name.
std::vector< double > nominal_out(casadi_int ind) const
Get nominal output value.
Function slice(const std::string &name, const std::vector< casadi_int > &order_in, const std::vector< casadi_int > &order_out, const Dict &opts=Dict()) const
returns a new function with a selection of inputs/outputs of the original
bool has_free() const
Does the function have free variables.
Function wrap_as_needed(const Dict &opts) const
Wrap in a Function with options.
casadi_int nnz_in() const
Get number of input nonzeros.
Function mapaccum(const std::string &name, casadi_int n, const std::vector< casadi_int > &accum_in, const std::vector< casadi_int > &accum_out, const Dict &opts=Dict()) const
Create a mapaccumulated version of this function.
void generate_lifted(Function &vdef_fcn, Function &vinit_fcn) const
Extract the functions needed for the Lifted Newton method.
double instruction_constant(casadi_int k) const
Get the floating point output argument of an instruction (SXFunction)
std::vector< std::string > get_free() const
Get free variables as a string.
Sparsity jac_sparsity(casadi_int oind, casadi_int iind, bool compact=false) const
Get, if necessary generate, the sparsity of a single Jacobian block.
bool uses_output() const
Do the derivative functions need nondifferentiated outputs?
bool has_function(const std::string &fname) const
Check if a particular dependency exists.
Function()
Default constructor, null pointer.
std::vector< MX > free_mx() const
Get all the free variables of the function.
const std::vector< MX > mx_out() const
Get symbolic primitives equivalent to the output expressions.
std::string generate(const Dict &opts=Dict()) const
Export / Generate C code for the function.
const std::vector< std::string > & name_out() const
Get output scheme.
void print_dimensions(std::ostream &stream=casadi::uout()) const
Print dimensions of inputs and outputs.
std::vector< MX > mapsum(const std::vector< MX > &x, const std::string ¶llelization="serial") const
Evaluate symbolically in parallel and sum (matrix graph)
void call(const SXDict &arg, SXDict &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
casadi_int size1_out(casadi_int ind) const
Get output dimension.
const Sparsity sparsity_jac(casadi_int iind, const std::string &oind, bool compact=false, bool symmetric=false) const
const SX sx_in(const std::string &iname) const
Get symbolic primitives equivalent to the input expressions.
const Sparsity & sparsity_in(casadi_int ind) const
Get sparsity of a given input.
void export_code(const std::string &lang, const std::string &fname, const Dict &options=Dict()) const
Export function in specific language.
void call(const std::vector< DM > &arg, std::vector< DM > &res, bool always_inline=false, bool never_inline=false) const
Evaluate the function symbolically or numerically.
static Function jit(const std::string &name, const std::string &body, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const Dict &opts=Dict())
To resolve ambiguity on some compilers.
casadi_int index_out(const std::string &name) const
Find the index for a string describing a particular entry of an output scheme.
std::vector< SX > free_sx() const
Get all the free variables of the function.
Dict stats(int mem=0) const
Get all statistics obtained at the end of the last evaluate call.
static Function if_else(const std::string &name, const Function &f_true, const Function &f_false, const Dict &opts=Dict())
Constructor (if-else)
SXDict convert_in(const std::vector< SX > &arg) const
Convert from/to input/output lists/map.
std::map< std::string, std::vector< std::string > > AuxOut
const SX sx_out(casadi_int oind) const
Get symbolic primitives equivalent to the output expressions.
std::vector< double > nz_from_in(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
Function map(casadi_int n, const std::string ¶llelization, casadi_int max_num_threads) const
Function factory(const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const AuxOut &aux=AuxOut(), const Dict &opts=Dict()) const
casadi_int size2_in(casadi_int ind) const
Get input dimension.
casadi_int instruction_id(casadi_int k) const
Identifier index of the instruction (SXFunction/MXFunction)
const Sparsity & sparsity_out(const std::string &iname) const
Get sparsity of a given output.
MXDict convert_out(const std::vector< MX > &arg) const
Convert from/to input/output lists/map.
const std::vector< SX > sx_in() const
Get symbolic primitives equivalent to the input expressions.
void assert_size_out(casadi_int i, casadi_int nrow, casadi_int ncol) const
Assert that an output dimension is equal so some given value.
void change_option(const std::string &option_name, const GenericType &option_value)
Change option after object creation for debugging.
std::vector< DM > generate_in(const std::string &fname)
Export an input file that can be passed to generate C code with a main.
Function jacobian_old(casadi_int iind, casadi_int oind) const
[DEPRECATED] Replaced by Function::factory.
static Function jit(const std::string &name, const std::string &body, const std::vector< std::string > &name_in, const std::vector< std::string > &name_out, const std::vector< Sparsity > &sparsity_in, const std::vector< Sparsity > &sparsity_out, const Dict &opts=Dict())
To resolve ambiguity on some compilers.
static Function bspline(const std::string &name, const std::vector< std::vector< double > > &knots, const std::vector< double > &coeffs, const std::vector< casadi_int > °ree, casadi_int m=1, const Dict &opts=Dict())
BSpline evaluator function.
double default_in(casadi_int ind) const
Get default input value.
std::pair< casadi_int, casadi_int > size_in(const std::string &iname) const
Get input dimension.
bool has_option(const std::string &option_name) const
Does a particular option exist.
Generic data type, can hold different types such as bool, casadi_int, std::string etc.
Sparse matrix class. SX and DM are specializations.
Helper class for Serialization.
SharedObject implements a reference counting framework similar for efficient and.
std::map< std::string, MX > MXDict
CASADI_EXPORT std::ostream & uout()
std::vector< SX > SXVector
std::vector< MX > MXVector
std::map< std::string, SX > SXDict
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::initializer_list< SX > SXIList
std::initializer_list< MX > MXIList
void CASADI_EXPORT _function_buffer_eval(void *raw)
std::map< std::string, DM > DMDict