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;
88 class CASADI_EXPORT
MX :
89 public SWIG_IF_ELSE(GenericExpressionCommon, GenericExpression<MX>),
90 public SWIG_IF_ELSE(PrintableCommon, Printable<MX>),
107 MX(casadi_int nrow, casadi_int ncol);
113 explicit MX(
const std::pair<casadi_int, casadi_int>& rc);
131 MX(
const Sparsity& sp,
const std::string& fname);
150 MX(
const std::vector<double> &x);
175 static std::vector<MX> createMultipleOutput(
MXNode* node);
200 bool __nonzero__()
const;
220 std::vector<MX> get_nonzeros()
const;
227 void erase(
const std::vector<casadi_int>& rr,
const std::vector<casadi_int>& cc,
235 void erase(
const std::vector<casadi_int>& rr,
bool ind1=
false);
242 void enlarge(casadi_int nrow, casadi_int ncol,
243 const std::vector<casadi_int>& rr,
const std::vector<casadi_int>& cc,
246 MX operator-()
const;
265 const MXNode* operator->()
const;
273 MX dep(casadi_int ch=0)
const;
278 casadi_int n_out()
const;
283 MX get_output(casadi_int oind)
const;
288 casadi_int n_dep()
const;
291 std::string name()
const;
294 explicit operator double()
const;
300 bool is_symbolic()
const;
303 bool is_constant()
const;
306 bool is_integer()
const;
311 bool is_doubled()
const;
314 bool is_call()
const;
320 bool is_output()
const;
325 bool has_output()
const;
328 casadi_int which_output()
const;
331 bool is_op(casadi_int op)
const;
334 bool is_multiplication()
const;
337 bool is_commutative()
const;
340 bool is_norm()
const;
347 bool is_valid_input()
const;
352 casadi_int n_primitives()
const;
357 std::vector<MX> primitives()
const;
363 std::vector<MX> split_primitives(
const MX& x)
const;
364 std::vector<SX> split_primitives(
const SX& x)
const;
365 std::vector<DM> split_primitives(
const DM& x)
const;
372 MX join_primitives(
const std::vector<MX>& v)
const;
373 SX join_primitives(
const std::vector<SX>& v)
const;
374 DM join_primitives(
const std::vector<DM>& v)
const;
386 bool has_duplicates()
const;
391 void reset_input()
const;
412 bool is_minus_one()
const;
417 bool is_half()
const;
422 bool is_value(
double val)
const;
432 bool is_minus_inf()
const;
437 bool is_transpose()
const;
443 bool is_binary()
const;
448 bool is_nonnegative()
const;
451 bool is_unary()
const;
454 casadi_int op()
const;
471 casadi_int get_temp()
const;
474 void set_temp(casadi_int t)
const;
481 static MX binary(casadi_int op,
const MX &x,
const MX &y,
482 bool unique_x=
false,
bool unique_y=
false);
483 static MX unary(casadi_int op,
const MX &x,
bool unique=
false);
491 static MX inf(casadi_int nrow=1, casadi_int ncol=1);
492 static MX inf(
const std::pair<casadi_int, casadi_int>& rc);
500 static MX nan(casadi_int nrow=1, casadi_int ncol=1);
501 static MX nan(
const std::pair<casadi_int, casadi_int>& rc);
507 static MX eye(casadi_int n);
520 MX nzref(
const Sparsity& sp,
const std::vector<casadi_int>& nz)
const;
525 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& rr)
const;
527 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Sparsity& sp)
const;
528 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& rr)
const;
529 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const casadi_int rr)
const {
536 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& rr,
const Slice& cc)
const;
538 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& rr, casadi_int cc)
const {
542 void get(
MX& SWIG_OUTPUT(m),
bool ind1, casadi_int rr,
const Slice& cc)
const {
547 void get(
MX& SWIG_OUTPUT(m),
bool ind1, casadi_int rr,
548 casadi_int cc)
const {
551 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& rr,
const Slice& cc)
const;
552 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& rr,
const MX& cc)
const;
553 void get(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& rr,
const MX& cc)
const;
558 void set(
const MX& m,
bool ind1,
const Slice& rr);
560 void set(
const MX& m,
bool ind1,
const Sparsity& sp);
565 void set(
const MX& m,
bool ind1,
const Slice& rr,
const Slice& cc);
573 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& kk)
const;
575 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& kk)
const;
576 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1, casadi_int kk)
const {
579 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& inner,
const Slice& outer)
const;
580 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const Slice& inner,
const MX& outer)
const;
581 void get_nz(
MX& SWIG_OUTPUT(m),
bool ind1,
const MX& inner,
const MX& outer)
const;
586 void set_nz(
const MX& m,
bool ind1,
const Slice& kk);
588 void set_nz(
const MX& m,
bool ind1,
const MX& kk);
607 static MX einstein(
const MX& A,
const MX& B,
const MX& C,
608 const std::vector<casadi_int>& dim_a,
const std::vector<casadi_int>& dim_b,
609 const std::vector<casadi_int>& dim_c,
610 const std::vector<casadi_int>& a,
const std::vector<casadi_int>& b,
611 const std::vector<casadi_int>& c);
613 static MX einstein(
const MX& A,
const MX& B,
614 const std::vector<casadi_int>& dim_a,
const std::vector<casadi_int>& dim_b,
615 const std::vector<casadi_int>& dim_c,
616 const std::vector<casadi_int>& a,
const std::vector<casadi_int>& b,
617 const std::vector<casadi_int>& c);
624 static bool is_equal(
const MX& x,
const MX& y, casadi_int depth=0);
625 static MX mmin(
const MX &x);
626 static MX mmax(
const MX &x);
631 static MX horzcat(
const std::vector<MX>& x);
632 static MX diagcat(
const std::vector<MX>& x);
633 static MX vertcat(
const std::vector<MX>& x);
634 static std::vector<MX> horzsplit(
const MX& x,
const std::vector<casadi_int>& offset);
635 static std::vector<MX> diagsplit(
const MX& x,
const std::vector<casadi_int>& offset1,
636 const std::vector<casadi_int>& offset2);
637 static std::vector<MX> vertsplit(
const MX& x,
const std::vector<casadi_int>& offset);
638 static MX blockcat(
const std::vector< std::vector<MX > > &v);
639 static MX mtimes(
const MX& x,
const MX& y,
640 const std::string& blas =
"reference");
641 static MX mac(
const MX& x,
const MX& y,
const MX& z,
642 const std::string& blas =
"reference");
643 static MX reshape(
const MX& x, casadi_int nrow, casadi_int ncol);
645 static MX sparsity_cast(
const MX& x,
const Sparsity& sp);
646 static MX kron(
const MX& x,
const MX& b);
648 static MX repmat(
const MX& x, casadi_int n, casadi_int m=1);
654 static MX jacobian(
const MX& f,
const MX& x,
const Dict& opts =
Dict());
655 static MX hessian(
const MX& f,
const MX& x,
const Dict& opts =
Dict());
656 static MX hessian(
const MX& f,
const MX& x,
MX& g,
const Dict& opts =
Dict());
657 static std::vector<std::vector<MX> >
658 forward(
const std::vector<MX> &ex,
659 const std::vector<MX> &arg,
660 const std::vector<std::vector<MX> > &v,
662 static std::vector<std::vector<MX> >
663 reverse(
const std::vector<MX> &ex,
664 const std::vector<MX> &arg,
665 const std::vector<std::vector<MX> > &v,
667 static std::vector<bool> which_depends(
const MX &expr,
const MX &var,
668 casadi_int order=1,
bool tr=
false);
669 static Sparsity jacobian_sparsity(
const MX& f,
const MX& x);
670 static MX substitute(
const MX& ex,
const MX& v,
const MX& vdef);
671 static std::vector<MX> substitute(
const std::vector<MX> &ex,
672 const std::vector<MX> &v,
673 const std::vector<MX> &vdef);
674 static void substitute_inplace(
const std::vector<MX>& v,
675 std::vector<MX>& vdef,
676 std::vector<MX>& ex,
bool reverse);
677 static MX solve(
const MX& a,
const MX& b);
678 static MX solve(
const MX& a,
const MX& b,
const std::string& lsolver,
680 static MX inv_minor(
const MX& A);
681 static MX inv_node(
const MX& A);
682 static MX inv(
const MX& A,
const std::string& lsolver=
"qr",
const Dict& dict =
Dict());
683 static MX pinv(
const MX& A,
const std::string& lsolver=
"qr",
685 static MX expm_const(
const MX& A,
const MX& t);
686 static MX expm(
const MX& A);
687 static casadi_int n_nodes(
const MX& x);
688 static std::string print_operator(
const MX& x,
const std::vector<std::string>& args);
689 static void extract(std::vector<MX>& ex, std::vector<MX>& v,
690 std::vector<MX>& vdef,
const Dict& opts =
Dict());
691 static void shared(std::vector<MX>& ex, std::vector<MX>& v,
692 std::vector<MX>& vdef,
const std::string& v_prefix,
const std::string& v_suffix);
694 const MX& if_false,
bool short_circuit=
false);
695 static MX conditional(
const MX& ind,
const std::vector<MX> &x,
const MX& x_default,
696 bool short_circuit=
false);
697 static bool depends_on(
const MX& x,
const MX& arg);
698 static bool contains_all(
const std::vector<MX>& v,
const std::vector<MX> &n);
699 static bool contains_any(
const std::vector<MX>& v,
const std::vector<MX> &n);
701 static MX transform(
const MX& x,
const Dict& opts =
Dict());
702 static MX transform(
const MX& x,
703 const std::vector<std::vector<GenericType> >& passes,
const Dict& opts =
Dict());
704 static std::vector<MX> transform(
const std::vector<MX>& x,
const Dict& opts =
Dict());
705 static std::vector<MX> transform(
const std::vector<MX>& x,
706 const std::vector<std::vector<GenericType> >& passes,
const Dict& opts =
Dict());
708 static MX mrdivide(
const MX& a,
const MX& b);
709 static MX mldivide(
const MX& a,
const MX& b);
711 static MX norm_fro(
const MX& x);
714 static MX unite(
const MX& A,
const MX& B);
715 static MX trace(
const MX& x);
716 static MX diag(
const MX& x);
717 static MX sum2(
const MX& x);
718 static MX sum1(
const MX& x);
719 static MX polyval(
const MX& p,
const MX& x);
720 static MX det(
const MX& x);
721 static MX det(
const MX& x,
const std::string& lsolver,
const Dict& opts=
Dict());
722 static std::vector<MX> symvar(
const MX& x);
723 static MX nullspace(
const MX& A);
724 static MX repsum(
const MX& x, casadi_int n, casadi_int m=1);
725 static MX densify(
const MX& x,
const MX& val=0);
726 static MX _bilin(
const MX& A,
const MX& x,
const MX& y);
727 static MX _rank1(
const MX& A,
const MX& alpha,
const MX& x,
const MX& y);
728 static MX project(
const MX& x,
const Sparsity& sp,
bool intersect=
false);
729 static MX cumsum(
const MX &x, casadi_int axis=-1);
730 static MX _logsumexp(
const MX& x);
731 static std::vector<MX> cse(
const std::vector<MX>& e);
732 static void extract_parametric(
const MX &expr,
const MX& par,
733 MX& expr_ret, std::vector<MX>& symbols, std::vector<MX>& parametric,
const Dict& opts);
734 static void separate_linear(
const MX &expr,
735 const MX &sym_lin,
const MX &sym_const,
736 MX& expr_const,
MX& expr_lin,
MX& expr_nonlin);
742 static MX low(
const MX& v,
const MX& p,
const Dict& options =
Dict());
743 static MX graph_substitute(
const MX& x,
const std::vector<MX> &v,
744 const std::vector<MX> &vdef);
745 static MX graph_substitute(
const MX& x,
const std::vector<MX> &v,
746 const std::vector<MX> &vdef,
bool& updated);
747 static std::vector<MX> graph_substitute(
const std::vector<MX> &ex,
748 const std::vector<MX> &v,
749 const std::vector<MX> &vdef);
750 static std::vector<MX> graph_substitute(
const std::vector<MX> &ex,
751 const std::vector<MX> &v,
752 const std::vector<MX> &vdef,
754 static MX matrix_expand(
const MX& e,
const std::vector<MX> &boundary,
755 const Dict& options);
756 static std::vector<MX> matrix_expand(
const std::vector<MX>& e,
757 const std::vector<MX>& boundary,
758 const Dict& options);
759 static MX lift(
const MX& x,
const MX& x_guess);
760 static DM evalf(
const MX& m);
761 static MX bspline(
const MX& x,
763 const std::vector< std::vector<double> >& knots,
764 const std::vector<casadi_int>& degree,
767 static MX bspline(
const MX& x,
const MX& coeffs,
768 const std::vector< std::vector<double> >& knots,
769 const std::vector<casadi_int>& degree,
772 static MX bspline(
const MX& x,
const MX& coeffs,
773 const std::vector<MX>& knots,
774 const std::vector<casadi_int>& degree,
777 static MX convexify(
const MX& H,
const Dict& opts =
Dict());
778 static MX stop_diff(
const MX& expr, casadi_int order);
779 static MX stop_diff(
const MX& expr,
const MX& var, casadi_int order);
780 static std::vector<MX> difference(
const std::vector<MX>& a,
const std::vector<MX>& b);
787 static bool simplify_ref_count(std::vector<MX>& arg,
788 std::vector<MX>& res,
792 static bool simplify_const_folding(std::vector<MX>& arg,
793 std::vector<MX>& res,
797 static bool simplify_combine_terms(std::vector<MX>& arg,
798 std::vector<MX>& res,
801 static DM bspline_dual(
const std::vector<double>& x,
802 const std::vector< std::vector<double> >& knots,
803 const std::vector<casadi_int>& degree,
813 static MX interpn_linear(
const std::vector<MX>& x,
const MX& v,
const std::vector<MX>& xq,
818 #if !defined(SWIG) || defined(DOXYGEN)
847 const std::vector<MX> &vdef) {
852 const std::vector<MX> &vdef,
bool& updated) {
862 inline friend std::vector<MX>
864 const std::vector<MX> &v,
865 const std::vector<MX> &vdef) {
869 inline friend std::vector<MX>
871 const std::vector<MX> &v,
872 const std::vector<MX> &vdef,
895 inline friend std::vector<MX>
897 const std::vector<MX> &boundary = std::vector<MX>(),
905 const std::vector< std::vector<double> >& knots,
906 const std::vector<casadi_int>& degree,
909 return MX::bspline(x, coeffs, knots, degree, m, opts);
913 const std::vector< std::vector<double> >& knots,
914 const std::vector<casadi_int>& degree,
917 return MX::bspline(x, coeffs, knots, degree, m, opts);
921 const std::vector<MX>& knots,
922 const std::vector<casadi_int>& degree,
925 return MX::bspline(x, coeffs, knots, degree, m, opts);
929 const std::vector< std::vector<double> >& knots,
930 const std::vector<casadi_int>& degree,
999 inline friend std::vector<MX>
difference(
const std::vector<MX>& a,
const std::vector<MX>& b) {
1011 MX attachAssert(
const MX& y,
const std::string& fail_message=
"")
const;
1018 MX monitor(
const std::string& comment)
const;
1027 MX dump(
const std::string& base_filename,
const Dict& opts=
Dict())
const;
1030 void reset_dump_count();
1043 static void set_max_depth(casadi_int eq_depth=1);
1048 static casadi_int get_max_depth();
1056 static std::vector<MX> get_input(
const Function& f);
1061 static std::vector<MX> get_free(
const Function& f);
1069 void eval_mx(
const std::vector<MX>& arg, std::vector<MX>& SWIG_OUTPUT(res),
1070 const std::vector<bool>& unique=std::vector<bool>())
const;
1077 void ad_forward(
const std::vector<std::vector<MX> >& fseed,
1078 std::vector<std::vector<MX> >& fsens)
const;
1079 void ad_reverse(
const std::vector<std::vector<MX> >& aseed,
1080 std::vector<std::vector<MX> >& asens)
const;
1084 MX(
const Sparsity& sp,
double val,
bool dummy);
1087 static MX _sym(
const std::string& name,
const Sparsity& sp);
1089 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
1090 static std::mutex& get_mutex_temp() {
return mutex_temp; }
1091 static std::mutex mutex_temp;
1096 MX(
MXNode* node,
bool dummy1,
bool dummy2,
bool dummy3,
bool dummy4);
1099 static casadi_int eq_depth_;
Helper class for Serialization.
Node class for MX objects.
void get_nz(MX &m, bool ind1, casadi_int kk) const
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.
void set_nz(const MX &m, bool ind1, casadi_int kk)
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
static DM evalf(const MX &m)
void get(MX &m, bool ind1, casadi_int rr, casadi_int cc) const
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
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())
static MX convexify(const MX &H, const Dict &opts=Dict())
void get(MX &m, bool ind1, casadi_int rr, const Slice &cc) const
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
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.
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