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 namespace casadi {
38 
42  class MXNode;
43  class Function;
44  class SerializingStream;
45  class DeserializingStream;
46 
47 #ifndef SWIG
48  struct ConvexifyData {
49  std::vector<casadi_int> scc_offset, scc_mapping;
50  Sparsity scc_sp;
51  Sparsity Hrsp;
52  Sparsity Hsp;
54  casadi_int sz_iw;
55  casadi_int sz_w;
56  casadi_int *iw;
57  double* w;
58  };
59 #endif
60 
80  class CASADI_EXPORT MX :
81  public SWIG_IF_ELSE(GenericExpressionCommon, GenericExpression<MX>),
82  public SWIG_IF_ELSE(PrintableCommon, Printable<MX>),
83  public GenericMatrix<MX>,
84  public SharedObject {
85  public:
89  static std::string type_name() {return "MX";}
90 
94  MX();
95 
99  MX(casadi_int nrow, casadi_int ncol);
100 
101 #ifndef SWIG
105  explicit MX(const std::pair<casadi_int, casadi_int>& rc);
106 #endif // SWIG
107 
113  explicit MX(const Sparsity& sp);
114 
118  MX(const Sparsity& sp, const MX& val);
119 
123  MX(const Sparsity& sp, const std::string& fname);
124 
128  MX(double x);
129 
130 #ifndef SWIG
134  MX(const std::vector<double> &x);
135 #endif
136 
140  MX(const Matrix<double> &x);
141 
143 
146  ~MX();
148 
149 #ifndef SWIG
151 
154  static MX create(MXNode* node);
155 
159  static std::vector<MX> createMultipleOutput(MXNode* node);
161 
165  const Sparsity& sparsity() const;
166 
169  typedef MX ScalarType;
171 
173  typedef GenericMatrix<MX> B;
174 
176  using B::horzsplit;
177  using B::diagsplit;
178  using B::vertsplit;
179  using B::mtimes;
180  using B::repmat;
181 #endif // SWIG
182 
184  bool __nonzero__() const;
185 
189  Sparsity get_sparsity() const { return sparsity();}
190 
196  void erase(const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
197  bool ind1=false);
198 
204  void erase(const std::vector<casadi_int>& rr, bool ind1=false);
205 
211  void enlarge(casadi_int nrow, casadi_int ncol,
212  const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
213  bool ind1=false);
214 
215  MX operator-() const;
216 
217 #ifndef SWIG
220 
223  MXNode* operator->();
224 
228  const MXNode* operator->() const;
231 #endif // SWIG
232 
236  MX dep(casadi_int ch=0) const;
237 
241  casadi_int n_out() const;
242 
246  MX get_output(casadi_int oind) const;
247 
251  casadi_int n_dep() const;
252 
254  std::string name() const;
255 
257  explicit operator double() const;
258 
260  explicit operator Matrix<double>() const;
261 
263  bool is_symbolic() const;
264 
266  bool is_constant() const;
267 
269  bool is_call() const;
270 
273 
275  bool is_output() const;
276 
278  casadi_int which_output() const;
279 
281  bool is_op(casadi_int op) const;
282 
284  bool is_multiplication() const;
285 
287  bool is_commutative() const;
288 
290  bool is_norm() const;
291 
297  bool is_valid_input() const;
298 
302  casadi_int n_primitives() const;
303 
307  std::vector<MX> primitives() const;
308 
310 
313  std::vector<MX> split_primitives(const MX& x) const;
314  std::vector<SX> split_primitives(const SX& x) const;
315  std::vector<DM> split_primitives(const DM& x) const;
317 
319 
322  MX join_primitives(const std::vector<MX>& v) const;
323  SX join_primitives(const std::vector<SX>& v) const;
324  DM join_primitives(const std::vector<DM>& v) const;
326 
328 
336  bool has_duplicates() const;
337 
341  void reset_input() const;
343 
347  bool is_eye() const;
348 
352  bool is_zero() const;
353 
357  bool is_one() const;
358 
362  bool is_minus_one() const;
363 
367  bool is_transpose() const;
368 
370  bool is_regular() const;
371 
373  bool is_binary() const;
374 
376  bool is_unary() const;
377 
379  casadi_int op() const;
380 
382  Dict info() const;
383 
387  void serialize(SerializingStream& s) const;
388 
393 
396  casadi_int get_temp() const;
397 
399  void set_temp(casadi_int t) const;
401 
403 
406  static MX binary(casadi_int op, const MX &x, const MX &y);
407  static MX unary(casadi_int op, const MX &x);
409 
411 
414  static MX inf(const Sparsity& sp);
415  static MX inf(casadi_int nrow=1, casadi_int ncol=1);
416  static MX inf(const std::pair<casadi_int, casadi_int>& rc);
418 
420 
423  static MX nan(const Sparsity& sp);
424  static MX nan(casadi_int nrow=1, casadi_int ncol=1);
425  static MX nan(const std::pair<casadi_int, casadi_int>& rc);
427 
431  static MX eye(casadi_int n);
432 
433 #ifndef SWIG
435  MXNode* get() const;
436 #endif // SWIG
437 
440  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr) const;
441  void get(MX& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& rr) const;
442  void get(MX& SWIG_OUTPUT(m), bool ind1, const Sparsity& sp) const;
443  void get(MX& SWIG_OUTPUT(m), bool ind1, const MX& rr) const;
444  void get(MX& SWIG_OUTPUT(m), bool ind1, const casadi_int rr) const {
445  get(m, ind1, Matrix<casadi_int>(rr));
446  }
448 
451  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr, const Slice& cc) const;
452  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr, const Matrix<casadi_int>& cc) const;
453  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr, casadi_int cc) const {
454  get(m, ind1, rr, Matrix<casadi_int>(cc));
455  }
456  void get(MX& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& rr, const Slice& cc) const;
457  void get(MX& SWIG_OUTPUT(m), bool ind1, casadi_int rr, const Slice& cc) const {
458  get(m, ind1, Matrix<casadi_int>(rr), cc);
459  }
460  void get(MX& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& rr,
461  const Matrix<casadi_int>& cc) const;
462  void get(MX& SWIG_OUTPUT(m), bool ind1, casadi_int rr,
463  casadi_int cc) const {
464  get(m, ind1, Matrix<casadi_int>(rr), Matrix<casadi_int>(cc));
465  }
466  void get(MX& SWIG_OUTPUT(m), bool ind1, const MX& rr, const Slice& cc) const;
467  void get(MX& SWIG_OUTPUT(m), bool ind1, const Slice& rr, const MX& cc) const;
468  void get(MX& SWIG_OUTPUT(m), bool ind1, const MX& rr, const MX& cc) const;
470 
473  void set(const MX& m, bool ind1, const Slice& rr);
474  void set(const MX& m, bool ind1, const Matrix<casadi_int>& rr);
475  void set(const MX& m, bool ind1, const Sparsity& sp);
477 
480  void set(const MX& m, bool ind1, const Slice& rr, const Slice& cc);
481  void set(const MX& m, bool ind1, const Slice& rr, const Matrix<casadi_int>& cc);
482  void set(const MX& m, bool ind1, const Matrix<casadi_int>& rr, const Slice& cc);
483  void set(const MX& m, bool ind1, const Matrix<casadi_int>& rr, const Matrix<casadi_int>& cc);
485 
488  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const Slice& kk) const;
489  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& kk) const;
490  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const MX& kk) const;
491  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, casadi_int kk) const {
492  get_nz(m, ind1, Matrix<casadi_int>(kk));
493  }
494  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const MX& inner, const Slice& outer) const;
495  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const Slice& inner, const MX& outer) const;
496  void get_nz(MX& SWIG_OUTPUT(m), bool ind1, const MX& inner, const MX& outer) const;
498 
501  void set_nz(const MX& m, bool ind1, const Slice& kk);
502  void set_nz(const MX& m, bool ind1, const Matrix<casadi_int>& kk);
503  void set_nz(const MX& m, bool ind1, const MX& kk);
504  void set_nz(const MX& m, bool ind1, casadi_int kk) { set_nz(m, ind1, Matrix<casadi_int>(kk)); }
506 
508 
522  static MX einstein(const MX& A, const MX& B, const MX& C,
523  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
524  const std::vector<casadi_int>& dim_c,
525  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
526  const std::vector<casadi_int>& c);
527 
528  static MX einstein(const MX& A, const MX& B,
529  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
530  const std::vector<casadi_int>& dim_c,
531  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
532  const std::vector<casadi_int>& c);
534 
535 #ifndef SWIG
539  static bool is_equal(const MX& x, const MX& y, casadi_int depth=0);
540  static MX mmin(const MX &x);
541  static MX mmax(const MX &x);
543 
546  static MX horzcat(const std::vector<MX>& x);
547  static MX diagcat(const std::vector<MX>& x);
548  static MX vertcat(const std::vector<MX>& x);
549  static std::vector<MX> horzsplit(const MX& x, const std::vector<casadi_int>& offset);
550  static std::vector<MX> diagsplit(const MX& x, const std::vector<casadi_int>& offset1,
551  const std::vector<casadi_int>& offset2);
552  static std::vector<MX> vertsplit(const MX& x, const std::vector<casadi_int>& offset);
553  static MX blockcat(const std::vector< std::vector<MX > > &v);
554  static MX mtimes(const MX& x, const MX& y);
555  static MX mac(const MX& x, const MX& y, const MX& z);
556  static MX reshape(const MX& x, casadi_int nrow, casadi_int ncol);
557  static MX reshape(const MX& x, const Sparsity& sp);
558  static MX sparsity_cast(const MX& x, const Sparsity& sp);
559  static MX kron(const MX& x, const MX& b);
560  static MX repmat(const MX& x, casadi_int n, casadi_int m=1);
562 
565  static MX jacobian(const MX& f, const MX& x, const Dict& opts = Dict());
566  static MX hessian(const MX& f, const MX& x, const Dict& opts = Dict());
567  static MX hessian(const MX& f, const MX& x, MX& g, const Dict& opts = Dict());
568  static std::vector<std::vector<MX> >
569  forward(const std::vector<MX> &ex,
570  const std::vector<MX> &arg,
571  const std::vector<std::vector<MX> > &v,
572  const Dict& opts = Dict());
573  static std::vector<std::vector<MX> >
574  reverse(const std::vector<MX> &ex,
575  const std::vector<MX> &arg,
576  const std::vector<std::vector<MX> > &v,
577  const Dict& opts = Dict());
578  static std::vector<bool> which_depends(const MX &expr, const MX &var,
579  casadi_int order=1, bool tr=false);
580  static Sparsity jacobian_sparsity(const MX& f, const MX& x);
581  static MX substitute(const MX& ex, const MX& v, const MX& vdef);
582  static std::vector<MX> substitute(const std::vector<MX> &ex,
583  const std::vector<MX> &v,
584  const std::vector<MX> &vdef);
585  static void substitute_inplace(const std::vector<MX>& v,
586  std::vector<MX>& vdef,
587  std::vector<MX>& ex, bool reverse);
588  static MX solve(const MX& a, const MX& b);
589  static MX solve(const MX& a, const MX& b, const std::string& lsolver,
590  const Dict& dict = Dict());
591  static MX inv_minor(const MX& A);
592  static MX inv_node(const MX& A);
593  static MX inv(const MX& A, const std::string& lsolver="qr", const Dict& dict = Dict());
594  static MX pinv(const MX& A, const std::string& lsolver="qr",
595  const Dict& dict = Dict());
596  static MX expm_const(const MX& A, const MX& t);
597  static MX expm(const MX& A);
598  static casadi_int n_nodes(const MX& x);
599  static std::string print_operator(const MX& x, const std::vector<std::string>& args);
600  static void extract(std::vector<MX>& ex, std::vector<MX>& v,
601  std::vector<MX>& vdef, const Dict& opts = Dict());
602  static void shared(std::vector<MX>& ex, std::vector<MX>& v,
603  std::vector<MX>& vdef, const std::string& v_prefix, const std::string& v_suffix);
604  static MX if_else(const MX& cond, const MX& if_true,
605  const MX& if_false, bool short_circuit=false);
606  static MX conditional(const MX& ind, const std::vector<MX> &x, const MX& x_default,
607  bool short_circuit=false);
608  static bool depends_on(const MX& x, const MX& arg);
609  static MX simplify(const MX& x);
610  static MX dot(const MX& x, const MX& y);
611  static MX mrdivide(const MX& a, const MX& b);
612  static MX mldivide(const MX& a, const MX& b);
613  static MX norm_2(const MX& x);
614  static MX norm_fro(const MX& x);
615  static MX norm_1(const MX& x);
616  static MX norm_inf(const MX& x);
617  static MX unite(const MX& A, const MX& B);
618  static MX trace(const MX& x);
619  static MX diag(const MX& x);
620  static MX sum2(const MX& x);
621  static MX sum1(const MX& x);
622  static MX polyval(const MX& p, const MX& x);
623  static MX det(const MX& x);
624  static std::vector<MX> symvar(const MX& x);
625  static MX nullspace(const MX& A);
626  static MX repsum(const MX& x, casadi_int n, casadi_int m=1);
627  static MX densify(const MX& x, const MX& val=0);
628  static MX _bilin(const MX& A, const MX& x, const MX& y);
629  static MX _rank1(const MX& A, const MX& alpha, const MX& x, const MX& y);
630  static MX project(const MX& x, const Sparsity& sp, bool intersect=false);
631  static MX cumsum(const MX &x, casadi_int axis=-1);
632  static MX _logsumexp(const MX& x);
633  static std::vector<MX> cse(const std::vector<MX>& e);
635 
638  static MX find(const MX& x);
639  static MX low(const MX& v, const MX& p, const Dict& options = Dict());
640  static MX graph_substitute(const MX& x, const std::vector<MX> &v,
641  const std::vector<MX> &vdef);
642  static std::vector<MX> graph_substitute(const std::vector<MX> &ex,
643  const std::vector<MX> &expr,
644  const std::vector<MX> &exprs);
645  static MX matrix_expand(const MX& e, const std::vector<MX> &boundary,
646  const Dict& options);
647  static std::vector<MX> matrix_expand(const std::vector<MX>& e,
648  const std::vector<MX>& boundary,
649  const Dict& options);
650  static MX lift(const MX& x, const MX& x_guess);
651  static DM evalf(const MX& m);
652  static MX bspline(const MX& x,
653  const DM& coeffs,
654  const std::vector< std::vector<double> >& knots,
655  const std::vector<casadi_int>& degree,
656  casadi_int m,
657  const Dict& opts = Dict());
658  static MX bspline(const MX& x, const MX& coeffs,
659  const std::vector< std::vector<double> >& knots,
660  const std::vector<casadi_int>& degree,
661  casadi_int m,
662  const Dict& opts = Dict());
663  static MX convexify(const MX& H, const Dict& opts = Dict());
664  static MX stop_diff(const MX& expr, casadi_int order);
665  static MX stop_diff(const MX& expr, const MX& var, casadi_int order);
666  static std::vector<MX> difference(const std::vector<MX>& a, const std::vector<MX>& b);
669 
670 #endif // SWIG
671 
672  static DM bspline_dual(const std::vector<double>& x,
673  const std::vector< std::vector<double> >& knots,
674  const std::vector<casadi_int>& degree,
675  const Dict& opts = Dict());
676 
684  static MX interpn_linear(const std::vector<MX>& x, const MX& v, const std::vector<MX>& xq,
685  const Dict& opts=Dict());
686 
687  MX printme(const MX& b) const;
688 
689 #if !defined(SWIG) || defined(DOXYGEN)
699  inline friend MX find(const MX& x) {
700  return MX::find(x);
701  }
702 
708  inline friend MX low(const MX& v, const MX& p, const Dict& options=Dict()) {
709  return MX::low(v, p, options);
710  }
711 
717  inline friend MX graph_substitute(const MX& ex, const std::vector<MX> &v,
718  const std::vector<MX> &vdef) {
719  return MX::graph_substitute(ex, v, vdef);
720  }
721 
728  inline friend std::vector<MX>
729  graph_substitute(const std::vector<MX> &ex,
730  const std::vector<MX> &v,
731  const std::vector<MX> &vdef) {
732  return MX::graph_substitute(ex, v, vdef);
733  }
734 
741  inline friend MX
742  matrix_expand(const MX& e, const std::vector<MX> &boundary = std::vector<MX>(),
743  const Dict& options = Dict()) {
744  return MX::matrix_expand(e, boundary, options);
745  }
746 
753  inline friend std::vector<MX>
754  matrix_expand(const std::vector<MX>& e,
755  const std::vector<MX> &boundary = std::vector<MX>(),
756  const Dict& options = Dict()) {
757  return MX::matrix_expand(e, boundary, options);
758  }
759 
760 
761  inline friend MX bspline(const MX& x,
762  const DM& coeffs,
763  const std::vector< std::vector<double> >& knots,
764  const std::vector<casadi_int>& degree,
765  casadi_int m,
766  const Dict& opts = Dict()) {
767  return MX::bspline(x, coeffs, knots, degree, m, opts);
768  }
769 
770  inline friend MX bspline(const MX& x, const MX& coeffs,
771  const std::vector< std::vector<double> >& knots,
772  const std::vector<casadi_int>& degree,
773  casadi_int m,
774  const Dict& opts = Dict()) {
775  return MX::bspline(x, coeffs, knots, degree, m, opts);
776  }
777 
778  inline friend DM bspline_dual(const std::vector<double>& x,
779  const std::vector< std::vector<double> >& knots,
780  const std::vector<casadi_int>& degree,
781  const Dict& opts = Dict()) {
782  return MX::bspline_dual(x, knots, degree, opts);
783  }
784 
785  inline friend MX convexify(const MX& H,
786  const Dict& opts = Dict()) {
787  return MX::convexify(H, opts);
788  }
789 
795  inline friend MX lift(const MX& x, const MX& x_guess) {
796  return MX::lift(x, x_guess);
797  }
798 
802  inline friend MX inv_node(const MX& x) {
803  return MX::inv_node(x);
804  }
805 
811  inline friend DM evalf(const MX& expr) {
812  return MX::evalf(expr);
813  }
814 
818  inline friend MX stop_diff(const MX& expr, casadi_int order) {
819  return MX::stop_diff(expr, order);
820  }
821 
827  inline friend MX no_grad(const MX& expr) {
828  return MX::stop_diff(expr, 1);
829  }
830 
836  inline friend MX no_hess(const MX& expr) {
837  return MX::stop_diff(expr, 2);
838  }
839 
840 
844  inline friend MX stop_diff(const MX& expr, const MX& var, casadi_int order) {
845  return MX::stop_diff(expr, var, order);
846  }
847 
849  inline friend std::vector<MX> difference(const std::vector<MX>& a, const std::vector<MX>& b) {
850  return MX::difference(a, b);
851  }
852 
854 #endif // SWIG
855 
861  MX attachAssert(const MX& y, const std::string& fail_message="") const;
862 
868  MX monitor(const std::string& comment) const;
869 
871  MX T() const;
872 
877 
881  static void set_max_depth(casadi_int eq_depth=1);
882 
886  static casadi_int get_max_depth();
887 
889  static bool test_cast(const SharedObjectInternal* ptr);
890 
894  static std::vector<MX> get_input(const Function& f);
895 
899  static std::vector<MX> get_free(const Function& f);
900 
902  typedef std::map<std::string, MX> MXDict;
903 
907  void eval_mx(const std::vector<MX>& arg, std::vector<MX>& SWIG_OUTPUT(res)) const;
908 
909 #ifndef SWIG
911 
914  void ad_forward(const std::vector<std::vector<MX> >& fseed,
915  std::vector<std::vector<MX> >& fsens) const;
916  void ad_reverse(const std::vector<std::vector<MX> >& aseed,
917  std::vector<std::vector<MX> >& asens) const;
919 
921  MX(const Sparsity& sp, double val, bool dummy);
922 
923  // Create matrix symbolic primitive
924  static MX _sym(const std::string& name, const Sparsity& sp);
925 
926  private:
927 
929  MX(MXNode* node, bool dummy1, bool dummy2, bool dummy3, bool dummy4);
930 
931  // Depth when checking equalities
932  static casadi_int eq_depth_;
933 
934 #endif // SWIG
935  };
936 
937 
940  typedef std::vector<MX> MXVector;
941  typedef std::initializer_list<MX> MXIList;
942  typedef std::vector<MXVector> MXVectorVector;
943  typedef std::map<std::string, MX> MXDict;
945 
946 } // namespace casadi
947 
948 #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:50
MX - Matrix expression.
Definition: mx.hpp:84
void get_nz(MX &m, bool ind1, casadi_int kk) const
Definition: mx.hpp:491
void erase(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
Erase a submatrix (leaving structural zeros in its place)
static std::vector< MX > get_free(const Function &f)
Get free variables.
bool is_multiplication() const
Check if multiplication.
bool is_minus_one() const
check if zero (note that false negative answers are possible)
bool is_valid_input() const
Check if matrix can be used to define function inputs.
static bool test_cast(const SharedObjectInternal *ptr)
Check if a particular cast is allowed.
bool is_eye() const
check if identity
void get_nz(MX &m, bool ind1, const Slice &inner, const MX &outer) const
static casadi_int get_max_depth()
Get the depth to which equalities are being checked for simplifications.
static MX nan(const Sparsity &sp)
create a matrix with all nan
std::vector< MX > split_primitives(const MX &x) const
Split up an expression along symbolic primitives.
MX operator-() const
bool is_output() const
Check if evaluation output.
casadi_int n_out() const
Number of outputs.
void get(MX &m, bool ind1, const Sparsity &sp) const
void erase(const std::vector< casadi_int > &rr, bool ind1=false)
Erase a submatrix (leaving structural zeros in its place)
static MX deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
static MX eye(casadi_int n)
Identity matrix.
casadi_int n_dep() const
Get the number of dependencies of a binary SXElem.
void get(MX &m, bool ind1, const MX &rr, const MX &cc) const
casadi_int n_primitives() const
Get the number of primitives for MXFunction inputs/outputs.
void set(const MX &m, bool ind1, const Matrix< casadi_int > &rr)
bool __nonzero__() const
Returns the truth value of an MX expression.
void get(MX &m, bool ind1, const MX &rr) const
static MX inf(casadi_int nrow=1, casadi_int ncol=1)
create a matrix with all inf
bool is_call() const
Check if evaluation.
std::string name() const
Get the name.
void get(MX &m, bool ind1, const MX &rr, const Slice &cc) const
MX(const Sparsity &sp, const std::string &fname)
Construct matrix with a given sparsity and a file with nonzeros.
void set(const MX &m, bool ind1, const Slice &rr, const Slice &cc)
bool is_constant() const
Check if constant.
Sparsity get_sparsity() const
Get an owning reference to the sparsity pattern.
Definition: mx.hpp:189
static MX nan(const std::pair< casadi_int, casadi_int > &rc)
create a matrix with all nan
bool is_commutative() const
Check if commutative operation.
MX(const Sparsity &sp, const MX &val)
Construct matrix with a given sparsity and nonzeros.
static MX einstein(const MX &A, const MX &B, const MX &C, const std::vector< casadi_int > &dim_a, const std::vector< casadi_int > &dim_b, const std::vector< casadi_int > &dim_c, const std::vector< casadi_int > &a, const std::vector< casadi_int > &b, const std::vector< casadi_int > &c)
Computes an einstein dense tensor contraction.
void set_nz(const MX &m, bool ind1, casadi_int kk)
Definition: mx.hpp:504
void set_nz(const MX &m, bool ind1, const MX &kk)
void get(MX &m, bool ind1, const casadi_int rr) const
Definition: mx.hpp:444
void set(const MX &m, bool ind1, const Sparsity &sp)
void get_nz(MX &m, bool ind1, const MX &inner, const MX &outer) const
void get_nz(MX &m, bool ind1, const MX &kk) const
static void set_max_depth(casadi_int eq_depth=1)
Set or reset the depth to which equalities are being checked for simplifications.
DM join_primitives(const std::vector< DM > &v) const
Join an expression along symbolic primitives.
MX T() const
Transpose the matrix.
void get(MX &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc) const
void get(MX &m, bool ind1, const Slice &rr, const MX &cc) const
void get(MX &m, bool ind1, casadi_int rr, casadi_int cc) const
Definition: mx.hpp:462
MX(casadi_int nrow, casadi_int ncol)
Create a sparse matrix with all structural zeros.
void get(MX &m, bool ind1, const Slice &rr, casadi_int cc) const
Definition: mx.hpp:453
Function which_function() const
Get function - only valid when is_call() is true.
void get(MX &m, bool ind1, const Slice &rr, const Slice &cc) const
void get_nz(MX &m, bool ind1, const MX &inner, const Slice &outer) const
static MX inf(const std::pair< casadi_int, casadi_int > &rc)
create a matrix with all inf
void get(MX &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc) const
MX(double x)
Create scalar constant (also implicit type conversion)
MX(const Sparsity &sp)
Create a sparse matrix from a sparsity pattern.
static std::string type_name()
Get type name.
Definition: mx.hpp:89
bool is_op(casadi_int op) const
Is it a certain operation.
void get(MX &m, bool ind1, const Matrix< casadi_int > &rr) const
bool is_norm() const
Check if norm.
void set_nz(const MX &m, bool ind1, const Slice &kk)
MX()
Default constructor.
static MX binary(casadi_int op, const MX &x, const MX &y)
Create nodes by their ID.
bool is_regular() const
Checks if expression does not contain NaN or Inf.
casadi_int which_output() const
Get the index of evaluation output - only valid when is_output() is true.
void serialize(SerializingStream &s) const
Serialize an object.
static MX nan(casadi_int nrow=1, casadi_int ncol=1)
create a matrix with all nan
void set(const MX &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc)
void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res) const
Evaluate the MX node with new symbolic dependencies.
SX join_primitives(const std::vector< SX > &v) const
Join an expression along symbolic primitives.
MX attachAssert(const MX &y, const std::string &fail_message="") const
returns itself, but with an assertion attached
Dict info() const
std::map< std::string, MX > MXDict
Readability typedef.
Definition: mx.hpp:902
void set(const MX &m, bool ind1, const Slice &rr)
std::vector< MX > primitives() const
Get primitives.
bool is_one() const
check if zero (note that false negative answers are possible)
void get_nz(MX &m, bool ind1, const Matrix< casadi_int > &kk) const
std::vector< DM > split_primitives(const DM &x) const
Split up an expression along symbolic primitives.
void get(MX &m, bool ind1, const Slice &rr) const
void set(const MX &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc)
MX join_primitives(const std::vector< MX > &v) const
Join an expression along symbolic primitives.
void get(MX &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc) const
MX(const Matrix< double > &x)
Create sparse matrix constant (also implicit type conversion)
MX dep(casadi_int ch=0) const
Get the nth dependency as MX.
void set(const MX &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc)
MX monitor(const std::string &comment) const
Monitor an expression.
Matrix< casadi_int > mapping() const
Get an IM representation of a GetNonzeros or SetNonzeros node.
static MX interpn_linear(const std::vector< MX > &x, const MX &v, const std::vector< MX > &xq, const Dict &opts=Dict())
Low-level access to inlined linear interpolation.
bool is_binary() const
Is binary operation.
void set_nz(const MX &m, bool ind1, const Matrix< casadi_int > &kk)
void get(MX &m, bool ind1, casadi_int rr, const Slice &cc) const
Definition: mx.hpp:457
std::vector< SX > split_primitives(const SX &x) const
Split up an expression along symbolic primitives.
bool is_unary() const
Is unary operation.
static MX einstein(const MX &A, const MX &B, const std::vector< casadi_int > &dim_a, const std::vector< casadi_int > &dim_b, const std::vector< casadi_int > &dim_c, const std::vector< casadi_int > &a, const std::vector< casadi_int > &b, const std::vector< casadi_int > &c)
Computes an einstein dense tensor contraction.
bool is_zero() const
check if zero (note that false negative answers are possible)
bool is_transpose() const
Is the expression a transpose?
void get_nz(MX &m, bool ind1, const Slice &kk) const
static MX unary(casadi_int op, const MX &x)
Create nodes by their ID.
bool is_symbolic() const
Check if symbolic.
void enlarge(casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
Enlarge matrix.
MX printme(const MX &b) const
static std::vector< MX > get_input(const Function &f)
Get function inputs.
MX get_output(casadi_int oind) const
Get an output.
casadi_int op() const
Get operation type.
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())
static MX inf(const Sparsity &sp)
create a matrix with all inf
Sparse matrix class. SX and DM are specializations.
Definition: matrix_decl.hpp:92
Helper class for Serialization.
SharedObject implements a reference counting framework similar for efficient and.
Class representing a Slice.
Definition: slice.hpp:48
General sparsity class.
Definition: sparsity.hpp:99
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:844
friend MX no_hess(const MX &expr)
Stop second derivatives of an expression wrt to all its symbolic variables.
Definition: mx.hpp:836
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:770
friend MX low(const MX &v, const MX &p, const Dict &options=Dict())
Find first nonzero.
Definition: mx.hpp:708
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:754
friend MX convexify(const MX &H, const Dict &opts=Dict())
Definition: mx.hpp:785
friend MX inv_node(const MX &x)
Inverse node.
Definition: mx.hpp:802
friend std::vector< MX > difference(const std::vector< MX > &a, const std::vector< MX > &b)
Definition: mx.hpp:849
friend MX find(const MX &x)
Find first nonzero, returned as row index.
Definition: mx.hpp:699
friend MX no_grad(const MX &expr)
Stop first derivatives of an expression wrt to all its symbolic variables.
Definition: mx.hpp:827
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:761
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:729
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:742
friend MX lift(const MX &x, const MX &x_guess)
Lift the expression.
Definition: mx.hpp:795
friend MX stop_diff(const MX &expr, casadi_int order)
Stop derivatives of an expression wrt to all its symbolic variables.
Definition: mx.hpp:818
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:778
friend DM evalf(const MX &expr)
Evaluates the expression numerically.
Definition: mx.hpp:811
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:717
The casadi namespace.
std::map< std::string, MX > MXDict
Definition: mx.hpp:943
std::vector< MX > MXVector
Definition: mx.hpp:940
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
std::vector< MXVector > MXVectorVector
Definition: mx.hpp:942
std::initializer_list< MX > MXIList
Definition: mx.hpp:941