26 #include "function_internal.hpp"
27 #include "casadi_misc.hpp"
28 #include "sx_function.hpp"
29 #include "mx_function.hpp"
31 #include "bspline.hpp"
35 #include "jit_function.hpp"
36 #include "serializing_stream.hpp"
37 #include "serializer.hpp"
39 #include "filesystem_impl.hpp"
47 #define THROW_ERROR(FNAME, WHAT) \
48 throw CasadiException("Error in Function::" FNAME " for '" + this->name() + "' "\
49 "[" + this->class_name() + "] at " + CASADI_WHERE + ":\n"\
53 #define THROW_ERROR_NOOBJ(FNAME, WHAT, CLASS_NAME) \
54 throw CasadiException("Error in Function::" FNAME " for '" + name + "' "\
55 "[" CLASS_NAME "] at " + CASADI_WHERE + ":\n"\
66 if (!file.good())
return false;
73 std::streampos cur_pos = file.tellg();
75 if (!file.good())
return false;
78 if (
str==tmp)
return true;
82 file.ignore(std::numeric_limits<std::streamsize>::max(),
'\n');
93 casadi_error(
"Not implemented");
97 const std::vector<SX>& ex_in,
const std::vector<SX>& ex_out,
103 const std::vector<SX>& ex_in,
const std::vector<SX>& ex_out,
104 const std::vector<std::string>& name_in,
105 const std::vector<std::string>& name_out,
111 const std::vector<MX>& ex_in,
const std::vector<MX>& ex_out,
117 const std::vector<MX>& ex_in,
const std::vector<MX>& ex_out,
118 const std::vector<std::string>& name_in,
119 const std::vector<std::string>& name_out,
184 const std::vector<std::string>& name_in,
const std::vector<std::string>& name_out,
190 const std::vector<std::string>& name_in,
const std::vector<std::string>& name_out,
197 const std::vector<std::string>& name_in,
198 const std::vector<std::string>& name_out,
201 for (
auto&& i : dict) {
202 std::vector<std::string>::const_iterator it;
205 ex_in[it-
name_in.begin()] = i.second;
208 ex_out[it-
name_out.begin()] = i.second;
211 casadi_error(
"Unknown dictionary entry: '" + i.first +
"'");
218 const std::vector<SX>& ex_in,
const std::vector<SX>& ex_out,
219 const std::vector<std::string>& name_in,
220 const std::vector<std::string>& name_out,
224 (*this)->construct(opts);
227 auto it = opts.find(
"external_transform");
228 if (it!=opts.end()) {
229 auto v = it->second.to_vector_vector();
230 for (
const std::vector<GenericType>& vec : v) {
231 casadi_assert(vec.size()>=2,
"external_transform: inner list must be length >=2");
232 casadi_assert(vec.size()<=3,
"external_transform: inner list must be length <=3");
233 std::string
name = vec[0].to_string();
234 std::string op = vec[1].to_string();
235 Dict opts = vec.size()==3 ? vec[2].to_dict() :
Dict();
240 }
catch(std::exception& e) {
241 THROW_ERROR_NOOBJ(
"Function", e.what(),
"SXFunction");
246 const std::vector<MX>& ex_in,
const std::vector<MX>& ex_out,
247 const std::vector<std::string>& name_in,
248 const std::vector<std::string>& name_out,
252 (*this)->construct(opts);
255 auto it = opts.find(
"post_expand");
256 if (it!=opts.end()) {
257 if (!it->second)
return;
258 auto it = opts.find(
"post_expand_options");
259 if (it==opts.end()) {
262 operator=((*this).expand((*this).name(), it->second));
267 it = opts.find(
"external_transform");
268 if (it!=opts.end()) {
269 auto v = it->second.to_vector_vector();
270 for (
const std::vector<GenericType>& vec : v) {
271 casadi_assert(vec.size()>=2,
"external_transform: inner list must be length >=2");
272 casadi_assert(vec.size()<=3,
"external_transform: inner list must be length <=3");
273 std::string
name = vec[0].to_string();
274 std::string op = vec[1].to_string();
275 Dict opts = vec.size()==3 ? vec[2].to_dict() :
Dict();
280 }
catch(std::exception& e) {
281 THROW_ERROR_NOOBJ(
"Function", e.what(),
"MXFunction");
286 const std::vector<std::string>& name_in,
287 const std::vector<std::string>& name_out,
295 const std::vector<std::string>& name_in,
296 const std::vector<std::string>& name_out,
297 const std::vector<Sparsity>& sparsity_in,
298 const std::vector<Sparsity>& sparsity_out,
303 }
catch(std::exception& e) {
304 THROW_ERROR_NOOBJ(
"jit", e.what(),
"JitFunction");
310 opts[
"ad_weight"] = (*this)->
ad_weight();
311 opts[
"ad_weight_sp"] = (*this)->sp_weight();
312 opts[
"max_num_dir"] = (*this)->max_num_dir_;
313 opts[
"is_diff_in"] = (*this)->is_diff_in_;
314 opts[
"is_diff_out"] = (*this)->is_diff_out_;
320 "Function with free symbols cannot be expanded. "
321 "List of free variables in your Function: " +
325 my_opts[
"ad_weight"] = (*this)->ad_weight();
326 my_opts[
"ad_weight_sp"] = (*this)->sp_weight();
327 my_opts[
"max_num_dir"] = (*this)->max_num_dir_;
328 my_opts[
"is_diff_in"] = (*this)->is_diff_in_;
329 my_opts[
"is_diff_out"] = (*this)->is_diff_out_;
331 std::vector<SX> ex_in =
sx_in();
332 std::vector<SX> ex_out =
Function(*
this)(ex_in);
358 bool always_inline,
bool never_inline)
const {
360 (*this)->call(arg, res, always_inline, never_inline);
361 }
catch(std::exception& e) {
362 THROW_ERROR(
"call", e.what());
367 bool always_inline,
bool never_inline)
const {
369 (*this)->call(arg, res, always_inline, never_inline);
370 }
catch(std::exception& e) {
371 THROW_ERROR(
"call", e.what());
376 bool always_inline,
bool never_inline)
const {
378 (*this)->call(arg, res, always_inline, never_inline);
379 }
catch(std::exception& e) {
380 THROW_ERROR(
"call", e.what());
385 casadi_assert_dev(arg.size()==
n_in());
386 auto arg_it=arg.begin();
387 std::vector<const double*> buf_arg(
sz_arg());
388 for (casadi_uint i=0; i<arg.size(); ++i) {
389 casadi_assert_dev(arg_it->size()==
nnz_in(i));
390 buf_arg[i] =
get_ptr(*arg_it++);
397 auto res_it=res.begin();
398 std::vector<double*> buf_res(
sz_res());
399 for (casadi_uint i=0; i<res.size(); ++i) {
401 buf_res[i] =
get_ptr(*res_it++);
407 casadi_assert_dev(res.size()==
n_out());
408 auto res_it=res.begin();
409 std::vector<double*> buf_res(
sz_res());
410 for (casadi_uint i=0; i<res.size(); ++i) {
411 casadi_assert_dev(*res_it!=0);
413 buf_res[i] =
get_ptr(**res_it++);
420 std::vector<const double*> ret(
sz_arg(),
nullptr);
423 for (
auto i=arg.begin(); i!=arg.end(); ++i) {
424 casadi_int ind =
index_in(i->first);
425 casadi_assert_dev(i->second.size()==
nnz_in(ind));
434 std::vector<double*> ret(
sz_res(),
nullptr);
437 for (
auto i=res.begin(); i!=res.end(); ++i) {
439 i->second.resize(
nnz_out(ind));
448 std::vector<double*> ret(
sz_res(),
nullptr);
451 for (
auto i=res.begin(); i!=res.end(); ++i) {
453 casadi_assert_dev(i->second!=0);
454 i->second->resize(
nnz_out(ind));
455 ret[ind] =
get_ptr(*i->second);
464 casadi_assert_dev(arg.size()>=
n_in());
468 casadi_assert_dev(res.size()>=
n_out());
472 std::vector<casadi_int> iw(
sz_iw());
473 std::vector<D> w(
sz_w());
492 int Function::rev(std::vector<bvec_t*> arg, std::vector<bvec_t*> res)
const {
494 casadi_assert_dev(arg.size()>=
n_in());
498 casadi_assert_dev(res.size()>=
n_out());
502 std::vector<casadi_int> iw(
sz_iw());
503 std::vector<bvec_t> w(
sz_w());
511 std::vector<MX> base_in = base.
mx_in();
512 std::vector<MX> out = base(base_in);
523 const Dict& opts)
const {
527 casadi_int base = 10;
528 auto it = options.find(
"base");
529 if (it!=options.end()) {
534 casadi_assert(N>0,
"mapaccum: N must be positive");
537 return mapaccum(
name, std::vector<Function>(N, *
this), n_accum, options);
538 casadi_assert(base>=2,
"mapaccum: base must be positive");
541 std::vector<Function> chain;
544 casadi_int r = N % base;
545 chain.insert(chain.end(), r, c);
547 c = c.
mapaccum(c.
name()+
"_acc"+
str(base), std::vector<Function>(base, c), n_accum, options);
553 const std::vector<Function>& chain, casadi_int n_accum,
554 const Dict& opts)
const {
558 casadi_assert(!chain.empty(),
"mapaccum: chain must be non-empty");
559 casadi_assert(n_accum<=std::min(
n_in,
n_out),
"mapaccum: too many accumulators");
561 if (chain.size()==1)
return chain[0];
563 std::vector<MX> arg =
mx_in();
566 std::vector<std::vector<MX>> varg(
n_in), vres(
n_out);
567 for (casadi_int i=0; i<n_accum; ++i) varg[i].push_back(arg[i]);
569 for (
const auto& f : chain) {
572 for (casadi_int i=n_accum; i<
n_in; ++i) {
574 varg[i].push_back(arg[i]);
580 for (casadi_int i=0; i<
n_out; ++i) vres[i].push_back(res[i]);
582 std::copy_n(res.begin(), n_accum, arg.begin());
583 for (casadi_int i=0; i<n_accum; ++i) {
585 casadi_int ncol_out=f.size2_out(i), ncol_in=
size2_in(i);
586 if (ncol_out>ncol_in) {
587 arg[i] = horzsplit(arg[i], {0, ncol_out-ncol_in, ncol_out}).back();
592 for (casadi_int i=0; i<
n_in; ++i) arg[i] = horzcat(varg[i]);
593 for (casadi_int i=0; i<
n_out; ++i) res[i] = horzcat(vres[i]);
598 const std::vector<casadi_int>& accum_in,
599 const std::vector<casadi_int>& accum_out,
600 const Dict& opts)
const {
606 casadi_assert_dev(accum_in.size()==accum_out.size());
607 casadi_int n_accum=accum_in.size();
610 if (accum_in==
range(n_accum) && accum_out==
range(n_accum)) {
616 std::vector<casadi_int> order_in = accum_in;
617 order_in.insert(order_in.end(), temp_in.begin(), temp_in.end());
619 std::vector<casadi_int> order_out = accum_out;
620 order_out.insert(order_out.end(), temp_out.begin(), temp_out.end());
628 const std::vector<std::string>& accum_in,
629 const std::vector<std::string>& accum_out,
630 const Dict& opts)
const {
631 std::vector<casadi_int> accum_in_num, accum_out_num;
632 for (
const std::string& s : accum_in) accum_in_num.push_back(
index_in(s));
633 for (
const std::string& s : accum_out) accum_out_num.push_back(
index_out(s));
634 return mapaccum(
name, n, accum_in_num, accum_out_num, opts);
638 const std::vector<bool>& reduce_in,
639 const std::vector<bool>& reduce_out,
640 const Dict& opts)
const {
642 *
this, n, reduce_in, reduce_out, opts);
646 const std::vector<casadi_int>& reduce_in,
const std::vector<casadi_int>& reduce_out,
647 const Dict& opts)
const {
651 std::vector<MX> arg = f.
mx_in();
652 std::vector<MX> f_arg = arg;
654 for (casadi_int i : reduce_in) {
656 f_arg[i] = repmat(arg[i], 1, n);
659 std::vector<MX> res = f(f_arg);
661 for (casadi_int i : reduce_out) {
662 res[i] = repsum(res[i], 1, n);
669 const std::vector<std::string>& reduce_in,
const std::vector<std::string>& reduce_out,
670 const Dict& opts)
const {
671 std::vector<casadi_int> reduce_in_num, reduce_out_num;
672 for (
const std::string& s : reduce_in) reduce_in_num.push_back(
index_in(s));
673 for (
const std::string& s : reduce_out) reduce_out_num.push_back(
index_out(s));
674 return map(
name, parallelization, n, reduce_in_num, reduce_out_num, opts);
679 casadi_int max_num_threads)
const {
680 casadi_assert(max_num_threads>=1,
"max_num_threads invalid.");
682 if (n<=max_num_threads)
return map(n, parallelization);
685 casadi_int d = n/max_num_threads;
686 if (d*max_num_threads==n) {
688 return map(d,
"serial").
map(max_num_threads, parallelization);
691 Function base =
map(d+1,
"serial").
map(max_num_threads, parallelization);
692 std::vector<MX> ret_in, base_in;
693 casadi_int rem = (d+1)*max_num_threads-n;
694 for (casadi_int i=0;i<
n_in();++i) {
696 ret_in.push_back(arg);
698 base_in.push_back(horzcat(arg, repmat(last_arg, 1, rem)));
700 std::vector<MX> ret_out = base(base_in);
701 for (casadi_int i=0;i<
n_out();++i) {
702 ret_out[i] = horzsplit(ret_out[i], {0, n*
size2_out(i), ret_out[i].size2()})[0];
711 casadi_assert(n>0,
"Degenerate map operation");
713 if (n==1)
return *
this;
715 if (parallelization==
"unroll" || parallelization==
"inline") {
717 std::vector<MX> arg(
n_in());
718 std::vector<std::vector<MX>> v(n, arg);
719 std::vector<MX> tmp(n);
720 for (casadi_int i=0; i<arg.size(); ++i) {
721 for (casadi_int k=0; k<n; ++k) {
724 arg[i] = horzcat(tmp);
727 if (parallelization==
"unroll") {
728 for (
auto&& w : v) w = (*this)(w);
730 for (
auto&& w : v)
call(std::vector<MX>(w), w, !
is_a(
"SXFunction"),
false);
733 std::vector<MX> res(
n_out());
734 for (casadi_int i=0; i<res.size(); ++i) {
735 for (casadi_int k=0; k<n; ++k) tmp[k] = v[k][i];
736 res[i] = horzcat(tmp);
742 return (*this)->map(n, parallelization);
747 slice(
const std::string& name,
const std::vector<casadi_int>& order_in,
748 const std::vector<casadi_int>& order_out,
const Dict& opts)
const {
750 return (*this)->
slice(
name, order_in, order_out, opts);
751 }
catch(std::exception& e) {
752 THROW_ERROR(
"slice", e.what());
757 const std::string& parallelization)
const {
759 return (*this)->mapsum_mx(x, parallelization);
760 }
catch(std::exception& e) {
761 THROW_ERROR(
"mapsum", e.what());
769 }
catch(std::exception& e) {
770 THROW_ERROR_NOOBJ(
"conditional", e.what(),
"Switch");
778 std::vector<MX> dummy_in = f.
mx_in();
779 std::vector<MX> dummy_out(f.
n_out());
780 for (casadi_int i = 0; i < dummy_out.size(); ++i) {
786 }
catch(std::exception& e) {
787 THROW_ERROR_NOOBJ(
"conditional", e.what(),
"Switch");
792 const std::vector< std::vector<double> >& knots,
793 const std::vector<double>& coeffs,
const std::vector<casadi_int>& degree,
794 casadi_int m,
const Dict& opts) {
796 casadi_assert(degree.size()==knots.size(),
"Degree list length (" +
str(degree.size()) +
") "
797 "must match knot list length (" +
str(knots.size()) +
").");
799 std::vector<std::string> lookup_mode;
802 opts_bspline[
"lookup_mode"] = lookup_mode;
805 }
catch(std::exception& e) {
806 THROW_ERROR_NOOBJ(
"bspline", e.what(),
"BSpline");
813 return create(
new Switch(
name, std::vector<Function>(1, f_false), f_true), opts);
814 }
catch(std::exception& e) {
815 THROW_ERROR_NOOBJ(
"if_else", e.what(),
"Switch");
820 return (*this)->n_in_;
824 return (*this)->n_out_;
828 return (*this)->size1_in(ind);
832 return (*this)->size2_in(ind);
836 return (*this)->size1_out(ind);
840 return (*this)->size2_out(ind);
844 return (*this)->size_in(ind);
848 return (*this)->size_out(ind);
852 return (*this)->nnz_in();
856 return (*this)->nnz_out();
860 return (*this)->numel_in();
864 return (*this)->numel_out();
868 return (*this)->nnz_in(ind);
872 return (*this)->nnz_out(ind);
876 return (*this)->numel_in(ind);
880 return (*this)->numel_out(ind);
884 return (*this)->uses_output();
887 #ifdef WITH_DEPRECATED_FEATURES
890 std::vector<std::string> s_in =
name_in();
891 std::vector<std::string> s_out =
name_out();
892 s_out.insert(s_out.begin(),
"jac:" +
name_out(oind) +
":" +
name_in(iind));
898 std::vector<std::string> s_in =
name_in();
899 std::vector<std::string> s_out =
name_out();
900 s_out.insert(s_out.begin(),
"grad:" +
name_out(oind) +
":" +
name_in(iind));
901 s_out.insert(s_out.begin(),
907 sparsity_jac(casadi_int iind, casadi_int oind,
bool compact,
bool symmetric)
const {
909 return (*this)->jac_sparsity(oind, iind, compact, symmetric);
910 }
catch(std::exception& e) {
911 THROW_ERROR(
"sparsity_jac", e.what());
919 }
catch(std::exception& e) {
920 THROW_ERROR(
"jacobian", e.what());
929 if (!(*this)->has_memory(mem)) {
931 "No stats available: Function/solver was not yet numerically evaluated.");
934 return (*this)->get_stats(
memory(mem));
935 }
catch(std::exception& e) {
936 THROW_ERROR(
"stats", e.what());
942 for (casadi_int oind = 0; oind <
n_out(); ++oind) {
943 for (casadi_int iind = 0; iind <
n_in(); ++iind) {
948 return (*this)->jac_sparsity_[compact];
953 bool symm = (*this)->jac_is_symm(oind, iind);
955 return (*this)->jac_sparsity(oind, iind, compact, symm);
956 }
catch(std::exception& e) {
957 THROW_ERROR(
"jac_sparsity", e.what());
962 return (*this)->name_in_;
966 return (*this)->name_out_;
971 return (*this)->index_in(
name);
972 }
catch(std::exception& e) {
973 THROW_ERROR(
"index_in", e.what());
979 return (*this)->index_out(
name);
980 }
catch(std::exception& e) {
981 THROW_ERROR(
"index_out", e.what());
986 for (
const std::string& s : (*this)->name_in_) {
987 if (s==
name)
return true;
993 for (
const std::string& s : (*this)->name_out_) {
994 if (s==
name)
return true;
1001 return (*this)->name_in_.at(ind);
1002 }
catch(std::exception& e) {
1003 THROW_ERROR(
"name_in", e.what());
1009 return (*this)->name_out_.at(ind);
1010 }
catch(std::exception& e) {
1011 THROW_ERROR(
"name_out", e.what());
1017 return (*this)->sparsity_in_.at(ind);
1018 }
catch(std::exception& e) {
1019 THROW_ERROR(
"sparsity_in", e.what());
1026 }
catch(std::exception& e) {
1027 THROW_ERROR(
"sparsity_in", e.what());
1033 return (*this)->sparsity_out_.at(ind);
1034 }
catch(std::exception& e) {
1035 THROW_ERROR(
"sparsity_out", e.what());
1042 }
catch(std::exception& e) {
1043 THROW_ERROR(
"sparsity_out", e.what());
1049 return (*this)->is_diff_in_.at(ind);
1050 }
catch(std::exception& e) {
1051 THROW_ERROR(
"is_diff_in", e.what());
1057 return (*this)->is_diff_out_.at(ind);
1058 }
catch(std::exception& e) {
1059 THROW_ERROR(
"is_diff_out", e.what());
1065 return (*this)->is_diff_in_;
1066 }
catch(std::exception& e) {
1067 THROW_ERROR(
"is_diff_in", e.what());
1073 return (*this)->is_diff_out_;
1074 }
catch(std::exception& e) {
1075 THROW_ERROR(
"is_diff_out", e.what());
1092 casadi_int* iw,
bvec_t* w,
int mem)
const {
1094 return (*this)->sp_forward(arg, res, iw, w,
memory(mem));
1095 }
catch(std::exception& e) {
1096 THROW_ERROR(
"operator()", e.what());
1102 return (*this)->sp_reverse(arg, res, iw, w,
memory(mem));
1103 }
catch(std::exception& e) {
1104 THROW_ERROR(
"rev", e.what());
1111 (*this)->set_work(
memory(mem), arg, res, iw, w);
1112 }
catch(std::exception& e) {
1113 THROW_ERROR(
"set_work", e.what());
1120 (*this)->set_temp(
memory(mem), arg, res, iw, w);
1121 }
catch(std::exception& e) {
1122 THROW_ERROR(
"set_temp", e.what());
1129 (*this)->setup(
memory(mem), arg, res, iw, w);
1130 }
catch(std::exception& e) {
1131 THROW_ERROR(
"setup", e.what());
1137 return (*this)->
forward(nfwd);
1138 }
catch(std::exception& e) {
1139 THROW_ERROR(
"forward", e.what());
1145 return (*this)->
reverse(nadj);
1146 }
catch(std::exception& e) {
1147 THROW_ERROR(
"reverse", e.what());
1152 (*this)->print_dimensions(stream);
1156 (*this)->print_options(stream);
1160 (*this)->print_option(
name, stream);
1165 return (*this)->has_option(option_name);
1166 }
catch(std::exception& e) {
1167 THROW_ERROR(
"has_option", e.what());
1176 casadi_error(
"Option '" + option_name +
"' does not exist");
1178 (*this)->change_option(option_name, option_value);
1179 }
catch(std::exception& e) {
1180 THROW_ERROR(
"change_option", e.what());
1185 return (*this)->get_free();
1199 return (*this)->generate_dependencies(fname, opts);
1211 for (casadi_int i=0; i<d.size(); ++i) {
1226 for (casadi_int i=0; i<d.size(); ++i) {
1238 "Dimension mismatch: file contains a vector of size " +
str(data.
numel())
1239 +
", while size " +
str(
nnz_in()) +
" was expected.");
1250 "Dimension mismatch: file contains a vector of size " +
str(data.
numel())
1251 +
", while size " +
str(
nnz_out()) +
" was expected.");
1257 std::ostream &stream,
const Dict& options)
const {
1258 return (*this)->export_code(lang, stream, options);
1262 const std::string &fname,
const Dict& options)
const {
1263 std::ofstream stream;
1265 return (*this)->export_code(lang, stream, options);
1275 std::stringstream ss;
1287 s.
pack(
"Function::null",
true);
1289 s.
pack(
"Function::null",
false);
1290 (*this)->serialize(s);
1302 std::stringstream ss;
1303 (*this)->export_code(lang, ss, options);
1309 static std::string
null =
"null";
1312 return (*this)->name_;
1318 if (
name.empty())
return false;
1321 for (
const char* kw : {
"null",
"jac",
"hess"}) {
1322 if (
name==kw)
return false;
1326 auto it=
name.begin();
1327 if (!std::isalpha(*it++))
return false;
1330 for (; it!=
name.end(); ++it) {
1333 if (it+1!=
name.end() && *(it+1)==
'_')
return false;
1336 if (!std::isalnum(*it))
return false;
1352 if (t==SerializerBase::SerializationType::SERIALIZED_FUNCTION) {
1355 casadi_error(
"File is not loadable with 'load'. Use 'FileDeserializer' instead.");
1360 std::stringstream ss;
1370 if (
name.empty())
return "unnamed";
1373 std::stringstream ss;
1376 if (!std::isalpha(
name.front())) ss <<
"a";
1379 bool previous_is_underscore =
false;
1380 for (
char c :
name) {
1381 if (std::isalnum(c)) {
1384 previous_is_underscore =
false;
1385 }
else if (!previous_is_underscore) {
1388 previous_is_underscore =
true;
1393 for (
const char* kw : {
"null",
"jac",
"hess"}) {
1394 if (ss.str()==kw) ss <<
"1";
1401 std::vector<DM> res;
1407 std::vector<SX> res;
1413 std::vector<MX> res;
1418 template<
typename M>
1420 bool always_inline,
bool never_inline)
const {
1422 std::vector<M> arg_v = (*this)->convert_arg(arg);
1425 std::vector<M> res_v;
1426 call(arg_v, res_v, always_inline, never_inline);
1430 for (casadi_int i=0; i<res_v.size(); ++i) {
1454 bool always_inline,
bool never_inline)
const {
1456 call_gen(arg, res, always_inline, never_inline);
1457 }
catch(std::exception& e) {
1458 THROW_ERROR(
"call", e.what());
1463 bool always_inline,
bool never_inline)
const {
1465 call_gen(arg, res, always_inline, never_inline);
1466 }
catch(std::exception& e) {
1467 THROW_ERROR(
"call", e.what());
1472 bool always_inline,
bool never_inline)
const {
1474 call_gen(arg, res, always_inline, never_inline);
1475 }
catch(std::exception& e) {
1476 THROW_ERROR(
"call", e.what());
1481 return (*this)->get_default_in(ind);
1485 return (*this)->get_max_in(ind);
1489 return (*this)->get_min_in(ind);
1493 return (*this)->get_nominal_in(ind);
1497 return (*this)->get_nominal_out(ind);
1500 #ifdef WITH_EXTRA_CHECKS
1502 thread_local casadi_int Function::call_depth_ = 0;
1506 casadi_int* iw,
double* w)
const {
1512 casadi_int* iw,
double* w,
int mem)
const {
1514 #ifdef WITH_EXTRA_CHECKS
1516 casadi_assert_dev(call_depth_>=0);
1519 casadi_int depth = call_depth_;
1521 int ret = (*this)->eval_gen(arg, res, iw, w,
memory(mem),
false,
false);
1522 #ifdef WITH_EXTRA_CHECKS
1524 casadi_assert_dev(call_depth_==depth);
1530 #ifdef WITH_EXTRA_CHECKS
1534 }
catch(std::exception& e) {
1535 #ifdef WITH_EXTRA_CHECKS
1538 (*this)->print_in(
uerr(), arg,
true);
1539 THROW_ERROR(
"operator()", e.
what());
1544 casadi_int* iw,
SXElem* w,
int mem)
const {
1546 return (*this)->eval_sx(arg, res, iw, w,
memory(mem),
false,
false);
1547 }
catch(std::exception& e) {
1548 THROW_ERROR(
"operator()", e.what());
1554 return (*this)->sx_in(iind);
1555 }
catch(std::exception& e) {
1556 THROW_ERROR(
"sx_in", e.what());
1562 return (*this)->sx_out(oind);
1563 }
catch(std::exception& e) {
1564 THROW_ERROR(
"sx_out", e.what());
1570 return (*this)->sx_in();
1571 }
catch(std::exception& e) {
1572 THROW_ERROR(
"sx_in", e.what());
1578 return (*this)->sx_out();
1579 }
catch(std::exception& e) {
1580 THROW_ERROR(
"sx_out", e.what());
1585 return (*this)->mx_in(ind);
1589 return (*this)->mx_out(ind);
1593 return (*this)->mx_in();
1597 return (*this)->mx_out();
1601 return (*this)->nz_in(arg);
1605 return (*this)->nz_out(res);
1609 return (*this)->nz_in(arg);
1613 return (*this)->nz_out(res);
1617 return (*this)->convert_arg(arg);
1621 return (*this)->convert_arg(arg);
1625 return (*this)->convert_res(arg);
1629 return (*this)->convert_res(arg);
1633 return (*this)->convert_arg(arg);
1637 return (*this)->convert_arg(arg);
1641 return (*this)->convert_res(arg);
1645 return (*this)->convert_res(arg);
1649 return (*this)->convert_arg(arg);
1653 return (*this)->convert_arg(arg);
1657 return (*this)->convert_res(arg);
1661 return (*this)->convert_res(arg);
1665 return (*this)->is_a(type, recursive);
1669 std::vector<MX>& subs_from, std::vector<MX>& subs_to)
const {
1670 return (*this)->merge(arg, subs_from, subs_to);
1675 return (*this)->free_sx();
1676 }
catch(std::exception& e) {
1677 THROW_ERROR(
"free_sx", e.what());
1683 return (*this)->free_mx();
1684 }
catch(std::exception& e) {
1685 THROW_ERROR(
"free_mx", e.what());
1690 return (*this)->has_spfwd();
1694 return (*this)->has_sprev();
1698 return (*this)->has_free();
1703 (*this)->generate_lifted(vdef_fcn, vinit_fcn);
1704 }
catch(std::exception& e) {
1705 THROW_ERROR(
"generate_lifted", e.what());
1711 return (*this)->n_instructions();
1712 }
catch(std::exception& e) {
1713 THROW_ERROR(
"n_instructions", e.what());
1719 return (*this)->instruction_MX(k);
1720 }
catch(std::exception& e) {
1721 THROW_ERROR(
"instruction_MX", e.what());
1727 return (*this)->instructions_sx();
1728 }
catch(std::exception& e) {
1729 THROW_ERROR(
"instructions_sx", e.what());
1735 return (*this)->instruction_id(k);
1736 }
catch(std::exception& e) {
1737 THROW_ERROR(
"instruction_id", e.what());
1743 return (*this)->instruction_input(k);
1744 }
catch(std::exception& e) {
1745 THROW_ERROR(
"instruction_input", e.what());
1751 return (*this)->instruction_constant(k);
1752 }
catch(std::exception& e) {
1753 THROW_ERROR(
"instruction_constant", e.what());
1759 return (*this)->instruction_output(k);
1760 }
catch(std::exception& e) {
1761 THROW_ERROR(
"instruction_output", e.what());
1767 return (*this)->n_nodes();
1768 }
catch(std::exception& e) {
1769 THROW_ERROR(
"n_nodes", e.what());
1774 return (*this)->checkout();
1778 (*this)->release(mem);
1782 return (*this)->memory(ind);
1787 "Incorrect shape for " +
str(*
this) +
" input " +
str(i) +
" \""
1788 +
name_in(i) +
"\". Expected " +
str(nrow) +
"-by-" +
str(ncol)
1795 "Incorrect shape for " +
str(*
this) +
" output " +
str(i) +
" \""
1801 casadi_int n,
bool allow_all_zero_sparse)
const {
1805 if (allow_all_zero_sparse &&
sparsity_out(i).nnz() == 0)
return;
1807 casadi_assert(
sparsity_out(i).is_stacked(sp, n),
"Mismatching sparsity "
1808 "(but correct dimensions) for " +
str(*
this) +
" output " +
name_out(i));
1812 factory(
const std::string& name,
1813 const std::vector<std::string>& s_in,
1814 const std::vector<std::string>& s_out,
1816 const Dict& opts)
const {
1818 return (*this)->
factory(
name, s_in, s_out, aux, opts);
1819 }
catch(std::exception& e) {
1820 THROW_ERROR(
"factory",
"Failed to create " +
name +
":" +
str(s_in) +
"->" +
str(s_out)
1821 +
" with " +
str(aux) +
":\n" +
str(e.what()));
1826 which_depends(
const std::string& s_in,
const std::vector<std::string>& s_out,
1827 casadi_int order,
bool tr)
const {
1829 return (*this)->which_depends(s_in, s_out,
order, tr);
1830 }
catch(std::exception& e) {
1831 THROW_ERROR(
"which_depends", e.what());
1837 return (*this)->cache();
1838 }
catch(std::exception& e) {
1839 THROW_ERROR(
"cache", e.what());
1846 return (*this)->get_function();
1847 }
catch(std::exception& e) {
1848 THROW_ERROR(
"get_function", e.what());
1855 return (*this)->get_function(
name);
1856 }
catch(std::exception& e) {
1857 THROW_ERROR(
"get_function", e.what());
1863 return (*this)->has_function(fname);
1864 }
catch(std::exception& e) {
1865 THROW_ERROR(
"has_function", e.what());
1873 if (max_depth < 0) max_depth = std::numeric_limits<casadi_int>::max();
1875 std::map<FunctionInternal*, Function> all_fun;
1876 (*this)->find(all_fun, max_depth);
1878 std::vector<Function> ret;
1879 ret.reserve(all_fun.size());
1880 for (
auto&& e : all_fun) ret.push_back(e.second);
1882 }
catch(std::exception& e) {
1883 THROW_ERROR(
"find", e.what());
1891 if (max_depth < 0) max_depth = std::numeric_limits<casadi_int>::max();
1893 std::map<FunctionInternal*, Function> all_fun;
1894 (*this)->find(all_fun, max_depth);
1896 for (
auto&& e : all_fun) {
1897 if (e.second.name() ==
name)
return e.second;
1900 casadi_error(
"'" +
name +
"' not found");
1901 }
catch(std::exception& e) {
1902 THROW_ERROR(
"find", e.what());
1910 return (*this)->
oracle();
1911 }
catch(std::exception& e) {
1912 THROW_ERROR(
"oracle", e.what());
1917 return (*this)->
wrap();
1926 casadi_assert(!
is_null(),
"lhs is null");
1927 casadi_assert(!f.
is_null(),
"rhs is null");
1929 }
catch(std::exception& e) {
1930 THROW_ERROR(
"operator==", e.what());
1935 return (*this)->info();
1947 w_.resize(f_.
sz_w());
1948 iw_.resize(f_.
sz_iw());
1949 arg_.resize(f_.
sz_arg());
1950 res_.resize(f_.
sz_res());
1952 mem_internal_ = f.
memory(mem_);
1953 f_node_ = f.operator->();
1970 w_ = f.w_; iw_ = f.iw_; arg_ = f.arg_; res_ = f.res_; f_node_ = f.f_node_;
1976 mem_internal_ = f_.
memory(mem_);
1983 casadi_assert(size>=f_.
nnz_in(i)*
sizeof(
double),
1984 "Buffer is not large enough. Needed " +
str(f_.
nnz_in(i)*
sizeof(
double)) +
1985 " bytes, got " +
str(size) +
".");
1989 casadi_assert(size>=f_.
nnz_out(i)*
sizeof(
double),
1990 "Buffer is not large enough. Needed " +
str(f_.
nnz_out(i)*
sizeof(
double)) +
1991 " bytes, got " +
str(size) +
".");
1995 if (f_node_->
eval_) {
2010 return f_.
stats(mem_);
const char * what() const override
Display error.
Helper class for C code generation.
void add(const Function &f, bool with_jac_sparsity=false)
Add a function (name generated)
std::string generate(const std::string &prefix="")
Generate file(s)
Function blind_unpack_function()
SerializerBase::SerializationType pop_type()
Helper class for Serialization.
void unpack(Sparsity &e)
Reconstruct an object from the input stream.
static void open(std::ofstream &, const std::string &path, std::ios_base::openmode mode=std::ios_base::out)
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 & operator=(const FunctionBuffer &f)
FunctionBuffer(const Function &f)
Main constructor.
int ret()
Get last return value.
Internal class for Function.
Function forward(casadi_int nfwd) const
Return function that calculates forward derivatives.
virtual Function slice(const std::string &name, const std::vector< casadi_int > &order_in, const std::vector< casadi_int > &order_out, const Dict &opts) const
returns a new function with a selection of inputs/outputs of the original
virtual double ad_weight() const
Weighting factor for chosing forward/reverse mode.
static Function deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
virtual Function factory(const std::string &name, const std::vector< std::string > &s_in, const std::vector< std::string > &s_out, const Function::AuxOut &aux, const Dict &opts) const
casadi_release_t release_
Release redirected to a C function.
virtual int eval(const double **arg, double **res, casadi_int *iw, double *w, void *mem) const
Evaluate numerically.
eval_t eval_
Numerical evaluation redirected to a C function.
Function wrap() const
Wrap in an Function instance consisting of only one MX call.
casadi_checkout_t checkout_
Checkout redirected to a C function.
Function reverse(casadi_int nadj) const
Return function that calculates adjoint derivatives.
virtual const Function & oracle() const
Get oracle.
Function jacobian() const
Return Jacobian of all input elements with respect to all output elements.
Function wrap_as_needed(const Dict &opts) const
Wrap in an Function instance consisting of only one MX call.
bool has_sprev() const
Is the class able to propagate seeds through the algorithm?
std::vector< double * > buf_out(VecRes res) const
Supported arguments for numerical evaluation and converters.
casadi_int numel_in() const
Get number of input elements.
Function forward(casadi_int nfwd) const
Get a function that calculates nfwd forward derivatives.
casadi_int nnz_out() const
Get number of output nonzeros.
static Function if_else(const std::string &name, const Function &f_true, const Function &f_false, const Dict &opts=Dict())
Constructor (if-else)
void sz_work(size_t &sz_arg, size_t &sz_res, size_t &sz_iw, size_t &sz_w) const
Get number of temporary variables needed.
const std::map< std::string, std::vector< double > > & MapArg
Supported arguments for numerical evaluation and converters.
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)
size_t sz_res() const
Get required length of res field.
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 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 print_option(const std::string &name, std::ostream &stream=casadi::uout()) const
Print all information there is to know about a certain option.
void construct(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)
Called by constructors.
std::string generate_dependencies(const std::string &fname, const Dict &opts=Dict()) const
Export / Generate C code for the dependency function.
static Function deserialize(std::istream &stream)
Build function from serialization.
static Function conditional(const std::string &name, const std::vector< Function > &f, const Function &f_def, const Dict &opts=Dict())
Constuct a switch function.
void save(const std::string &fname, const Dict &opts=Dict()) const
Save Function to a file.
std::vector< bool > is_diff_in() const
Get differentiability of inputs/output.
std::vector< std::string > get_function() const
Get a list of all functions.
std::vector< double > nz_from_in(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
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.
const MX mx_in(casadi_int ind) const
Get symbolic primitives equivalent to the input expressions.
bool has_spfwd() const
Is the class able to propagate seeds through the algorithm?
void set_temp(const double **arg, double **res, casadi_int *iw, double *w, int mem=0) const
Set the (temporary) work vectors.
const std::vector< std::vector< double > > & VecArg
Supported arguments for numerical evaluation and converters.
double max_in(casadi_int ind) const
Get largest input value.
const Sparsity & sparsity_out(casadi_int ind) const
Get sparsity of a given output.
FunctionInternal * get() const
static bool proceed_to(std::istream &file, const std::string &str)
Helper function for parsing .casadi files.
casadi_int size1_in(casadi_int ind) const
Get input dimension.
std::vector< std::vector< double > * > VPrRes
Supported arguments for numerical evaluation and converters.
Function fold(casadi_int N, const Dict &opts=Dict()) const
Create a mapaccumulated version of this function.
const std::vector< MX > mx_in() const
Get symbolic primitives equivalent to the input expressions.
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.
const std::vector< std::string > & name_in() const
Get input scheme.
const std::string & name() const
Name of the function.
Dict cache() const
Get all functions in the cache.
casadi_int numel_out() const
Get number of output elements.
std::vector< const double * > buf_in(VecArg arg) const
Supported arguments for numerical evaluation and converters.
Function wrap() const
Wrap in an Function instance consisting of only one MX call.
static std::string fix_name(const std::string &name)
Turn a string into a valid function name as defined by "check_name".
std::vector< Function > find_functions(casadi_int max_depth=-1) const
Get all functions embedded in the expression graphs.
Function reverse(casadi_int nadj) const
Get a function that calculates nadj adjoint derivatives.
Function oracle() const
Get oracle.
static bool test_cast(const SharedObjectInternal *ptr)
Check if a particular cast is allowed.
Function jacobian() const
Calculate all Jacobian blocks.
void call_gen(std::vector< const D * > arg, std::vector< D * > res) const
Evaluate with temporary memory allocation.
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.
std::vector< casadi_int > instruction_input(casadi_int k) const
Locations in the work vector for the inputs of the instruction.
static Function create(FunctionInternal *node)
Create from node.
std::vector< double > nominal_in(casadi_int ind) const
Get nominal input value.
std::vector< MX > mapsum(const std::vector< MX > &x, const std::string ¶llelization="serial") const
Evaluate symbolically in parallel and sum (matrix graph)
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.
static bool check_name(const std::string &name)
Check if a string is a valid function name.
casadi_int checkout() const
Checkout a memory object.
std::vector< MX > free_mx() const
Get all the free variables of the function.
Function hessian_old(casadi_int iind, casadi_int oind) const
[DEPRECATED] Replaced by Function::factory.
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
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Get output dimension.
std::map< std::string, std::vector< double > > & MapRes
Supported arguments for numerical evaluation and converters.
int rev(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w, int mem=0) const
Propagate sparsity backward.
void setup(const double **arg, double **res, casadi_int *iw, double *w, int mem=0) const
Set the (persistent and temporary) work vectors.
const Sparsity & sparsity_in(casadi_int ind) const
Get sparsity of a given input.
Function find_function(const std::string &name, casadi_int max_depth=-1) const
Get a specific function embedded in the expression graphs.
std::vector< casadi_int > instruction_output(casadi_int k) const
Location in the work vector for the output of the instruction.
std::vector< double > nz_from_out(const std::vector< DM > &arg) const
Convert from/to flat vector of input/output nonzeros.
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)
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())
Create a just-in-time compiled function from a C language string.
std::vector< double > nominal_out(casadi_int ind) const
Get nominal output value.
size_t sz_iw() const
Get required length of iw field.
const std::vector< SX > sx_out() const
Get symbolic primitives equivalent to the output expressions.
casadi_int n_out() const
Get the number of function outputs.
std::vector< bool > is_diff_out() const
Get differentiability of inputs/output.
casadi_int n_in() const
Get the number of function inputs.
bool has_out(const std::string &name) const
Does the function have a particularly named output?
void * memory(int ind) const
Get memory object.
static std::vector< SX > order(const std::vector< SX > &expr)
std::vector< std::string > get_free() const
Get free variables as a string.
DMDict convert_in(const std::vector< DM > &arg) const
Convert from/to input/output lists/map.
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.
size_t sz_w() const
Get required length of w field.
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.
bool has_in(const std::string &name) const
Does the function have a particularly named input?
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.
const std::vector< SX > sx_in() const
Get symbolic primitives equivalent to the input expressions.
Function wrap_as_needed(const Dict &opts) const
Wrap in a Function with options.
bool operator==(const Function &f) const
Check if same as another function.
casadi_int nnz_in() const
Get number of input nonzeros.
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)
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.
static Function load(const std::string &filename)
Build function from serialization.
void print_dimensions(std::ostream &stream=casadi::uout()) const
Print dimensions of inputs and outputs.
void merge(const std::vector< MX > &arg, std::vector< MX > &subs_from, std::vector< MX > &subs_to) const
List merge opportunitities.
std::vector< DM > operator()(const std::vector< DM > &arg) const
std::map< std::string, std::vector< double > * > MPrRes
Supported arguments for numerical evaluation and converters.
casadi_int size1_out(casadi_int ind) const
Get output dimension.
std::vector< DM > nz_to_in(const std::vector< double > &arg) const
Convert from/to flat vector of input/output nonzeros.
void export_code(const std::string &lang, const std::string &fname, const Dict &options=Dict()) const
Export function in specific language.
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Get input dimension.
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.
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< DM > nz_to_out(const std::vector< double > &arg) const
Convert from/to flat vector of input/output nonzeros.
Dict stats(int mem=0) const
Get all statistics obtained at the end of the last evaluate call.
const std::vector< Sparsity > & jac_sparsity(bool compact=false) const
Get, if necessary generate, the sparsity of all Jacobian blocks.
std::map< std::string, std::vector< std::string > > AuxOut
std::vector< std::vector< double > > & VecRes
Supported arguments for numerical evaluation and converters.
void set_work(const double **&arg, double **&res, casadi_int *&iw, double *&w, int mem=0) const
Set the (persistent) work vectors.
void serialize(std::ostream &stream, const Dict &opts=Dict()) const
Serialize.
std::vector< SX > free_sx() const
Get all the free variables of the function.
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 std::vector< std::string > & name_out() const
Get output scheme.
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.
const std::vector< MX > mx_out() const
Get symbolic primitives equivalent to the output expressions.
Function jacobian_old(casadi_int iind, casadi_int oind) const
[DEPRECATED] Replaced by Function::factory.
FunctionInternal * operator->() const
Const access functions of the node.
double default_in(casadi_int ind) const
Get default input value.
bool has_option(const std::string &option_name) const
Does a particular option exist.
casadi_int numel() const
Get the number of elements.
bool is_dense() const
Check if the matrix expression is dense.
bool is_empty(bool both=false) const
Check if the sparsity is empty, i.e. if one of the dimensions is zero.
bool is_vector() const
Check if the matrix is a row or column vector.
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.
static MX zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
GenericShared & operator=(const GenericShared &ref)
Assignment operator.
SharedObjectInternal * get() const
Get a const pointer to the node.
bool is_null() const
Is a null pointer?
void own(SharedObjectInternal *node)
Generic data type, can hold different types such as bool, casadi_int, std::string etc.
Internal node class for MXFunction.
static std::vector< MX > order(const std::vector< MX > &expr)
static MX bspline(const MX &x, const DM &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > °ree, casadi_int m, const Dict &opts=Dict())
static Function create(const std::string &name, const std::string ¶llelization, const Function &f, casadi_int n, const std::vector< bool > &reduce_in, const std::vector< bool > &reduce_out, const Dict &opts=Dict())
std::vector< Scalar > & nonzeros()
static Matrix< double > from_file(const std::string &filename, const std::string &format_hint="")
void construct(const Dict &opts)
Construct.
int checkout() const
Checkout a memory object.
The basic scalar symbolic class of CasADi.
Internal node class for SXFunction.
static std::vector< SX > order(const std::vector< SX > &expr)
void pack(const Sparsity &e)
Helper class for Serialization.
void pack(const Sparsity &e)
Serializes an object to the output stream.
Class representing a Slice.
casadi_int size1() const
Get the number of rows.
casadi_int size2() const
Get the number of columns.
bool is_dense() const
Is dense?
std::map< std::string, MX > MXDict
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.
std::string join(const std::vector< std::string > &l, const std::string &delim)
unsigned long long bvec_t
bool isUnique(const std::vector< T > &v)
std::vector< SX > SXVector
std::vector< MX > MXVector
std::map< std::string, SX > SXDict
std::string str(const T &v)
String representation, any type.
std::vector< casadi_int > lookupvector(const std::vector< casadi_int > &v, casadi_int size)
Returns a vector for quickly looking up entries of supplied list.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::vector< std::string > StringVector
void normalized_setup(std::istream &stream)
void update_dict(Dict &target, const Dict &source, bool recurse)
Update the target dictionary in place with source elements.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.
std::initializer_list< SX > SXIList
std::initializer_list< MX > MXIList
bool in_range(const std::vector< T > &v, casadi_int upper)
Check if for each element of v holds: v_i < upper.
std::vector< casadi_int > complement(const std::vector< casadi_int > &v, casadi_int size)
Returns the list of all i in [0, size[ not found in supplied list.
void CASADI_EXPORT _function_buffer_eval(void *raw)
Dict extract_from_dict(const Dict &d, const std::string &key, T &value)
std::map< std::string, DM > DMDict
std::string filename(const std::string &path)
Function external_transform(const std::string &name, const std::string &op, const Function &f, const Dict &opts)
Apply a transformation defined externally.
void normalized_out(std::ostream &stream, double val)