28 #include "shared_object.hpp"
29 #include "matrix_fwd.hpp"
32 #include "generic_matrix.hpp"
33 #include "generic_expression.hpp"
34 #include "generic_type.hpp"
35 #include "printable.hpp"
37 #ifdef CASADI_WITH_THREAD
38 #ifdef CASADI_WITH_THREAD_MINGW
39 #include <mingw.mutex.h>
52 class SerializingStream;
53 class DeserializingStream;
141 class CASADI_EXPORT
MX :
142 public SWIG_IF_ELSE(GenericExpressionCommon, GenericExpression<MX>),
143 public SWIG_IF_ELSE(PrintableCommon, Printable<MX>),
226 MX(casadi_int nrow, casadi_int ncol);
232 explicit MX(
const std::pair<casadi_int, casadi_int>& rc);
380 MX(
const Sparsity& sp,
const std::string& fname);
461 MX(
const std::vector<double> &x);
533 static std::vector<MX> createMultipleOutput(
MXNode* node);
618 bool __nonzero__()
const;
635 std::vector<MX> get_nonzeros()
const;
678 void erase(
const std::vector<casadi_int>& rr,
const std::vector<casadi_int>& cc,
714 void erase(
const std::vector<casadi_int>& rr,
bool ind1=
false);
761 void enlarge(casadi_int nrow, casadi_int ncol,
762 const std::vector<casadi_int>& rr,
const std::vector<casadi_int>& cc,
795 MX operator-()
const;
832 const MXNode* operator->()
const;
884 MX dep(casadi_int ch=0)
const;
933 casadi_int n_out()
const;
987 MX get_output(casadi_int oind)
const;
1036 casadi_int n_dep()
const;
1084 std::string name()
const;
1127 explicit operator double()
const;
1221 bool is_symbolic()
const;
1262 bool is_constant()
const;
1292 bool is_integer()
const;
1328 bool is_doubled()
const;
1382 bool is_call()
const;
1493 bool is_output()
const;
1539 bool has_output()
const;
1582 casadi_int which_output()
const;
1627 bool is_op(casadi_int op)
const;
1660 bool is_multiplication()
const;
1696 bool is_commutative()
const;
1728 bool is_norm()
const;
1776 bool is_valid_input()
const;
1813 casadi_int n_primitives()
const;
1864 std::vector<MX> primitives()
const;
1920 std::vector<MX> split_primitives(
const MX& x)
const;
1921 std::vector<SX> split_primitives(
const SX& x)
const;
1922 std::vector<DM> split_primitives(
const DM& x)
const;
1976 MX join_primitives(
const std::vector<MX>& v)
const;
1977 SX join_primitives(
const std::vector<SX>& v)
const;
1978 DM join_primitives(
const std::vector<DM>& v)
const;
2027 bool has_duplicates()
const;
2032 void reset_input()
const;
2065 bool is_eye()
const;
2139 bool is_one()
const;
2168 bool is_minus_one()
const;
2173 bool is_half()
const;
2212 bool is_value(
double val)
const;
2242 bool is_inf()
const;
2270 bool is_minus_inf()
const;
2306 bool is_transpose()
const;
2391 bool is_binary()
const;
2434 bool is_nonnegative()
const;
2473 bool is_unary()
const;
2517 casadi_int op()
const;
2613 casadi_int get_temp()
const;
2616 void set_temp(casadi_int t)
const;
2679 static MX binary(casadi_int op,
const MX &x,
const MX &y,
2680 bool unique_x=
false,
bool unique_y=
false);
2681 static MX unary(casadi_int op,
const MX &x,
bool unique=
false);
2716 static MX inf(casadi_int nrow=1, casadi_int ncol=1);
2717 static MX inf(
const std::pair<casadi_int, casadi_int>& rc);
2751 static MX nan(casadi_int nrow=1, casadi_int ncol=1);
2752 static MX nan(
const std::pair<casadi_int, casadi_int>& rc);
2780 static MX eye(casadi_int n);
2793 MX nzref(
const Sparsity& sp,
const std::vector<casadi_int>& nz)
const;
2887 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& rr)
const;
2889 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Sparsity& sp)
const;
2890 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& rr)
const;
2891 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const casadi_int rr)
const {
2951 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& rr,
const Slice& cc)
const;
2953 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& rr, casadi_int cc)
const {
2957 void get(
MX& SWIG_OUTPUT(m),
bool ind1, casadi_int rr,
const Slice& cc)
const {
2962 void get(
MX& SWIG_OUTPUT(m),
bool ind1, casadi_int rr,
2963 casadi_int cc)
const {
2966 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& rr,
const Slice& cc)
const;
2967 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& rr,
const MX& cc)
const;
2968 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& rr,
const MX& cc)
const;
3049 void set(
const MX& m,
bool ind1,
const Slice& rr);
3051 void set(
const MX& m,
bool ind1,
const Sparsity& sp);
3112 void set(
const MX& m,
bool ind1,
const Slice& rr,
const Slice& cc);
3172 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& kk)
const;
3174 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& kk)
const;
3175 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1, casadi_int kk)
const {
3178 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& inner,
const Slice& outer)
const;
3179 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& inner,
const MX& outer)
const;
3180 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& inner,
const MX& outer)
const;
3235 void set_nz(
const MX& m,
bool ind1,
const Slice& kk);
3237 void set_nz(
const MX& m,
bool ind1,
const MX& kk);
3310 static MX einstein(
const MX& A,
const MX& B,
const MX& C,
3311 const std::vector<casadi_int>& dim_a,
const std::vector<casadi_int>& dim_b,
3312 const std::vector<casadi_int>& dim_c,
3313 const std::vector<casadi_int>& a,
const std::vector<casadi_int>& b,
3314 const std::vector<casadi_int>& c);
3316 static MX einstein(
const MX& A,
const MX& B,
3317 const std::vector<casadi_int>& dim_a,
const std::vector<casadi_int>& dim_b,
3318 const std::vector<casadi_int>& dim_c,
3319 const std::vector<casadi_int>& a,
const std::vector<casadi_int>& b,
3320 const std::vector<casadi_int>& c);
3327 static bool is_equal(
const MX& x,
const MX& y, casadi_int depth=0);
3328 static MX mmin(
const MX &x);
3329 static MX mmax(
const MX &x);
3334 static MX horzcat(
const std::vector<MX>& x);
3335 static MX diagcat(
const std::vector<MX>& x);
3336 static MX vertcat(
const std::vector<MX>& x);
3337 static std::vector<MX> horzsplit(
const MX& x,
const std::vector<casadi_int>& offset);
3338 static std::vector<MX> diagsplit(
const MX& x,
const std::vector<casadi_int>& offset1,
3339 const std::vector<casadi_int>& offset2);
3340 static std::vector<MX> vertsplit(
const MX& x,
const std::vector<casadi_int>& offset);
3341 static MX blockcat(
const std::vector< std::vector<MX > > &v);
3342 static MX mtimes(
const MX& x,
const MX& y,
3343 const std::string& blas =
"reference");
3344 static MX mac(
const MX& x,
const MX& y,
const MX& z,
3345 const std::string& blas =
"reference");
3346 static MX reshape(
const MX& x, casadi_int nrow, casadi_int ncol);
3348 static MX sparsity_cast(
const MX& x,
const Sparsity& sp);
3349 static MX kron(
const MX& x,
const MX& b);
3351 static MX repmat(
const MX& x, casadi_int n, casadi_int m=1);
3357 static MX jacobian(
const MX& f,
const MX& x,
const Dict& opts =
Dict());
3358 static MX hessian(
const MX& f,
const MX& x,
const Dict& opts =
Dict());
3359 static MX hessian(
const MX& f,
const MX& x,
MX& g,
const Dict& opts =
Dict());
3360 static std::vector<std::vector<MX> >
3361 forward(
const std::vector<MX> &ex,
3362 const std::vector<MX> &arg,
3363 const std::vector<std::vector<MX> > &v,
3365 static std::vector<std::vector<MX> >
3366 reverse(
const std::vector<MX> &ex,
3367 const std::vector<MX> &arg,
3368 const std::vector<std::vector<MX> > &v,
3370 static std::vector<bool> which_depends(
const MX &expr,
const MX &var,
3371 casadi_int order=1,
bool tr=
false);
3372 static Sparsity jacobian_sparsity(
const MX& f,
const MX& x);
3373 static MX substitute(
const MX& ex,
const MX& v,
const MX& vdef);
3374 static std::vector<MX> substitute(
const std::vector<MX> &ex,
3375 const std::vector<MX> &v,
3376 const std::vector<MX> &vdef);
3377 static void substitute_inplace(
const std::vector<MX>& v,
3378 std::vector<MX>& vdef,
3379 std::vector<MX>& ex,
bool reverse);
3380 static MX solve(
const MX& a,
const MX& b);
3381 static MX solve(
const MX& a,
const MX& b,
const std::string& lsolver,
3383 static MX inv_minor(
const MX& A);
3384 static MX inv_node(
const MX& A);
3385 static MX inv(
const MX& A,
const std::string& lsolver=
"qr",
const Dict& dict =
Dict());
3386 static MX pinv(
const MX& A,
const std::string& lsolver=
"qr",
3388 static MX expm_const(
const MX& A,
const MX& t);
3389 static MX expm(
const MX& A);
3390 static casadi_int n_nodes(
const MX& x);
3391 static std::string print_operator(
const MX& x,
const std::vector<std::string>& args);
3392 static void extract(std::vector<MX>& ex, std::vector<MX>& v,
3393 std::vector<MX>& vdef,
const Dict& opts =
Dict());
3394 static void shared(std::vector<MX>& ex, std::vector<MX>& v,
3395 std::vector<MX>& vdef,
const std::string& v_prefix,
const std::string& v_suffix);
3397 const MX& if_false,
bool short_circuit=
false);
3398 static MX conditional(
const MX& ind,
const std::vector<MX> &x,
const MX& x_default,
3399 bool short_circuit=
false);
3400 static bool depends_on(
const MX& x,
const MX& arg);
3401 static bool contains_all(
const std::vector<MX>& v,
const std::vector<MX> &n);
3402 static bool contains_any(
const std::vector<MX>& v,
const std::vector<MX> &n);
3404 static MX transform(
const MX& x,
const Dict& opts =
Dict());
3405 static MX transform(
const MX& x,
3406 const std::vector<std::vector<GenericType> >& passes,
const Dict& opts =
Dict());
3407 static std::vector<MX> transform(
const std::vector<MX>& x,
const Dict& opts =
Dict());
3408 static std::vector<MX> transform(
const std::vector<MX>& x,
3409 const std::vector<std::vector<GenericType> >& passes,
const Dict& opts =
Dict());
3410 static MX dot(
const MX& x,
const MX& y);
3411 static MX mrdivide(
const MX& a,
const MX& b);
3412 static MX mldivide(
const MX& a,
const MX& b);
3414 static MX norm_fro(
const MX& x);
3417 static MX unite(
const MX& A,
const MX& B);
3418 static MX trace(
const MX& x);
3419 static MX diag(
const MX& x);
3420 static MX sum2(
const MX& x);
3421 static MX sum1(
const MX& x);
3422 static MX polyval(
const MX& p,
const MX& x);
3423 static MX det(
const MX& x);
3424 static MX det(
const MX& x,
const std::string& lsolver,
const Dict& opts=
Dict());
3425 static std::vector<MX> symvar(
const MX& x);
3426 static MX nullspace(
const MX& A);
3427 static MX repsum(
const MX& x, casadi_int n, casadi_int m=1);
3428 static MX densify(
const MX& x,
const MX& val=0);
3429 static MX _bilin(
const MX& A,
const MX& x,
const MX& y);
3430 static MX _rank1(
const MX& A,
const MX& alpha,
const MX& x,
const MX& y);
3431 static MX project(
const MX& x,
const Sparsity& sp,
bool intersect=
false);
3432 static MX cumsum(
const MX &x, casadi_int axis=-1);
3433 static MX _logsumexp(
const MX& x);
3434 static std::vector<MX> cse(
const std::vector<MX>& e);
3435 static void extract_parametric(
const MX &expr,
const MX& par,
3436 MX& expr_ret, std::vector<MX>& symbols, std::vector<MX>& parametric,
const Dict& opts);
3437 static void separate_linear(
const MX &expr,
3438 const MX &sym_lin,
const MX &sym_const,
3439 MX& expr_const,
MX& expr_lin,
MX& expr_nonlin);
3445 static MX low(
const MX& v,
const MX& p,
const Dict& options =
Dict());
3446 static MX graph_substitute(
const MX& x,
const std::vector<MX> &v,
3447 const std::vector<MX> &vdef);
3448 static MX graph_substitute(
const MX& x,
const std::vector<MX> &v,
3449 const std::vector<MX> &vdef,
bool& updated);
3450 static std::vector<MX> graph_substitute(
const std::vector<MX> &ex,
3451 const std::vector<MX> &v,
3452 const std::vector<MX> &vdef);
3453 static std::vector<MX> graph_substitute(
const std::vector<MX> &ex,
3454 const std::vector<MX> &v,
3455 const std::vector<MX> &vdef,
3457 static MX matrix_expand(
const MX& e,
const std::vector<MX> &boundary,
3458 const Dict& options);
3459 static std::vector<MX> matrix_expand(
const std::vector<MX>& e,
3460 const std::vector<MX>& boundary,
3461 const Dict& options);
3462 static MX lift(
const MX& x,
const MX& x_guess);
3463 static DM evalf(
const MX& m);
3464 static MX bspline(
const MX& x,
3466 const std::vector< std::vector<double> >& knots,
3467 const std::vector<casadi_int>& degree,
3470 static MX bspline(
const MX& x,
const MX& coeffs,
3471 const std::vector< std::vector<double> >& knots,
3472 const std::vector<casadi_int>& degree,
3475 static MX bspline(
const MX& x,
const MX& coeffs,
3476 const std::vector<MX>& knots,
3477 const std::vector<casadi_int>& degree,
3480 static MX convexify(
const MX& H,
const Dict& opts =
Dict());
3481 static MX stop_diff(
const MX& expr, casadi_int order);
3482 static MX stop_diff(
const MX& expr,
const MX& var, casadi_int order);
3483 static std::vector<MX> difference(
const std::vector<MX>& a,
const std::vector<MX>& b);
3490 static bool simplify_ref_count(std::vector<MX>& arg,
3491 std::vector<MX>& res,
3495 static bool simplify_const_folding(std::vector<MX>& arg,
3496 std::vector<MX>& res,
3500 static bool simplify_combine_terms(std::vector<MX>& arg,
3501 std::vector<MX>& res,
3554 static DM bspline_dual(
const std::vector<double>& x,
3555 const std::vector< std::vector<double> >& knots,
3556 const std::vector<casadi_int>& degree,
3624 static MX interpn_linear(
const std::vector<MX>& x,
const MX& v,
const std::vector<MX>& xq,
3669 #if !defined(SWIG) || defined(DOXYGEN)
3803 return MX::low(v, p, options);
3888 const std::vector<MX> &vdef) {
3893 const std::vector<MX> &vdef,
bool& updated) {
3934 inline friend std::vector<MX>
3936 const std::vector<MX> &v,
3937 const std::vector<MX> &vdef) {
3941 inline friend std::vector<MX>
3943 const std::vector<MX> &v,
3944 const std::vector<MX> &vdef,
4030 inline friend std::vector<MX>
4032 const std::vector<MX> &boundary = std::vector<MX>(),
4117 const std::vector< std::vector<double> >& knots,
4118 const std::vector<casadi_int>& degree,
4121 return MX::bspline(x, coeffs, knots, degree, m, opts);
4170 const std::vector< std::vector<double> >& knots,
4171 const std::vector<casadi_int>& degree,
4174 return MX::bspline(x, coeffs, knots, degree, m, opts);
4217 const std::vector<MX>& knots,
4218 const std::vector<casadi_int>& degree,
4221 return MX::bspline(x, coeffs, knots, degree, m, opts);
4226 const std::vector< std::vector<double> >& knots,
4227 const std::vector<casadi_int>& degree,
4674 inline friend std::vector<MX>
difference(
const std::vector<MX>& a,
const std::vector<MX>& b) {
4740 MX attachAssert(
const MX& y,
const std::string& fail_message=
"")
const;
4779 MX monitor(
const std::string& comment)
const;
4795 MX dump(
const std::string& base_filename,
const Dict& opts=
Dict())
const;
4798 void reset_dump_count();
4944 static void set_max_depth(casadi_int eq_depth=1);
4951 static casadi_int get_max_depth();
4994 static std::vector<MX> get_input(
const Function& f);
5050 static std::vector<MX> get_free(
const Function& f);
5110 void eval_mx(
const std::vector<MX>& arg, std::vector<MX>& SWIG_OUTPUT(res),
5111 const std::vector<bool>& unique=std::vector<bool>())
const;
5118 void ad_forward(
const std::vector<std::vector<MX> >& fseed,
5119 std::vector<std::vector<MX> >& fsens)
const;
5120 void ad_reverse(
const std::vector<std::vector<MX> >& aseed,
5121 std::vector<std::vector<MX> >& asens)
const;
5125 MX(
const Sparsity& sp,
double val,
bool dummy);
5128 static MX _sym(
const std::string& name,
const Sparsity& sp);
5130 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
5131 static std::mutex& get_mutex_temp() {
return mutex_temp; }
5132 static std::mutex mutex_temp;
5137 MX(
MXNode* node,
bool dummy1,
bool dummy2,
bool dummy3,
bool dummy4);
5140 static casadi_int eq_depth_;
5226 CASADI_EXPORT std::string
export_graph(
const std::vector<MX>& expressions,
5228 CASADI_EXPORT
void export_graph(
const MX& expression,
const std::string& fname,
5230 CASADI_EXPORT
void export_graph(
const std::vector<MX>& expressions,
const std::string& fname,
Helper class for Serialization.
Node class for MX objects.
void get_nz(MX &m, bool ind1, casadi_int kk) const
Get a set of nonzeros (what x.nz[k] does)
static MX lift(const MX &x, const MX &x_guess)
GenericMatrix< MX > B
Base class.
static std::vector< MX > difference(const std::vector< MX > &a, const std::vector< MX > &b)
static MX find(const MX &x)
static MX stop_diff(const MX &expr, casadi_int order)
Sparsity get_sparsity() const
Get an owning reference to the sparsity pattern.
MX operator+() const
Unary plus: returns the expression itself.
void set_nz(const MX &m, bool ind1, casadi_int kk)
Assign to a set of nonzeros (what x.nz[k] = m does)
static MX matrix_expand(const MX &e, const std::vector< MX > &boundary, const Dict &options)
void get(MX &m, bool ind1, const casadi_int rr) const
Get a submatrix by linear index (what x[k] does)
static DM evalf(const MX &m)
void get(MX &m, bool ind1, casadi_int rr, casadi_int cc) const
Get a submatrix by row and column index (what x[i, j] does)
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())
void get(MX &m, bool ind1, const Slice &rr, casadi_int cc) const
Get a submatrix by row and column index (what x[i, j] does)
static std::string type_name()
Get type name.
static MX inv_node(const MX &A)
static MX graph_substitute(const MX &x, const std::vector< MX > &v, const std::vector< MX > &vdef)
static MX kron_contract(const MX &m, const MX &x, bool inner)
std::map< std::string, MX > MXDict
Readability typedef.
static DM bspline_dual(const std::vector< double > &x, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > °ree, const Dict &opts=Dict())
Evaluate the B-spline basis functions at given points.
static MX convexify(const MX &H, const Dict &opts=Dict())
void get(MX &m, bool ind1, casadi_int rr, const Slice &cc) const
Get a submatrix by row and column index (what x[i, j] does)
static MX low(const MX &v, const MX &p, const Dict &options=Dict())
Helper class for Serialization.
GenericShared implements a reference counting framework similar for efficient and.
Class representing a Slice.
std::map< std::string, MX > MXDict
bool is_equal(double x, double y, casadi_int depth=0)
template class CASADI_EXPORT Matrix< double >
T norm_1(const std::vector< T > &x)
T norm_inf(const std::vector< T > &x)
double if_else(double x, double y, double z)
std::vector< casadi_int > find(const std::vector< T > &v)
find nonzeros
std::vector< MX > MXVector
void linspace(std::vector< T > &v, const F &first, const L &last)
Matlab's linspace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::vector< T > cumsum(const std::vector< T > &values)
cumulative sum
double printme(double x, double y)
std::vector< MXVector > MXVectorVector
CASADI_EXPORT std::string export_graph(const MX &expression, const Dict &opts=Dict())
Export expressions as .html, .dot, or .casadi_viz, defaulting to expression view.
T dot(const std::vector< T > &a, const std::vector< T > &b)
const double nan
Not a number.
MX kron_contract(const MX &m, const MX &x, bool inner)
Kronecker contraction, the adjoint of kron.
T norm_2(const std::vector< T > &x)
std::initializer_list< MX > MXIList
std::vector< T > reverse(const std::vector< T > &v)
Reverse a list.
bool is_regular(const std::vector< T > &v)
Checks if array does not contain NaN or Inf.
double simplify(double x)
std::vector< casadi_int > scc_offset
casadi_convexify_config< double > config
std::vector< casadi_int > scc_mapping