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;
126 public SWIG_IF_ELSE(PrintableCommon, Printable<Function>) {
317 const std::vector<SX>& ex_in,
318 const std::vector<SX>& ex_out,
321 const std::vector<SX>& ex_in,
322 const std::vector<SX>& ex_out,
323 const std::vector<std::string>& name_in,
324 const std::vector<std::string>& name_out,
326 Function(
const std::string& name,
const std::map<std::string, SX>& dict,
327 const std::vector<std::string>& name_in,
328 const std::vector<std::string>& name_out,
401 const std::vector<MX>& ex_in,
402 const std::vector<MX>& ex_out,
405 const std::vector<MX>& ex_in,
406 const std::vector<MX>& ex_out,
407 const std::vector<std::string>& name_in,
408 const std::vector<std::string>& name_out,
410 Function(
const std::string& name,
const std::map<std::string, MX>& dict,
411 const std::vector<std::string>& name_in,
412 const std::vector<std::string>& name_out,
428 const StringVector& name_in,
const StringVector& name_out,
431 const StringVector& name_in,
const StringVector& name_out,
434 const StringVector& name_in,
const StringVector& name_out,
443 const StringVector& name_in,
const StringVector& name_out,
446 const StringVector& name_in,
const StringVector& name_out,
449 const StringVector& name_in,
const StringVector& name_out,
492 static Function jit(
const std::string& name,
const std::string& body,
493 const std::vector<std::string>& name_in,
494 const std::vector<std::string>& name_out,
496 static Function jit(
const std::string& name,
const std::string& body,
497 const std::vector<std::string>& name_in,
498 const std::vector<std::string>& name_out,
499 const std::vector<Sparsity>& sparsity_in,
500 const std::vector<Sparsity>& sparsity_out,
718 const std::vector<std::vector<GenericType> >& passes,
727 static Function create(FunctionInternal* node);
732 static Function create(FunctionInternal* node,
const Dict& opts);
867 std::pair<casadi_int, casadi_int>
size_in(casadi_int ind)
const;
868 std::pair<casadi_int, casadi_int>
size_in(
const std::string& iname)
const {
869 return size_in(index_in(iname));
915 std::pair<casadi_int, casadi_int>
size_out(casadi_int ind)
const;
916 std::pair<casadi_int, casadi_int>
size_out(
const std::string& oname)
const {
917 return size_out(index_out(oname));
963 casadi_int
nnz_in(
const std::string& iname)
const {
return nnz_in(index_in(iname));}
1003 casadi_int
nnz_out(
const std::string& oname)
const {
return nnz_out(index_out(oname));}
1016 std::vector<bool>
activity(
const std::vector<bool>& arg)
const;
1546 typedef std::map<std::string, std::vector<std::string> >
AuxOut;
1668 const std::vector<std::string>& s_in,
1669 const std::vector<std::string>& s_out,
1906 const std::vector<std::string>& s_out,
1907 casadi_int order=1,
bool tr=
false)
const;
2119 #ifdef WITH_DEPRECATED_FEATURES
2138 bool compact=
false,
bool symmetric=
false)
const;
2140 bool compact=
false,
bool symmetric=
false)
const {
2141 return sparsity_jac(index_in(iind), oind, compact, symmetric);
2144 bool compact=
false,
bool symmetric=
false)
const {
2145 return sparsity_jac(iind, index_out(oind), compact, symmetric);
2148 bool compact=
false,
bool symmetric=
false)
const {
2149 return sparsity_jac(index_in(iind), index_out(oind), compact, symmetric);
2410 void call(
const std::vector<DM> &arg, std::vector<DM>& SWIG_OUTPUT(res),
2411 bool always_inline=
false,
bool never_inline=
false)
const;
2412 void call(
const std::vector<SX> &arg, std::vector<SX>& SWIG_OUTPUT(res),
2413 bool always_inline=
false,
bool never_inline=
false)
const;
2414 void call(
const std::vector<MX> &arg, std::vector<MX>& SWIG_OUTPUT(res),
2415 bool always_inline=
false,
bool never_inline=
false)
const;
2417 bool always_inline=
false,
bool never_inline=
false)
const;
2419 bool always_inline=
false,
bool never_inline=
false)
const;
2421 bool always_inline=
false,
bool never_inline=
false)
const;
2426 bool operator==(
const Function& f)
const;
2430 std::vector<DM> operator()(
const std::vector<DM>& arg)
const;
2431 std::vector<SX> operator()(
const std::vector<SX>& arg)
const;
2432 std::vector<MX> operator()(
const std::vector<MX>& arg)
const;
2442 void operator()(std::vector<const double*> arg, std::vector<double*> res)
const;
2443 void operator()(std::vector<const bvec_t*> arg, std::vector<bvec_t*> res)
const;
2444 void operator()(std::vector<const SXElem*> arg, std::vector<SXElem*> res)
const;
2445 template<
typename D>
void call_gen(std::vector<const D*> arg, std::vector<D*> res)
const;
2452 typedef const std::vector<std::vector<double>>& VecArg;
2453 std::vector<const double*> buf_in(VecArg arg)
const;
2454 typedef std::vector<std::vector<double>>& VecRes;
2455 std::vector<double*> buf_out(VecRes res)
const;
2456 typedef std::vector<std::vector<double>*> VPrRes;
2457 std::vector<double*> buf_out(VPrRes res)
const;
2459 typedef const std::map<std::string, std::vector<double>>& MapArg;
2460 std::vector<const double*> buf_in(MapArg arg)
const;
2461 typedef std::map<std::string, std::vector<double>>& MapRes;
2462 std::vector<double*> buf_out(MapRes res)
const;
2463 typedef std::map<std::string, std::vector<double>*> MPrRes;
2464 std::vector<double*> buf_out(MPrRes res)
const;
2471 void operator()(VecArg arg, VecRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
2472 void operator()(VecArg arg, MapRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
2473 void operator()(VecArg arg, VPrRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
2474 void operator()(VecArg arg, MPrRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
2476 void operator()(MapArg arg, VecRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
2477 void operator()(MapArg arg, MapRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
2478 void operator()(MapArg arg, VPrRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
2479 void operator()(MapArg arg, MPrRes res)
const { (*this)(buf_in(arg), buf_out(res)); }
2484 std::vector<DM> operator()(
const DM& arg0)
const {
2485 return operator()(std::vector<DM>{arg0});
2487 std::vector<SX> operator()(
const SX& arg0)
const {
2488 return operator()(std::vector<SX>{arg0});
2490 std::vector<MX> operator()(
const MX& arg0)
const {
2491 return operator()(std::vector<MX>{arg0});
2498 int operator()(
const double** arg,
double** res,
2499 casadi_int* iw,
double* w,
int mem)
const;
2504 int operator()(
const double** arg,
double** res,
2505 casadi_int* iw,
double* w)
const;
2512 int operator()(
const SXElem** arg, SXElem** res,
2513 casadi_int* iw, SXElem* w,
int mem=0)
const;
2518 int operator()(
const bvec_t** arg, bvec_t** res,
2519 casadi_int* iw, bvec_t* w,
int mem=0)
const;
2524 int eval_activity(
const bvec_t** arg, bvec_t** res,
2525 casadi_int* iw, bvec_t* w,
int mem=0)
const;
2530 int rev(bvec_t** arg, bvec_t** res, casadi_int* iw, bvec_t* w,
int mem=0)
const;
2535 int rev(std::vector<bvec_t*> arg, std::vector<bvec_t*> res)
const;
2597 std::vector<MX>
mapsum(
const std::vector<MX > &x,
2598 const std::string& parallelization=
"serial")
const;
2706 const std::vector<casadi_int>& accum_in,
2707 const std::vector<casadi_int>& accum_out,
2710 const std::vector<std::string>& accum_in,
2711 const std::vector<std::string>& accum_out,
2792 Function map(casadi_int n,
const std::string& parallelization=
"serial")
const;
2794 casadi_int max_num_threads)
const;
2854 Function map(
const std::string& name,
const std::string& parallelization, casadi_int n,
2855 const std::vector<casadi_int>& reduce_in,
2856 const std::vector<casadi_int>& reduce_out,
2858 Function map(
const std::string& name,
const std::string& parallelization, casadi_int n,
2859 const std::vector<std::string>& reduce_in,
2860 const std::vector<std::string>& reduce_out,
2863 const std::vector<bool>& reduce_in,
2864 const std::vector<bool>& reduce_out=std::vector<bool>(),
2923 Function slice(
const std::string& name,
const std::vector<casadi_int>& order_in,
2924 const std::vector<casadi_int>& order_out,
const Dict& opts=
Dict())
const;
3111 const std::vector< std::vector<double> >& knots,
const std::vector<double>& coeffs,
3112 const std::vector<casadi_int>& degree, casadi_int m=1,
const Dict& opts=
Dict());
3536 void generate_in(
const std::string& fname,
const std::vector<DM>& arg);
3646 const std::string &fname,
const Dict& options=
Dict())
const;
3652 void serialize(std::ostream &stream,
const Dict& opts=
Dict())
const;
3785 void export_code(
const std::string& lang,
3786 std::ostream &stream,
const Dict& options=
Dict())
const;
3792 FunctionInternal* get()
const;
3795 template<
typename T>
3797 T* ret =
dynamic_cast<T*
>(get());
3798 casadi_assert_dev(ret!=
nullptr);
3805 FunctionInternal* operator->()
const;
3808 static bool test_cast(
const SharedObjectInternal* ptr);
3935 return sx_in(index_in(iname));
3940 return mx_in(index_in(iname));
3944 template<
typename T>
3945 const T sym_in(casadi_int iind)
const;
3946 template<
typename T>
3947 const T sym_in(
const std::string& iname)
const {
3948 return sym_in<T>(index_in(iname));
3950 template<
typename T>
3951 const std::vector<T> sym_in()
const;
3963 return sx_out(index_out(oname));
3968 return mx_out(index_out(oname));
4043 std::vector<double>
nz_from_in(
const std::vector<DM>& arg)
const;
4045 std::vector<DM>
nz_to_in(
const std::vector<double>& arg)
const;
4046 std::vector<DM>
nz_to_out(
const std::vector<double>& arg)
const;
4253 Function& SWIG_OUTPUT(vinit_fcn))
const;
4571 void sz_work(
size_t& sz_arg,
size_t& sz_res,
size_t& sz_iw,
size_t& sz_w)
const;
4576 void set_work(
const double**& arg,
double**& res,
4577 casadi_int*& iw,
double*& w,
int mem=0)
const;
4582 void set_temp(
const double** arg,
double** res,
4583 casadi_int* iw,
double* w,
int mem=0)
const;
4588 void setup(
const double** arg,
double** res, casadi_int* iw,
double* w,
int mem=0)
const;
4593 template<
typename M>
4594 void call_gen(
const std::map<std::string, M>& arg, std::map<std::string, M>& res,
4595 bool always_inline,
bool never_inline)
const;
4600 void merge(
const std::vector<MX>& arg,
4601 std::vector<MX>& subs_from, std::vector<MX>& subs_to)
const;
4675 bool is_a(
const std::string& type,
bool recursive=
true)
const;
4888 casadi_int n = 1,
bool allow_all_zero_sparse =
true)
const;
4935 void* memory(
int ind)
const;
4937 static std::vector<SX> order(
const std::vector<SX>& expr);
4938 static std::vector<MX> order(
const std::vector<MX>& expr);
5188 void construct(
const std::string& name,
5189 const std::vector<SX>& ex_in,
const std::vector<SX>& ex_out,
5190 const std::vector<std::string>& name_in,
5191 const std::vector<std::string>& name_out,
5193 void construct(
const std::string& name,
5194 const std::vector<MX>& ex_in,
const std::vector<MX>& ex_out,
5195 const std::vector<std::string>& name_in,
5196 const std::vector<std::string>& name_out,
5198 template<
typename M>
5199 void construct(
const std::string& name,
const std::map<std::string, M>& dict,
5200 const std::vector<std::string>& name_in,
5201 const std::vector<std::string>& name_out,
5206 static bool proceed_to(std::istream& file,
const std::string& str);
5209 Function mapaccum(
const std::string& name,
const std::vector<Function>& chain,
5210 casadi_int n_accum=1,
const Dict& opts =
Dict())
const;
5212 #ifdef WITH_EXTRA_CHECKS
5216 static thread_local casadi_int call_depth_;
5265 std::vector<double> w_;
5266 std::vector<casadi_int> iw_;
5267 std::vector<const double*> arg_;
5268 std::vector<double*> res_;
5269 FunctionInternal* f_node_;
5271 void *mem_internal_;
5295 void set_arg(casadi_int i,
const double* a, casadi_int size);
5307 void set_res(casadi_int i,
double* a, casadi_int size);
5319 const SX CASADI_EXPORT Function::sym_in(casadi_int iind)
const;
5321 const MX CASADI_EXPORT Function::sym_in(casadi_int iind)
const;
5323 const std::vector<SX> CASADI_EXPORT Function::sym_in()
const;
5325 const std::vector<MX> CASADI_EXPORT Function::sym_in()
const;
5329 #include "casadi_interrupt.hpp"
5330 #include "runtime/shared.hpp"
Helper class for Serialization.
Evaluate a Function repeatedly with minimal overhead.
void set_res(casadi_int i, double *a, casadi_int size)
Bind a contiguous buffer that receives the nonzeros of output i.
void set_arg(casadi_int i, const double *a, casadi_int size)
Bind a contiguous buffer holding the nonzeros of input i.
Dict stats() const
Get the statistics of the memory object used by this buffer, see Function::stats.
FunctionBuffer(const Function &f)
Create a buffer for f, allocating its work vectors and a memory object.
int ret()
Get the return code of the last evaluation (0 on success)
const MX mx_in(const std::string &iname) const
Create fresh symbols with the names and sparsity patterns of the inputs.
bool has_sprev() const
Check whether the class supports forward (has_spfwd) or reverse (has_sprev)
casadi_int numel_in() const
Get the number of elements (rows times columns) of one input, or of all.
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 where some inputs are shared and some outputs are summed.
std::vector< bool > is_diff_in() const
Check which inputs or outputs are marked differentiable.
Function forward(casadi_int nfwd) const
Get a function computing nfwd forward directional derivatives.
casadi_int nnz_out() const
Get the number of structural nonzeros of one output, or of all outputs.
const std::vector< std::string > & name_in() const
Get the names of all inputs, in order.
void print_options(std::ostream &stream=casadi::uout()) const
Print the name, type and description of every option of this class.
casadi_int n_instructions() const
Get the number of instructions of the algorithm (SXFunction and MXFunction)
std::string export_code(const std::string &lang, const Dict &options=Dict()) const
Export the algorithm as source code in another language.
size_t sz_res() const
Get the length of the output pointer array needed to evaluate (at least.
void generate_in(const std::string &fname, const std::vector< DM > &arg)
Write or read a text file with the nonzeros of all inputs.
void call(const std::vector< SX > &arg, std::vector< SX > &res, bool always_inline=false, bool never_inline=false) const
Evaluate with a list or a dict of arguments; the result has the same form.
void print_option(const std::string &name, std::ostream &stream=casadi::uout()) const
Print the type and description of one option; unknown names print a.
std::pair< casadi_int, casadi_int > size_out(const std::string &oname) const
Get the shape of an output: rows, columns or both.
std::string generate_dependencies(const std::string &fname, const Dict &opts=Dict()) const
Generate C code for the problem functions of a solver object.
std::vector< double > nz_from_out(const std::vector< DM > &arg) const
Convert between a list of input/output matrices and one flat list of.
void save(const std::string &fname, const Dict &opts=Dict()) const
Save the function to a file that load reads back.
const std::string & name() const
Get the name given at construction ("null" for a null object)
void call(const std::vector< MX > &arg, std::vector< MX > &res, bool always_inline=false, bool never_inline=false) const
Evaluate with a list or a dict of arguments; the result has the same form.
void assert_size_in(casadi_int i, casadi_int nrow, casadi_int ncol) const
Raise an error unless input i is nrow-by-ncol.
casadi_int size2_out(casadi_int ind) const
Get the shape of an output: rows, columns or both.
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
Find which entries of an input the outputs depend on, linearly or not.
void call(const MXDict &arg, MXDict &res, bool always_inline=false, bool never_inline=false) const
Evaluate with a list or a dict of arguments; the result has the same form.
const Sparsity & sparsity_out(casadi_int ind) const
Get the sparsity pattern of an output, by index or name.
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 where some inputs are shared and some outputs are summed.
const MX mx_in(casadi_int ind) const
Create fresh symbols with the names and sparsity patterns of the inputs.
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 a function from MX input and output expressions.
bool has_spfwd() const
Check whether the class supports forward (has_spfwd) or reverse (has_sprev)
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Get the shape of an output: rows, columns or both.
std::vector< DM > generate_out(const std::string &fname)
Write or read a text file with the nonzeros of all outputs.
double max_in(casadi_int ind) const
Get the largest admissible value of input ind (inf unless a solver.
std::vector< DM > convert_out(const DMDict &arg) const
Convert between a list and a dict of inputs or outputs.
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 a function from MX input and output expressions.
casadi_int nnz_out(const std::string &oname) const
Get the number of structural nonzeros of one output, or of all outputs.
casadi_int size1_in(casadi_int ind) const
Get the shape of an input: rows, columns or both.
Function fold(casadi_int N, const Dict &opts=Dict()) const
Create a function that applies this function N times, feeding outputs back.
casadi_int nnz_in(casadi_int ind) const
Get the number of structural nonzeros of one input, or of all inputs.
std::vector< SX > convert_out(const SXDict &arg) const
Convert between a list and a dict of inputs or outputs.
Function mapaccum(const std::string &name, casadi_int N, const Dict &opts=Dict()) const
Create a function that applies this function N times, feeding outputs back.
Function expand() const
Convert an MXFunction into an equivalent SXFunction.
MXDict convert_in(const std::vector< MX > &arg) const
Convert between a list and a dict of inputs or outputs.
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Get the shape of an input: rows, columns or both.
casadi_int nnz_out(casadi_int ind) const
Get the number of structural nonzeros of one output, or of all outputs.
Dict info() const
Get class-specific information as a dict.
static bool check_name(const std::string &name)
Check whether a string is a valid function name.
Dict cache() const
Get the derivative and map functions currently cached for this function.
static Function conditional(const std::string &name, const std::vector< Function > &f, const Function &f_def, const Dict &opts=Dict())
Create a function that selects one of several functions by an index input.
std::vector< casadi_int > instruction_input(casadi_int k) const
Get the work-vector locations read by instruction k.
const std::vector< Sparsity > & jac_sparsity(bool compact=false) const
Get the sparsity patterns of all Jacobian blocks.
casadi_int numel_out() const
Get the number of elements (rows times columns) of one output, or of all.
casadi_int size2_in(const std::string &iname) const
Get the shape of an input: rows, columns or both.
std::vector< MX > convert_in(const MXDict &arg) const
Convert between a list and a dict of inputs or outputs.
std::vector< SX > convert_in(const SXDict &arg) const
Convert between a list and a dict of inputs or outputs.
Function wrap() const
Wrap in an MXFunction whose graph is a single call to this function.
std::vector< double > nominal_in(casadi_int ind) const
Get the nominal value of each nonzero of input ind.
casadi_int numel_in(const std::string &iname) const
Get the number of elements (rows times columns) of one input, or of all.
casadi_int nnz_in(const std::string &iname) const
Get the number of structural nonzeros of one input, or of all inputs.
const MX mx_out(casadi_int ind) const
Create fresh symbols with the names and sparsity patterns of the outputs.
void reset_dump_count()
Reset to zero the counter that numbers the files written by dump_in,.
Function reverse(casadi_int nadj) const
Get a function computing nadj reverse (adjoint) directional derivatives.
std::vector< DM > nz_to_in(const std::vector< double > &arg) const
Convert between a list of input/output matrices and one flat list of.
casadi_int size1_out(const std::string &oname) const
Get the shape of an output: rows, columns or both.
static Function deserialize(const std::string &s)
Build a function from a string produced by serialize.
Function oracle() const
Get the user-supplied problem function behind a solver object.
std::vector< MX > convert_out(const MXDict &arg) const
Convert between a list and a dict of inputs or outputs.
const Sparsity sparsity_jac(const std::string &iind, const std::string &oind, bool compact=false, bool symmetric=false) const
Function jacobian() const
Get a function computing all Jacobian blocks at once.
casadi_int numel_in(casadi_int ind) const
Get the number of elements (rows times columns) of one input, or of all.
const std::vector< MX > mx_in() const
Create fresh symbols with the names and sparsity patterns of the inputs.
void release(int mem) const
Give back a memory object obtained with checkout.
casadi_int index_in(const std::string &name) const
Get the index of the input with a given name.
Function expand(const std::string &name, const Dict &opts=Dict()) const
Convert an MXFunction into an equivalent SXFunction.
std::vector< bool > activity(const std::vector< bool > &arg) const
Output signal activity induced by a given input activity.
std::vector< std::string > get_function() const
Get the names of the functions this function directly owns.
const MX mx_out(const std::string &oname) const
Create fresh symbols with the names and sparsity patterns of the outputs.
Function wrap_as_needed(const std::string &name, const Dict &opts) const
Wrap in an MXFunction constructed with the given options.
std::vector< Function > find_functions(casadi_int max_depth=-1) const
Get all functions embedded in this function, recursively.
std::vector< DM > nz_to_out(const std::vector< double > &arg) const
Convert between a list of input/output matrices and one flat list of.
const SX sx_out(const std::string &oname) const
Create fresh symbols with the names and sparsity patterns of the outputs.
static Function deserialize(std::istream &stream)
Build a function from a serialization stream.
static std::string fix_name(const std::string &name)
Turn any string into a valid function name as defined by check_name.
std::vector< bool > is_diff_out() const
Check which inputs or outputs are marked differentiable.
casadi_int checkout() const
Reserve a memory object for evaluation and return its index.
bool is_diff_out(casadi_int ind) const
Check which inputs or outputs are marked differentiable.
Function hessian_old(casadi_int iind, casadi_int oind) const
[DEPRECATED] Hessian and gradient of scalar output oind w.r.t. input
std::vector< DM > convert_in(const DMDict &arg) const
Convert between a list and a dict of inputs or outputs.
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 function that applies this function N times, feeding outputs back.
casadi_int n_nodes() const
Get the number of nodes in the expression graph (SXFunction and MXFunction)
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 a function from SX input and output expressions.
void export_graph(const std::string &fname, const Dict &opts=Dict()) const
Export a Function graph as .html, .dot, or .casadi_viz.
const std::string & name_in(casadi_int ind) const
Get the name of input ind; out of range raises an error.
Function find_function(const std::string &name, casadi_int max_depth=-1) const
Get an embedded function by name, searching recursively.
Function get_function(const std::string &name) const
Get a directly owned function by name; unknown names raise an error.
SX instructions_sx() const
Get the SX expression of every instruction of an SXFunction, as one vector.
void assert_sparsity_out(casadi_int i, const Sparsity &sp, casadi_int n=1, bool allow_all_zero_sparse=true) const
Raise an error unless output i has the sparsity sp repeated n.
MX instruction_MX(casadi_int k) const
Get the MX expression computed by instruction k of an MXFunction.
const SX sx_in(casadi_int iind) const
Create fresh symbols with the names and sparsity patterns of the inputs.
Function mapaccum(casadi_int N, const Dict &opts=Dict()) const
Create a function that applies this function N times, feeding outputs back.
const std::vector< SX > sx_out() const
Create fresh symbols with the names and sparsity patterns of the outputs.
casadi_int numel_out(casadi_int ind) const
Get the number of elements (rows times columns) of one output, or of all.
size_t sz_iw() const
Get the length of the integer work vector needed to evaluate.
void call(const DMDict &arg, DMDict &res, bool always_inline=false, bool never_inline=false) const
Evaluate with a list or a dict of arguments; the result has the same form.
casadi_int n_out() const
Get the number of function outputs.
std::vector< casadi_int > instruction_output(casadi_int k) const
Get the work-vector locations written by instruction k.
const Sparsity & sparsity_in(const std::string &iname) const
Get the sparsity pattern of an input, by index or name.
std::string serialize(const Dict &opts=Dict()) const
Serialize to a string that deserialize turns back into an equal function.
static Function conditional(const std::string &name, const Function &f, const Dict &opts=Dict())
Create a function that calls f when its first input is nonzero and.
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 a function from SX input and output expressions.
bool has_out(const std::string &name) const
Check whether an output with the given name exists.
static Function load(const std::string &filename)
Read a function from a file written by save.
casadi_int size1_in(const std::string &iname) const
Get the shape of an input: rows, columns or both.
bool is_diff_in(casadi_int ind) const
Check which inputs or outputs are marked differentiable.
DMDict convert_in(const std::vector< DM > &arg) const
Convert between a list and a dict of inputs or outputs.
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 a function from SX input and output expressions.
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 where some inputs are shared and some outputs are summed.
const std::string & name_out(casadi_int ind) const
Get the name of output ind; out of range raises an error.
Function map(casadi_int n, const std::string ¶llelization="serial") const
Create a function that evaluates this function n times on stacked arguments.
DMDict convert_out(const std::vector< DM > &arg) const
Convert between a list and a dict of inputs or outputs.
static Function deserialize(DeserializingStream &s)
Build a function from a DeserializingStream (C++ serialization API)
casadi_int size2_out(const std::string &oname) const
Get the shape of an output: rows, columns or both.
size_t sz_w() const
Get the length of the real work vector needed to evaluate.
casadi_int numel_out(const std::string &oname) const
Get the number of elements (rows times columns) of one output, or of all.
Function mapaccum(const std::string &name, casadi_int N, casadi_int n_accum, const Dict &opts=Dict()) const
Create a function that applies this function N times, feeding outputs back.
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 a function from MX input and output expressions.
SXDict convert_out(const std::vector< SX > &arg) const
Convert between a list and a dict of inputs or outputs.
size_t sz_arg() const
Get the length of the input pointer array needed to evaluate (at least n_in)
void generate_out(const std::string &fname, const std::vector< DM > &arg)
Write or read a text file with the nonzeros of all outputs.
std::string generate(const std::string &fname, const Dict &opts=Dict()) const
Generate self-contained C code for the function.
bool is_a(const std::string &type, bool recursive=true) const
Check whether the function is of a given class.
Function transform(const Dict &opts=Dict()) const
Rebuild the function after graph simplification or other passes.
double min_in(casadi_int ind) const
Get the smallest admissible value of input ind (-inf unless a solver.
static std::string type_name()
Get the type name, always "Function".
bool has_in(const std::string &name) const
Check whether an input with the given name exists.
Function transform(const std::string &fname, const Dict &opts=Dict()) const
Rebuild the function after graph simplification or other passes.
std::vector< double > nominal_out(casadi_int ind) const
Get the nominal value of each nonzero of output ind; all ones by default.
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
Create a function with a subset or reordering of the inputs and outputs.
Function transform(const std::string &fname, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict()) const
Rebuild the function after graph simplification or other passes.
bool has_free() const
Check whether the outputs contain symbols that are not inputs.
Function wrap_as_needed(const Dict &opts) const
Wrap in an MXFunction constructed with the given options.
casadi_int nnz_in() const
Get the number of structural nonzeros of one input, or of all inputs.
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 function that applies this function N times, feeding outputs back.
void generate_lifted(Function &vdef_fcn, Function &vinit_fcn) const
Extract the functions needed for the Lifted Newton method (MXFunction only)
double instruction_constant(casadi_int k) const
Get the value of a constant instruction (OP_CONST) of an SXFunction.
std::vector< std::string > get_free() const
Get the names of the free variables; empty when there are none.
Sparsity jac_sparsity(casadi_int oind, casadi_int iind, bool compact=false) const
Get the sparsity pattern of the Jacobian of output oind w.r.t. input.
bool uses_output() const
Check whether the derivative functions read the nondifferentiated outputs.
bool has_function(const std::string &fname) const
Check if a particular dependency exists.
Function()
Default constructor, creates a null object.
std::vector< MX > free_mx() const
Get the free variables of an MXFunction as MX symbols; other classes raise.
const std::vector< MX > mx_out() const
Create fresh symbols with the names and sparsity patterns of the outputs.
std::string generate(const Dict &opts=Dict()) const
Generate C code into a file named after the function (name() + ".c")
const std::vector< std::string > & name_out() const
Get the names of all outputs, in order.
void print_dimensions(std::ostream &stream=casadi::uout()) const
Print the name and shape of every input and output.
std::vector< MX > mapsum(const std::vector< MX > &x, const std::string ¶llelization="serial") const
Evaluate on horizontally stacked MX arguments and sum the results.
void call(const SXDict &arg, SXDict &res, bool always_inline=false, bool never_inline=false) const
Evaluate with a list or a dict of arguments; the result has the same form.
casadi_int size1_out(casadi_int ind) const
Get the shape of an output: rows, columns or both.
const Sparsity sparsity_jac(casadi_int iind, const std::string &oind, bool compact=false, bool symmetric=false) const
std::string export_graph(const Dict &opts=Dict()) const
Return the .casadi_viz JSON bundle without writing a file.
const SX sx_in(const std::string &iname) const
Create fresh symbols with the names and sparsity patterns of the inputs.
const Sparsity & sparsity_in(casadi_int ind) const
Get the sparsity pattern of an input, by index or name.
void export_code(const std::string &lang, const std::string &fname, const Dict &options=Dict()) const
Export the algorithm as source code in another language.
void call(const std::vector< DM > &arg, std::vector< DM > &res, bool always_inline=false, bool never_inline=false) const
Evaluate with a list or a dict of arguments; the result has the same form.
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
Get the index of the output with a given name; unknown names raise an error.
std::vector< SX > free_sx() const
Get the free variables of an SXFunction as SX symbols; other classes raise.
Dict stats(int mem=0) const
Get the statistics recorded by the last numerical evaluation.
static Function if_else(const std::string &name, const Function &f_true, const Function &f_false, const Dict &opts=Dict())
Create a function that evaluates f_true or f_false depending on.
Function transform(const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict()) const
Rebuild the function after graph simplification or other passes.
SXDict convert_in(const std::vector< SX > &arg) const
Convert between a list and a dict of inputs or outputs.
std::map< std::string, std::vector< std::string > > AuxOut
const SX sx_out(casadi_int oind) const
Create fresh symbols with the names and sparsity patterns of the outputs.
std::vector< double > nz_from_in(const std::vector< DM > &arg) const
Convert between a list of input/output matrices and one flat list of.
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
Build a function computing derivatives by naming inputs and outputs.
casadi_int size2_in(casadi_int ind) const
Get the shape of an input: rows, columns or both.
casadi_int instruction_id(casadi_int k) const
Get the operation code of instruction k (SXFunction and MXFunction)
const Sparsity & sparsity_out(const std::string &iname) const
Get the sparsity pattern of an output, by index or name.
MXDict convert_out(const std::vector< MX > &arg) const
Convert between a list and a dict of inputs or outputs.
const std::vector< SX > sx_in() const
Create fresh symbols with the names and sparsity patterns of the inputs.
void assert_size_out(casadi_int i, casadi_int nrow, casadi_int ncol) const
Raise an error unless output i is nrow-by-ncol.
void change_option(const std::string &option_name, const GenericType &option_value)
Change a debugging option on an existing object.
std::vector< DM > generate_in(const std::string &fname)
Write or read a text file with the nonzeros of all inputs.
Function jacobian_old(casadi_int iind, casadi_int oind) const
[DEPRECATED] Jacobian of output oind w.r.t. input iind, followed by
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())
Create a function evaluating a B-spline with known coefficients.
Function wrap(const std::string &name) const
Wrap in an MXFunction whose graph is a single call to this function.
double default_in(casadi_int ind) const
Get the value used for input ind when a call by name omits it.
std::pair< casadi_int, casadi_int > size_in(const std::string &iname) const
Get the shape of an input: rows, columns or both.
bool has_option(const std::string &option_name) const
Check whether this class accepts an option with the given name.
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.
GenericShared 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