mx_node.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_NODE_HPP
27 #define CASADI_MX_NODE_HPP
28 
29 #include "mx.hpp"
30 #include "shared_object_internal.hpp"
31 #include "sx_elem.hpp"
32 #include "calculus.hpp"
33 #include "code_generator.hpp"
34 #include "linsol.hpp"
35 #include <vector>
36 #include <stack>
37 
38 namespace casadi {
39 
40  class SerializingStream;
41  class DeserializingStream;
42 
50  class CASADI_EXPORT MXNode : public SharedObjectInternal {
51  friend class MX;
52 
53  public:
55  MXNode();
56 
60  ~MXNode() override=0;
61 
65  virtual bool __nonzero__() const;
66 
70  virtual bool is_zero() const { return false;}
71 
75  virtual bool is_one() const { return false;}
76 
80  virtual bool is_minus_one() const { return false;}
81 
85  virtual bool is_value(double val) const { return false;}
86 
90  virtual bool is_eye() const { return false;}
91 
95  virtual bool is_unary() const { return false;}
96 
100  virtual bool is_binary() const { return false;}
101 
105  void can_inline(std::map<const MXNode*, casadi_int>& nodeind) const;
106 
110  std::string print_compact(std::map<const MXNode*, casadi_int>& nodeind,
111  std::vector<std::string>& intermed) const;
112 
116  virtual std::string disp(const std::vector<std::string>& arg) const = 0;
117 
121  virtual void add_dependency(CodeGenerator& g) const {}
122 
126  virtual bool has_refcount() const { return false;}
127 
131  virtual void codegen_incref(CodeGenerator& g, std::set<void*>& added) const {}
132 
136  virtual void codegen_decref(CodeGenerator& g, std::set<void*>& added) const {}
137 
141  virtual void generate(CodeGenerator& g,
142  const std::vector<casadi_int>& arg,
143  const std::vector<casadi_int>& res) const;
144 
148  virtual int eval(const double** arg, double** res, casadi_int* iw, double* w) const;
149 
153  virtual int eval_sx(const SXElem** arg, SXElem** res, casadi_int* iw, SXElem* w) const;
154 
158  virtual void eval_mx(const std::vector<MX>& arg, std::vector<MX>& res) const;
159 
163  virtual void ad_forward(const std::vector<std::vector<MX> >& fseed,
164  std::vector<std::vector<MX> >& fsens) const;
165 
169  virtual void ad_reverse(const std::vector<std::vector<MX> >& aseed,
170  std::vector<std::vector<MX> >& asens) const;
171 
175  virtual int sp_forward(const bvec_t** arg, bvec_t** res, casadi_int* iw, bvec_t* w) const;
176 
180  virtual int sp_reverse(bvec_t** arg, bvec_t** res, casadi_int* iw, bvec_t* w) const;
181 
185  virtual const std::string& name() const;
186 
190  std::string class_name() const override;
191 
195  void disp(std::ostream& stream, bool more) const override;
196 
200  virtual bool is_valid_input() const { return false;}
201 
205  virtual casadi_int n_primitives() const;
206 
210  virtual void primitives(std::vector<MX>::iterator& it) const;
211 
213 
216  virtual void split_primitives(const MX& x, std::vector<MX>::iterator& it) const;
217  virtual void split_primitives(const SX& x, std::vector<SX>::iterator& it) const;
218  virtual void split_primitives(const DM& x, std::vector<DM>::iterator& it) const;
220 
222  template<typename T>
223  T join_primitives_gen(typename std::vector<T>::const_iterator& it) const;
224 
226 
229  virtual MX join_primitives(std::vector<MX>::const_iterator& it) const;
230  virtual SX join_primitives(std::vector<SX>::const_iterator& it) const;
231  virtual DM join_primitives(std::vector<DM>::const_iterator& it) const;
233 
237  virtual bool has_duplicates() const;
238 
242  virtual void reset_input() const;
243 
247  virtual bool is_output() const {return false;}
248 
252  virtual bool has_output() const {return false;}
253 
257  virtual casadi_int which_output() const;
258 
262  virtual const Function& which_function() const;
263 
267  virtual casadi_int op() const = 0;
268 
270  virtual Dict info() const;
271 
275  void serialize(SerializingStream& s) const;
276 
280  virtual void serialize_body(SerializingStream& s) const;
281 
288  virtual void serialize_type(SerializingStream& s) const;
289 
297 
301  static bool is_equal(const MXNode* x, const MXNode* y, casadi_int depth);
302  virtual bool is_equal(const MXNode* node, casadi_int depth) const { return false;}
303 
307  inline static bool maxDepth() { return MX::get_max_depth();}
308 
314  bool sameOpAndDeps(const MXNode* node, casadi_int depth) const;
315 
319  const MX& dep(casadi_int ind=0) const { return dep_.at(ind);}
320 
324  casadi_int n_dep() const;
325 
329  virtual casadi_int nout() const { return 1;}
330 
334  virtual MX get_output(casadi_int oind) const;
335 
337  const Sparsity& sparsity() const { return sparsity_;}
338 
340  virtual const Sparsity& sparsity(casadi_int oind) const;
341 
342  template<class T>
343  bool matches_sparsity(const std::vector<T>& arg) const {
344  for (casadi_int i=0;i<dep_.size();++i) {
345  if (dep_[i].sparsity()!=arg[i].sparsity()) {
346  return false;
347  }
348  }
349  return true;
350  }
351 
353  casadi_int numel() const { return sparsity().numel(); }
354  casadi_int nnz(casadi_int i=0) const { return sparsity(i).nnz(); }
355  casadi_int size1() const { return sparsity().size1(); }
356  casadi_int size2() const { return sparsity().size2(); }
357  std::pair<casadi_int, casadi_int> size() const { return sparsity().size();}
358 
359  // Get IO index
360  virtual casadi_int ind() const;
361 
362  // Get IO segment
363  virtual casadi_int segment() const;
364 
365  // Get IO offset
366  virtual casadi_int offset() const;
367 
369  void set_sparsity(const Sparsity& sparsity);
370 
374  virtual size_t sz_arg() const { return n_dep();}
375 
379  virtual size_t sz_res() const { return nout();}
380 
384  virtual size_t sz_iw() const { return 0;}
385 
389  virtual size_t sz_w() const { return 0;}
390 
392  void set_dep(const MX& dep);
393 
395  void set_dep(const MX& dep1, const MX& dep2);
396 
398  void set_dep(const MX& dep1, const MX& dep2, const MX& dep3);
399 
401  void set_dep(const std::vector<MX>& dep);
402 
404  inline static MX to_matrix(const MX& x, const Sparsity& sp) {
405  if (x.size()==sp.size()) {
406  return x;
407  } else {
408  return MX(sp, x);
409  }
410  }
411 
413  virtual double to_double() const;
414 
416  virtual DM get_DM() const;
417 
419  virtual casadi_int n_inplace() const { return 0;}
420 
422  virtual Matrix<casadi_int> mapping() const;
423 
425  virtual MX get_horzcat(const std::vector<MX>& x) const;
426 
428  virtual std::vector<MX> get_horzsplit(const std::vector<casadi_int>& output_offset) const;
429 
431  virtual MX get_repmat(casadi_int m, casadi_int n) const;
432 
434  virtual MX get_repsum(casadi_int m, casadi_int n) const;
435 
437  virtual MX get_vertcat(const std::vector<MX>& x) const;
438 
440  virtual std::vector<MX> get_vertsplit(const std::vector<casadi_int>& output_offset) const;
441 
443  virtual MX get_diagcat(const std::vector<MX>& x) const;
444 
446  virtual std::vector<MX> get_diagsplit(const std::vector<casadi_int>& offset1,
447  const std::vector<casadi_int>& offset2) const;
448 
450  virtual MX get_transpose() const;
451 
453  virtual MX get_reshape(const Sparsity& sp) const;
454 
456  virtual MX get_sparsity_cast(const Sparsity& sp) const;
457 
461  virtual MX get_mac(const MX& y, const MX& z) const;
462 
466  virtual MX get_einstein(const MX& A, const MX& B,
467  const std::vector<casadi_int>& dim_c, const std::vector<casadi_int>& dim_a,
468  const std::vector<casadi_int>& dim_b,
469  const std::vector<casadi_int>& c, const std::vector<casadi_int>& a,
470  const std::vector<casadi_int>& b) const;
471 
475  virtual MX get_bilin(const MX& x, const MX& y) const;
476 
480  virtual MX get_rank1(const MX& alpha, const MX& x, const MX& y) const;
481 
485  virtual MX get_logsumexp() const;
486 
494  virtual MX get_solve(const MX& r, bool tr, const Linsol& linear_solver) const;
495 
503  virtual MX get_solve_triu(const MX& r, bool tr) const;
504 
512  virtual MX get_solve_tril(const MX& r, bool tr) const;
513 
521  virtual MX get_solve_triu_unity(const MX& r, bool tr) const;
522 
530  virtual MX get_solve_tril_unity(const MX& r, bool tr) const;
531 
539  virtual MX get_nzref(const Sparsity& sp, const std::vector<casadi_int>& nz) const;
540 
544  virtual MX get_nz_ref(const MX& nz) const;
545 
549  virtual MX get_nz_ref(const MX& inner, const Slice& outer) const;
550 
554  virtual MX get_nz_ref(const Slice& inner, const MX& outer) const;
555 
559  virtual MX get_nz_ref(const MX& inner, const MX& outer) const;
560 
567  virtual MX get_nzassign(const MX& y, const std::vector<casadi_int>& nz) const;
568 
575  virtual MX get_nzadd(const MX& y, const std::vector<casadi_int>& nz) const;
576 
583  virtual MX get_nzassign(const MX& y, const MX& nz) const;
584 
591  virtual MX get_nzassign(const MX& y, const MX& inner, const Slice& outer) const;
592 
599  virtual MX get_nzassign(const MX& y, const Slice& inner, const MX& outer) const;
600 
607  virtual MX get_nzassign(const MX& y, const MX& inner, const MX& outer) const;
608 
615  virtual MX get_nzadd(const MX& y, const MX& nz) const;
616 
623  virtual MX get_nzadd(const MX& y, const MX& inner, const Slice& outer) const;
624 
631  virtual MX get_nzadd(const MX& y, const Slice& inner, const MX& outer) const;
632 
639  virtual MX get_nzadd(const MX& y, const MX& inner, const MX& outer) const;
640 
642  virtual MX get_subref(const Slice& i, const Slice& j) const;
643 
645  virtual MX get_subassign(const MX& y, const Slice& i, const Slice& j) const;
646 
648  virtual MX get_project(const Sparsity& sp) const;
649 
651  virtual MX get_unary(casadi_int op) const;
652 
654  MX get_binary(casadi_int op, const MX& y) const;
655 
657  virtual MX _get_binary(casadi_int op, const MX& y, bool scX, bool scY) const;
658 
660  virtual MX get_det() const;
661 
663  virtual MX get_inv() const;
664 
666  virtual MX get_dot(const MX& y) const;
667 
669  virtual MX get_norm_fro() const;
670 
672  virtual MX get_norm_2() const;
673 
675  virtual MX get_norm_inf() const;
676 
678  virtual MX get_norm_1() const;
679 
681  virtual MX get_mmin() const;
682 
684  virtual MX get_mmax() const;
685 
687  MX get_assert(const MX& y, const std::string& fail_message) const;
688 
690  MX get_monitor(const std::string& comment) const;
691 
693  MX get_find() const;
694 
696  MX get_low(const MX& v, const Dict& options) const;
697 
699  MX get_bspline(const std::vector<double>& knots,
700  const std::vector<casadi_int>& offset,
701  const std::vector<double>& coeffs,
702  const std::vector<casadi_int>& degree,
703  casadi_int m,
704  const std::vector<casadi_int>& lookup_mode) const;
706  MX get_bspline(const MX& coeffs, const std::vector<double>& knots,
707  const std::vector<casadi_int>& offset,
708  const std::vector<casadi_int>& degree,
709  casadi_int m,
710  const std::vector<casadi_int>& lookup_mode) const;
711 
713  MX get_convexify(const Dict& opts) const;
714 
719  mutable casadi_int temp;
720 
724  std::vector<MX> dep_;
725 
730 
734  static void copy_fwd(const bvec_t* arg, bvec_t* res, casadi_int len);
735 
739  static void copy_rev(bvec_t* arg, bvec_t* res, casadi_int len);
740 
741  static std::map<casadi_int, MXNode* (*)(DeserializingStream&)> deserialize_map;
742 
743  protected:
748  };
749 
751 } // namespace casadi
752 
753 #endif // CASADI_MX_NODE_HPP
Helper class for C code generation.
Helper class for Serialization.
Function object.
Definition: function.hpp:60
std::pair< casadi_int, casadi_int > size() const
Get the shape.
Linear solver.
Definition: linsol.hpp:55
Node class for MX objects.
Definition: mx_node.hpp:50
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
virtual MX get_nz_ref(const Slice &inner, const MX &outer) const
Get the nonzeros of matrix, parametrically.
virtual MX get_bilin(const MX &x, const MX &y) const
Bilinear form.
virtual MX get_horzcat(const std::vector< MX > &x) const
Create a horizontal concatenation node.
virtual MX get_norm_1() const
1-norm
virtual bool has_output() const
Check if a multiple output node.
Definition: mx_node.hpp:252
virtual int eval_sx(const SXElem **arg, SXElem **res, casadi_int *iw, SXElem *w) const
Evaluate symbolically (SX)
std::string class_name() const override
Get name of public class.
virtual MX get_repmat(casadi_int m, casadi_int n) const
Create a repeated matrix node.
virtual MX get_nzassign(const MX &y, const MX &inner, const Slice &outer) const
Assign the nonzeros of a matrix to another matrix, parametrically.
~MXNode() override=0
Destructor.
virtual MX get_nzassign(const MX &y, const MX &nz) const
Assign the nonzeros of a matrix to another matrix, parametrically.
virtual void serialize_type(SerializingStream &s) const
Serialize type information.
void disp(std::ostream &stream, bool more) const override
Print a description.
virtual MX get_det() const
Determinant.
virtual bool is_zero() const
Check if identically zero.
Definition: mx_node.hpp:70
virtual size_t sz_arg() const
Get required length of arg field.
Definition: mx_node.hpp:374
MXNode(DeserializingStream &s)
Deserializing constructor.
virtual MX get_nzassign(const MX &y, const std::vector< casadi_int > &nz) const
Assign the nonzeros of a matrix to another matrix.
virtual void serialize_body(SerializingStream &s) const
Serialize an object without type information.
virtual const std::string & name() const
Get the name.
virtual int sp_forward(const bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
Propagate sparsity forward.
virtual void eval_mx(const std::vector< MX > &arg, std::vector< MX > &res) const
Evaluate symbolically (MX)
virtual const Sparsity & sparsity(casadi_int oind) const
Get the sparsity of output oind.
static bool is_equal(const MXNode *x, const MXNode *y, casadi_int depth)
Check if two nodes are equivalent up to a given depth.
virtual void generate(CodeGenerator &g, const std::vector< casadi_int > &arg, const std::vector< casadi_int > &res) const
Generate code for the operation.
virtual MX get_inv() const
Inverse.
virtual Dict info() const
virtual MX get_einstein(const MX &A, const MX &B, const std::vector< casadi_int > &dim_c, const std::vector< casadi_int > &dim_a, const std::vector< casadi_int > &dim_b, const std::vector< casadi_int > &c, const std::vector< casadi_int > &a, const std::vector< casadi_int > &b) const
Einstein product and addition.
virtual const Function & which_function() const
Get called function.
void can_inline(std::map< const MXNode *, casadi_int > &nodeind) const
Find out which nodes can be inlined.
virtual bool is_valid_input() const
Check if valid function input.
Definition: mx_node.hpp:200
virtual MX get_nz_ref(const MX &inner, const Slice &outer) const
Get the nonzeros of matrix, parametrically.
MX get_find() const
Find.
virtual MX get_repsum(casadi_int m, casadi_int n) const
Create a repeated sum node.
static bool maxDepth()
Get equality checking depth.
Definition: mx_node.hpp:307
virtual MX get_subassign(const MX &y, const Slice &i, const Slice &j) const
Get submatrix assignment.
virtual MX get_nzassign(const MX &y, const Slice &inner, const MX &outer) const
Assign the nonzeros of a matrix to another matrix, parametrically.
MX get_bspline(const std::vector< double > &knots, const std::vector< casadi_int > &offset, const std::vector< double > &coeffs, const std::vector< casadi_int > &degree, casadi_int m, const std::vector< casadi_int > &lookup_mode) const
BSpline.
virtual size_t sz_w() const
Get required length of w field.
Definition: mx_node.hpp:389
virtual bool __nonzero__() const
Check the truth value of this node.
virtual MX join_primitives(std::vector< MX >::const_iterator &it) const
Join an expression along symbolic primitives.
virtual bool is_one() const
Check if identically one.
Definition: mx_node.hpp:75
static void copy_rev(bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities backwards through a copy operation.
virtual bool is_binary() const
Check if binary operation.
Definition: mx_node.hpp:100
virtual Matrix< casadi_int > mapping() const
Get an IM representation of a GetNonzeros or SetNonzeros node.
virtual void add_dependency(CodeGenerator &g) const
Add a dependent function.
Definition: mx_node.hpp:121
virtual MX get_nzadd(const MX &y, const std::vector< casadi_int > &nz) const
Add the nonzeros of a matrix to another matrix.
virtual void split_primitives(const MX &x, std::vector< MX >::iterator &it) const
Split up an expression along symbolic primitives.
virtual void ad_forward(const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const
Calculate forward mode directional derivatives.
virtual void split_primitives(const DM &x, std::vector< DM >::iterator &it) const
Split up an expression along symbolic primitives.
virtual MX get_subref(const Slice &i, const Slice &j) const
Get submatrix reference.
virtual double to_double() const
Get the value (only for scalar constant nodes)
virtual MX _get_binary(casadi_int op, const MX &y, bool scX, bool scY) const
Get a binary operation operation (matrix-matrix)
MX get_binary(casadi_int op, const MX &y) const
Get a binary operation operation.
virtual MX get_transpose() const
Transpose.
virtual MX get_nzref(const Sparsity &sp, const std::vector< casadi_int > &nz) const
Get the nonzeros of matrix.
virtual casadi_int n_inplace() const
Can the operation be performed inplace (i.e. overwrite the result)
Definition: mx_node.hpp:419
virtual bool has_duplicates() const
Detect duplicate symbolic expressions.
virtual MX get_solve_triu_unity(const MX &r, bool tr) const
Solve a system of linear equations, upper triangular A, unity diagonal.
std::pair< casadi_int, casadi_int > size() const
Definition: mx_node.hpp:357
virtual MX get_sparsity_cast(const Sparsity &sp) const
Sparsity cast.
virtual void ad_reverse(const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const
Calculate reverse mode directional derivatives.
Sparsity sparsity_
The sparsity pattern.
Definition: mx_node.hpp:729
virtual void reset_input() const
Reset the marker for an input expression.
virtual DM get_DM() const
Get the value (only for constant nodes)
virtual MX get_nzadd(const MX &y, const MX &inner, const MX &outer) const
Add the nonzeros of a matrix to another matrix, parametrically.
virtual MX get_nzadd(const MX &y, const MX &nz) const
Add the nonzeros of a matrix to another matrix, parametrically.
virtual MX get_nzassign(const MX &y, const MX &inner, const MX &outer) const
Assign the nonzeros of a matrix to another matrix, parametrically.
MXNode()
Constructor.
virtual MX get_norm_fro() const
Frobenius norm.
casadi_int temp
Definition: mx_node.hpp:719
casadi_int numel() const
Get shape.
Definition: mx_node.hpp:353
const Sparsity & sparsity() const
Get the sparsity.
Definition: mx_node.hpp:337
virtual DM join_primitives(std::vector< DM >::const_iterator &it) const
Join an expression along symbolic primitives.
virtual size_t sz_res() const
Get required length of res field.
Definition: mx_node.hpp:379
casadi_int size2() const
Definition: mx_node.hpp:356
virtual MX get_rank1(const MX &alpha, const MX &x, const MX &y) const
Bilinear form.
casadi_int nnz(casadi_int i=0) const
Definition: mx_node.hpp:354
bool matches_sparsity(const std::vector< T > &arg) const
Definition: mx_node.hpp:343
virtual void codegen_incref(CodeGenerator &g, std::set< void * > &added) const
Codegen incref.
Definition: mx_node.hpp:131
virtual MX get_unary(casadi_int op) const
Get a unary operation.
virtual int sp_reverse(bvec_t **arg, bvec_t **res, casadi_int *iw, bvec_t *w) const
Propagate sparsity backwards.
virtual casadi_int nout() const
Number of outputs.
Definition: mx_node.hpp:329
virtual bool is_value(double val) const
Check if a certain value.
Definition: mx_node.hpp:85
virtual MX get_nzadd(const MX &y, const Slice &inner, const MX &outer) const
Add the nonzeros of a matrix to another matrix, parametrically.
virtual void primitives(std::vector< MX >::iterator &it) const
Get symbolic primitives.
const MX & dep(casadi_int ind=0) const
dependencies - functions that have to be evaluated before this one
Definition: mx_node.hpp:319
std::vector< MX > dep_
dependencies - functions that have to be evaluated before this one
Definition: mx_node.hpp:724
virtual bool is_unary() const
Check if unary operation.
Definition: mx_node.hpp:95
virtual void codegen_decref(CodeGenerator &g, std::set< void * > &added) const
Codegen decref.
Definition: mx_node.hpp:136
void set_dep(const MX &dep1, const MX &dep2)
Set binary dependencies.
MX get_monitor(const std::string &comment) const
Monitor.
virtual MX get_mac(const MX &y, const MX &z) const
Matrix multiplication and addition.
casadi_int n_dep() const
Number of dependencies.
virtual MX get_nz_ref(const MX &nz) const
Get the nonzeros of matrix, parametrically.
virtual MX get_solve(const MX &r, bool tr, const Linsol &linear_solver) const
Solve a system of linear equations.
virtual casadi_int n_primitives() const
Get the number of symbolic primitives.
virtual std::vector< MX > get_horzsplit(const std::vector< casadi_int > &output_offset) const
Create a horizontal split node.
virtual void split_primitives(const SX &x, std::vector< SX >::iterator &it) const
Split up an expression along symbolic primitives.
MX get_convexify(const Dict &opts) const
Convexify.
void set_sparsity(const Sparsity &sparsity)
Set the sparsity.
virtual MX get_project(const Sparsity &sp) const
Create set sparse.
virtual casadi_int op() const =0
Get the operation.
virtual MX get_diagcat(const std::vector< MX > &x) const
Create a diagonal concatenation node.
MX get_bspline(const MX &coeffs, const std::vector< double > &knots, const std::vector< casadi_int > &offset, const std::vector< casadi_int > &degree, casadi_int m, const std::vector< casadi_int > &lookup_mode) const
BSpline.
virtual MX get_output(casadi_int oind) const
Get an output.
virtual MX get_nz_ref(const MX &inner, const MX &outer) const
Get the nonzeros of matrix, parametrically.
casadi_int size1() const
Definition: mx_node.hpp:355
virtual MX get_logsumexp() const
Logsumexp.
virtual MX get_solve_triu(const MX &r, bool tr) const
Solve a system of linear equations, upper triangular A.
virtual bool has_refcount() const
Is reference counting needed in codegen?
Definition: mx_node.hpp:126
virtual MX get_mmax() const
Max.
virtual casadi_int offset() const
virtual bool is_minus_one() const
Check if identically minus one.
Definition: mx_node.hpp:80
static std::map< casadi_int, MXNode *(*)(DeserializingStream &)> deserialize_map
Definition: mx_node.hpp:741
MX get_low(const MX &v, const Dict &options) const
Find.
virtual casadi_int which_output() const
Get function output.
virtual std::vector< MX > get_diagsplit(const std::vector< casadi_int > &offset1, const std::vector< casadi_int > &offset2) const
Create a diagonal split node.
void set_dep(const std::vector< MX > &dep)
Set multiple dependencies.
virtual MX get_norm_inf() const
Infinity norm.
bool sameOpAndDeps(const MXNode *node, casadi_int depth) const
Checks if two nodes have the same operation and have.
virtual MX get_vertcat(const std::vector< MX > &x) const
Create a vertical concatenation node (vectors only)
virtual MX get_solve_tril(const MX &r, bool tr) const
Solve a system of linear equations, lower triangular A.
void set_dep(const MX &dep)
Set unary dependency.
MX get_assert(const MX &y, const std::string &fail_message) const
Assertion.
virtual MX get_mmin() const
Min.
virtual int eval(const double **arg, double **res, casadi_int *iw, double *w) const
Evaluate numerically.
virtual casadi_int ind() const
void set_dep(const MX &dep1, const MX &dep2, const MX &dep3)
Set ternary dependencies.
virtual std::string disp(const std::vector< std::string > &arg) const =0
Print expression.
virtual SX join_primitives(std::vector< SX >::const_iterator &it) const
Join an expression along symbolic primitives.
virtual MX get_norm_2() const
Spectral norm.
virtual MX get_dot(const MX &y) const
Inner product.
virtual casadi_int segment() const
virtual MX get_reshape(const Sparsity &sp) const
Reshape.
virtual bool is_output() const
Check if evaluation output.
Definition: mx_node.hpp:247
virtual bool is_equal(const MXNode *node, casadi_int depth) const
Definition: mx_node.hpp:302
virtual MX get_nzadd(const MX &y, const MX &inner, const Slice &outer) const
Add the nonzeros of a matrix to another matrix, parametrically.
static void copy_fwd(const bvec_t *arg, bvec_t *res, casadi_int len)
Propagate sparsities forward through a copy operation.
virtual size_t sz_iw() const
Get required length of iw field.
Definition: mx_node.hpp:384
virtual bool is_eye() const
Check if identity matrix.
Definition: mx_node.hpp:90
virtual std::vector< MX > get_vertsplit(const std::vector< casadi_int > &output_offset) const
Create a vertical split node (vectors only)
static MX to_matrix(const MX &x, const Sparsity &sp)
Convert scalar to matrix.
Definition: mx_node.hpp:404
T join_primitives_gen(typename std::vector< T >::const_iterator &it) const
Join an expression along symbolic primitives (template)
void serialize(SerializingStream &s) const
Serialize an object.
virtual MX get_solve_tril_unity(const MX &r, bool tr) const
Solve a system of linear equations, lower triangular A, unity diagnal.
std::string print_compact(std::map< const MXNode *, casadi_int > &nodeind, std::vector< std::string > &intermed) const
Print compact.
MX - Matrix expression.
Definition: mx.hpp:84
static casadi_int get_max_depth()
Get the depth to which equalities are being checked for simplifications.
Sparse matrix class. SX and DM are specializations.
Definition: matrix_decl.hpp:92
Helper class for Serialization.
Class representing a Slice.
Definition: slice.hpp:48
General sparsity class.
Definition: sparsity.hpp:99
std::pair< casadi_int, casadi_int > size() const
Get the shape.
The casadi namespace.
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.