mx.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_MX_HPP
27 #define CASADI_MX_HPP
28 #include "shared_object.hpp"
29 #include "matrix_fwd.hpp"
30 #include "sx_fwd.hpp"
31 #include "dm.hpp"
32 #include "generic_matrix.hpp"
33 #include "generic_expression.hpp"
34 #include "generic_type.hpp"
35 #include "printable.hpp"
36 #include <vector>
37 #ifdef CASADI_WITH_THREAD
38 #ifdef CASADI_WITH_THREAD_MINGW
39 #include <mingw.mutex.h>
40 #else // CASADI_WITH_THREAD_MINGW
41 #include <mutex>
42 #endif // CASADI_WITH_THREAD_MINGW
43 #endif //CASADI_WITH_THREAD
44 
45 namespace casadi {
46 
50  class MXNode;
51  class Function;
52  class SerializingStream;
53  class DeserializingStream;
54 
55 #ifndef SWIG
56  struct ConvexifyData {
57  std::vector<casadi_int> scc_offset, scc_mapping;
62  casadi_int sz_iw;
63  casadi_int sz_w;
64  casadi_int *iw;
65  double* w;
66  };
67 #endif
68 
88  class CASADI_EXPORT MX :
89  public SWIG_IF_ELSE(GenericExpressionCommon, GenericExpression<MX>),
90  public SWIG_IF_ELSE(PrintableCommon, Printable<MX>),
91  public GenericMatrix<MX>,
92  public SharedObject {
93  public:
97  static std::string type_name() {return "MX";}
98 
102  MX();
103 
107  MX(casadi_int nrow, casadi_int ncol);
108 
109 #ifndef SWIG
113  explicit MX(const std::pair<casadi_int, casadi_int>& rc);
114 #endif // SWIG
115 
121  explicit MX(const Sparsity& sp);
122 
126  MX(const Sparsity& sp, const MX& val);
127 
131  MX(const Sparsity& sp, const std::string& fname);
132 
133 
139  MX(const Matrix<double>& val, const std::string& name);
140 
144  MX(double x);
145 
146 #ifndef SWIG
150  MX(const std::vector<double> &x);
151 #endif
152 
156  MX(const Matrix<double> &x);
157 
159 
162  ~MX();
164 
165 #ifndef SWIG
167 
170  static MX create(MXNode* node);
171 
175  static std::vector<MX> createMultipleOutput(MXNode* node);
177 
181  const Sparsity& sparsity() const;
182 
185  typedef MX ScalarType;
187 
190 
192  using B::horzsplit;
193  using B::diagsplit;
194  using B::vertsplit;
195  using B::mtimes;
196  using B::repmat;
197 #endif // SWIG
198 
200  bool __nonzero__() const;
201 
205  Sparsity get_sparsity() const { return sparsity();}
206 
220  std::vector<MX> get_nonzeros() const;
221 
227  void erase(const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
228  bool ind1=false);
229 
235  void erase(const std::vector<casadi_int>& rr, bool ind1=false);
236 
242  void enlarge(casadi_int nrow, casadi_int ncol,
243  const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
244  bool ind1=false);
245 
246  MX operator-() const;
247 
248 #ifndef SWIG
251 
254  MXNode* operator->();
255 
259  const MXNode* operator->() const;
262 #endif // SWIG
263 
267  MX dep(casadi_int ch=0) const;
268 
272  casadi_int n_out() const;
273 
277  MX get_output(casadi_int oind) const;
278 
282  casadi_int n_dep() const;
283 
285  std::string name() const;
286 
288  explicit operator double() const;
289 
291  explicit operator Matrix<double>() const;
292 
294  bool is_symbolic() const;
295 
297  bool is_constant() const;
298 
300  bool is_call() const;
301 
303  Function which_function() const;
304 
306  bool is_output() const;
307 
311  bool has_output() const;
312 
314  casadi_int which_output() const;
315 
317  bool is_op(casadi_int op) const;
318 
320  bool is_multiplication() const;
321 
323  bool is_commutative() const;
324 
326  bool is_norm() const;
327 
333  bool is_valid_input() const;
334 
338  casadi_int n_primitives() const;
339 
343  std::vector<MX> primitives() const;
344 
346 
349  std::vector<MX> split_primitives(const MX& x) const;
350  std::vector<SX> split_primitives(const SX& x) const;
351  std::vector<DM> split_primitives(const DM& x) const;
353 
355 
358  MX join_primitives(const std::vector<MX>& v) const;
359  SX join_primitives(const std::vector<SX>& v) const;
360  DM join_primitives(const std::vector<DM>& v) const;
362 
364 
372  bool has_duplicates() const;
373 
377  void reset_input() const;
379 
383  bool is_eye() const;
384 
388  bool is_zero() const;
389 
393  bool is_one() const;
394 
398  bool is_minus_one() const;
399 
403  bool is_transpose() const;
404 
406  bool is_regular() const;
407 
409  bool is_binary() const;
410 
412  bool is_unary() const;
413 
415  casadi_int op() const;
416 
418  Dict info() const;
419 
423  void serialize(SerializingStream& s) const;
424 
428  static MX deserialize(DeserializingStream& s);
429 
432  casadi_int get_temp() const;
433 
435  void set_temp(casadi_int t) const;
437 
439 
442  static MX binary(casadi_int op, const MX &x, const MX &y);
443  static MX unary(casadi_int op, const MX &x);
445 
447 
450  static MX inf(const Sparsity& sp);
451  static MX inf(casadi_int nrow=1, casadi_int ncol=1);
452  static MX inf(const std::pair<casadi_int, casadi_int>& rc);
454 
456 
459  static MX nan(const Sparsity& sp);
460  static MX nan(casadi_int nrow=1, casadi_int ncol=1);
461  static MX nan(const std::pair<casadi_int, casadi_int>& rc);
463 
467  static MX eye(casadi_int n);
468 
469 #ifndef SWIG
471  MXNode* get() const;
472 #endif // SWIG
473 
476  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr) const;
477  void get(MX& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& rr) const;
478  void get(MX& SWIG_OUTPUT(m), bool ind1, const Sparsity& sp) const;
479  void get(MX& SWIG_OUTPUT(m), bool ind1, const MX& rr) const;
480  void get(MX& SWIG_OUTPUT(m), bool ind1, const casadi_int rr) const {
481  get(m, ind1, Matrix<casadi_int>(rr));
482  }
484 
487  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr, const Slice& cc) const;
488  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr, const Matrix<casadi_int>& cc) const;
489  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr, casadi_int cc) const {
490  get(m, ind1, rr, Matrix<casadi_int>(cc));
491  }
492  void get(MX& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& rr, const Slice& cc) const;
493  void get(MX& SWIG_OUTPUT(m), bool ind1, casadi_int rr, const Slice& cc) const {
494  get(m, ind1, Matrix<casadi_int>(rr), cc);
495  }
496  void get(MX& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& rr,
497  const Matrix<casadi_int>& cc) const;
498  void get(MX& SWIG_OUTPUT(m), bool ind1, casadi_int rr,
499  casadi_int cc) const {
500  get(m, ind1, Matrix<casadi_int>(rr), Matrix<casadi_int>(cc));
501  }
502  void get(MX& SWIG_OUTPUT(m), bool ind1, const MX& rr, const Slice& cc) const;
503  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr, const MX& cc) const;
504  void get(MX& SWIG_OUTPUT(m), bool ind1, const MX& rr, const MX& cc) const;
506 
509  void set(const MX& m, bool ind1, const Slice& rr);
510  void set(const MX& m, bool ind1, const Matrix<casadi_int>& rr);
511  void set(const MX& m, bool ind1, const Sparsity& sp);
513 
516  void set(const MX& m, bool ind1, const Slice& rr, const Slice& cc);
517  void set(const MX& m, bool ind1, const Slice& rr, const Matrix<casadi_int>& cc);
518  void set(const MX& m, bool ind1, const Matrix<casadi_int>& rr, const Slice& cc);
519  void set(const MX& m, bool ind1, const Matrix<casadi_int>& rr, const Matrix<casadi_int>& cc);
521 
524  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const Slice& kk) const;
525  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& kk) const;
526  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const MX& kk) const;
527  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, casadi_int kk) const {
528  get_nz(m, ind1, Matrix<casadi_int>(kk));
529  }
530  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const MX& inner, const Slice& outer) const;
531  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const Slice& inner, const MX& outer) const;
532  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const MX& inner, const MX& outer) const;
534 
537  void set_nz(const MX& m, bool ind1, const Slice& kk);
538  void set_nz(const MX& m, bool ind1, const Matrix<casadi_int>& kk);
539  void set_nz(const MX& m, bool ind1, const MX& kk);
540  void set_nz(const MX& m, bool ind1, casadi_int kk) { set_nz(m, ind1, Matrix<casadi_int>(kk)); }
542 
544 
558  static MX einstein(const MX& A, const MX& B, const MX& C,
559  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
560  const std::vector<casadi_int>& dim_c,
561  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
562  const std::vector<casadi_int>& c);
563 
564  static MX einstein(const MX& A, const MX& B,
565  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
566  const std::vector<casadi_int>& dim_c,
567  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
568  const std::vector<casadi_int>& c);
570 
571 #ifndef SWIG
575  static bool is_equal(const MX& x, const MX& y, casadi_int depth=0);
576  static MX mmin(const MX &x);
577  static MX mmax(const MX &x);
579 
582  static MX horzcat(const std::vector<MX>& x);
583  static MX diagcat(const std::vector<MX>& x);
584  static MX vertcat(const std::vector<MX>& x);
585  static std::vector<MX> horzsplit(const MX& x, const std::vector<casadi_int>& offset);
586  static std::vector<MX> diagsplit(const MX& x, const std::vector<casadi_int>& offset1,
587  const std::vector<casadi_int>& offset2);
588  static std::vector<MX> vertsplit(const MX& x, const std::vector<casadi_int>& offset);
589  static MX blockcat(const std::vector< std::vector<MX > > &v);
590  static MX mtimes(const MX& x, const MX& y);
591  static MX mac(const MX& x, const MX& y, const MX& z);
592  static MX reshape(const MX& x, casadi_int nrow, casadi_int ncol);
593  static MX reshape(const MX& x, const Sparsity& sp);
594  static MX sparsity_cast(const MX& x, const Sparsity& sp);
595  static MX kron(const MX& x, const MX& b);
596  static MX repmat(const MX& x, casadi_int n, casadi_int m=1);
598 
601  static MX jacobian(const MX& f, const MX& x, const Dict& opts = Dict());
602  static MX hessian(const MX& f, const MX& x, const Dict& opts = Dict());
603  static MX hessian(const MX& f, const MX& x, MX& g, const Dict& opts = Dict());
604  static std::vector<std::vector<MX> >
605  forward(const std::vector<MX> &ex,
606  const std::vector<MX> &arg,
607  const std::vector<std::vector<MX> > &v,
608  const Dict& opts = Dict());
609  static std::vector<std::vector<MX> >
610  reverse(const std::vector<MX> &ex,
611  const std::vector<MX> &arg,
612  const std::vector<std::vector<MX> > &v,
613  const Dict& opts = Dict());
614  static std::vector<bool> which_depends(const MX &expr, const MX &var,
615  casadi_int order=1, bool tr=false);
616  static Sparsity jacobian_sparsity(const MX& f, const MX& x);
617  static MX substitute(const MX& ex, const MX& v, const MX& vdef);
618  static std::vector<MX> substitute(const std::vector<MX> &ex,
619  const std::vector<MX> &v,
620  const std::vector<MX> &vdef);
621  static void substitute_inplace(const std::vector<MX>& v,
622  std::vector<MX>& vdef,
623  std::vector<MX>& ex, bool reverse);
624  static MX solve(const MX& a, const MX& b);
625  static MX solve(const MX& a, const MX& b, const std::string& lsolver,
626  const Dict& dict = Dict());
627  static MX inv_minor(const MX& A);
628  static MX inv_node(const MX& A);
629  static MX inv(const MX& A, const std::string& lsolver="qr", const Dict& dict = Dict());
630  static MX pinv(const MX& A, const std::string& lsolver="qr",
631  const Dict& dict = Dict());
632  static MX expm_const(const MX& A, const MX& t);
633  static MX expm(const MX& A);
634  static casadi_int n_nodes(const MX& x);
635  static std::string print_operator(const MX& x, const std::vector<std::string>& args);
636  static void extract(std::vector<MX>& ex, std::vector<MX>& v,
637  std::vector<MX>& vdef, const Dict& opts = Dict());
638  static void shared(std::vector<MX>& ex, std::vector<MX>& v,
639  std::vector<MX>& vdef, const std::string& v_prefix, const std::string& v_suffix);
640  static MX if_else(const MX& cond, const MX& if_true,
641  const MX& if_false, bool short_circuit=false);
642  static MX conditional(const MX& ind, const std::vector<MX> &x, const MX& x_default,
643  bool short_circuit=false);
644  static bool depends_on(const MX& x, const MX& arg);
645  static bool contains_all(const std::vector<MX>& v, const std::vector<MX> &n);
646  static bool contains_any(const std::vector<MX>& v, const std::vector<MX> &n);
647  static MX simplify(const MX& x);
648  static MX dot(const MX& x, const MX& y);
649  static MX mrdivide(const MX& a, const MX& b);
650  static MX mldivide(const MX& a, const MX& b);
651  static MX norm_2(const MX& x);
652  static MX norm_fro(const MX& x);
653  static MX norm_1(const MX& x);
654  static MX norm_inf(const MX& x);
655  static MX unite(const MX& A, const MX& B);
656  static MX trace(const MX& x);
657  static MX diag(const MX& x);
658  static MX sum2(const MX& x);
659  static MX sum1(const MX& x);
660  static MX polyval(const MX& p, const MX& x);
661  static MX det(const MX& x);
662  static std::vector<MX> symvar(const MX& x);
663  static MX nullspace(const MX& A);
664  static MX repsum(const MX& x, casadi_int n, casadi_int m=1);
665  static MX densify(const MX& x, const MX& val=0);
666  static MX _bilin(const MX& A, const MX& x, const MX& y);
667  static MX _rank1(const MX& A, const MX& alpha, const MX& x, const MX& y);
668  static MX project(const MX& x, const Sparsity& sp, bool intersect=false);
669  static MX cumsum(const MX &x, casadi_int axis=-1);
670  static MX _logsumexp(const MX& x);
671  static std::vector<MX> cse(const std::vector<MX>& e);
672  static void extract_parametric(const MX &expr, const MX& par,
673  MX& expr_ret, std::vector<MX>& symbols, std::vector<MX>& parametric, const Dict& opts);
674  static void separate_linear(const MX &expr,
675  const MX &sym_lin, const MX &sym_const,
676  MX& expr_const, MX& expr_lin, MX& expr_nonlin);
678 
681  static MX find(const MX& x);
682  static MX low(const MX& v, const MX& p, const Dict& options = Dict());
683  static MX graph_substitute(const MX& x, const std::vector<MX> &v,
684  const std::vector<MX> &vdef);
685  static MX graph_substitute(const MX& x, const std::vector<MX> &v,
686  const std::vector<MX> &vdef, bool& updated);
687  static std::vector<MX> graph_substitute(const std::vector<MX> &ex,
688  const std::vector<MX> &v,
689  const std::vector<MX> &vdef);
690  static std::vector<MX> graph_substitute(const std::vector<MX> &ex,
691  const std::vector<MX> &v,
692  const std::vector<MX> &vdef,
693  bool& updated);
694  static MX matrix_expand(const MX& e, const std::vector<MX> &boundary,
695  const Dict& options);
696  static std::vector<MX> matrix_expand(const std::vector<MX>& e,
697  const std::vector<MX>& boundary,
698  const Dict& options);
699  static MX lift(const MX& x, const MX& x_guess);
700  static DM evalf(const MX& m);
701  static MX bspline(const MX& x,
702  const DM& coeffs,
703  const std::vector< std::vector<double> >& knots,
704  const std::vector<casadi_int>& degree,
705  casadi_int m,
706  const Dict& opts = Dict());
707  static MX bspline(const MX& x, const MX& coeffs,
708  const std::vector< std::vector<double> >& knots,
709  const std::vector<casadi_int>& degree,
710  casadi_int m,
711  const Dict& opts = Dict());
712  static MX convexify(const MX& H, const Dict& opts = Dict());
713  static MX stop_diff(const MX& expr, casadi_int order);
714  static MX stop_diff(const MX& expr, const MX& var, casadi_int order);
715  static std::vector<MX> difference(const std::vector<MX>& a, const std::vector<MX>& b);
718 
719 #endif // SWIG
720 
721  static DM bspline_dual(const std::vector<double>& x,
722  const std::vector< std::vector<double> >& knots,
723  const std::vector<casadi_int>& degree,
724  const Dict& opts = Dict());
725 
733  static MX interpn_linear(const std::vector<MX>& x, const MX& v, const std::vector<MX>& xq,
734  const Dict& opts=Dict());
735 
736  MX printme(const MX& b) const;
737 
738 #if !defined(SWIG) || defined(DOXYGEN)
748  inline friend MX find(const MX& x) {
749  return MX::find(x);
750  }
751 
757  inline friend MX low(const MX& v, const MX& p, const Dict& options=Dict()) {
758  return MX::low(v, p, options);
759  }
760 
766  inline friend MX graph_substitute(const MX& ex, const std::vector<MX> &v,
767  const std::vector<MX> &vdef) {
768  return MX::graph_substitute(ex, v, vdef);
769  }
770 
771  inline friend MX graph_substitute(const MX& ex, const std::vector<MX> &v,
772  const std::vector<MX> &vdef, bool& updated) {
773  return MX::graph_substitute(ex, v, vdef, updated);
774  }
775 
782  inline friend std::vector<MX>
783  graph_substitute(const std::vector<MX> &ex,
784  const std::vector<MX> &v,
785  const std::vector<MX> &vdef) {
786  return MX::graph_substitute(ex, v, vdef);
787  }
788 
789  inline friend std::vector<MX>
790  graph_substitute(const std::vector<MX> &ex,
791  const std::vector<MX> &v,
792  const std::vector<MX> &vdef,
793  bool& updated) {
794  return MX::graph_substitute(ex, v, vdef, updated);
795  }
796 
803  inline friend MX
804  matrix_expand(const MX& e, const std::vector<MX> &boundary = std::vector<MX>(),
805  const Dict& options = Dict()) {
806  return MX::matrix_expand(e, boundary, options);
807  }
808 
815  inline friend std::vector<MX>
816  matrix_expand(const std::vector<MX>& e,
817  const std::vector<MX> &boundary = std::vector<MX>(),
818  const Dict& options = Dict()) {
819  return MX::matrix_expand(e, boundary, options);
820  }
821 
822 
823  inline friend MX bspline(const MX& x,
824  const DM& coeffs,
825  const std::vector< std::vector<double> >& knots,
826  const std::vector<casadi_int>& degree,
827  casadi_int m,
828  const Dict& opts = Dict()) {
829  return MX::bspline(x, coeffs, knots, degree, m, opts);
830  }
831 
832  inline friend MX bspline(const MX& x, const MX& coeffs,
833  const std::vector< std::vector<double> >& knots,
834  const std::vector<casadi_int>& degree,
835  casadi_int m,
836  const Dict& opts = Dict()) {
837  return MX::bspline(x, coeffs, knots, degree, m, opts);
838  }
839 
840  inline friend DM bspline_dual(const std::vector<double>& x,
841  const std::vector< std::vector<double> >& knots,
842  const std::vector<casadi_int>& degree,
843  const Dict& opts = Dict()) {
844  return MX::bspline_dual(x, knots, degree, opts);
845  }
846 
847  inline friend MX convexify(const MX& H,
848  const Dict& opts = Dict()) {
849  return MX::convexify(H, opts);
850  }
851 
857  inline friend MX lift(const MX& x, const MX& x_guess) {
858  return MX::lift(x, x_guess);
859  }
860 
864  inline friend MX inv_node(const MX& x) {
865  return MX::inv_node(x);
866  }
867 
873  inline friend DM evalf(const MX& expr) {
874  return MX::evalf(expr);
875  }
876 
880  inline friend MX stop_diff(const MX& expr, casadi_int order) {
881  return MX::stop_diff(expr, order);
882  }
883 
889  inline friend MX no_grad(const MX& expr) {
890  return MX::stop_diff(expr, 1);
891  }
892 
898  inline friend MX no_hess(const MX& expr) {
899  return MX::stop_diff(expr, 2);
900  }
901 
902 
906  inline friend MX stop_diff(const MX& expr, const MX& var, casadi_int order) {
907  return MX::stop_diff(expr, var, order);
908  }
909 
911  inline friend std::vector<MX> difference(const std::vector<MX>& a, const std::vector<MX>& b) {
912  return MX::difference(a, b);
913  }
914 
916 #endif // SWIG
917 
923  MX attachAssert(const MX& y, const std::string& fail_message="") const;
924 
930  MX monitor(const std::string& comment) const;
931 
933  MX T() const;
934 
938  Matrix<casadi_int> mapping() const;
939 
943  static void set_max_depth(casadi_int eq_depth=1);
944 
948  static casadi_int get_max_depth();
949 
951  static bool test_cast(const SharedObjectInternal* ptr);
952 
956  static std::vector<MX> get_input(const Function& f);
957 
961  static std::vector<MX> get_free(const Function& f);
962 
964  typedef std::map<std::string, MX> MXDict;
965 
969  void eval_mx(const std::vector<MX>& arg, std::vector<MX>& SWIG_OUTPUT(res)) const;
970 
971 #ifndef SWIG
973 
976  void ad_forward(const std::vector<std::vector<MX> >& fseed,
977  std::vector<std::vector<MX> >& fsens) const;
978  void ad_reverse(const std::vector<std::vector<MX> >& aseed,
979  std::vector<std::vector<MX> >& asens) const;
981 
983  MX(const Sparsity& sp, double val, bool dummy);
984 
985  // Create matrix symbolic primitive
986  static MX _sym(const std::string& name, const Sparsity& sp);
987 
988 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
989  static std::mutex& get_mutex_temp() { return mutex_temp; }
990  static std::mutex mutex_temp;
991 #endif //CASADI_WITH_THREADSAFE_SYMBOLICS
992  private:
993 
995  MX(MXNode* node, bool dummy1, bool dummy2, bool dummy3, bool dummy4);
996 
997  // Depth when checking equalities
998  static casadi_int eq_depth_;
999 
1000 #endif // SWIG
1001  };
1002 
1003 
1006  typedef std::vector<MX> MXVector;
1007  typedef std::initializer_list<MX> MXIList;
1008  typedef std::vector<MXVector> MXVectorVector;
1009  typedef std::map<std::string, MX> MXDict;
1011 
1012 } // namespace casadi
1013 
1014 #endif // CASADI_MX_HPP
Helper class for Serialization.
Function object.
Definition: function.hpp:60
Matrix base class.
Node class for MX objects.
Definition: mx_node.hpp:51
MX - Matrix expression.
Definition: mx.hpp:92
void get_nz(MX &m, bool ind1, casadi_int kk) const
Definition: mx.hpp:527
static MX lift(const MX &x, const MX &x_guess)
Definition: mx.cpp:734
GenericMatrix< MX > B
Base class.
Definition: mx.hpp:189
static std::vector< MX > difference(const std::vector< MX > &a, const std::vector< MX > &b)
Definition: mx.cpp:2613
static MX find(const MX &x)
Definition: mx.cpp:2108
static MX stop_diff(const MX &expr, casadi_int order)
Definition: mx.cpp:2541
Sparsity get_sparsity() const
Get an owning reference to the sparsity pattern.
Definition: mx.hpp:205
MX ScalarType
Definition: mx.hpp:185
void set_nz(const MX &m, bool ind1, casadi_int kk)
Definition: mx.hpp:540
static MX matrix_expand(const MX &e, const std::vector< MX > &boundary, const Dict &options)
Definition: mx.cpp:1943
void get(MX &m, bool ind1, const casadi_int rr) const
Definition: mx.hpp:480
static DM evalf(const MX &m)
Definition: mx.cpp:739
void get(MX &m, bool ind1, casadi_int rr, casadi_int cc) const
Definition: mx.hpp:498
static MX bspline(const MX &x, const DM &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > &degree, casadi_int m, const Dict &opts=Dict())
Definition: mx.cpp:2116
void get(MX &m, bool ind1, const Slice &rr, casadi_int cc) const
Definition: mx.hpp:489
static std::string type_name()
Get type name.
Definition: mx.hpp:97
static MX inv_node(const MX &A)
Definition: mx.cpp:1926
static MX graph_substitute(const MX &x, const std::vector< MX > &v, const std::vector< MX > &vdef)
Definition: mx.cpp:1450
std::map< std::string, MX > MXDict
Readability typedef.
Definition: mx.hpp:964
static DM bspline_dual(const std::vector< double > &x, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > &degree, const Dict &opts=Dict())
Definition: mx.cpp:2133
static MX convexify(const MX &H, const Dict &opts=Dict())
Definition: mx.cpp:2140
void get(MX &m, bool ind1, casadi_int rr, const Slice &cc) const
Definition: mx.hpp:493
static MX low(const MX &v, const MX &p, const Dict &options=Dict())
Definition: mx.cpp:2112
Helper class for Serialization.
GenericShared implements a reference counting framework similar for efficient and.
Class representing a Slice.
Definition: slice.hpp:48
General sparsity class.
Definition: sparsity.hpp:106
friend MX stop_diff(const MX &expr, const MX &var, casadi_int order)
Stop derivatives of an expression wrt to a select set of symbolic variables.
Definition: mx.hpp:906
friend MX no_hess(const MX &expr)
Stop second derivatives of an expression wrt to all its symbolic variables.
Definition: mx.hpp:898
friend MX bspline(const MX &x, const MX &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > &degree, casadi_int m, const Dict &opts=Dict())
Definition: mx.hpp:832
friend MX low(const MX &v, const MX &p, const Dict &options=Dict())
Find first nonzero.
Definition: mx.hpp:757
friend std::vector< MX > matrix_expand(const std::vector< MX > &e, const std::vector< MX > &boundary=std::vector< MX >(), const Dict &options=Dict())
Expand MX graph to SXFunction call.
Definition: mx.hpp:816
friend MX convexify(const MX &H, const Dict &opts=Dict())
Definition: mx.hpp:847
friend MX inv_node(const MX &x)
Inverse node.
Definition: mx.hpp:864
friend std::vector< MX > difference(const std::vector< MX > &a, const std::vector< MX > &b)
Definition: mx.hpp:911
friend MX find(const MX &x)
Find first nonzero, returned as row index.
Definition: mx.hpp:748
friend MX no_grad(const MX &expr)
Stop first derivatives of an expression wrt to all its symbolic variables.
Definition: mx.hpp:889
friend MX graph_substitute(const MX &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated)
Definition: mx.hpp:771
friend MX bspline(const MX &x, const DM &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > &degree, casadi_int m, const Dict &opts=Dict())
Definition: mx.hpp:823
friend std::vector< MX > graph_substitute(const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef)
Substitute multiple expressions in graph.
Definition: mx.hpp:783
friend std::vector< MX > graph_substitute(const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated)
Definition: mx.hpp:790
friend MX matrix_expand(const MX &e, const std::vector< MX > &boundary=std::vector< MX >(), const Dict &options=Dict())
Expand MX graph to SXFunction call.
Definition: mx.hpp:804
friend MX lift(const MX &x, const MX &x_guess)
Lift the expression.
Definition: mx.hpp:857
friend MX stop_diff(const MX &expr, casadi_int order)
Stop derivatives of an expression wrt to all its symbolic variables.
Definition: mx.hpp:880
friend DM bspline_dual(const std::vector< double > &x, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > &degree, const Dict &opts=Dict())
Definition: mx.hpp:840
friend DM evalf(const MX &expr)
Evaluates the expression numerically.
Definition: mx.hpp:873
friend MX graph_substitute(const MX &ex, const std::vector< MX > &v, const std::vector< MX > &vdef)
Substitute single expression in graph.
Definition: mx.hpp:766
The casadi namespace.
Definition: archiver.cpp:28
std::map< std::string, MX > MXDict
Definition: mx.hpp:1009
bool is_equal(double x, double y, casadi_int depth=0)
Definition: calculus.hpp:281
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)
Definition: calculus.hpp:290
std::vector< casadi_int > find(const std::vector< T > &v)
find nonzeros
std::vector< MX > MXVector
Definition: mx.hpp:1006
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::vector< T > cumsum(const std::vector< T > &values)
cumulative sum
const double inf
infinity
Definition: calculus.hpp:50
double printme(double x, double y)
Definition: calculus.hpp:273
std::vector< MXVector > MXVectorVector
Definition: mx.hpp:1008
T dot(const std::vector< T > &a, const std::vector< T > &b)
const double nan
Not a number.
Definition: calculus.hpp:53
T norm_2(const std::vector< T > &x)
std::initializer_list< MX > MXIList
Definition: mx.hpp:1007
bool is_zero(const T &x)
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)
Definition: calculus.hpp:271
std::vector< casadi_int > scc_offset
Definition: mx.hpp:57
casadi_int * iw
Definition: mx.hpp:64
casadi_convexify_config< double > config
Definition: mx.hpp:61
casadi_int sz_iw
Definition: mx.hpp:62
Sparsity Hrsp
Definition: mx.hpp:59
double * w
Definition: mx.hpp:65
casadi_int sz_w
Definition: mx.hpp:63
Sparsity Hsp
Definition: mx.hpp:60
std::vector< casadi_int > scc_mapping
Definition: mx.hpp:57
Sparsity scc_sp
Definition: mx.hpp:58