List of all members | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends
casadi::MX Class Reference

MX - Matrix expression. More...

#include <mx.hpp>

Detailed Description

The MX class is used to build up trees made up from MXNodes. It is a more general graph representation than the scalar expression, SX, and much less efficient for small objects. On the other hand, the class allows much more general operations than does SX, in particular matrix valued operations and calls to arbitrary differentiable functions.

The MX class is designed to have identical syntax with the Matrix<> template class, and uses DM (i.e. Matrix<double>) as its internal representation of the values at a node. By keeping the syntaxes identical, it is possible to switch from one class to the other, as well as inlining MX functions to SXElem functions.

Note that an operation is always "lazy", making a matrix multiplication will create a matrix multiplication node, not perform the actual multiplication.

Author
Joel Andersson
Date
2010-2011

Extra doc: https://github.com/casadi/casadi/wiki/L_py

Definition at line 88 of file mx.hpp.

Inheritance diagram for casadi::MX:
Inheritance graph
[legend]
Collaboration diagram for casadi::MX:
Collaboration graph
[legend]

Public Types

typedef MX ScalarType
 
typedef GenericMatrix< MXB
 Base class. More...
 
typedef std::map< std::string, MXMXDict
 Readability typedef. More...
 
using internal_base_type = SharedObjectInternal
 
using base_type = SharedObject
 

Public Member Functions

 MX ()
 Default constructor. More...
 
 MX (casadi_int nrow, casadi_int ncol)
 Create a sparse matrix with all structural zeros. More...
 
 MX (const std::pair< casadi_int, casadi_int > &rc)
 Create a sparse matrix with all structural zeros. More...
 
 MX (const Sparsity &sp)
 Create a sparse matrix from a sparsity pattern. More...
 
 MX (const Sparsity &sp, const MX &val)
 Construct matrix with a given sparsity and nonzeros. More...
 
 MX (const Sparsity &sp, const std::string &fname)
 Construct matrix with a given sparsity and a file with nonzeros. More...
 
 MX (const Matrix< double > &val, const std::string &name)
 Construct matrix with a given sparsity and nonzeros,. More...
 
 MX (double x)
 Create scalar constant (also implicit type conversion) More...
 
 MX (const std::vector< double > &x)
 Create vector constant (also implicit type conversion) More...
 
 MX (const Matrix< double > &x)
 Create sparse matrix constant (also implicit type conversion) More...
 
 ~MX ()
 Destructor. More...
 
const Sparsitysparsity () const
 Get the sparsity pattern. More...
 
bool __nonzero__ () const
 Returns the truth value of an MX expression. More...
 
Sparsity get_sparsity () const
 Get an owning reference to the sparsity pattern. More...
 
std::vector< MXget_nonzeros () const
 Get nonzeros as list of scalar MXes. More...
 
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) More...
 
void erase (const std::vector< casadi_int > &rr, bool ind1=false)
 Erase a submatrix (leaving structural zeros in its place) More...
 
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. More...
 
MX operator- () const
 
MX operator+ () const
 
MX inv () const
 Element-wise inverse. More...
 
MX dep (casadi_int ch=0) const
 Get the nth dependency as MX. More...
 
casadi_int n_out () const
 Number of outputs. More...
 
MX get_output (casadi_int oind) const
 Get an output. More...
 
casadi_int n_dep () const
 Get the number of dependencies of a binary SXElem. More...
 
std::string name () const
 Get the name. More...
 
 operator double () const
 Get the value (only for scalar constant nodes) More...
 
 operator Matrix< double > () const
 Get the value (only for constant nodes) More...
 
bool is_symbolic () const
 Check if symbolic. More...
 
bool is_constant () const
 Check if constant. More...
 
bool is_integer () const
 Check if integer. More...
 
bool is_doubled () const
 Check if the node is the sum of two equal expressions. More...
 
bool is_call () const
 Check if evaluation. More...
 
Function which_function () const
 Get function - only valid when is_call() is true. More...
 
bool is_output () const
 Check if evaluation output. More...
 
bool has_output () const
 Check if a multiple output node. More...
 
casadi_int which_output () const
 Get the index of evaluation output - only valid when is_output() is true. More...
 
bool is_op (casadi_int op) const
 Is it a certain operation. More...
 
bool is_multiplication () const
 Check if multiplication. More...
 
bool is_commutative () const
 Check if commutative operation. More...
 
bool is_norm () const
 Check if norm. More...
 
bool is_valid_input () const
 Check if matrix can be used to define function inputs. More...
 
casadi_int n_primitives () const
 Get the number of primitives for MXFunction inputs/outputs. More...
 
std::vector< MXprimitives () const
 Get primitives. More...
 
bool has_duplicates () const
 Detect duplicate symbolic expressions. More...
 
void reset_input () const
 Reset the marker for an input expression. More...
 
bool is_eye () const
 check if identity More...
 
bool is_zero () const
 check if zero (note that false negative answers are possible) More...
 
bool is_one () const
 check if one (note that false negative answers are possible) More...
 
bool is_minus_one () const
 check if minus one (note that false negative answers are possible) More...
 
bool is_half () const
 check if 0.5 (note that false negative answers are possible) More...
 
bool is_value (double val) const
 check if a certain value (note that false negative answers are possible) More...
 
bool is_inf () const
 check if inf (note that false negative answers are possible) More...
 
bool is_minus_inf () const
 check if -inf (note that false negative answers are possible) More...
 
bool is_transpose () const
 Is the expression a transpose? More...
 
bool is_regular () const
 Checks if expression does not contain NaN or Inf. More...
 
bool is_binary () const
 Is binary operation. More...
 
bool is_nonnegative () const
 Check if a value is always nonnegative (false negatives are allowed) More...
 
bool is_unary () const
 Is unary operation. More...
 
casadi_int op () const
 Get operation type. More...
 
Dict info () const
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
casadi_int get_temp () const
 
void set_temp (casadi_int t) const
 Set the temporary variable. More...
 
MXNodeget () const
 Get a const pointer to the node. More...
 
MX nzref (const Sparsity &sp, const std::vector< casadi_int > &nz) const
 Low-level access to get_nzref. More...
 
MX printme (const MX &b) const
 
MX attachAssert (const MX &y, const std::string &fail_message="") const
 returns itself, but with an assertion attached More...
 
MX monitor (const std::string &comment) const
 Monitor an expression. More...
 
MX dump (const std::string &base_filename, const Dict &opts=Dict()) const
 Dump an expression. More...
 
void reset_dump_count ()
 Reset the dump counter. More...
 
MX T () const
 Transpose the matrix. More...
 
Matrix< casadi_int > mapping () const
 Get an IM representation of a GetNonzeros or SetNonzeros node. More...
 
void eval_mx (const std::vector< MX > &arg, std::vector< MX > &res, const std::vector< bool > &unique=std::vector< bool >()) const
 Evaluate the MX node with new symbolic dependencies. More...
 
 MX (const Sparsity &sp, double val, bool dummy)
 Construct constant matrix with a given sparsity and values. More...
 
casadi_int nnz () const
 Get the number of (structural) non-zero elements. More...
 
casadi_int nnz_lower () const
 Get the number of non-zeros in the lower triangular half. More...
 
casadi_int nnz_upper () const
 Get the number of non-zeros in the upper triangular half. More...
 
casadi_int nnz_diag () const
 Get get the number of non-zeros on the diagonal. More...
 
casadi_int numel () const
 Get the number of elements. More...
 
casadi_int size1 () const
 Get the first dimension (i.e. number of rows) More...
 
casadi_int rows () const
 Get the number of rows, Octave-style syntax. More...
 
casadi_int size2 () const
 Get the second dimension (i.e. number of columns) More...
 
casadi_int columns () const
 Get the number of columns, Octave-style syntax. More...
 
std::string dim (bool with_nz=false) const
 Get string representation of dimensions. More...
 
std::pair< casadi_int, casadi_int > size () const
 Get the shape. More...
 
casadi_int size (casadi_int axis) const
 Get the size along a particular dimensions. More...
 
bool is_empty (bool both=false) const
 Check if the sparsity is empty, i.e. if one of the dimensions is zero. More...
 
bool is_dense () const
 Check if the matrix expression is dense. More...
 
bool is_scalar (bool scalar_and_dense=false) const
 Check if the matrix expression is scalar. More...
 
bool is_square () const
 Check if the matrix expression is square. More...
 
bool is_vector () const
 Check if the matrix is a row or column vector. More...
 
bool is_row () const
 Check if the matrix is a row vector (i.e. size1()==1) More...
 
bool is_column () const
 Check if the matrix is a column vector (i.e. size2()==1) More...
 
bool is_triu () const
 Check if the matrix is upper triangular. More...
 
bool is_tril () const
 Check if the matrix is lower triangular. More...
 
const MX nz (const K &k) const
 Get vector nonzero or slice of nonzeros. More...
 
NonZeros< MX, K > nz (const K &k)
 Access vector nonzero or slice of nonzeros. More...
 
const MX operator() (const RR &rr) const
 Get vector element or slice. More...
 
const MX operator() (const RR &rr, const CC &cc) const
 Get Matrix element or slice. More...
 
SubIndex< MX, RR > operator() (const RR &rr)
 Access Matrix elements (one argument) More...
 
SubMatrix< MX, RR, CC > operator() (const RR &rr, const CC &cc)
 Access Matrix elements (two arguments) More...
 
std::string class_name () const
 Get class name. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a description of the object. More...
 
std::string get_str (bool more=false) const
 Get string representation. More...
 
void print_ptr (std::ostream &stream=casadi::uout()) const
 
void own (SharedObjectInternal *node)
 
void assign (SharedObjectInternal *node)
 Assign the node to a node class pointer without reference counting. More...
 
casadi_int getCount () const
 Get the reference count. More...
 
void swap (GenericShared &other)
 Swap content with another instance. More...
 
std::string debug_repr () const
 
bool is_null () const
 Is a null pointer? More...
 
casadi_int __hash__ () const
 Returns a number that is unique for a given Node. More...
 
GenericWeakRef< SharedObject, SharedObjectInternal > * weak ()
 Get a weak reference to the object. More...
 
MXNodeoperator-> ()
 Access a member of the node. More...
 
const MXNodeoperator-> () const
 Const access a member of the node. More...
 
std::vector< MXsplit_primitives (const MX &x) const
 Split up an expression along symbolic primitives. More...
 
std::vector< SXsplit_primitives (const SX &x) const
 Split up an expression along symbolic primitives. More...
 
std::vector< DMsplit_primitives (const DM &x) const
 Split up an expression along symbolic primitives. More...
 
MX join_primitives (const std::vector< MX > &v) const
 Join an expression along symbolic primitives. More...
 
SX join_primitives (const std::vector< SX > &v) const
 Join an expression along symbolic primitives. More...
 
DM join_primitives (const std::vector< DM > &v) const
 Join an expression along symbolic primitives. More...
 
void get (MX &m, bool ind1, const Slice &rr) const
 
void get (MX &m, bool ind1, const Matrix< casadi_int > &rr) const
 
void get (MX &m, bool ind1, const Sparsity &sp) const
 
void get (MX &m, bool ind1, const MX &rr) const
 
void get (MX &m, bool ind1, const casadi_int rr) const
 
void get (MX &m, bool ind1, const Slice &rr, const Slice &cc) const
 
void get (MX &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc) const
 
void get (MX &m, bool ind1, const Slice &rr, casadi_int cc) const
 
void get (MX &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc) const
 
void get (MX &m, bool ind1, casadi_int rr, const Slice &cc) const
 
void get (MX &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc) const
 
void get (MX &m, bool ind1, casadi_int rr, casadi_int cc) const
 
void get (MX &m, bool ind1, const MX &rr, const Slice &cc) const
 
void get (MX &m, bool ind1, const Slice &rr, const MX &cc) const
 
void get (MX &m, bool ind1, const MX &rr, const MX &cc) const
 
void set (const MX &m, bool ind1, const Slice &rr)
 
void set (const MX &m, bool ind1, const Matrix< casadi_int > &rr)
 
void set (const MX &m, bool ind1, const Sparsity &sp)
 
void set (const MX &m, bool ind1, const Slice &rr, const Slice &cc)
 
void set (const MX &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc)
 
void set (const MX &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc)
 
void set (const MX &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc)
 
void get_nz (MX &m, bool ind1, const Slice &kk) const
 
void get_nz (MX &m, bool ind1, const Matrix< casadi_int > &kk) const
 
void get_nz (MX &m, bool ind1, const MX &kk) const
 
void get_nz (MX &m, bool ind1, casadi_int kk) const
 
void get_nz (MX &m, bool ind1, const MX &inner, const Slice &outer) const
 
void get_nz (MX &m, bool ind1, const Slice &inner, const MX &outer) const
 
void get_nz (MX &m, bool ind1, const MX &inner, const MX &outer) const
 
void set_nz (const MX &m, bool ind1, const Slice &kk)
 
void set_nz (const MX &m, bool ind1, const Matrix< casadi_int > &kk)
 
void set_nz (const MX &m, bool ind1, const MX &kk)
 
void set_nz (const MX &m, bool ind1, casadi_int kk)
 
void ad_forward (const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const
 Called from MXFunction. More...
 
void ad_reverse (const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const
 Called from MXFunction. More...
 
std::vector< casadi_int > get_row () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
std::vector< casadi_int > get_colind () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
const casadi_int * row () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
casadi_int row (casadi_int el) const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
const casadi_int * colind () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
casadi_int colind (casadi_int col) const
 Get the sparsity pattern. See the Sparsity class for details. More...
 

Static Public Member Functions

static std::string type_name ()
 Get type name. More...
 
static MX create (MXNode *node)
 Create from node. More...
 
static std::vector< MXcreateMultipleOutput (MXNode *node)
 Create from node (multiple-outputs) More...
 
static MX deserialize (DeserializingStream &s)
 Deserialize with type disambiguation. More...
 
static MX eye (casadi_int n)
 Identity matrix. More...
 
static bool simplify_ref_count (std::vector< MX > &arg, std::vector< MX > &res, const Dict &opts=Dict())
 
static bool simplify_const_folding (std::vector< MX > &arg, std::vector< MX > &res, const Dict &opts=Dict())
 
static bool simplify_combine_terms (std::vector< MX > &arg, std::vector< MX > &res, const Dict &opts=Dict())
 
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 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. More...
 
static void set_max_depth (casadi_int eq_depth=1)
 Set or reset the depth to which equalities are being checked for simplifications. More...
 
static casadi_int get_max_depth ()
 Get the depth to which equalities are being checked for simplifications. More...
 
static bool test_cast (const SharedObjectInternal *ptr)
 Check if a particular cast is allowed. More...
 
static std::vector< MXget_input (const Function &f)
 Get function inputs. More...
 
static std::vector< MXget_free (const Function &f)
 Get free variables. More...
 
static MX _sym (const std::string &name, const Sparsity &sp)
 
static MX logsumexp (const MX &x)
 
static MX binary (casadi_int op, const MX &x, const MX &y, bool unique_x=false, bool unique_y=false)
 Create nodes by their ID. More...
 
static MX unary (casadi_int op, const MX &x, bool unique=false)
 Create nodes by their ID. More...
 
static MX inf (const Sparsity &sp)
 create a matrix with all inf More...
 
static MX inf (casadi_int nrow=1, casadi_int ncol=1)
 create a matrix with all inf More...
 
static MX inf (const std::pair< casadi_int, casadi_int > &rc)
 create a matrix with all inf More...
 
static MX nan (const Sparsity &sp)
 create a matrix with all nan More...
 
static MX nan (casadi_int nrow=1, casadi_int ncol=1)
 create a matrix with all nan More...
 
static MX nan (const std::pair< casadi_int, casadi_int > &rc)
 create a matrix with all nan More...
 
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. More...
 
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. More...
 
static bool is_equal (const MX &x, const MX &y, casadi_int depth=0)
 
static MX mmin (const MX &x)
 
static MX mmax (const MX &x)
 
static MX horzcat (const std::vector< MX > &x)
 
static MX diagcat (const std::vector< MX > &x)
 
static MX vertcat (const std::vector< MX > &x)
 
static std::vector< MXhorzsplit (const MX &x, const std::vector< casadi_int > &offset)
 
static std::vector< MXdiagsplit (const MX &x, const std::vector< casadi_int > &offset1, const std::vector< casadi_int > &offset2)
 
static std::vector< MXvertsplit (const MX &x, const std::vector< casadi_int > &offset)
 
static MX blockcat (const std::vector< std::vector< MX > > &v)
 
static MX mtimes (const MX &x, const MX &y, const std::string &blas="reference")
 
static MX mac (const MX &x, const MX &y, const MX &z, const std::string &blas="reference")
 
static MX reshape (const MX &x, casadi_int nrow, casadi_int ncol)
 
static MX reshape (const MX &x, const Sparsity &sp)
 
static MX sparsity_cast (const MX &x, const Sparsity &sp)
 
static MX kron (const MX &x, const MX &b)
 
static MX kron_contract (const MX &m, const MX &x, bool inner)
 
static MX repmat (const MX &x, casadi_int n, casadi_int m=1)
 
static MX linspace (const MX &a, const MX &b, casadi_int nsteps)
 
static MX jacobian (const MX &f, const MX &x, const Dict &opts=Dict())
 
static MX hessian (const MX &f, const MX &x, const Dict &opts=Dict())
 
static MX hessian (const MX &f, const MX &x, MX &g, const Dict &opts=Dict())
 
static std::vector< std::vector< MX > > forward (const std::vector< MX > &ex, const std::vector< MX > &arg, const std::vector< std::vector< MX > > &v, const Dict &opts=Dict())
 
static std::vector< std::vector< MX > > reverse (const std::vector< MX > &ex, const std::vector< MX > &arg, const std::vector< std::vector< MX > > &v, const Dict &opts=Dict())
 
static std::vector< bool > which_depends (const MX &expr, const MX &var, casadi_int order=1, bool tr=false)
 
static Sparsity jacobian_sparsity (const MX &f, const MX &x)
 
static MX substitute (const MX &ex, const MX &v, const MX &vdef)
 
static std::vector< MXsubstitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef)
 
static void substitute_inplace (const std::vector< MX > &v, std::vector< MX > &vdef, std::vector< MX > &ex, bool reverse)
 
static MX solve (const MX &a, const MX &b)
 
static MX solve (const MX &a, const MX &b, const std::string &lsolver, const Dict &dict=Dict())
 
static MX inv_minor (const MX &A)
 
static MX inv_node (const MX &A)
 
static MX inv (const MX &A, const std::string &lsolver="qr", const Dict &dict=Dict())
 
static MX pinv (const MX &A, const std::string &lsolver="qr", const Dict &dict=Dict())
 
static MX expm_const (const MX &A, const MX &t)
 
static MX expm (const MX &A)
 
static casadi_int n_nodes (const MX &x)
 
static std::string print_operator (const MX &x, const std::vector< std::string > &args)
 
static void extract (std::vector< MX > &ex, std::vector< MX > &v, std::vector< MX > &vdef, const Dict &opts=Dict())
 
static void shared (std::vector< MX > &ex, std::vector< MX > &v, std::vector< MX > &vdef, const std::string &v_prefix, const std::string &v_suffix)
 
static MX if_else (const MX &cond, const MX &if_true, const MX &if_false, bool short_circuit=false)
 
static MX conditional (const MX &ind, const std::vector< MX > &x, const MX &x_default, bool short_circuit=false)
 
static bool depends_on (const MX &x, const MX &arg)
 
static bool contains_all (const std::vector< MX > &v, const std::vector< MX > &n)
 
static bool contains_any (const std::vector< MX > &v, const std::vector< MX > &n)
 
static MX simplify (const MX &x)
 
static MX transform (const MX &x, const Dict &opts=Dict())
 
static MX transform (const MX &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict())
 
static std::vector< MXtransform (const std::vector< MX > &x, const Dict &opts=Dict())
 
static std::vector< MXtransform (const std::vector< MX > &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict())
 
static MX dot (const MX &x, const MX &y)
 
static MX mrdivide (const MX &a, const MX &b)
 
static MX mldivide (const MX &a, const MX &b)
 
static MX norm_2 (const MX &x)
 
static MX norm_fro (const MX &x)
 
static MX norm_1 (const MX &x)
 
static MX norm_inf (const MX &x)
 
static MX unite (const MX &A, const MX &B)
 
static MX trace (const MX &x)
 
static MX diag (const MX &x)
 
static MX sum2 (const MX &x)
 
static MX sum1 (const MX &x)
 
static MX polyval (const MX &p, const MX &x)
 
static MX det (const MX &x)
 
static MX det (const MX &x, const std::string &lsolver, const Dict &opts=Dict())
 
static std::vector< MXsymvar (const MX &x)
 
static MX nullspace (const MX &A)
 
static MX repsum (const MX &x, casadi_int n, casadi_int m=1)
 
static MX densify (const MX &x, const MX &val=0)
 
static MX _bilin (const MX &A, const MX &x, const MX &y)
 
static MX _rank1 (const MX &A, const MX &alpha, const MX &x, const MX &y)
 
static MX project (const MX &x, const Sparsity &sp, bool intersect=false)
 
static MX cumsum (const MX &x, casadi_int axis=-1)
 
static MX _logsumexp (const MX &x)
 
static std::vector< MXcse (const std::vector< MX > &e)
 
static void extract_parametric (const MX &expr, const MX &par, MX &expr_ret, std::vector< MX > &symbols, std::vector< MX > &parametric, const Dict &opts)
 
static void separate_linear (const MX &expr, const MX &sym_lin, const MX &sym_const, MX &expr_const, MX &expr_lin, MX &expr_nonlin)
 
static MX find (const MX &x)
 
static MX low (const MX &v, const MX &p, const Dict &options=Dict())
 
static MX graph_substitute (const MX &x, const std::vector< MX > &v, const std::vector< MX > &vdef)
 
static MX graph_substitute (const MX &x, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated)
 
static std::vector< MXgraph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef)
 
static std::vector< MXgraph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated)
 
static MX matrix_expand (const MX &e, const std::vector< MX > &boundary, const Dict &options)
 
static std::vector< MXmatrix_expand (const std::vector< MX > &e, const std::vector< MX > &boundary, const Dict &options)
 
static MX lift (const MX &x, const MX &x_guess)
 
static DM evalf (const MX &m)
 
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())
 
static 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())
 
static MX bspline (const MX &x, const MX &coeffs, const std::vector< MX > &knots, const std::vector< casadi_int > &degree, casadi_int m, const Dict &opts=Dict())
 
static MX convexify (const MX &H, const Dict &opts=Dict())
 
static MX stop_diff (const MX &expr, casadi_int order)
 
static MX stop_diff (const MX &expr, const MX &var, casadi_int order)
 
static std::vector< MXdifference (const std::vector< MX > &a, const std::vector< MX > &b)
 
static MX interp1d (const std::vector< double > &x, const MX &v, const std::vector< double > &xq, const std::string &mode, bool equidistant)
 Functions called by friend functions defined here. More...
 
static casadi_int sprank (const MX &x)
 Functions called by friend functions defined here. More...
 
static casadi_int norm_0_mul (const MX &x, const MX &y)
 Functions called by friend functions defined here. More...
 
static MX tril (const MX &x, bool includeDiagonal=true)
 Functions called by friend functions defined here. More...
 
static MX triu (const MX &x, bool includeDiagonal=true)
 Functions called by friend functions defined here. More...
 
static MX sumsqr (const MX &x)
 Functions called by friend functions defined here. More...
 
static MX linspace (const MX &a, const MX &b, casadi_int nsteps)
 Functions called by friend functions defined here. More...
 
static MX cross (const MX &a, const MX &b, casadi_int dim=-1)
 Functions called by friend functions defined here. More...
 
static MX skew (const MX &a)
 Functions called by friend functions defined here. More...
 
static MX inv_skew (const MX &a)
 Functions called by friend functions defined here. More...
 
static MX tril2symm (const MX &x)
 Functions called by friend functions defined here. More...
 
static MX triu2symm (const MX &x)
 Functions called by friend functions defined here. More...
 
static MX repsum (const MX &x, casadi_int n, casadi_int m=1)
 Functions called by friend functions defined here. More...
 
static MX diff (const MX &x, casadi_int n=1, casadi_int axis=-1)
 Functions called by friend functions defined here. More...
 
static bool is_linear (const MX &expr, const MX &var)
 Functions called by friend functions defined here. More...
 
static bool is_quadratic (const MX &expr, const MX &var)
 Functions called by friend functions defined here. More...
 
static void quadratic_coeff (const MX &expr, const MX &var, MX &A, MX &b, MX &c, bool check)
 Functions called by friend functions defined here. More...
 
static void linear_coeff (const MX &expr, const MX &var, MX &A, MX &b, bool check)
 Functions called by friend functions defined here. More...
 
static MX mpower (const MX &x, const MX &y)
 
static MX soc (const MX &x, const MX &y)
 
static MX linearize (const MX &f, const MX &x, const MX &x0, const Dict &opts=Dict())
 
static MX gradient (const MX &ex, const MX &arg, const Dict &opts=Dict())
 
static MX tangent (const MX &ex, const MX &arg, const Dict &opts=Dict())
 
static MX jtimes (const MX &ex, const MX &arg, const MX &v, bool tr=false, const Dict &opts=Dict())
 
static MX bilin (const MX &A, const MX &x, const MX &y)
 Calculate bilinear/quadratic form x^T A y. More...
 
static MX rank1 (const MX &A, const MX &alpha, const MX &x, const MX &y)
 Make a rank-1 update to a matrix A. More...
 
Construct symbolic primitives

The "sym" function is intended to work in a similar way as "sym" used in the Symbolic Toolbox for Matlab but instead creating a CasADi symbolic primitive.

static MX sym (const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
 Create an nrow-by-ncol symbolic primitive. More...
 
static MX sym (const std::string &name, const std::pair< casadi_int, casadi_int > &rc)
 Construct a symbolic primitive with given dimensions. More...
 
static MX sym (const std::string &name, const Sparsity &sp)
 Create symbolic primitive with a given sparsity pattern. More...
 
static std::vector< MXsym (const std::string &name, const Sparsity &sp, casadi_int p)
 Create a vector of length p with with matrices. More...
 
static std::vector< MXsym (const std::string &name, casadi_int nrow, casadi_int ncol, casadi_int p)
 Create a vector of length p with nrow-by-ncol symbolic primitives. More...
 
static std::vector< std::vector< MX > > sym (const std::string &name, const Sparsity &sp, casadi_int p, casadi_int r)
 Create a vector of length r of vectors of length p with. More...
 
static std::vector< std::vector< MX > > sym (const std::string &name, casadi_int nrow, casadi_int ncol, casadi_int p, casadi_int r)
 Create a vector of length r of vectors of length p. More...
 
static MX zeros (casadi_int nrow=1, casadi_int ncol=1)
 Create a dense matrix or a matrix with specified sparsity with all entries zero. More...
 
static MX zeros (const Sparsity &sp)
 Create a dense matrix or a matrix with specified sparsity with all entries zero. More...
 
static MX zeros (const std::pair< casadi_int, casadi_int > &rc)
 Create a dense matrix or a matrix with specified sparsity with all entries zero. More...
 
static MX ones (casadi_int nrow=1, casadi_int ncol=1)
 Create a dense matrix or a matrix with specified sparsity with all entries one. More...
 
static MX ones (const Sparsity &sp)
 Create a dense matrix or a matrix with specified sparsity with all entries one. More...
 
static MX ones (const std::pair< casadi_int, casadi_int > &rc)
 Create a dense matrix or a matrix with specified sparsity with all entries one. More...
 

Protected Member Functions

void count_up ()
 
void count_down ()
 

Static Private Member Functions

static MX printme (const MX &x, const MX &y)
 

Friends

MX find (const MX &x)
 Find first nonzero, returned as row index. More...
 
MX low (const MX &v, const MX &p, const Dict &options=Dict())
 Find first nonzero. More...
 
MX graph_substitute (const MX &ex, const std::vector< MX > &v, const std::vector< MX > &vdef)
 Substitute single expression in graph. More...
 
MX graph_substitute (const MX &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated)
 
std::vector< MXgraph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef)
 Substitute multiple expressions in graph. More...
 
std::vector< MXgraph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated)
 
MX matrix_expand (const MX &e, const std::vector< MX > &boundary=std::vector< MX >(), const Dict &options=Dict())
 Expand MX graph to SXFunction call. More...
 
std::vector< MXmatrix_expand (const std::vector< MX > &e, const std::vector< MX > &boundary=std::vector< MX >(), const Dict &options=Dict())
 Expand MX graph to SXFunction call. More...
 
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())
 
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())
 
MX bspline (const MX &x, const MX &coeffs, const std::vector< MX > &knots, const std::vector< casadi_int > &degree, casadi_int m, const Dict &opts=Dict())
 
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())
 
MX convexify (const MX &H, const Dict &opts=Dict())
 
MX lift (const MX &x, const MX &x_guess)
 Lift the expression. More...
 
MX inv_node (const MX &x)
 Inverse node. More...
 
DM evalf (const MX &expr)
 Evaluates the expression numerically. More...
 
MX stop_diff (const MX &expr, casadi_int order)
 Stop derivatives of an expression wrt to all its symbolic variables. More...
 
MX no_grad (const MX &expr)
 Stop first derivatives of an expression wrt to all its symbolic variables. More...
 
MX no_hess (const MX &expr)
 Stop second derivatives of an expression wrt to all its symbolic variables. More...
 
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. More...
 
std::vector< MXdifference (const std::vector< MX > &a, const std::vector< MX > &b)
 

Member Typedef Documentation

◆ B

Definition at line 189 of file mx.hpp.

◆ base_type

Definition at line 103 of file shared_object.hpp.

◆ internal_base_type

Definition at line 102 of file shared_object.hpp.

◆ MXDict

typedef std::map<std::string, MX> casadi::MX::MXDict

Definition at line 1064 of file mx.hpp.

◆ ScalarType

Scalar type

Definition at line 185 of file mx.hpp.

Constructor & Destructor Documentation

◆ MX() [1/11]

casadi::MX::MX ( )

◆ MX() [2/11]

casadi::MX::MX ( casadi_int  nrow,
casadi_int  ncol 
)

Extra doc: https://github.com/casadi/casadi/wiki/L_q1

Definition at line 110 of file mx.cpp.

110  {
111  own(ConstantMX::create(Sparsity(nrow, ncol), 0));
112  }
static ConstantMX * create(const Sparsity &sp, casadi_int val)

References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

◆ MX() [3/11]

casadi::MX::MX ( const std::pair< casadi_int, casadi_int > &  rc)
explicit

◆ MX() [4/11]

casadi::MX::MX ( const Sparsity sp)
explicit

Same as MX::ones(sparsity)

Extra doc: https://github.com/casadi/casadi/wiki/L_q3

Definition at line 106 of file mx.cpp.

106  {
107  own(ConstantMX::create(sp, 1));
108  }

References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

◆ MX() [5/11]

casadi::MX::MX ( const Sparsity sp,
const MX val 
)

Extra doc: https://github.com/casadi/casadi/wiki/L_q4

Definition at line 85 of file mx.cpp.

85  {
86  if (sp.is_reshape(val.sparsity())) {
87  *this = reshape(val, sp);
88  } else if (val.is_scalar()) {
89  // Dense matrix if val dense
90  if (val.is_dense()) {
91  if (val.is_constant()) {
92  own(ConstantMX::create(sp, static_cast<double>(val)));
93  } else {
94  *this = val->get_nzref(sp, std::vector<casadi_int>(sp.nnz(), 0));
95  }
96  } else {
97  // Empty matrix
98  own(ConstantMX::create(Sparsity(sp.size()), 0));
99  }
100  } else {
101  casadi_assert_dev(val.is_column() && sp.nnz()==val.size1());
102  *this = densify(val)->get_nzref(sp, range(sp.nnz()));
103  }
104  }
virtual MX get_nzref(const Sparsity &sp, const std::vector< casadi_int > &nz, bool unique=false) const
Get the nonzeros of matrix.
Definition: mx_node.cpp:660
static MX reshape(const MX &x, casadi_int nrow, casadi_int ncol)
Definition: mx.cpp:1343
static MX densify(const MX &x, const MX &val=0)
Definition: mx.cpp:923
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.

References casadi::ConstantMX::create(), densify(), casadi::MXNode::get_nzref(), casadi::GenericMatrix< MatType >::is_column(), is_constant(), casadi::GenericMatrix< MatType >::is_dense(), casadi::Sparsity::is_reshape(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::Sparsity::nnz(), casadi::GenericShared< SharedObject, SharedObjectInternal >::own(), casadi::range(), reshape(), casadi::Sparsity::size(), casadi::GenericMatrix< MatType >::size1(), and sparsity().

◆ MX() [6/11]

casadi::MX::MX ( const Sparsity sp,
const std::string &  fname 
)

◆ MX() [7/11]

casadi::MX::MX ( const Matrix< double > &  val,
const std::string &  name 
)

configurable in codegen via a pool

Extra doc: https://github.com/casadi/casadi/wiki/L_2aa

Definition at line 126 of file mx.cpp.

126  {
127  own(ConstantMX::create(val, name));
128  }
std::string name() const
Get the name.
Definition: mx.cpp:791

References casadi::ConstantMX::create(), name(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

◆ MX() [8/11]

casadi::MX::MX ( double  x)

Extra doc: https://github.com/casadi/casadi/wiki/L_q6

Definition at line 73 of file mx.cpp.

73  {
75  }
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern *.
Definition: sparsity.cpp:1028

References casadi::ConstantMX::create(), casadi::Sparsity::dense(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

◆ MX() [9/11]

casadi::MX::MX ( const std::vector< double > &  x)

◆ MX() [10/11]

casadi::MX::MX ( const Matrix< double > &  x)

◆ ~MX()

casadi::MX::~MX ( )

Extra doc: https://github.com/casadi/casadi/wiki/L_q9

Definition at line 58 of file mx.cpp.

58  {
59  }

◆ MX() [11/11]

casadi::MX::MX ( const Sparsity sp,
double  val,
bool  dummy 
)

Definition at line 118 of file mx.cpp.

118  {
119  own(ConstantMX::create(sp, val));
120  }

References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().

Member Function Documentation

◆ __hash__()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::__hash__
inherited

If the Object does not point to any node, "0" is returned.

Extra doc: https://github.com/casadi/casadi/wiki/L_av

Definition at line 123 of file generic_shared_impl.hpp.

148  {
149  return reinterpret_cast<casadi_int>(get());
150  }

◆ __nonzero__()

bool casadi::MX::__nonzero__ ( ) const

Definition at line 145 of file mx.cpp.

145  {
146  return (*this)->__nonzero__();
147  }

◆ _bilin()

MX casadi::MX::_bilin ( const MX A,
const MX x,
const MX y 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 3209 of file mx.cpp.

3209  {
3210  return A->get_bilin(x, y);
3211  }

References casadi::MXNode::get_bilin().

◆ _logsumexp()

MX casadi::MX::_logsumexp ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 3217 of file mx.cpp.

3217  {
3218  return x->get_logsumexp();
3219  }

References casadi::MXNode::get_logsumexp().

◆ _rank1()

MX casadi::MX::_rank1 ( const MX A,
const MX alpha,
const MX x,
const MX y 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 3213 of file mx.cpp.

3213  {
3214  return A->get_rank1(alpha, x, y);
3215  }

References casadi::MXNode::get_rank1().

◆ _sym()

MX casadi::MX::_sym ( const std::string &  name,
const Sparsity sp 
)
static

Definition at line 946 of file mx.cpp.

946  {
947  if (sp.nnz()==0) {
948  return MX::zeros(sp);
949  } else {
950  return MX::create(new SymbolicMX(name, sp));
951  }
952  }
static MX zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
static MX create(MXNode *node)
Create from node.
Definition: mx.cpp:69

References create(), name(), casadi::Sparsity::nnz(), and casadi::GenericMatrix< MX >::zeros().

◆ ad_forward()

void casadi::MX::ad_forward ( const std::vector< std::vector< MX > > &  fseed,
std::vector< std::vector< MX > > &  fsens 
) const

Extra doc: https://github.com/casadi/casadi/wiki/L_ro

Definition at line 3232 of file mx.cpp.

3233  {
3234  try {
3235  (*this)->ad_forward(fseed, fsens);
3236  } catch (std::exception& e) {
3237  CASADI_THROW_ERROR_OBJ("ad_forward", e.what());
3238  }
3239  }

◆ ad_reverse()

void casadi::MX::ad_reverse ( const std::vector< std::vector< MX > > &  aseed,
std::vector< std::vector< MX > > &  asens 
) const

Extra doc: https://github.com/casadi/casadi/wiki/L_ro

Definition at line 3241 of file mx.cpp.

3242  {
3243  try {
3244  (*this)->ad_reverse(aseed, asens);
3245  } catch (std::exception& e) {
3246  CASADI_THROW_ERROR_OBJ("ad_reverse", e.what());
3247  }
3248  }

◆ assign()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::assign ( Internal *  node)
inherited

improper use will cause memory leaks!

Extra doc: https://github.com/casadi/casadi/wiki/L_at

Definition at line 96 of file generic_shared_impl.hpp.

86  {
87  node = node_;
88  }

◆ attachAssert()

MX casadi::MX::attachAssert ( const MX y,
const std::string &  fail_message = "" 
) const

If y does not evaluate to 1, a runtime error is raised

Extra doc: https://github.com/casadi/casadi/wiki/L_rg

Examples
misc/assertion.py.

Definition at line 743 of file mx.cpp.

743  {
744  casadi_assert(y.is_scalar(),
745  "Error in attachAssert: assertion expression y must be scalar, "
746  "but got " + y.dim());
747  return(*this)->get_assert(y, fail_message);
748  }

References casadi::GenericMatrix< MatType >::dim(), and casadi::GenericMatrix< MatType >::is_scalar().

◆ bilin()

static MX casadi::GenericMatrix< MX >::bilin ( const MX A,
const MX x,
const MX y 
)
staticinherited
Parameters
[in]ycan be omitted, in which case x^T A x is calculated

Extra doc: https://github.com/casadi/casadi/wiki/L_1bo

◆ binary()

MX casadi::MX::binary ( casadi_int  op,
const MX x,
const MX y,
bool  unique_x = false,
bool  unique_y = false 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r1

Definition at line 533 of file mx.cpp.

533  {
534  // Check, correct dimensions
535  if (x.size()!=y.size() && !x.is_scalar() && !y.is_scalar()) {
536  // x and y are horizontal multiples of each other?
537  if (!x.is_empty() && !y.is_empty()) {
538  if (x.size1() == y.size1() && x.size2() % y.size2() == 0) {
539  return binary(op, x, repmat(y, 1, x.size2() / y.size2()), unique_x, false);
540  } else if (y.size1() == x.size1() && y.size2() % x.size2() == 0) {
541  return binary(op, repmat(x, 1, y.size2() / x.size2()), y, false, unique_y);
542  }
543  }
544  // x and y are empty horizontal multiples of each other?
545  if (x.size1()==0 && y.size1()==0 && x.size2()>0 && y.size2()>0) {
546  if (x.size2() % y.size2() == 0) {
547  return MX(0, x.size2());
548  } else if (y.size2() % x.size2() == 0) {
549  return MX(0, y.size2());
550  }
551  }
552  // Dimension mismatch
553  casadi_error("Dimension mismatch for " + casadi_math<double>::print(op, "x", "y") +
554  ", x is " + x.dim() + ", while y is " + y.dim());
555  }
556  // Call internal class
557  return x->get_binary(op, y, unique_x, unique_y);
558  }
static MX repmat(const MX &x, casadi_int n, casadi_int m=1)
Definition: mx.cpp:2085
MX()
Default constructor.
Definition: mx.cpp:61
static MX binary(casadi_int op, const MX &x, const MX &y, bool unique_x=false, bool unique_y=false)
Create nodes by their ID.
Definition: mx.cpp:533
casadi_int op() const
Get operation type.
Definition: mx.cpp:851
static std::string print(unsigned char op, const std::string &x, const std::string &y)
Print.
Definition: calculus.hpp:1651

References casadi::GenericMatrix< MatType >::dim(), casadi::MXNode::get_binary(), casadi::GenericMatrix< MatType >::is_empty(), casadi::GenericMatrix< MatType >::is_scalar(), MX(), op(), repmat(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().

Referenced by casadi::BinaryMX< ScX, ScY >::eval_mx(), and printme().

◆ blockcat()

MX casadi::MX::blockcat ( const std::vector< std::vector< MX > > &  v)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1263 of file mx.cpp.

1263  {
1264  // Quick return if no block rows
1265  if (v.empty()) return MX(0, 0);
1266 
1267  // Make sure same number of block columns
1268  casadi_int ncols = v.front().size();
1269  for (auto&& e : v) {
1270  casadi_assert(e.size()==ncols, "blockcat: Inconsistent number of block columns");
1271  }
1272 
1273  // Quick return if no block columns
1274  if (v.front().empty()) return MX(0, 0);
1275 
1276  // Horizontally concatenate all columns for each row, then vertically concatenate rows
1277  std::vector<MX> rows;
1278  for (auto&& e : v) {
1279  rows.push_back(horzcat(e));
1280  }
1281  return vertcat(rows);
1282  }
casadi_int rows() const
Get the number of rows, Octave-style syntax.
static MX horzcat(const std::vector< MX > &x)
Definition: mx.cpp:1119
static MX vertcat(const std::vector< MX > &x)
Definition: mx.cpp:1165

References horzcat(), MX(), casadi::GenericMatrix< MX >::rows(), and vertcat().

Referenced by casadi::Expm::get_forward(), casadi::Nlpsol::get_forward(), casadi::Expm::get_reverse(), and casadi::Nlpsol::get_reverse().

◆ bspline() [1/3]

MX casadi::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() 
)
static

Functions called by friend functions defined for this class

Definition at line 2224 of file mx.cpp.

2229  {
2230  return BSpline::create(x, knots, coeffs.nonzeros(), degree, m, opts);
2231  }
static MX create(const MX &x, const std::vector< std::vector< double > > &knots, const std::vector< double > &coeffs, const std::vector< casadi_int > &degree, casadi_int m, const Dict &opts)
Definition: bspline.cpp:273

References casadi::BSpline::create(), and casadi::Matrix< Scalar >::nonzeros().

Referenced by casadi::Function::bspline(), casadi::BSplineInterpolant::construct_graph(), and casadi::BSplineCommon::jac().

◆ bspline() [2/3]

MX casadi::MX::bspline ( const MX x,
const MX coeffs,
const std::vector< MX > &  knots,
const std::vector< casadi_int > &  degree,
casadi_int  m,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for this class

Definition at line 2241 of file mx.cpp.

2245  {
2246  return BSplineParametric::create(x, coeffs, knots, degree, m, opts);
2247  }
static MX create(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)
Definition: bspline.cpp:310

References casadi::BSplineParametric::create().

◆ bspline() [3/3]

MX casadi::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() 
)
static

Functions called by friend functions defined for this class

Definition at line 2233 of file mx.cpp.

2237  {
2238  return BSplineParametric::create(x, coeffs, knots, degree, m, opts);
2239  }

References casadi::BSplineParametric::create().

◆ bspline_dual()

DM casadi::MX::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

Definition at line 2249 of file mx.cpp.

2252  {
2253  return BSpline::dual(x, knots, degree, opts);
2254  }
static DM dual(const std::vector< double > &x, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > &degree, const Dict &opts)
Definition: bspline.cpp:487

References casadi::BSpline::dual().

Referenced by casadi::BSplineInterpolant::construct_graph().

◆ class_name()

std::string casadi::SharedObject::class_name ( ) const
inherited

◆ colind() [1/2]

const casadi_int* casadi::GenericMatrix< MX >::colind ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b8

Definition at line 198 of file generic_matrix.hpp.

198 { return sparsity().colind(); }
Sparsity sparsity() const
Get the sparsity pattern.
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
Definition: sparsity.cpp:168

◆ colind() [2/2]

casadi_int casadi::GenericMatrix< MX >::colind ( casadi_int  col) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b8

Definition at line 201 of file generic_matrix.hpp.

201 { return sparsity().colind(col); }

◆ columns()

casadi_int casadi::GenericMatrix< MX >::columns ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1av

Definition at line 124 of file generic_matrix.hpp.

124 {return size2();}
casadi_int size2() const
Get the second dimension (i.e. number of columns)

◆ conditional()

MX casadi::MX::conditional ( const MX ind,
const std::vector< MX > &  x,
const MX x_default,
bool  short_circuit = false 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1395 of file mx.cpp.

1396  {
1397  if (short_circuit) {
1398  // Get symbolic primitives
1399  std::vector<MX> arg = x;
1400  arg.push_back(x_default);
1401  arg = symvar(veccat(arg));
1402 
1403  // Form functions for cases
1404  std::vector<Function> f(x.size());
1405  for (casadi_int k=0; k<x.size(); ++k) {
1406  std::stringstream ss;
1407  ss << "f_case" << k;
1408  f[k] = Function(ss.str(), arg, {x[k]});
1409  }
1410  Function f_default("f_default", arg, {x_default});
1411 
1412  // Form Switch
1413  Function sw = Function::conditional("switch", f, f_default);
1414 
1415  // Call the Switch
1416  std::vector<MX> sw_arg;
1417  sw_arg.push_back(ind);
1418  sw_arg.insert(sw_arg.end(), arg.begin(), arg.end());
1419  return sw(sw_arg).at(0);
1420  } else {
1421  MX ret = x_default;
1422  for (casadi_int k=0; k<x.size(); ++k) {
1423  ret = if_else(ind==static_cast<double>(k), x[k], ret);
1424  }
1425  return ret;
1426  }
1427  }
static Function conditional(const std::string &name, const std::vector< Function > &f, const Function &f_def, const Dict &opts=Dict())
Constuct a switch function.
Definition: function.cpp:917
static std::vector< MX > symvar(const MX &x)
Definition: mx.cpp:2041
static MX if_else(const MX &cond, const MX &if_true, const MX &if_false, bool short_circuit=false)
Definition: mx.cpp:1373
static MatType veccat(const std::vector< MatType > &x)

References casadi::Function::conditional(), if_else(), symvar(), and casadi::SparsityInterface< MatType >::veccat().

◆ contains_all()

bool casadi::MX::contains_all ( const std::vector< MX > &  v,
const std::vector< MX > &  n 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2184 of file mx.cpp.

2184  {
2185  if (n.empty()) return true;
2186 
2187  // Set to contain all nodes
2188  std::set<MXNode*> l;
2189  for (const MX& e : v) l.insert(e.get());
2190 
2191  size_t l_unique = l.size();
2192 
2193  for (const MX& e : n) l.insert(e.get());
2194 
2195  return l.size()==l_unique;
2196  }

◆ contains_any()

bool casadi::MX::contains_any ( const std::vector< MX > &  v,
const std::vector< MX > &  n 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2198 of file mx.cpp.

2198  {
2199  if (n.empty()) return true;
2200 
2201  // Set to contain all nodes
2202  std::set<MXNode*> l;
2203  for (const MX& e : v) l.insert(e.get());
2204 
2205  size_t l_unique = l.size();
2206 
2207  std::set<MXNode*> r;
2208  for (const MX& e : n) r.insert(e.get());
2209 
2210  size_t r_unique = r.size();
2211  for (const MX& e : n) l.insert(e.get());
2212 
2213  return l.size()<l_unique+r_unique;
2214  }

◆ convexify()

MX casadi::MX::convexify ( const MX H,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for this class

Definition at line 2256 of file mx.cpp.

2257  {
2258  return H->get_convexify(opts);
2259  }

References casadi::MXNode::get_convexify().

◆ count_down()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_down
protectedinherited

Definition at line 133 of file generic_shared_impl.hpp.

46  {
47 #ifdef WITH_EXTRA_CHECKS
48  casadi_assert_dev(Function::call_depth_==0);
49 #endif // WITH_EXTRA_CHECKS
50  if (!node) return;
51 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
52  GenericWeakRef<Shared, Internal>* weak_ref =
53  node->weak_ref_.load(std::memory_order_acquire);
54 #else
55  GenericWeakRef<Shared, Internal>* weak_ref = node->weak_ref_;
56 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
57  if (weak_ref) {
58 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
59  // get_mutex() returns a shared_ptr copy, so the mutex outlives this lock
60  // even if delete node (below) destroys the WeakRefInternal holding it
61  auto mutex = weak_ref->get_mutex();
62  // Avoid triggering a delete while a weak_ref.shared_if_alive is being called
63  std::lock_guard<std::mutex> lock(*mutex);
64 #endif // CASADI_WITH_THREADSAFE_SYMBOLICS
65 
66  if (--static_cast<Internal*>(node)->count == 0) {
67  delete node;
68  node = nullptr;
69  }
70  } else {
71  if (--static_cast<Internal*>(node)->count == 0) {
72  delete node;
73  node = nullptr;
74  }
75  }
76  }

◆ count_up()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::count_up
protectedinherited

Definition at line 132 of file generic_shared_impl.hpp.

36  {
37 #ifdef WITH_EXTRA_CHECKS
38  casadi_assert_dev(Function::call_depth_==0);
39 #endif // WITH_EXTRA_CHECKS
40 
41  if (node) static_cast<Internal*>(node)->count++;
42 
43  }

◆ create()

MX casadi::MX::create ( MXNode node)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_qa

Definition at line 69 of file mx.cpp.

69  {
70  return MX(node, false, false, false, false);
71  }

References MX().

Referenced by casadi::MXNode::_get_binary(), _sym(), casadi::Kron::create(), casadi::KronContract::create(), casadi::GetNonzerosParam::create(), casadi::SetNonzerosParam< Add >::create(), casadi::SetNonzeros< Add >::create(), casadi::Multiplication::create(), casadi::GetNonzeros::create(), casadi::Call::create_call(), createMultipleOutput(), deserialize(), casadi::MXNode::get_assert(), casadi::MXNode::get_bilin(), casadi::MXNode::get_bspline(), casadi::MXNode::get_convexify(), casadi::MXNode::get_det(), casadi::MXNode::get_diagcat(), casadi::MXNode::get_dot(), casadi::MXNode::get_dump(), casadi::MXNode::get_einstein(), casadi::MXNode::get_find(), casadi::MXNode::get_horzcat(), casadi::MXNode::get_inv(), casadi::MXNode::get_logsumexp(), casadi::MXNode::get_low(), casadi::MXNode::get_mmax(), casadi::MXNode::get_mmin(), casadi::MXNode::get_monitor(), casadi::MXNode::get_norm_1(), casadi::MXNode::get_norm_2(), casadi::MXNode::get_norm_fro(), casadi::MXNode::get_norm_inf(), casadi::Constant< Value >::get_nzref(), casadi::Call::get_output(), casadi::MultipleOutput::get_output(), casadi::MXNode::get_project(), casadi::Constant< Value >::get_project(), casadi::MXNode::get_rank1(), casadi::MXNode::get_repmat(), casadi::MXNode::get_repsum(), casadi::MXNode::get_reshape(), casadi::Constant< Value >::get_reshape(), casadi::MXNode::get_solve(), casadi::MXNode::get_solve_tril(), casadi::MXNode::get_solve_tril_unity(), casadi::MXNode::get_solve_triu(), casadi::MXNode::get_solve_triu_unity(), casadi::MXNode::get_sparsity_cast(), casadi::MXNode::get_subassign(), casadi::MXNode::get_subref(), casadi::MXNode::get_transpose(), casadi::Constant< Value >::get_transpose(), casadi::MXNode::get_unary(), casadi::MXNode::get_vertcat(), inf(), casadi::MXFunction::init(), and nan().

◆ createMultipleOutput()

std::vector< MX > casadi::MX::createMultipleOutput ( MXNode node)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_qb

Definition at line 130 of file mx.cpp.

130  {
131  casadi_assert_dev(dynamic_cast<MultipleOutput*>(node) != nullptr);
132  MX x = MX::create(node);
133  std::vector<MX> ret(x->nout());
134  for (casadi_int i=0; i<ret.size(); ++i) {
135  ret[i] = x.get_output(i);
136  if (ret[i].is_empty(true)) {
137  ret[i] = MX(0, 0);
138  } else if (ret[i].nnz()==0) {
139  ret[i] = MX(ret[i].size());
140  }
141  }
142  return ret;
143  }
bool is_empty(bool both=false) const
Check if the sparsity is empty, i.e. if one of the dimensions is zero.
std::pair< casadi_int, casadi_int > size() const
Get the shape.
casadi_int nnz() const
Get the number of (structural) non-zero elements.

References create(), get_output(), casadi::GenericMatrix< MX >::is_empty(), MX(), casadi::GenericMatrix< MX >::nnz(), casadi::MXNode::nout(), and casadi::GenericMatrix< MX >::size().

Referenced by casadi::Call::create(), casadi::MXNode::get_diagsplit(), casadi::MXNode::get_horzsplit(), and casadi::MXNode::get_vertsplit().

◆ cross()

MX casadi::GenericMatrix< MX >::cross ( const MX a,
const MX b,
casadi_int  dim = -1 
)
staticinherited

Definition at line 227 of file generic_matrix.hpp.

1421  {
1422  casadi_assert(a.size1()==b.size1() && a.size2()==b.size2(),
1423  "cross(a, b): Inconsistent dimensions. Dimension of a ("
1424  + a.dim() + " ) must equal that of b (" + b.dim() + ").");
1425 
1426  casadi_assert(a.size1()==3 || a.size2()==3,
1427  "cross(a, b): One of the dimensions of a should have length 3, but got "
1428  + a.dim() + ".");
1429  casadi_assert(dim==-1 || dim==1 || dim==2,
1430  "cross(a, b, dim): Dim must be 1, 2 or -1 (automatic).");
1431 
1432  std::vector<MatType> ret(3);
1433 
1434  bool t = a.size1()==3;
1435 
1436  if (dim==1) t = true;
1437  if (dim==2) t = false;
1438 
1439  MatType a1 = t ? a(0, Slice()) : a(Slice(), 0);
1440  MatType a2 = t ? a(1, Slice()) : a(Slice(), 1);
1441  MatType a3 = t ? a(2, Slice()) : a(Slice(), 2);
1442 
1443  MatType b1 = t ? b(0, Slice()) : b(Slice(), 0);
1444  MatType b2 = t ? b(1, Slice()) : b(Slice(), 1);
1445  MatType b3 = t ? b(2, Slice()) : b(Slice(), 2);
1446 
1447  ret[0] = a2*b3-a3*b2;
1448  ret[1] = a3*b1-a1*b3;
1449  ret[2] = a1*b2-a2*b1;
1450 
1451  return t ? vertcat(ret) : horzcat(ret);
1452  }
std::string dim(bool with_nz=false) const
Get string representation of dimensions.
friend MatType vertcat(const std::vector< MatType > &v)
Concatenate a list of matrices vertically.
friend MatType horzcat(const std::vector< MatType > &v)
Concatenate a list of matrices horizontally.

◆ cse()

std::vector< MX > casadi::MX::cse ( const std::vector< MX > &  e)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2642 of file mx.cpp.

2642  {
2643  std::vector<MX> orig = e;
2644  bool updated = true;
2645  while (updated) {
2646  Function f("f", std::vector<MX>{}, orig,
2647  {{"live_variables", false}, {"max_io", 0}, {"cse", false}, {"allow_free", true}});
2648  MXFunction *ff = f.get<MXFunction>();
2649 
2650  // Symbolic work, non-differentiated
2651  std::vector<MX> swork(ff->workloc_.size()-1);
2652 
2653  // Allocate storage for split outputs
2654  std::vector<std::vector<MX> > res_split(orig.size());
2655  for (casadi_int i=0; i<orig.size(); ++i) res_split[i].resize(orig[i].n_primitives());
2656 
2657  std::vector<MX> arg1, res1;
2658  std::vector<MX> res(orig.size());
2659 
2660  std::unordered_map<std::string, MX > cache;
2661  IncrementalSerializerMX s;
2662 
2663  SimpleCache<FunctionInternal*, std::string> function_serialize_cache;
2664  SimpleCache<std::string, Function> function_cache;
2665 
2666  // Pre-cache the original nodes
2667  // This makes sure we recycle old nodes when possible
2668  for (auto it=ff->algorithm_.begin(); it!=ff->algorithm_.end(); ++it) {
2669  if (it->op == OP_INPUT || it->op==OP_OUTPUT || it->op==OP_PARAMETER) continue;
2670 
2671  std::string key = s.pack(it->data);
2672 
2673  auto itk = cache.find(key);
2674  if (itk==cache.end()) {
2675  cache[key] = it->data;
2676  }
2677  }
2678 
2679  // Loop over computational nodes in forward order
2680  casadi_int alg_counter = 0;
2681  for (auto it=ff->algorithm_.begin(); it!=ff->algorithm_.end(); ++it, ++alg_counter) {
2682  if (it->op == OP_INPUT) {
2683  // pass
2684  } else if (it->op==OP_OUTPUT) {
2685  // Collect the results
2686  res_split.at(it->data->ind()).at(it->data->segment()) = swork[it->arg.front()];
2687  } else if (it->op==OP_PARAMETER) {
2688  // Fetch parameter
2689  MX& target = swork[it->res.front()];
2690  target = it->data;
2691  cache[s.pack(target)] = target;
2692  } else {
2693 
2694  // Arguments of the operation
2695  arg1.resize(it->arg.size());
2696  for (casadi_int i=0; i<arg1.size(); ++i) {
2697  casadi_int el = it->arg[i]; // index of the argument
2698  arg1[i] = el<0 ? MX(it->data->dep(i).size()) : swork[el];
2699  }
2700 
2701  // Perform the operation
2702  res1.resize(it->res.size());
2703  it->data->eval_mx(arg1, res1);
2704 
2705  // Get the result
2706  for (casadi_int i=0; i<res1.size(); ++i) {
2707  casadi_int el = it->res[i]; // index of the output
2708 
2709  MX& out_i = res1[i];
2710 
2711  // Default assumption is that out_i is not an output node
2712  casadi_int output_node = -1;
2713 
2714  if (out_i.is_output()) {
2715  output_node = out_i.which_output();
2716  // First pack/cache the parent (MultipleOutput node e.g. Call, Horzsplit)
2717  out_i = out_i.dep(0);
2718 
2719  // If we are a call node,
2720  if (out_i.op()==OP_CALL) {
2721  FunctionInternal* fptr = out_i.which_function().get();
2722 
2723  // Get or compute serialization (cached)
2724  std::string key_s;
2725  if (!function_serialize_cache.incache(fptr, key_s)) {
2726  key_s = out_i.which_function().serialize();
2727  function_serialize_cache.tocache(fptr, key_s);
2728  }
2729 
2730  // Get or store canonical function (cached)
2731  Function canonical;
2732  if (!function_cache.incache(key_s, canonical)) {
2733  function_cache.tocache(key_s, out_i.which_function());
2734  } else {
2735  out_i = Call::create_call(canonical, out_i->dep_);
2736  }
2737  }
2738  }
2739 
2740  while (true) {
2741  // Replace out_i by a cached variant if possible
2742  std::string key = s.pack(out_i);
2743 
2744  auto itk = cache.find(key);
2745  if (itk==cache.end()) {
2746  cache[key] = out_i;
2747  } else {
2748  out_i = itk->second;
2749  }
2750 
2751  if (output_node==-1) {
2752  break; // Job is done
2753  } else {
2754  // Recreate the output node on top of the parent
2755  out_i = out_i.get_output(output_node);
2756  output_node = -1;
2757  // Loop once more
2758  }
2759  }
2760 
2761  if (el>=0) swork[el] = out_i;
2762  }
2763  }
2764  }
2765 
2766  // Join split outputs
2767  for (casadi_int i=0; i<res.size(); ++i) res[i] = orig[i].join_primitives(res_split[i]);
2768 
2769  std::vector<MX> subs_from;
2770  std::vector<MX> subs_to;
2771  for (const auto& e : function_cache.cache_map()) {
2772  e.second->merge(res, subs_from, subs_to);
2773  }
2774  orig = graph_substitute(res, subs_from, subs_to, updated);
2775  }
2776 
2777  return orig;
2778  }
static MX create_call(const Function &fcn, const std::vector< MX > &arg)
Create function call node.
casadi_int n_primitives() const
Get the number of primitives for MXFunction inputs/outputs.
Definition: mx.cpp:958
static MX graph_substitute(const MX &x, const std::vector< MX > &v, const std::vector< MX > &vdef)
Definition: mx.cpp:1551
MX join_primitives(const std::vector< MX > &v) const
Join an expression along symbolic primitives.
Definition: mx.cpp:994
@ OP_OUTPUT
Definition: calculus.hpp:82
@ OP_INPUT
Definition: calculus.hpp:82
@ OP_PARAMETER
Definition: calculus.hpp:85
@ OP_CALL
Definition: calculus.hpp:88

References casadi::SimpleCache< K, T >::cache_map(), casadi::Call::create_call(), dep(), casadi::MXNode::dep_, casadi::Function::get(), get_output(), graph_substitute(), casadi::SimpleCache< K, T >::incache(), is_output(), join_primitives(), MX(), n_primitives(), op(), casadi::OP_CALL, casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, casadi::Function::serialize(), casadi::SimpleCache< K, T >::tocache(), which_function(), and which_output().

◆ cumsum()

MX casadi::MX::cumsum ( const MX x,
casadi_int  axis = -1 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 698 of file mx.cpp.

698  {
699  if (axis==-1) axis = x.is_row();
700  MX r = axis==0 ? x.T() : x;
701  Sparsity sl = r(Slice(), 0).sparsity();
702  MX acc = MX::sym("acc", sl);
703  MX u = MX::sym("u", sl);
704 
705  Function f("f", {acc, u}, {acc+u});
706  f = f.mapaccum(r.size2());
707  MX ret = f(std::vector<MX>{0, r})[0];
708 
709  return axis==0 ? ret.T() : ret;
710  }
static MX sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.

References casadi::GenericMatrix< MatType >::is_row(), casadi::Function::mapaccum(), casadi::GenericMatrix< MatType >::size2(), sparsity(), casadi::GenericMatrix< MX >::sym(), and T().

◆ debug_repr()

std::string casadi::GenericShared< SharedObject , SharedObjectInternal >::debug_repr
inherited

Definition at line 112 of file generic_shared_impl.hpp.

91  {
92  if (node) {
93  return node->debug_repr(node);
94  } else {
95  return "NULL";
96  }
97  }
std::string debug_repr(const Internal *) const

◆ densify()

MX casadi::MX::densify ( const MX x,
const MX val = 0 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 923 of file mx.cpp.

923  {
924  casadi_assert_dev(val.is_scalar());
925  if (x.is_dense()) {
926  return x; // Already ok
927  } else if (val->is_zero()) {
928  return project(x, Sparsity::dense(x.size()));
929  } else {
930  MX ret = MX::repmat(val, x.size());
931  ret(x.sparsity()) = x;
932  return ret;
933  }
934  }
static MX project(const MX &x, const Sparsity &sp, bool intersect=false)
Definition: mx.cpp:906

References casadi::Sparsity::dense(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::MXNode::is_zero(), project(), repmat(), casadi::GenericMatrix< MatType >::size(), and sparsity().

Referenced by MX(), and set().

◆ dep()

MX casadi::MX::dep ( casadi_int  ch = 0) const

◆ depends_on()

bool casadi::MX::depends_on ( const MX x,
const MX arg 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2165 of file mx.cpp.

2165  {
2166  if (x.nnz()==0) return false;
2167 
2168  // Construct a temporary algorithm
2169  Function temp("tmp_depends_on", {arg}, {x}, Dict{{"max_io", 0}, {"allow_free", true}});
2170 
2171  // Perform a single dependency sweep
2172  std::vector<bvec_t> t_in(arg.nnz(), 1), t_out(x.nnz());
2173  temp({get_ptr(t_in)}, {get_ptr(t_out)});
2174 
2175  // Loop over results
2176  for (casadi_int i=0; i<t_out.size(); ++i) {
2177  if (t_out[i]) return true;
2178  }
2179 
2180  return false;
2181  }
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.
T * get_ptr(std::vector< T > &v)
Get a pointer to the data contained in the vector.

References casadi::get_ptr(), and casadi::GenericMatrix< MatType >::nnz().

◆ deserialize()

MX casadi::MX::deserialize ( DeserializingStream s)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r0

Definition at line 863 of file mx.cpp.

863  {
864  return MX::create(MXNode::deserialize(s));
865  }
static MXNode * deserialize(DeserializingStream &s)
Deserialize with type disambiguation.
Definition: mx_node.cpp:547

References create(), and casadi::MXNode::deserialize().

◆ det() [1/2]

MX casadi::MX::det ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2020 of file mx.cpp.

2020  {
2021  return det(x, "qr");
2022  }
static MX det(const MX &x)
Definition: mx.cpp:2020

◆ det() [2/2]

MX casadi::MX::det ( const MX x,
const std::string &  lsolver,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2024 of file mx.cpp.

2024  {
2025  Linsol mysolver("det", lsolver, x.sparsity(), opts);
2026  return mysolver.det(x);
2027  }

References casadi::Linsol::det(), and sparsity().

◆ diag()

MX casadi::MX::diag ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1464 of file mx.cpp.

1464  {
1465  // Nonzero mapping
1466  std::vector<casadi_int> mapping;
1467 
1468  // Get the sparsity
1469  Sparsity sp = x.sparsity().get_diag(mapping);
1470 
1471  // Create a reference to the nonzeros
1472  return x->get_nzref(sp, mapping);
1473  }
Matrix< casadi_int > mapping() const
Get an IM representation of a GetNonzeros or SetNonzeros node.
Definition: mx.cpp:886
const Sparsity & sparsity() const
Const access the sparsity - reference to data member.
Sparsity get_diag(std::vector< casadi_int > &mapping) const
Definition: sparsity.cpp:612

References casadi::Sparsity::get_diag(), casadi::MXNode::get_nzref(), mapping(), and sparsity().

◆ diagcat()

MX casadi::MX::diagcat ( const std::vector< MX > &  x)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1155 of file mx.cpp.

1155  {
1156  // Quick return if empty or single element
1157  if (x.empty()) return MX();
1158  if (x.size()==1) return x.front();
1159  // Call recursively if any 0-by-0 matrices
1160  if (has_empty(x, true)) return diagcat(trim_empty(x, true));
1161  // Create diagcat node
1162  return x.front()->get_diagcat(x);
1163  }
static MX diagcat(const std::vector< MX > &x)
Definition: mx.cpp:1155
std::vector< MX > trim_empty(const std::vector< MX > &x, bool both=false)
Definition: mx.cpp:1111
bool has_empty(const std::vector< MX > &x, bool both=false)
Definition: mx.cpp:1104

References casadi::has_empty(), MX(), and casadi::trim_empty().

◆ diagsplit()

std::vector< MX > casadi::MX::diagsplit ( const MX x,
const std::vector< casadi_int > &  offset1,
const std::vector< casadi_int > &  offset2 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1223 of file mx.cpp.

1224  {
1225  // Consistency check
1226  casadi_assert_dev(!offset1.empty());
1227  casadi_assert_dev(offset1.front()==0);
1228  casadi_assert_dev(offset1.back()==x.size1());
1229  casadi_assert_dev(is_monotone(offset1));
1230 
1231  // Consistency check
1232  casadi_assert_dev(!offset2.empty());
1233  casadi_assert_dev(offset2.front()==0);
1234  casadi_assert_dev(offset2.back()==x.size2());
1235  casadi_assert_dev(is_monotone(offset2));
1236 
1237  return x->get_diagsplit(offset1, offset2);
1238  }
bool is_monotone(const std::vector< T > &v)
Check if the vector is monotone.

References casadi::MXNode::get_diagsplit(), casadi::is_monotone(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().

◆ diff()

MX casadi::GenericMatrix< MX >::diff ( const MX x,
casadi_int  n = 1,
casadi_int  axis = -1 
)
staticinherited

Definition at line 233 of file generic_matrix.hpp.

1801  {
1802  casadi_assert(axis==-1 || axis==0 || axis==1, "Axis argument invalid");
1803  casadi_assert(n>=1, "n argument invalid");
1804 
1805  MatType ret = x;
1806  for (casadi_int i=0;i<n;++i) {
1807  // Matlab's special case
1808  if (axis==-1 && ret.is_scalar()) return MatType();
1809 
1810  casadi_int local_axis = (axis==-1) ? ret.is_row() : axis;
1811  if (local_axis==0) {
1812  if (ret.size1()<=1) {
1813  ret = MatType::zeros(0, ret.size2());
1814  } else {
1815  ret = ret(Slice(1, ret.size1()), Slice())-ret(Slice(0, ret.size1()-1), Slice());
1816  }
1817  } else {
1818  if (ret.size2()<=1) {
1819  ret = MatType::zeros(ret.size1(), 0);
1820  } else {
1821  ret = ret(Slice(), Slice(1, ret.size2()))-ret(Slice(), Slice(0, ret.size2()-1));
1822  }
1823  }
1824  }
1825  return ret;
1826  }

◆ difference()

std::vector< MX > casadi::MX::difference ( const std::vector< MX > &  a,
const std::vector< MX > &  b 
)
static

Functions called by friend functions defined for this class

Definition at line 3099 of file mx.cpp.

3099  {
3100  // Create a set of MXNodes from b
3101  std::set<MXNode*> bs;
3102  for (const auto& e : b) {
3103  if (!e.is_null()) bs.insert(e.get());
3104  }
3105  std::vector<MX> ret;
3106  for (auto&& e : a) {
3107  // If the element is not in the set, add it to the return vector
3108  if (bs.find(e.get())==bs.end()) {
3109  ret.push_back(e);
3110  }
3111  }
3112  return ret;
3113  }

Referenced by stop_diff().

◆ dim()

std::string casadi::GenericMatrix< MX >::dim ( bool  with_nz = false) const
inherited

The representation is e.g. "4x5" or "4x5,10nz"

Extra doc: https://github.com/casadi/casadi/wiki/L_1aw

Definition at line 131 of file generic_matrix.hpp.

1370  {
1371  return sparsity().dim(with_nz);
1372  }
std::string dim(bool with_nz=false) const
Get the dimension as a string.
Definition: sparsity.cpp:588

◆ disp()

void casadi::SharedObject::disp ( std::ostream &  stream,
bool  more = false 
) const
inherited

Definition at line 35 of file shared_object.cpp.

35  {
36  if (is_null()) {
37  stream << "NULL";
38  } else {
39  (*this)->disp(stream, more);
40  }
41  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().

Referenced by casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().

◆ dot()

MX casadi::MX::dot ( const MX x,
const MX y 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 735 of file mx.cpp.

735  {
736  return x->get_dot(y);
737  }

References casadi::MXNode::get_dot().

◆ dump()

MX casadi::MX::dump ( const std::string &  base_filename,
const Dict opts = Dict() 
) const

Returns itself, but with the side effect of dumping values to file Allowed options: "dir" (dump directory), "format" (file format, default "mtx"), "verbose" (print filename on each dump, default false)

Extra doc: https://github.com/casadi/casadi/wiki/L_2f9

Definition at line 754 of file mx.cpp.

754  {
755  return(*this)->get_dump(base_filename, opts);
756  }

References casadi::MXNode::get_dump().

◆ einstein() [1/2]

MX casadi::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 
)
static

Computes the product: C_c = A_a + B_b where a b c are index/einstein notation in an encoded form

For example, an matrix-matrix product may be written as: C_ij = A_ik B_kj

The encoded form uses strictly negative numbers to indicate labels. For the above example, we would have: a {-1, -3} b {-3, -2} c {-1 -2}

Extra doc: https://github.com/casadi/casadi/wiki/L_r5

Definition at line 682 of file mx.cpp.

686  {
687  return C->get_einstein(A, B, dim_c, dim_a, dim_b, c, a, b);
688  }
GenericMatrix< MX > B
Base class.
Definition: mx.hpp:189

References casadi::C.

Referenced by casadi::Einstein::ad_forward(), casadi::Einstein::ad_reverse(), and casadi::derivative_coeff_mx().

◆ einstein() [2/2]

MX casadi::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 
)
static

Computes the product: C_c = A_a + B_b where a b c are index/einstein notation in an encoded form

For example, an matrix-matrix product may be written as: C_ij = A_ik B_kj

The encoded form uses strictly negative numbers to indicate labels. For the above example, we would have: a {-1, -3} b {-3, -2} c {-1 -2}

Extra doc: https://github.com/casadi/casadi/wiki/L_r5

Definition at line 690 of file mx.cpp.

694  {
695  return MX::zeros(product(dim_c), 1)->get_einstein(A, B, dim_c, dim_a, dim_b, c, a, b);
696  }
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.
Definition: mx_node.cpp:585
T product(const std::vector< T > &values)
product

References casadi::MXNode::get_einstein(), casadi::product(), and casadi::GenericMatrix< MX >::zeros().

◆ enlarge()

void casadi::MX::enlarge ( casadi_int  nrow,
casadi_int  ncol,
const std::vector< casadi_int > &  rr,
const std::vector< casadi_int > &  cc,
bool  ind1 = false 
)

Make the matrix larger by inserting empty rows and columns, keeping the existing non-zeros

Extra doc: https://github.com/casadi/casadi/wiki/L_qg

Definition at line 662 of file mx.cpp.

664  {
665  Sparsity sp = sparsity();
666  sp.enlarge(nrow, ncol, rr, cc, ind1);
667 
668  MX ret = (*this)->get_nzref(sp, range(nnz())); // FIXME?
669  *this = ret;
670  }
const Sparsity & sparsity() const
Get the sparsity pattern.
Definition: mx.cpp:612

References casadi::Sparsity::enlarge(), casadi::MXNode::get_nzref(), casadi::GenericMatrix< MX >::nnz(), casadi::range(), and sparsity().

◆ erase() [1/2]

void casadi::MX::erase ( const std::vector< casadi_int > &  rr,
bool  ind1 = false 
)

Erase elements of a matrix

Extra doc: https://github.com/casadi/casadi/wiki/L_qf

Definition at line 648 of file mx.cpp.

648  {
649  // Get sparsity of the new matrix
650  Sparsity sp = sparsity();
651 
652  // Erase from sparsity pattern
653  std::vector<casadi_int> mapping = sp.erase(rr, ind1);
654 
655  // Create new matrix
656  if (mapping.size()!=nnz()) {
657  MX ret = (*this)->get_nzref(sp, mapping);
658  *this = ret;
659  }
660  }
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)

References casadi::Sparsity::erase(), casadi::MXNode::get_nzref(), mapping(), casadi::GenericMatrix< MX >::nnz(), casadi::GenericMatrix< MatType >::size(), and sparsity().

◆ erase() [2/2]

void casadi::MX::erase ( const std::vector< casadi_int > &  rr,
const std::vector< casadi_int > &  cc,
bool  ind1 = false 
)

Erase rows and/or columns of a matrix

Extra doc: https://github.com/casadi/casadi/wiki/L_qe

Definition at line 616 of file mx.cpp.

616  {
617  // Get sparsity of the new matrix
618  Sparsity sp = sparsity();
619 
620  // Erase from sparsity pattern
621  std::vector<casadi_int> mapping = sp.erase(rr, cc, ind1);
622 
623  // Create new matrix
624  if (mapping.size()!=nnz()) {
625  MX ret = (*this)->get_nzref(sp, mapping);
626  *this = ret;
627  }
628  }

References casadi::Sparsity::erase(), casadi::MXNode::get_nzref(), mapping(), casadi::GenericMatrix< MX >::nnz(), casadi::GenericMatrix< MatType >::size(), and sparsity().

Referenced by set().

◆ eval_mx()

void casadi::MX::eval_mx ( const std::vector< MX > &  arg,
std::vector< MX > &  res,
const std::vector< bool > &  unique = std::vector<bool>() 
) const

Extra doc: https://github.com/casadi/casadi/wiki/L_rn

Definition at line 3222 of file mx.cpp.

3223  {
3224  try {
3225  res.resize((*this)->nout());
3226  (*this)->eval_mx(arg, res, unique);
3227  } catch (std::exception& e) {
3228  CASADI_THROW_ERROR_OBJ("eval_mx", e.what());
3229  }
3230  }

◆ evalf()

DM casadi::MX::evalf ( const MX m)
static

Functions called by friend functions defined for this class

Definition at line 768 of file mx.cpp.

768  {
769  Function f("f", std::vector<MX>{}, {m}, {{"allow_free", true}});
770  return f(std::vector<DM>{})[0];
771  }

◆ expm()

MX casadi::MX::expm ( const MX A)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2154 of file mx.cpp.

2154  {
2155  Function ret = expmsol("mysolver", "slicot", A.sparsity());
2156  return ret(std::vector<MX>{A, 1})[0];
2157  }
Function expmsol(const std::string &name, const std::string &solver, const Sparsity &A, const Dict &opts)
Definition: expm.cpp:44

References casadi::expmsol(), and sparsity().

◆ expm_const()

MX casadi::MX::expm_const ( const MX A,
const MX t 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2147 of file mx.cpp.

2147  {
2148  Dict opts;
2149  opts["const_A"] = true;
2150  Function ret = expmsol("mysolver", "slicot", A.sparsity(), opts);
2151  return ret(std::vector<MX>{A, t})[0];
2152  }

References casadi::expmsol(), and sparsity().

◆ extract()

void casadi::MX::extract ( std::vector< MX > &  ex,
std::vector< MX > &  v,
std::vector< MX > &  vdef,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1740 of file mx.cpp.

1741  {
1742  try {
1743  // Read options
1744  std::string v_prefix = "v_", v_suffix = "";
1745  bool lift_shared = true, lift_calls = false;
1746  casadi_int v_ind = 0;
1747  for (auto&& op : opts) {
1748  if (op.first == "prefix") {
1749  v_prefix = std::string(op.second);
1750  } else if (op.first == "suffix") {
1751  v_suffix = std::string(op.second);
1752  } else if (op.first == "lift_shared") {
1753  lift_shared = op.second;
1754  } else if (op.first == "lift_calls") {
1755  lift_calls = op.second;
1756  } else if (op.first == "offset") {
1757  v_ind = op.second;
1758  } else {
1759  casadi_error("No such option: " + std::string(op.first));
1760  }
1761  }
1762  // Sort the expression
1763  Function f("tmp_extract", std::vector<MX>{}, ex, Dict{{"max_io", 0}, {"allow_free", true}});
1764  auto *ff = f.get<MXFunction>();
1765  // Get references to the internal data structures
1766  const std::vector<MXAlgEl>& algorithm = ff->algorithm_;
1767  std::vector<MX> work(ff->workloc_.size()-1);
1768  // Count how many times an expression has been used
1769  std::vector<casadi_int> usecount(work.size(), 0);
1770  // Remember the origin of every calculation
1771  std::vector<std::pair<casadi_int, casadi_int> > origin(work.size(), std::make_pair(-1, -1));
1772  // Which evaluations to replace
1773  std::vector<std::pair<casadi_int, casadi_int> > replace;
1774  // Evaluate the algorithm to identify which evaluations to replace
1775  casadi_int k=0;
1776  for (auto it=algorithm.begin(); it<algorithm.end(); ++it, ++k) {
1777  // Increase usage counters
1778  switch (it->op) {
1779  case OP_CONST:
1780  case OP_PARAMETER:
1781  break;
1782  default: // Unary operation, binary operation or output
1783  for (casadi_int c=0; c<it->arg.size(); ++c) {
1784  // Identify nodes used more than once
1785  if (lift_calls && it->op == OP_CALL) {
1786  // If not already marked for replacing
1787  if (usecount.at(it->arg[c]) >= 0) {
1788  replace.push_back(origin.at(it->arg[c]));
1789  usecount.at(it->arg[c]) = -1; // Do not replace again
1790  }
1791  } else if (lift_shared && work[it->arg[c]].op() != OP_PARAMETER
1792  && work[it->arg[c]].op() != OP_CONST) {
1793  if (usecount.at(it->arg[c]) == 0) {
1794  // First time node is used
1795  usecount.at(it->arg[c]) = 1;
1796  } else if (usecount.at(it->arg[c]) == 1) {
1797  // Second time node is used
1798  replace.push_back(origin.at(it->arg[c]));
1799  usecount.at(it->arg[c]) = -1; // Do not replace again
1800  }
1801  }
1802  }
1803  }
1804  // Perform the operation
1805  switch (it->op) {
1806  case OP_OUTPUT:
1807  break;
1808  case OP_CONST:
1809  usecount[it->res.front()] = -1; // Never extract constants
1810  break;
1811  default:
1812  for (casadi_int c=0; c<it->res.size(); ++c) {
1813  if (it->res[c]>=0) {
1814  work[it->res[c]] = it->data.get_output(c);
1815  origin[it->res[c]] = std::make_pair(k, c);
1816  if (lift_calls && it->op == OP_CALL) {
1817  // If function call, replace right away
1818  replace.push_back(origin.at(it->res[c]));
1819  usecount.at(it->res[c]) = -1; // Do not replace again
1820  } else {
1821  usecount.at(it->res[c]) = 0; // Not (yet) extracted
1822  }
1823  }
1824  }
1825  break;
1826  }
1827  }
1828  // New variables and definitions
1829  v.clear();
1830  v.reserve(replace.size());
1831  vdef.clear();
1832  vdef.reserve(replace.size());
1833  // Quick return
1834  if (replace.empty()) return;
1835  // Sort the elements to be replaced in the order of appearence in the algorithm
1836  sort(replace.begin(), replace.end());
1837  std::vector<std::pair<casadi_int, casadi_int> >::const_iterator replace_it=replace.begin();
1838  // Arguments for calling the atomic operations
1839  std::vector<MX> oarg, ores;
1840  // Evaluate the algorithm
1841  k = 0;
1842  for (auto it=algorithm.begin(); it<algorithm.end(); ++it, ++k) {
1843  switch (it->op) {
1844  case OP_OUTPUT:
1845  casadi_assert(it->data->segment()==0, "Not implemented");
1846  ex[it->data->ind()] = work[it->arg.front()];
1847  break;
1848  case OP_CONST:
1849  work[it->res.front()] = it->data;
1850  break;
1851  default:
1852  {
1853  if (it->op == OP_PARAMETER) {
1854  // Free parameter
1855  work[it->res.front()] = it->data;
1856  } else {
1857  // Arguments of the operation
1858  oarg.resize(it->arg.size());
1859  for (casadi_int i=0; i<oarg.size(); ++i) {
1860  casadi_int el = it->arg[i];
1861  oarg[i] = el<0 ? MX(it->data->dep(i).size()) : work.at(el);
1862  }
1863  // Perform the operation
1864  ores.resize(it->res.size());
1865  it->data->eval_mx(oarg, ores);
1866  // Get the result
1867  for (casadi_int i=0; i<ores.size(); ++i) {
1868  casadi_int el = it->res[i];
1869  if (el>=0) work.at(el) = ores[i];
1870  }
1871  }
1872  // Possibly replace results with new variables
1873  for (casadi_int c=0; c<it->res.size(); ++c) {
1874  // Output index
1875  casadi_int ind = it->res[c];
1876  // In the list of nodes for replacing?
1877  bool replace_node = replace_it != replace.end()
1878  && replace_it->first==k && replace_it->second==c;
1879  // Call node (introduce variable for outputs, even if unused)
1880  bool output_node = lift_calls && it->op == OP_CALL;
1881  // Skip if no reason to replace
1882  if (!replace_node && !output_node) continue;
1883  // Create a new variable
1884  Sparsity v_sp = it->op == OP_PARAMETER ? it->data.sparsity() : ores.at(c).sparsity();
1885  v.push_back(MX::sym(v_prefix + std::to_string(v_ind++) + v_suffix, v_sp));
1886  // Add definition of new variable
1887  if (ind >= 0) {
1888  // Replace existing call
1889  casadi_assert(replace_node, "Consistency check");
1890  // Store the result
1891  vdef.push_back(work[ind]);
1892  // Use in calculations
1893  work[ind] = v.back();
1894  // Go to the next element to be replaced
1895  replace_it++;
1896  } else {
1897  // New node corresponding to an output
1898  casadi_assert(output_node, "Consistency check");
1899  // Store the result
1900  vdef.push_back(ores.at(c));
1901  }
1902  }
1903  }
1904  }
1905  }
1906  // Ensure all nodes have been replaced
1907  casadi_assert(replace_it == replace.end(), "Consistency check failed");
1908  } catch (std::exception& e) {
1909  CASADI_THROW_ERROR("extract", e.what());
1910  }
1911  }
CASADI_EXPORT std::string replace(const std::string &s, const std::string &p, const std::string &r)
Replace all occurences of p with r in s.
void sort(const std::vector< T > &values, std::vector< T > &sorted_values, std::vector< casadi_int > &indices, bool invert_indices=false)
Sort the data in a vector.
@ OP_CONST
Definition: calculus.hpp:79

References casadi::MXFunction::algorithm_, casadi::Function::get(), MX(), op(), casadi::OP_CALL, casadi::OP_CONST, casadi::OP_OUTPUT, casadi::OP_PARAMETER, casadi::replace(), casadi::sort(), and casadi::GenericMatrix< MX >::sym().

Referenced by shared().

◆ extract_parametric()

void casadi::MX::extract_parametric ( const MX expr,
const MX par,
MX expr_ret,
std::vector< MX > &  symbols,
std::vector< MX > &  parametric,
const Dict opts 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2810 of file mx.cpp.

2812  {
2813  std::string v_prefix = "e_";
2814  std::string v_suffix = "";
2815  bool extract_trivial = false;
2816  casadi_int v_offset = 0;
2817  for (auto&& op : opts) {
2818  if (op.first == "prefix") {
2819  v_prefix = std::string(op.second);
2820  } else if (op.first == "suffix") {
2821  v_suffix = std::string(op.second);
2822  } else if (op.first == "offset") {
2823  v_offset = op.second;
2824  } else if (op.first == "extract_trivial") {
2825  extract_trivial = op.second;
2826  } else {
2827  casadi_error("No such option: " + std::string(op.first));
2828  }
2829  }
2830  Function f("f", {par}, {expr}, {{"live_variables", false},
2831  {"max_io", 0}, {"allow_free", true}});
2832  MXFunction *ff = f.get<MXFunction>();
2833 
2834  // Work vector
2835  std::vector< MX > w(ff->workloc_.size()-1);
2836 
2837  // Status of the expression:
2838  // 0: dependant on constants only
2839  // 1: dependant on parameters/constants only
2840  // 2: dependant on non-parameters
2841  std::vector< char > expr_status(ff->workloc_.size()-1, 0);
2842 
2843  // Split up inputs analogous to symbolic primitives
2844  std::vector<MX> arg_split = par.split_primitives(par);
2845 
2846  // Allocate storage for split outputs
2847  std::vector<MX> res_split;
2848  res_split.resize(expr.n_primitives());
2849 
2850  // Scratch space for node inputs/outputs
2851  std::vector<MX > arg1, res1;
2852 
2853  // Map of registered symbols
2854  std::map<MXNode*, MX> symbol_map;
2855 
2856  // Flat list of registerd symbols and parametric expressions
2857  std::vector<MX> symbol_v, parametric_v;
2858 
2859  // Loop over computational nodes in forward order
2860  casadi_int alg_counter = 0;
2861  for (auto it=ff->algorithm_.begin(); it!=ff->algorithm_.end(); ++it, ++alg_counter) {
2862  if (it->op == OP_INPUT) {
2863  w[it->res.front()] = arg_split.at(it->data->segment());
2864  expr_status[it->res.front()] = 1;
2865  } else if (it->op==OP_OUTPUT) {
2866  MX arg = w[it->arg.front()];
2867  if (expr_status[it->arg.front()]==1) {
2868  arg = register_symbol(arg, symbol_map, symbol_v, parametric_v,
2869  extract_trivial, v_offset, v_prefix, v_suffix);
2870  }
2871  // Collect the results
2872  res_split.at(it->data->segment()) = arg;
2873  } else if (it->op==OP_CONST) {
2874  // Fetch constant
2875  w[it->res.front()] = it->data;
2876  expr_status[it->res.front()] = 0;
2877  } else if (it->op==OP_PARAMETER) {
2878  // Free variables
2879  w[it->res.front()] = it->data;
2880  expr_status[it->res.front()] = 2;
2881  } else {
2882  // Arguments of the operation
2883  arg1.resize(it->arg.size());
2884  for (casadi_int i=0; i<arg1.size(); ++i) {
2885  casadi_int el = it->arg[i]; // index of the argument
2886  arg1[i] = el<0 ? MX(it->data->dep(i).size()) : w[el];
2887  }
2888 
2889  // Check worst case status of inputs
2890  char max_status = 0;
2891  for (casadi_int i=0; i<arg1.size(); ++i) {
2892  casadi_int el = it->arg[i]; // index of the argument
2893  if (el>=0) {
2894  max_status = std::max(max_status, expr_status[it->arg[i]]);
2895  }
2896  }
2897  bool any_tainted = max_status==2;
2898 
2899  if (any_tainted) {
2900  // Loop over all inputs
2901  for (casadi_int i=0; i<arg1.size(); ++i) {
2902  casadi_int el = it->arg[i]; // index of the argument
2903 
2904  // For each parametric input being mixed into a non-parametric expression
2905  if (el>=0 && expr_status[el]==1) {
2906 
2907  arg1[i] = register_symbol(w[el], symbol_map, symbol_v, parametric_v,
2908  extract_trivial, v_offset, v_prefix, v_suffix);
2909  }
2910  }
2911  }
2912 
2913  // Perform the operation
2914  res1.resize(it->res.size());
2915  it->data->eval_mx(arg1, res1);
2916 
2917  // Get the result
2918  for (casadi_int i=0; i<res1.size(); ++i) {
2919  casadi_int el = it->res[i]; // index of the output
2920  if (el>=0) {
2921  w[el] = res1[i];
2922  // Update expression status
2923  expr_status[el] = max_status;
2924  }
2925  }
2926  }
2927  }
2928 
2929  // Join split outputs
2930  expr_ret = expr.join_primitives(res_split);
2931 
2932  symbols = symbol_v;
2933  parametric = parametric_v;
2934  }
MX register_symbol(const MX &node, std::map< MXNode *, MX > &symbol_map, std::vector< MX > &symbol_v, std::vector< MX > &parametric_v, bool extract_trivial, casadi_int v_offset, const std::string &v_prefix, const std::string &v_suffix)
Definition: mx.cpp:2780

References join_primitives(), MX(), n_primitives(), op(), casadi::OP_CONST, casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, casadi::register_symbol(), and split_primitives().

◆ eye()

MX casadi::MX::eye ( casadi_int  n)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r4

Definition at line 600 of file mx.cpp.

600  {
601  return MX(DM::eye(n));
602  }
static Matrix< double > eye(casadi_int n)
create an n-by-n identity matrix

References casadi::Matrix< double >::eye(), and MX().

Referenced by casadi::OptiNode::canon_expr(), and inv().

◆ find()

MX casadi::MX::find ( const MX x)
static

Functions called by friend functions defined for this class

Definition at line 2216 of file mx.cpp.

2216  {
2217  return x->get_find();
2218  }

References casadi::MXNode::get_find().

Referenced by casadi::DaeBuilderInternal::create(), graph_substitute(), casadi::DaeBuilderInternal::hess_v_v_from_calls(), casadi::DaeBuilderInternal::jac_vdef_v_from_calls(), and casadi::register_symbol().

◆ forward()

std::vector< std::vector< MX > > casadi::MX::forward ( const std::vector< MX > &  ex,
const std::vector< MX > &  arg,
const std::vector< std::vector< MX > > &  v,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1949 of file mx.cpp.

1951  {
1952  try {
1953  // Read options
1954  bool always_inline = true;
1955  bool never_inline = false;
1956 
1957  Dict h_opts;
1958  Dict opts_remainder = extract_from_dict(opts, "helper_options", h_opts);
1959  h_opts["allow_free"] = true;
1960  for (auto&& op : opts_remainder) {
1961  if (op.first=="always_inline") {
1962  always_inline = op.second;
1963  } else if (op.first=="never_inline") {
1964  never_inline = op.second;
1965  } else {
1966  casadi_error("No such option: " + std::string(op.first));
1967  }
1968  }
1969  // Call internal function on a temporary object
1970  Function temp("forward_temp", arg, ex, h_opts);
1971  std::vector<std::vector<MX> > ret;
1972  temp->call_forward(arg, ex, v, ret, always_inline, never_inline);
1973  return ret;
1974  } catch (std::exception& e) {
1975  CASADI_THROW_ERROR("forward", e.what());
1976  }
1977  }
Dict extract_from_dict(const Dict &d, const std::string &key, T &value)

References casadi::FunctionInternal::call_forward(), casadi::extract_from_dict(), and op().

◆ get() [1/16]

MXNode * casadi::MX::get ( ) const

◆ get() [2/16]

void casadi::MX::get ( MX m,
bool  ind1,
casadi_int  rr,
casadi_int  cc 
) const
inline

Get a submatrix, two arguments

Definition at line 547 of file mx.hpp.

548  {
549  get(m, ind1, Matrix<casadi_int>(rr), Matrix<casadi_int>(cc));
550  }
MXNode * get() const
Get a const pointer to the node.
Definition: mx.cpp:564
template class CASADI_EXPORT Matrix< casadi_int >

◆ get() [3/16]

void casadi::MX::get ( MX m,
bool  ind1,
casadi_int  rr,
const Slice cc 
) const
inline

Get a submatrix, two arguments

Definition at line 542 of file mx.hpp.

542  {
543  get(m, ind1, Matrix<casadi_int>(rr), cc);
544  }

◆ get() [4/16]

void casadi::MX::get ( MX m,
bool  ind1,
const casadi_int  rr 
) const
inline

Get a submatrix, single argument

Definition at line 529 of file mx.hpp.

529  {
530  get(m, ind1, Matrix<casadi_int>(rr));
531  }

◆ get() [5/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Matrix< casadi_int > &  rr 
) const

Get a submatrix, single argument

Definition at line 188 of file mx.cpp.

188  {
189  // If the indexed matrix is dense, use nonzero indexing
190  if (is_dense()) {
191  get_nz(m, ind1, rr);
192  return;
193  }
194 
195  // If indexed matrix was a row/column vector, make sure that the result is too
196  bool tr = (is_column() && rr.is_row()) || (is_row() && rr.is_column());
197 
198  // Get the sparsity pattern - does bounds checking
199  std::vector<casadi_int> mapping;
200  Sparsity sp = sparsity().sub(rr.nonzeros(), tr ? rr.sparsity().T() : rr.sparsity(),
201  mapping, ind1);
202 
203  // Create return MX
204  m = (*this)->get_nzref(sp, mapping);
205  }
bool is_dense() const
Check if the matrix expression is dense.
bool is_column() const
Check if the matrix is a column vector (i.e. size2()==1)
bool is_row() const
Check if the matrix is a row vector (i.e. size1()==1)
void get_nz(MX &m, bool ind1, const Slice &kk) const
Definition: mx.cpp:405
std::vector< Scalar > & nonzeros()
Sparsity sub(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, std::vector< casadi_int > &mapping, bool ind1=false) const
Get a submatrix.
Definition: sparsity.cpp:334
Sparsity T() const
Transpose the matrix.
Definition: sparsity.cpp:394

References get_nz(), casadi::MXNode::get_nzref(), casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MX >::is_column(), casadi::GenericMatrix< MX >::is_dense(), casadi::GenericMatrix< MX >::is_row(), casadi::GenericMatrix< MatType >::is_row(), mapping(), casadi::Matrix< Scalar >::nonzeros(), casadi::Matrix< Scalar >::sparsity(), sparsity(), casadi::Sparsity::sub(), and casadi::Sparsity::T().

◆ get() [6/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Matrix< casadi_int > &  rr,
const Matrix< casadi_int > &  cc 
) const

Get a submatrix, two arguments

Definition at line 168 of file mx.cpp.

168  {
169  // Make sure dense vectors
170  casadi_assert(rr.is_dense() && rr.is_vector(),
171  "Marix::get: First index must be a dense vector");
172  casadi_assert(cc.is_dense() && cc.is_vector(),
173  "Marix::get: Second index must be a dense vector");
174 
175  // Get the sparsity pattern - does bounds checking
176  std::vector<casadi_int> mapping;
177  Sparsity sp = sparsity().sub(rr.nonzeros(), cc.nonzeros(), mapping, ind1);
178 
179  // Create return MX
180  m = (*this)->get_nzref(sp, mapping);
181  }
bool is_vector() const
Check if the matrix is a row or column vector.

References casadi::MXNode::get_nzref(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_vector(), mapping(), casadi::Matrix< Scalar >::nonzeros(), sparsity(), and casadi::Sparsity::sub().

◆ get() [7/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Matrix< casadi_int > &  rr,
const Slice cc 
) const

Get a submatrix, two arguments

Definition at line 163 of file mx.cpp.

163  {
164  // Fall back on (IM, IM)
165  get(m, ind1, rr, cc.all(size2(), ind1));
166  }

References casadi::Slice::all(), get(), and casadi::GenericMatrix< MX >::size2().

◆ get() [8/16]

void casadi::MX::get ( MX m,
bool  ind1,
const MX rr 
) const

Get a submatrix, single argument

Definition at line 215 of file mx.cpp.

215  {
216  casadi_assert(is_dense(), "Parametric slicing only supported for dense matrices."
217  "Got " + dim(true) + " instead.");
218  get_nz(m, ind1, rr);
219  }

References casadi::GenericMatrix< MX >::dim(), get_nz(), and casadi::GenericMatrix< MX >::is_dense().

◆ get() [9/16]

void casadi::MX::get ( MX m,
bool  ind1,
const MX rr,
const MX cc 
) const

Get a submatrix, two arguments

Definition at line 231 of file mx.cpp.

231  {
232  casadi_assert(is_dense(), "Parametric slicing only supported for dense matrices.");
233  m = (*this)->get_nz_ref(ind1 ? rr-1 : rr, floor(ind1 ? cc-1 : cc)*size1());
234  }
casadi_int size1() const
Get the first dimension (i.e. number of rows)
static MX floor(const MX &x)
Round down to nearest integer: x -> floor(x)

References casadi::GenericExpression< MX >::floor(), casadi::MXNode::get_nz_ref(), casadi::GenericMatrix< MX >::is_dense(), and casadi::GenericMatrix< MX >::size1().

◆ get() [10/16]

void casadi::MX::get ( MX m,
bool  ind1,
const MX rr,
const Slice cc 
) const

Get a submatrix, two arguments

Definition at line 226 of file mx.cpp.

226  {
227  casadi_assert(is_dense(), "Parametric slicing only supported for dense matrices.");
228  m = (*this)->get_nz_ref(ind1 ? rr-1 : rr, cc.apply(size2())*size1());
229  }

References casadi::Slice::apply(), casadi::MXNode::get_nz_ref(), casadi::GenericMatrix< MX >::is_dense(), casadi::GenericMatrix< MX >::size1(), and casadi::GenericMatrix< MX >::size2().

◆ get() [11/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Slice rr 
) const

Get a submatrix, single argument

Definition at line 183 of file mx.cpp.

183  {
184  // Fall back on IM
185  get(m, ind1, rr.all(numel(), ind1));
186  }
casadi_int numel() const
Get the number of elements.

References casadi::Slice::all(), get(), and casadi::GenericMatrix< MX >::numel().

◆ get() [12/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Slice rr,
casadi_int  cc 
) const
inline

Get a submatrix, two arguments

Definition at line 538 of file mx.hpp.

538  {
539  get(m, ind1, rr, Matrix<casadi_int>(cc));
540  }

◆ get() [13/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Slice rr,
const Matrix< casadi_int > &  cc 
) const

Get a submatrix, two arguments

Definition at line 158 of file mx.cpp.

158  {
159  // Fall back on (IM, IM)
160  get(m, ind1, rr.all(size1(), ind1), cc);
161  }

References casadi::Slice::all(), get(), and casadi::GenericMatrix< MX >::size1().

◆ get() [14/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Slice rr,
const MX cc 
) const

Get a submatrix, two arguments

Definition at line 221 of file mx.cpp.

221  {
222  casadi_assert(is_dense(), "Parametric slicing only supported for dense matrices. ");
223  m = (*this)->get_nz_ref(rr.apply(size1()), floor(ind1 ? cc-1 : cc)*size1());
224  }

References casadi::Slice::apply(), casadi::GenericExpression< MX >::floor(), casadi::MXNode::get_nz_ref(), casadi::GenericMatrix< MX >::is_dense(), and casadi::GenericMatrix< MX >::size1().

◆ get() [15/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Slice rr,
const Slice cc 
) const

Get a submatrix, two arguments

Definition at line 153 of file mx.cpp.

153  {
154  // Fall back on (IM, IM)
155  get(m, ind1, rr.all(size1(), ind1), cc.all(size2(), ind1));
156  }

References casadi::Slice::all(), get(), casadi::GenericMatrix< MX >::size1(), and casadi::GenericMatrix< MX >::size2().

◆ get() [16/16]

void casadi::MX::get ( MX m,
bool  ind1,
const Sparsity sp 
) const

Get a submatrix, single argument

Definition at line 207 of file mx.cpp.

207  {
208  casadi_assert(size()==sp.size(),
209  "get(Sparsity sp): shape mismatch. This matrix has shape "
210  + str(size()) + ", but supplied sparsity index has shape "
211  + str(sp.size()) + ".");
212  m = project(*this, sp);
213  }
std::string str(const T &v)
String representation, any type.

References project(), casadi::GenericMatrix< MX >::size(), casadi::Sparsity::size(), and casadi::str().

◆ get_colind()

std::vector<casadi_int> casadi::GenericMatrix< MX >::get_colind ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b8

Definition at line 195 of file generic_matrix.hpp.

195 { return sparsity().get_colind(); }
std::vector< casadi_int > get_colind() const
Get the column index for each column.
Definition: sparsity.cpp:364

◆ get_free()

std::vector< MX > casadi::MX::get_free ( const Function f)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_rm

Definition at line 3205 of file mx.cpp.

3205  {
3206  return f.free_mx();
3207  }

References casadi::Function::free_mx().

◆ get_input()

std::vector< MX > casadi::MX::get_input ( const Function f)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_rl

Definition at line 3201 of file mx.cpp.

3201  {
3202  return f.mx_in();
3203  }

References casadi::Function::mx_in().

◆ get_max_depth()

casadi_int casadi::MX::get_max_depth ( )
static

Extra doc: https://github.com/casadi/casadi/wiki/L_rk

Definition at line 942 of file mx.cpp.

942  {
943  return eq_depth_;
944  }

Referenced by is_doubled(), and casadi::MXNode::maxDepth().

◆ get_nonzeros()

std::vector< MX > casadi::MX::get_nonzeros ( ) const

Since MX is not a containter, the scalar MXes may be complex When the expression satisfies is_valid_input, the results may be simple

For example: vertcat(x,y).nonzeros() will return {x,y}

See also
expr.nz[:]

Extra doc: https://github.com/casadi/casadi/wiki/L_2bh

Definition at line 630 of file mx.cpp.

630  {
631  std::vector<MX> ret;
632  std::vector<MX> p = primitives();
633  for (const MX& e : p) {
634  if (e.is_scalar()) {
635  ret.push_back(e);
636  } else {
637  // Get nonzeros sparsity cast
638  MX nz;
639  e.get_nz(nz, false, Slice());
640  for (casadi_int i=0; i<nz.nnz(); ++i) {
641  ret.push_back(nz(i));
642  }
643  }
644  }
645  return ret;
646  }
const MX nz(const K &k) const
Get vector nonzero or slice of nonzeros.
std::vector< MX > primitives() const
Get primitives.
Definition: mx.cpp:962

References get_nz(), casadi::GenericMatrix< MatType >::nnz(), casadi::GenericMatrix< MX >::nz(), and primitives().

◆ get_nz() [1/7]

void casadi::MX::get_nz ( MX m,
bool  ind1,
casadi_int  kk 
) const
inline

Get a set of nonzeros

Definition at line 576 of file mx.hpp.

576  {
577  get_nz(m, ind1, Matrix<casadi_int>(kk));
578  }

◆ get_nz() [2/7]

void casadi::MX::get_nz ( MX m,
bool  ind1,
const Matrix< casadi_int > &  kk 
) const

Get a set of nonzeros

Definition at line 410 of file mx.cpp.

410  {
411  // If indexed matrix was a row/column vector, make sure that the result is too
412  bool tr = (is_column() && kk.is_row()) || (is_row() && kk.is_column());
413 
414  // Quick return if no entries
415  if (kk.nnz()==0) {
416  m = MX::zeros(tr ? kk.sparsity().T() : kk.sparsity());
417  return;
418  }
419 
420  // Check bounds
421  casadi_int sz = nnz();
422  casadi_assert_in_range(kk.nonzeros(), -sz+ind1, sz+ind1);
423 
424  // Handle index-1, negative indices
425  if (ind1 || *std::min_element(kk->begin(), kk->end())<0) {
426  Matrix<casadi_int> kk_mod = kk;
427  for (auto&& i : kk_mod.nonzeros()) {
428  casadi_assert(!(ind1 && i<=0),
429  "Matlab is 1-based, but requested index " + str(i) + ". "
430  "Note that negative slices are disabled in the Matlab interface. "
431  "Possibly you may want to use 'end'.");
432  if (ind1) i--;
433  if (i<0) i += sz;
434  }
435  get_nz(m, false, kk_mod); // Call recursively
436  return;
437  }
438 
439  // Return reference to the nonzeros
440  m = (*this)->get_nzref(tr ? kk.sparsity().T() : kk.sparsity(), kk.nonzeros());
441  }

References get_nz(), casadi::MXNode::get_nzref(), casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MX >::is_column(), casadi::GenericMatrix< MX >::is_row(), casadi::GenericMatrix< MatType >::is_row(), casadi::GenericMatrix< MX >::nnz(), casadi::GenericMatrix< MatType >::nnz(), casadi::Matrix< Scalar >::nonzeros(), casadi::Matrix< Scalar >::sparsity(), casadi::str(), casadi::Sparsity::T(), and casadi::GenericMatrix< MX >::zeros().

◆ get_nz() [3/7]

void casadi::MX::get_nz ( MX m,
bool  ind1,
const MX inner,
const MX outer 
) const

Get a set of nonzeros

Definition at line 448 of file mx.cpp.

448  {
449  // Create return MX
450  m = (*this)->get_nz_ref(ind1 ? inner-1.0: inner, ind1 ? outer-1.0: outer);
451  }

References casadi::MXNode::get_nz_ref().

◆ get_nz() [4/7]

void casadi::MX::get_nz ( MX m,
bool  ind1,
const MX inner,
const Slice outer 
) const

Get a set of nonzeros

Definition at line 458 of file mx.cpp.

458  {
459  // Create return MX
460  m = (*this)->get_nz_ref(ind1 ? inner-1.0: inner, ind1 ? outer-1: outer);
461  }

References casadi::MXNode::get_nz_ref().

◆ get_nz() [5/7]

void casadi::MX::get_nz ( MX m,
bool  ind1,
const MX kk 
) const

Get a set of nonzeros

Definition at line 443 of file mx.cpp.

443  {
444  // Create return MX
445  m = (*this)->get_nz_ref(ind1 ? kk-1.0 : kk);
446  }

References casadi::MXNode::get_nz_ref().

◆ get_nz() [6/7]

void casadi::MX::get_nz ( MX m,
bool  ind1,
const Slice inner,
const MX outer 
) const

Get a set of nonzeros

Definition at line 453 of file mx.cpp.

453  {
454  // Create return MX
455  m = (*this)->get_nz_ref(ind1 ? inner-1: inner, ind1 ? outer-1.0: outer);
456  }

References casadi::MXNode::get_nz_ref().

◆ get_nz() [7/7]

void casadi::MX::get_nz ( MX m,
bool  ind1,
const Slice kk 
) const

Get a set of nonzeros

Definition at line 405 of file mx.cpp.

405  {
406  // Fallback on IM
407  get_nz(m, ind1, kk.all(nnz(), ind1));
408  }

References casadi::Slice::all(), and casadi::GenericMatrix< MX >::nnz().

Referenced by get(), casadi::get_boor(), get_nonzeros(), get_nz(), casadi::interpn_G(), and interpn_linear().

◆ get_output()

MX casadi::MX::get_output ( casadi_int  oind) const

Extra doc: https://github.com/casadi/casadi/wiki/L_ql

Definition at line 902 of file mx.cpp.

902  {
903  return (*this)->get_output(oind);
904  }

References casadi::MXNode::get_output().

Referenced by createMultipleOutput(), cse(), and graph_substitute().

◆ get_row()

std::vector<casadi_int> casadi::GenericMatrix< MX >::get_row ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b8

Definition at line 194 of file generic_matrix.hpp.

194 { return sparsity().get_row(); }
std::vector< casadi_int > get_row() const
Get the row for each non-zero entry.
Definition: sparsity.cpp:372

◆ get_sparsity()

Sparsity casadi::MX::get_sparsity ( ) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_qd

Definition at line 205 of file mx.hpp.

205 { return sparsity();}

◆ get_str()

std::string casadi::SharedObject::get_str ( bool  more = false) const
inlineinherited

Definition at line 91 of file shared_object.hpp.

91  {
92  std::stringstream ss;
93  disp(ss, more);
94  return ss.str();
95  }
void disp(std::ostream &stream, bool more=false) const
Print a description of the object.

◆ get_temp()

casadi_int casadi::MX::get_temp ( ) const

Get the temporary variable

Definition at line 890 of file mx.cpp.

890  {
891  return (*this)->temp;
892  }

◆ getCount()

casadi_int casadi::GenericShared< SharedObject , SharedObjectInternal >::getCount
inherited

Definition at line 102 of file generic_shared_impl.hpp.

138  {
139  return (*this)->getCount();
140  }

◆ gradient()

static MX casadi::GenericMatrix< MX >::gradient ( const MX ex,
const MX arg,
const Dict opts = Dict() 
)
staticinherited

Functions called by friend functions defined here

◆ graph_substitute() [1/4]

MX casadi::MX::graph_substitute ( const MX x,
const std::vector< MX > &  v,
const std::vector< MX > &  vdef 
)
static

Functions called by friend functions defined for this class

Definition at line 1551 of file mx.cpp.

1552  {
1553  return graph_substitute(std::vector<MX>{x}, v, vdef).at(0);
1554  }

Referenced by cse(), graph_substitute(), and matrix_expand().

◆ graph_substitute() [2/4]

MX casadi::MX::graph_substitute ( const MX x,
const std::vector< MX > &  v,
const std::vector< MX > &  vdef,
bool &  updated 
)
static

Functions called by friend functions defined for this class

Definition at line 1556 of file mx.cpp.

1557  {
1558  return graph_substitute(std::vector<MX>{x}, v, vdef, updated).at(0);
1559  }

References graph_substitute().

◆ graph_substitute() [3/4]

std::vector< MX > casadi::MX::graph_substitute ( const std::vector< MX > &  ex,
const std::vector< MX > &  v,
const std::vector< MX > &  vdef 
)
static

Functions called by friend functions defined for this class

Definition at line 1561 of file mx.cpp.

1563  {
1564  bool updated;
1565  return graph_substitute(ex, v, vdef, updated);
1566  }

References graph_substitute().

◆ graph_substitute() [4/4]

std::vector< MX > casadi::MX::graph_substitute ( const std::vector< MX > &  ex,
const std::vector< MX > &  v,
const std::vector< MX > &  vdef,
bool &  updated 
)
static

Functions called by friend functions defined for this class

Definition at line 1567 of file mx.cpp.

1570  {
1571  casadi_assert(v.size()==vdef.size(),
1572  "Mismatch in the number of expression to substitute: "
1573  + str(v.size()) + " <-> " + str(vdef.size()) + ".");
1574 
1575  updated = false;
1576 
1577  // Quick return if all equal
1578  bool all_equal = true;
1579  for (casadi_int k=0; k<v.size(); ++k) {
1580  if (v[k].size()!=vdef[k].size() || !is_equal(v[k], vdef[k])) {
1581  all_equal = false;
1582  break;
1583  }
1584  }
1585  if (all_equal) return ex;
1586 
1587  // Validate dimensions
1588  for (casadi_int i=0;i<v.size();++i) {
1589  casadi_assert(v[i].size()==vdef[i].size(),
1590  "Inconsistent shapes for i = " + str(i) + ": v[i] " + v[i].dim() +
1591  " <-> vdef[i] " + vdef[i].dim());
1592  }
1593 
1594  // Sort the expression
1595  Dict opts({{"max_io", 0}, {"allow_free", true}});
1596  Function f("tmp_graph_substitute", std::vector<MX>{}, ex, opts);
1597  MXFunction *ff = f.get<MXFunction>();
1598 
1599  // Get references to the internal data structures
1600  const std::vector<MXAlgEl>& algorithm = ff->algorithm_;
1601  std::vector<MX> swork(ff->workloc_.size()-1);
1602 
1603  // A boolean vector indicated whoch nodes are tainted by substitutions
1604  std::vector<bool> tainted(swork.size());
1605 
1606  // Construct lookup table for expressions,
1607  // giving priority to first occurances
1608  std::map<const MXNode*, casadi_int> expr_lookup;
1609  for (casadi_int i=0;i<v.size();++i) {
1610  auto it = expr_lookup.find(v[i].operator->());
1611  if (it==expr_lookup.end()) expr_lookup[v[i].operator->()] = i;
1612  }
1613 
1614  // Construct found map
1615  std::vector<bool> expr_found(v.size(), false);
1616 
1617  // Allocate output vector
1618  std::vector<MX> f_out(f.n_out());
1619  std::vector<MX> oarg, ores;
1620 
1621  // expr_lookup iterator
1622  std::map<const MXNode*, casadi_int>::const_iterator it_lookup;
1623 
1624  // Allocate storage for split outputs
1625  std::vector<std::vector<MX>> out_split(ex.size());
1626  for (casadi_int i = 0; i < out_split.size(); ++i) out_split[i].resize(ex[i].n_primitives());
1627 
1628  for (auto it=algorithm.begin(); it!=algorithm.end(); ++it) {
1629 
1630  if (it->op != OP_OUTPUT) {
1631  // Check if it->data points to a supplied expr
1632  it_lookup = expr_lookup.find((it->data).operator->());
1633 
1634  if (it_lookup!=expr_lookup.end()) {
1635  // Fill in that expression in-place
1636  MX e = vdef[it_lookup->second];
1637 
1638  // If node is of a MultipleOutput type
1639  if (e->has_output()) {
1640  for (casadi_int i=0;i<it->res.size();++i) {
1641  casadi_int k = it->res[i];
1642  if (k!=-1) {
1643  swork[k] = e.get_output(i);
1644  tainted[k] = true;
1645  }
1646  }
1647  } else {
1648  swork[it->res.front()] = e;
1649  tainted[it->res.front()] = true;
1650  }
1651  expr_found[it_lookup->second] = true;
1652  continue;
1653  } else if (it->data->has_output()) {
1654  bool any_tainted = false;
1655  // Loop over all oputputs of MultiOutput
1656  for (casadi_int i=0;i<it->res.size();++i) {
1657  // Create Output node (cached)
1658  casadi_int k = it->res[i];
1659  if (k!=-1) {
1660  MX out = it->data.get_output(i);
1661  // Check if out points to a supplied expr
1662  it_lookup = expr_lookup.find(out.operator->());
1663  if (it_lookup!=expr_lookup.end()) {
1664  // Fill in that expression in-place
1665  MX e = vdef[it_lookup->second];
1666  swork[k] = e;
1667  tainted[k] = true;
1668  any_tainted = true;
1669  expr_found[it_lookup->second] = true;
1670  }
1671  }
1672  }
1673  if (any_tainted) continue;
1674  }
1675  }
1676 
1677  switch (it->op) {
1678  case OP_INPUT:
1679  tainted[it->res.front()] = false;
1680  break;
1681  case OP_PARAMETER:
1682  swork[it->res.front()] = it->data;
1683  tainted[it->res.front()] = false;
1684  break;
1685  case OP_OUTPUT:
1686  out_split.at(it->data->ind()).at(it->data->segment()) = swork[it->arg.front()];
1687  break;
1688  default:
1689  {
1690  bool node_tainted = false;
1691 
1692  // Arguments of the operation
1693  oarg.resize(it->arg.size());
1694  for (casadi_int i=0; i<oarg.size(); ++i) {
1695  casadi_int el = it->arg[i];
1696  if (el>=0) node_tainted = node_tainted || tainted[el];
1697  oarg[i] = el<0 ? MX(it->data->dep(i).size()) : swork.at(el);
1698  }
1699 
1700  // Perform the operation
1701  ores.resize(it->res.size());
1702  if (!node_tainted) {
1703  if (it->data.has_output()) {
1704  for (casadi_int i=0;i<it->res.size();++i) {
1705  ores.at(i) = it->data.get_output(i);
1706  }
1707  } else {
1708  ores.at(0) = it->data;
1709  }
1710  } else {
1711  it->data->eval_mx(oarg, ores);
1712  }
1713 
1714  // Get the result
1715  for (casadi_int i=0; i<ores.size(); ++i) {
1716  casadi_int el = it->res[i];
1717  if (el>=0) swork.at(el) = ores[i];
1718  if (el>=0) tainted[el] = node_tainted;
1719  }
1720  }
1721  }
1722  }
1723 
1724  // Join primitives
1725  for (size_t k = 0; k < out_split.size(); ++k) {
1726  f_out[k] = ex[k].join_primitives(out_split.at(k));
1727  }
1728 
1729  bool all_found=true;
1730  for (casadi_int i=0;i<v.size();++i) {
1731  all_found = all_found && expr_found[i];
1732  }
1733 
1734  updated = any(expr_found);
1735 
1736  return f_out;
1737 
1738  }
static bool is_equal(const MX &x, const MX &y, casadi_int depth=0)
Definition: mx.cpp:867
bool any(const std::vector< bool > &v)
Check if any arguments are true.
Definition: casadi_misc.cpp:88

References casadi::MXFunction::algorithm_, casadi::any(), casadi::GenericMatrix< MX >::dim(), find(), get_output(), casadi::MXNode::get_output(), casadi::MXNode::has_output(), is_equal(), MX(), n_primitives(), casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, casadi::GenericMatrix< MX >::size(), and casadi::str().

◆ has_duplicates()

bool casadi::MX::has_duplicates ( ) const

If there are symbolic primitives appearing more than once, the function will return true and the names of the duplicate expressions will be passed to casadi_warning. Note: Will mark the node using MX::set_temp. Make sure to call reset_input() after usage.

Extra doc: https://github.com/casadi/casadi/wiki/L_qs

Definition at line 1018 of file mx.cpp.

1018  {
1019  return (*this)->has_duplicates();
1020  }

◆ has_output()

bool casadi::MX::has_output ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_284

Definition at line 815 of file mx.cpp.

815  {
816  return (*this)->has_output();
817  }

◆ hessian() [1/2]

MX casadi::MX::hessian ( const MX f,
const MX x,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1932 of file mx.cpp.

1932  {
1933  MX g;
1934  return hessian(f, x, g, opts);
1935  }
static MX hessian(const MX &f, const MX &x, const Dict &opts=Dict())
Definition: mx.cpp:1932

◆ hessian() [2/2]

MX casadi::MX::hessian ( const MX f,
const MX x,
MX g,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1937 of file mx.cpp.

1937  {
1938  try {
1939  Dict all_opts = opts;
1940  g = gradient(f, x, opts);
1941  if (!opts.count("symmetric")) all_opts["symmetric"] = true;
1942  return jacobian(g, x, all_opts);
1943  } catch (std::exception& e) {
1944  CASADI_THROW_ERROR("hessian", e.what());
1945  }
1946  }
static MX jacobian(const MX &f, const MX &x, const Dict &opts=Dict())
Definition: mx.cpp:1920
friend MX gradient(const MX &ex, const MX &arg, const Dict &opts=Dict())
Calculate the gradient of an expression.

References casadi::GenericMatrix< MX >::gradient, and jacobian().

◆ horzcat()

MX casadi::MX::horzcat ( const std::vector< MX > &  x)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1119 of file mx.cpp.

1119  {
1120  // Check dimensions
1121  if (x.size()>1) {
1122  std::vector<MX> ne = trim_empty(x, true);
1123  for (casadi_int i=0;i<ne.size();i++) {
1124  casadi_assert(ne[i].size1()==ne[0].size1(),
1125  "horzcat dimension mismatch x[" + str(i) + "]:" + ne[i].dim() +
1126  " and x[0]: " + ne[0].dim() + ".");
1127  }
1128  }
1129 
1130  if (x.empty()) {
1131  return MX(1, 0);
1132  } else if (x.size()==1) {
1133  return x.front();
1134  } else if (has_empty(x)) {
1135  std::vector<MX> ret = trim_empty(x);
1136  if (ret.empty()) {
1137  // We still want horzcat(zeros(0,5),zeros(0,5)) -> zeros(0,10)
1138  ret = trim_empty(x, true);
1139  casadi_int s = 0;
1140  casadi_int nrow = 0;
1141  for (casadi_int i=0;i<ret.size();++i) {
1142  s+= ret[i].size2();
1143  casadi_assert_dev(nrow==0 || nrow==ret[i].size1());
1144  nrow = ret[i].size1();
1145  }
1146  return MX::zeros(nrow, s);
1147  } else {
1148  return horzcat(ret);
1149  }
1150  } else {
1151  return x.front()->get_horzcat(x);
1152  }
1153  }
static MX ne(const MX &x, const MX &y)
Logical not equal to: (x,y) -> x != y.

References casadi::GenericMatrix< MX >::dim(), casadi::has_empty(), MX(), casadi::GenericExpression< MX >::ne(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MX >::size1(), casadi::str(), casadi::trim_empty(), and casadi::GenericMatrix< MX >::zeros().

Referenced by blockcat(), and vertcat().

◆ horzsplit()

std::vector< MX > casadi::MX::horzsplit ( const MX x,
const std::vector< casadi_int > &  offset 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1206 of file mx.cpp.

1206  {
1207  // Consistency check
1208  casadi_assert_dev(!offset.empty());
1209  casadi_assert_dev(offset.front()==0);
1210  casadi_assert_dev(offset.back()==x.size2());
1211  casadi_assert_dev(is_monotone(offset));
1212 
1213  // Trivial return if possible
1214  if (offset.size()==1) {
1215  return std::vector<MX>(0);
1216  } else if (offset.size()==2) {
1217  return std::vector<MX>(1, x);
1218  } else {
1219  return x->get_horzsplit(offset);
1220  }
1221  }
static std::vector< casadi_int > offset(const std::vector< MatType > &v, bool vert=true)

References casadi::MXNode::get_horzsplit(), casadi::is_monotone(), casadi::SparsityInterface< MatType >::offset(), and casadi::GenericMatrix< MatType >::size2().

Referenced by vertsplit().

◆ if_else()

MX casadi::MX::if_else ( const MX cond,
const MX if_true,
const MX if_false,
bool  short_circuit = false 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1373 of file mx.cpp.

1373  {
1374  if (short_circuit) {
1375  // Get symbolic primitives
1376  std::vector<MX> arg = symvar(veccat(std::vector<MX>{x_true, x_false}));
1377 
1378  // Form functions for cases
1379  Function f_true("f_true", arg, {x_true});
1380  Function f_false("f_false", arg, {x_false});
1381 
1382  // Form Switch
1383  Function sw = Function::if_else("switch", f_true, f_false);
1384 
1385  // Call the Switch
1386  std::vector<MX> sw_arg;
1387  sw_arg.push_back(cond);
1388  sw_arg.insert(sw_arg.end(), arg.begin(), arg.end());
1389  return sw(sw_arg).at(0);
1390  } else {
1391  return if_else_zero(cond, x_true) + if_else_zero(!cond, x_false);
1392  }
1393  }
static Function if_else(const std::string &name, const Function &f_true, const Function &f_false, const Dict &opts=Dict())
Constructor (if-else)
Definition: function.cpp:962
static MX if_else_zero(const MX &x, const MX &y)
Conditional assignment: (x,y) -> x ? y : 0.

References casadi::Function::if_else(), casadi::GenericExpression< MX >::if_else_zero(), symvar(), and casadi::SparsityInterface< MatType >::veccat().

Referenced by conditional().

◆ inf() [1/3]

MX casadi::MX::inf ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r2

Definition at line 576 of file mx.cpp.

576  {
577  return inf(Sparsity::dense(nrow, ncol));
578  }
static MX inf(const Sparsity &sp)
create a matrix with all inf
Definition: mx.cpp:584

References casadi::Sparsity::dense(), and inf().

◆ inf() [2/3]

MX casadi::MX::inf ( const Sparsity sp)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r2

Definition at line 584 of file mx.cpp.

584  {
585  return create(ConstantMX::create(sp, std::numeric_limits<double>::infinity()));
586  }

References casadi::ConstantMX::create(), and create().

Referenced by inf(), and casadi::init_gen().

◆ inf() [3/3]

MX casadi::MX::inf ( const std::pair< casadi_int, casadi_int > &  rc)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r2

Definition at line 580 of file mx.cpp.

580  {
581  return inf(rc.first, rc.second);
582  }

References inf().

◆ info()

Dict casadi::MX::info ( ) const

Obtain information about node

Definition at line 855 of file mx.cpp.

855  {
856  return (*this)->info();
857  }

Referenced by casadi::MXFunction::export_code_body(), and casadi::Onnx::load().

◆ interp1d()

MX casadi::GenericMatrix< MX >::interp1d ( const std::vector< double > &  x,
const MX v,
const std::vector< double > &  xq,
const std::string &  mode,
bool  equidistant 
)
staticinherited

Definition at line 213 of file generic_matrix.hpp.

1459  {
1460 
1461  bool mode_floor = false;
1462  bool mode_ceil = false;
1463  if (mode=="floor") {
1464  mode_floor = true;
1465  } else if (mode=="ceil") {
1466  mode_ceil = true;
1467  } else if (mode=="linear") {
1468  //
1469  } else {
1470  casadi_error("interp1d(x, v, xq, mode): "
1471  "Mode must be 'floor', 'ceil' or 'linear'. Got '" + mode + "' instead.");
1472  }
1473 
1474  casadi_assert(is_increasing(x), "interp1d(x, v, xq): x must be increasing.");
1475 
1476  casadi_assert(x.size()==v.size1(),
1477  "interp1d(x, v, xq): dimensions mismatch. v expected to have " + str(x.size()) + " rows,"
1478  " but got " + str(v.size1()) + " instead.");
1479 
1480  // Need at least two elements
1481  casadi_assert(x.size()>=2, "interp1d(x, v, xq): x must be at least length 2.");
1482 
1483  // Vectors to compose a sparse matrix
1484  std::vector<double> val;
1485  std::vector<casadi_int> colind(1, 0);
1486  std::vector<casadi_int> row;
1487 
1488  // Number of nonzeros in to-be composed matrix
1489  casadi_int nnz = 0;
1490  for (casadi_int i=0;i<xq.size();++i) {
1491  // Obtain index corresponding to xq[i]
1492  double ind = index_interp1d(x, xq[i], equidistant);
1493 
1494  if (mode_floor) ind = floor(ind);
1495  if (mode_ceil) ind = ceil(ind);
1496 
1497  // Split into integer and fractional part
1498  double int_partd;
1499  double frac_part = modf(ind, &int_partd);
1500  casadi_int int_part = static_cast<casadi_int>(int_partd);
1501 
1502  if (frac_part==0) {
1503  // Create a single entry
1504  val.push_back(1);
1505  row.push_back(int_part);
1506  nnz+=1;
1507  colind.push_back(nnz);
1508  } else {
1509  // Create a double entry
1510  val.push_back(1-frac_part);
1511  val.push_back(frac_part);
1512  row.push_back(int_part);
1513  row.push_back(int_part+1);
1514  nnz+=2;
1515  colind.push_back(nnz);
1516  }
1517  }
1518 
1519  // Construct sparsity for composed matrix
1520  Sparsity sp(x.size(), xq.size() , colind, row);
1521 
1522  return MatType::mtimes(MatType(sp, val).T(), v);
1523 
1524  }
const casadi_int * colind() const
const casadi_int * row() const
double index_interp1d(const std::vector< double > &x, double xq, bool equidistant)
bool is_increasing(const std::vector< T > &v)
Check if the vector is strictly increasing.

◆ interpn_linear()

MX casadi::MX::interpn_linear ( const std::vector< MX > &  x,
const MX v,
const std::vector< MX > &  xq,
const Dict opts = Dict() 
)
static

Usually, you want to be using 'interpolant' instead.

Accepts lookup_mode option.

Extra doc: https://github.com/casadi/casadi/wiki/L_r6

Definition at line 3145 of file mx.cpp.

3146  {
3147 
3148  casadi_int n_dim = x.size();
3149  std::vector<std::string> lookup_mode(n_dim, "auto");
3150  for (auto&& op : opts) {
3151  if (op.first=="lookup_mode") {
3152  lookup_mode = op.second;
3153  } else {
3154  casadi_error("Unknown option '" + op.first + "'.");
3155  }
3156  }
3157 
3158  casadi_assert_dev(xq.size()==n_dim);
3159  casadi_assert_dev(v.is_vector());
3160 
3161  // Extract grid dimensions
3162  std::vector<casadi_int> x_dims;
3163  for (auto e : x) x_dims.push_back(e.numel());
3164 
3165  // Determine multipicity of output
3166  casadi_int n_out = v.numel()/product(x_dims);
3167  casadi_assert(n_out*product(x_dims)==v.numel(),
3168  "Dimension mismatch: coefficients (" + str(v.numel()) + ") should be "
3169  "an integer multiple of product-of-dimensions (" + str(product(x_dims)) + ").");
3170 
3171  // Dimension check xq
3172  casadi_int nq = xq[0].numel();
3173  for (auto e : xq) {
3174  casadi_assert_dev(e.is_vector() && e.numel()==nq);
3175  }
3176 
3177  // Compute stride vector
3178  std::vector<casadi_int> strides;
3179  strides.push_back(n_out);
3180  for (auto d : x_dims) strides.push_back(strides.back()*d);
3181 
3182  // Pre-compute lower index and normalized coordinate
3183  // (Allows for more sub-expression sharing)
3184  std::vector<MX> xis, Ls, Lps;
3185  for (casadi_int i=0;i<n_dim;++i) {
3186  MX L = low(x[i], xq[i], {{"lookup_mode", lookup_mode[i]}});
3187  MX Lp = L+1;
3188  MX xl, xu;
3189  x[i].get_nz(xl, false, L);
3190  x[i].get_nz(xu, false, Lp);
3191  xis.push_back((xq[i]-xl)/(xu-xl));
3192  Ls.push_back(L);
3193  Lps.push_back(Lp);
3194  }
3195 
3196  Slice I(0, n_out);
3197 
3198  return interpn_G(n_dim, v, xis, Ls, Lps, strides, I);
3199  }
casadi_int n_out() const
Number of outputs.
Definition: mx.cpp:898
static MX low(const MX &v, const MX &p, const Dict &options=Dict())
Definition: mx.cpp:2220
MX interpn_G(casadi_int i, const MX &v, const std::vector< MX > &xis, const std::vector< MX > &L, const std::vector< MX > &Lp, const std::vector< casadi_int > &strides, const Slice &I, const MX &offset=0)
Definition: mx.cpp:3115

References get_nz(), casadi::interpn_G(), casadi::GenericMatrix< MatType >::is_vector(), low(), n_out(), casadi::GenericMatrix< MatType >::numel(), op(), casadi::product(), casadi::GenericMatrix< MatType >::size(), and casadi::str().

Referenced by casadi::LinearInterpolant::do_inline().

◆ inv() [1/2]

MX casadi::MX::inv ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_2dz

Definition at line 1087 of file mx.cpp.

1087  {
1088  if (is_op(OP_INV)) {
1089  return dep(0);
1090  } else {
1091  return (*this)->get_unary(OP_INV);
1092  }
1093  }
bool is_op(casadi_int op) const
Is it a certain operation.
Definition: mx.cpp:823
MX dep(casadi_int ch=0) const
Get the nth dependency as MX.
Definition: mx.cpp:783
@ OP_INV
Definition: calculus.hpp:73

References dep(), is_op(), and casadi::OP_INV.

◆ inv() [2/2]

MX casadi::MX::inv ( const MX A,
const std::string &  lsolver = "qr",
const Dict dict = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2037 of file mx.cpp.

2037  {
2038  return solve(x, MX::eye(x.size1()), lsolver, dict);
2039  }
static MX eye(casadi_int n)
Identity matrix.
Definition: mx.cpp:600
static MX solve(const MX &a, const MX &b)
Definition: mx.cpp:2115

References eye(), casadi::GenericMatrix< MatType >::size1(), and solve().

◆ inv_minor()

MX casadi::MX::inv_minor ( const MX A)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2033 of file mx.cpp.

2033  {
2034  casadi_error("Not implemented");
2035  }

◆ inv_node()

MX casadi::MX::inv_node ( const MX A)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2029 of file mx.cpp.

2029  {
2030  return x->get_inv();
2031  }

References casadi::MXNode::get_inv().

◆ inv_skew()

MX casadi::GenericMatrix< MX >::inv_skew ( const MX a)
staticinherited

Definition at line 229 of file generic_matrix.hpp.

1538  {
1539  casadi_assert(a.size1()==3 && a.size2()==3,
1540  "inv_skew(a): Expecting 3-by-3 matrix, got " + a.dim() + ".");
1541 
1542  return 0.5*vertcat(std::vector<MatType>({a(2, 1)-a(1, 2), a(0, 2)-a(2, 0), a(1, 0)-a(0, 1)}));
1543  }

◆ is_binary()

bool casadi::MX::is_binary ( ) const

Definition at line 843 of file mx.cpp.

843  {
844  return (*this)->is_binary();
845  }

Referenced by casadi::MXFunction::export_code_body(), and is_commutative().

◆ is_call()

bool casadi::MX::is_call ( ) const

Definition at line 803 of file mx.cpp.

803  {
804  return (*this)->op()==OP_CALL;
805  }

References casadi::OP_CALL.

Referenced by casadi::BlazingSplineFunction::merge().

◆ is_column()

bool casadi::GenericMatrix< MX >::is_column ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b5

Definition at line 178 of file generic_matrix.hpp.

178 { return sparsity().is_column();}
bool is_column() const
Check if the pattern is a column vector (i.e. size2()==1)
Definition: sparsity.cpp:285

◆ is_commutative()

bool casadi::MX::is_commutative ( ) const

Definition at line 879 of file mx.cpp.

879  {
880  if (is_unary()) return true;
881  casadi_assert(is_binary() || is_unary(),
882  "MX::is_commutative: must be binary or unary operation");
883  return operation_checker<CommChecker>(op());
884  }
bool is_binary() const
Is binary operation.
Definition: mx.cpp:843
bool is_unary() const
Is unary operation.
Definition: mx.cpp:847

References is_binary(), is_unary(), and op().

◆ is_constant()

bool casadi::MX::is_constant ( ) const

◆ is_dense()

bool casadi::GenericMatrix< MX >::is_dense ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b0

Definition at line 153 of file generic_matrix.hpp.

153 { return sparsity().is_dense();}
bool is_dense() const
Is dense?
Definition: sparsity.cpp:273

◆ is_doubled()

bool casadi::MX::is_doubled ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_2e0

Definition at line 1082 of file mx.cpp.

1082  {
1083  return (op()==OP_ADD && is_equal(dep(0), dep(1), get_max_depth())) ||
1084  (op()==OP_TWICE);
1085  }
static casadi_int get_max_depth()
Get the depth to which equalities are being checked for simplifications.
Definition: mx.cpp:942
@ OP_TWICE
Definition: calculus.hpp:67
@ OP_ADD
Definition: calculus.hpp:65

References dep(), get_max_depth(), is_equal(), op(), casadi::OP_ADD, and casadi::OP_TWICE.

◆ is_empty()

bool casadi::GenericMatrix< MX >::is_empty ( bool  both = false) const
inlineinherited

(or optionally both dimensions)

Extra doc: https://github.com/casadi/casadi/wiki/L_1az

Definition at line 148 of file generic_matrix.hpp.

148 { return sparsity().is_empty(both);}
bool is_empty(bool both=false) const
Check if the sparsity is empty.
Definition: sparsity.cpp:144

◆ is_equal()

bool casadi::MX::is_equal ( const MX x,
const MX y,
casadi_int  depth = 0 
)
static

Functions called by friend functions defined for GenericExpression

Definition at line 867 of file mx.cpp.

867  {
868  return MXNode::is_equal(x.get(), y.get(), depth);
869  }
static bool is_equal(const MXNode *x, const MXNode *y, casadi_int depth)
Check if two nodes are equivalent up to a given depth.
Definition: mx_node.cpp:1317

References get(), and casadi::MXNode::is_equal().

Referenced by casadi::BinaryMX< ScX, ScY >::_get_binary(), casadi::UnaryMX::_get_binary(), casadi::Call::common_cond(), casadi::MXNode::get_binary(), graph_substitute(), is_doubled(), casadi::BinaryMX< ScX, ScY >::is_equal(), casadi::MXNode::sameOpAndDeps(), and substitute().

◆ is_eye()

bool casadi::MX::is_eye ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qu

Definition at line 1026 of file mx.cpp.

1026  {
1027  return (*this)->is_eye();
1028  }

Referenced by mac().

◆ is_half()

bool casadi::MX::is_half ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_2ep

Definition at line 1046 of file mx.cpp.

1046  {
1047  return (*this)->is_half();
1048  }

◆ is_inf()

bool casadi::MX::is_inf ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_2e1

Definition at line 1070 of file mx.cpp.

1070  {
1071  return (*this)->is_inf();
1072  }

◆ is_integer()

bool casadi::MX::is_integer ( ) const

Definition at line 1078 of file mx.cpp.

1078  {
1079  return (*this)->is_integer();
1080  }

◆ is_linear()

bool casadi::GenericMatrix< MX >::is_linear ( const MX expr,
const MX var 
)
staticinherited

Definition at line 235 of file generic_matrix.hpp.

1770  {
1771  return !any(MatType::which_depends(expr, var, 2, true));
1772  }

◆ is_minus_inf()

bool casadi::MX::is_minus_inf ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_2e2

Definition at line 1074 of file mx.cpp.

1074  {
1075  return (*this)->is_minus_inf();
1076  }

◆ is_minus_one()

bool casadi::MX::is_minus_one ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qx

Definition at line 1042 of file mx.cpp.

1042  {
1043  return (*this)->is_value(-1);
1044  }

◆ is_multiplication()

bool casadi::MX::is_multiplication ( ) const

Definition at line 827 of file mx.cpp.

827  {
828  return (*this)->op()==OP_MTIMES;
829  }
@ OP_MTIMES
Definition: calculus.hpp:100

References casadi::OP_MTIMES.

◆ is_nonnegative()

bool casadi::MX::is_nonnegative ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_2e3

Definition at line 1054 of file mx.cpp.

1054  {
1055  return (*this)->is_nonnegative();
1056  }

◆ is_norm()

bool casadi::MX::is_norm ( ) const

Definition at line 831 of file mx.cpp.

831  {
832  return dynamic_cast<const Norm*>(get())!=nullptr;
833  }

References get().

◆ is_null()

Definition at line 116 of file generic_shared_impl.hpp.

120  {
121  return node==nullptr;
122  }

◆ is_one()

bool casadi::MX::is_one ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qw

Definition at line 1038 of file mx.cpp.

1038  {
1039  return (*this)->is_one();
1040  }

◆ is_op()

bool casadi::MX::is_op ( casadi_int  op) const

Definition at line 823 of file mx.cpp.

823  {
824  return (*this)->op()==op;
825  }

References op().

Referenced by casadi::OptiNode::canon_expr(), inv(), and casadi::DaeBuilderInternal::when().

◆ is_output()

bool casadi::MX::is_output ( ) const

Definition at line 811 of file mx.cpp.

811  {
812  return (*this)->is_output();
813  }

Referenced by casadi::DaeBuilderInternal::create(), cse(), and casadi::DaeBuilderInternal::jac_vdef_v_from_calls().

◆ is_quadratic()

bool casadi::GenericMatrix< MX >::is_quadratic ( const MX expr,
const MX var 
)
staticinherited

Definition at line 236 of file generic_matrix.hpp.

1775  {
1776  return is_linear(gradient(expr, var), var);
1777  }
static bool is_linear(const MX &expr, const MX &var)

◆ is_regular()

bool casadi::MX::is_regular ( ) const

Definition at line 1062 of file mx.cpp.

1062  {
1063  if (is_constant()) {
1064  return static_cast<DM>(*this).is_regular();
1065  } else {
1066  casadi_error("Cannot check regularity for symbolic MX");
1067  }
1068  }
bool is_constant() const
Check if constant.
Definition: mx.cpp:799
bool is_regular() const
Checks if expression does not contain NaN or Inf.

References is_constant(), and casadi::Matrix< Scalar >::is_regular().

◆ is_row()

bool casadi::GenericMatrix< MX >::is_row ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b4

Definition at line 173 of file generic_matrix.hpp.

173 { return sparsity().is_row();}
bool is_row() const
Check if the pattern is a row vector (i.e. size1()==1)
Definition: sparsity.cpp:281

◆ is_scalar()

bool casadi::GenericMatrix< MX >::is_scalar ( bool  scalar_and_dense = false) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b1

Definition at line 158 of file generic_matrix.hpp.

1375  {
1376  return sparsity().is_scalar(scalar_and_dense);
1377  }
bool is_scalar(bool scalar_and_dense=false) const
Is scalar?
Definition: sparsity.cpp:269

◆ is_square()

bool casadi::GenericMatrix< MX >::is_square ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b2

Definition at line 163 of file generic_matrix.hpp.

163 { return sparsity().is_square();}
bool is_square() const
Is square?
Definition: sparsity.cpp:293

◆ is_symbolic()

bool casadi::MX::is_symbolic ( ) const

◆ is_transpose()

bool casadi::MX::is_transpose ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qy

Definition at line 1058 of file mx.cpp.

1058  {
1059  return op()==OP_TRANSPOSE;
1060  }
@ OP_TRANSPOSE
Definition: calculus.hpp:106

References op(), and casadi::OP_TRANSPOSE.

◆ is_tril()

bool casadi::GenericMatrix< MX >::is_tril ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b7

Definition at line 188 of file generic_matrix.hpp.

188 { return sparsity().is_tril();}
bool is_tril(bool strictly=false) const
Is lower triangular?
Definition: sparsity.cpp:321

◆ is_triu()

bool casadi::GenericMatrix< MX >::is_triu ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b6

Definition at line 183 of file generic_matrix.hpp.

183 { return sparsity().is_triu();}
bool is_triu(bool strictly=false) const
Is upper triangular?
Definition: sparsity.cpp:325

◆ is_unary()

bool casadi::MX::is_unary ( ) const

Definition at line 847 of file mx.cpp.

847  {
848  return (*this)->is_unary();
849  }

Referenced by casadi::MXFunction::export_code_body(), and is_commutative().

◆ is_valid_input()

bool casadi::MX::is_valid_input ( ) const

Valid inputs for MXFunctions are combinations of Reshape, concatenations and SymbolicMX

Extra doc: https://github.com/casadi/casadi/wiki/L_qn

Definition at line 954 of file mx.cpp.

954  {
955  return (*this)->is_valid_input();
956  }

Referenced by casadi::DaeBuilderInternal::der(), casadi::OptiNode::set_domain(), and casadi::OptiNode::to_function().

◆ is_value()

bool casadi::MX::is_value ( double  val) const

Extra doc: https://github.com/casadi/casadi/wiki/L_2eq

Definition at line 1050 of file mx.cpp.

1050  {
1051  return (*this)->is_value(val);
1052  }

◆ is_vector()

bool casadi::GenericMatrix< MX >::is_vector ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b3

Definition at line 168 of file generic_matrix.hpp.

168 { return sparsity().is_vector();}
bool is_vector() const
Check if the pattern is a row or column vector.
Definition: sparsity.cpp:289

◆ is_zero()

bool casadi::MX::is_zero ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qv

Definition at line 1030 of file mx.cpp.

1030  {
1031  if (nnz()==0) {
1032  return true;
1033  } else {
1034  return (*this)->is_zero();
1035  }
1036  }

References casadi::GenericMatrix< MX >::nnz().

Referenced by casadi::MXNode::_get_binary(), casadi::MXNode::get_dot(), casadi::MXNode::get_einstein(), casadi::MXNode::get_mac(), and mac().

◆ jacobian()

MX casadi::MX::jacobian ( const MX f,
const MX x,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1920 of file mx.cpp.

1920  {
1921  try {
1922  Dict h_opts;
1923  Dict opts_remainder = extract_from_dict(opts, "helper_options", h_opts);
1924  h_opts["allow_free"] = true;
1925  Function h("helper_jacobian_MX", {x}, {f}, h_opts);
1926  return h.get<MXFunction>()->jac(opts_remainder).at(0);
1927  } catch (std::exception& e) {
1928  CASADI_THROW_ERROR("jacobian", e.what());
1929  }
1930  }

References casadi::extract_from_dict(), and casadi::Function::get().

Referenced by hessian(), and casadi::Scpgen::init().

◆ jacobian_sparsity()

Sparsity casadi::MX::jacobian_sparsity ( const MX f,
const MX x 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2016 of file mx.cpp.

2016  {
2017  return _jacobian_sparsity(f, x);
2018  }
Sparsity _jacobian_sparsity(const MatType &expr, const MatType &var)

References casadi::_jacobian_sparsity().

◆ join_primitives() [1/3]

DM casadi::MX::join_primitives ( const std::vector< DM > &  v) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qr

Definition at line 1010 of file mx.cpp.

1010  {
1011  casadi_assert(v.size()==n_primitives(), "Wrong number of primitives supplied");
1012  std::vector<DM>::const_iterator it=v.begin();
1013  DM ret = (*this)->join_primitives(it);
1014  casadi_assert_dev(it==v.end());
1015  return ret;
1016  }

References n_primitives().

◆ join_primitives() [2/3]

MX casadi::MX::join_primitives ( const std::vector< MX > &  v) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qr

Definition at line 994 of file mx.cpp.

994  {
995  casadi_assert(v.size()==n_primitives(), "Wrong number of primitives supplied");
996  std::vector<MX>::const_iterator it=v.begin();
997  MX ret = (*this)->join_primitives(it);
998  casadi_assert_dev(it==v.end());
999  return ret;
1000  }

References casadi::MXNode::join_primitives(), and n_primitives().

Referenced by cse(), casadi::DaeBuilderInternal::der(), extract_parametric(), separate_linear(), simplify_const_folding(), and simplify_ref_count().

◆ join_primitives() [3/3]

SX casadi::MX::join_primitives ( const std::vector< SX > &  v) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qr

Definition at line 1002 of file mx.cpp.

1002  {
1003  casadi_assert(v.size()==n_primitives(), "Wrong number of primitives supplied");
1004  std::vector<SX>::const_iterator it=v.begin();
1005  SX ret = (*this)->join_primitives(it);
1006  casadi_assert_dev(it==v.end());
1007  return ret;
1008  }
Matrix< SXElem > SX
Definition: sx_fwd.hpp:32

References n_primitives().

◆ jtimes()

static MX casadi::GenericMatrix< MX >::jtimes ( const MX ex,
const MX arg,
const MX v,
bool  tr = false,
const Dict opts = Dict() 
)
staticinherited

Functions called by friend functions defined here

◆ kron()

MX casadi::MX::kron ( const MX x,
const MX b 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 2077 of file mx.cpp.

2077  {
2078  return a->get_kron(b);
2079  }

References casadi::MXNode::get_kron().

◆ kron_contract()

MX casadi::MX::kron_contract ( const MX m,
const MX x,
bool  inner 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 2081 of file mx.cpp.

2081  {
2082  return m->get_kron_contract(x, inner);
2083  }

References casadi::MXNode::get_kron_contract().

Referenced by casadi::kron_contract().

◆ lift()

MX casadi::MX::lift ( const MX x,
const MX x_guess 
)
static

Functions called by friend functions defined for this class

Definition at line 763 of file mx.cpp.

763  {
764  casadi_assert_dev(x.sparsity()==x_guess.sparsity());
765  return x->_get_binary(OP_LIFT, x_guess, false, false);
766  }
@ OP_LIFT
Definition: calculus.hpp:191

References casadi::MXNode::_get_binary(), casadi::OP_LIFT, and sparsity().

◆ linear_coeff()

void casadi::GenericMatrix< MX >::linear_coeff ( const MX expr,
const MX var,
MX A,
MX b,
bool  check 
)
staticinherited

Definition at line 239 of file generic_matrix.hpp.

1792  {
1793  casadi_assert(expr.is_vector(), "'linear_coeff' only defined for vector expressions.");
1794  if (check)
1795  casadi_assert(is_linear(expr, var), "'linear_coeff' called on non-linear expression.");
1796  A = substitute(jacobian(expr, var), var, 0);
1797  b = vec(substitute(expr, var, 0));
1798  }
static MatType vec(const MatType &x)
friend MX substitute(const MX &ex, const MX &v, const MX &vdef)
Substitute variable v with expression vdef in an expression ex.
friend MX jacobian(const MX &ex, const MX &arg, const Dict &opts=Dict())
Calculate Jacobian.

◆ linearize()

static MX casadi::GenericMatrix< MX >::linearize ( const MX f,
const MX x,
const MX x0,
const Dict opts = Dict() 
)
staticinherited

Functions called by friend functions defined here

◆ linspace() [1/2]

MX casadi::GenericMatrix< MX >::linspace ( const MX a,
const MX b,
casadi_int  nsteps 
)
staticinherited

Definition at line 226 of file generic_matrix.hpp.

1408  {
1409  std::vector<MatType> ret(nsteps);
1410  ret[0] = a;
1411  MatType step = (b-a)/static_cast<MatType>(nsteps-1);
1412 
1413  for (casadi_int i=1; i<nsteps-1; ++i)
1414  ret[i] = a + i * step;
1415 
1416  ret[nsteps-1] = b;
1417  return vertcat(ret);
1418  }

◆ linspace() [2/2]

MX casadi::MX::linspace ( const MX a,
const MX b,
casadi_int  nsteps 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2103 of file mx.cpp.

2103  {
2104  // Specialized over GenericMatrix<MX>::linspace to keep the MX graph
2105  // O(1) in nsteps. The FP recipe (a + i*step interior, literal b at
2106  // the endpoint) matches the generic implementation and numpy.linspace
2107  // bit-for-bit; see test_linspace in test/python/matrix.py.
2108  if (nsteps < 2) return b;
2109  MX step = (b - a) / static_cast<double>(nsteps - 1);
2110  std::vector<double> idx(nsteps - 1);
2111  for (casadi_int i = 0; i < nsteps - 1; ++i) idx[i] = static_cast<double>(i);
2112  return vertcat(std::vector<MX>{a + DM(idx) * step, b});
2113  }

References vertcat().

◆ logsumexp()

static MX casadi::GenericMatrix< MX >::logsumexp ( const MX x)
staticinherited

◆ low()

MX casadi::MX::low ( const MX v,
const MX p,
const Dict options = Dict() 
)
static

Functions called by friend functions defined for this class

Definition at line 2220 of file mx.cpp.

2220  {
2221  return p->get_low(v, options);
2222  }

References casadi::MXNode::get_low().

Referenced by interpn_linear().

◆ mac()

MX casadi::MX::mac ( const MX x,
const MX y,
const MX z,
const std::string &  blas = "reference" 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 712 of file mx.cpp.

712  {
713  if (x.is_scalar() || y.is_scalar()) {
714  // Use element-wise multiplication if at least one factor scalar
715  return z + x*y;
716  }
717 
718  // Check matching dimensions
719  casadi_assert(x.size2()==y.size1(),
720  "Matrix product with incompatible dimensions. Lhs is "
721  + x.dim() + " and rhs is " + y.dim() + ".");
722 
723  // Check if we can simplify the product
724  if (x.is_eye()) {
725  return y + z;
726  } else if (y.is_eye()) {
727  return x + z;
728  } else if (x.is_zero() || y.is_zero()) {
729  return z;
730  } else {
731  return x->get_mac(y, z, blas);
732  }
733  }

References casadi::GenericMatrix< MatType >::dim(), casadi::MXNode::get_mac(), is_eye(), casadi::GenericMatrix< MatType >::is_scalar(), is_zero(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().

Referenced by mtimes().

◆ mapping()

Matrix< casadi_int > casadi::MX::mapping ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_ri

Definition at line 886 of file mx.cpp.

886  {
887  return (*this)->mapping();
888  }

Referenced by diag(), erase(), get(), and unite().

◆ matrix_expand() [1/2]

MX casadi::MX::matrix_expand ( const MX e,
const std::vector< MX > &  boundary,
const Dict options 
)
static

Functions called by friend functions defined for this class

Definition at line 2046 of file mx.cpp.

2046  {
2047  return matrix_expand(std::vector<MX>{e}, boundary, options).at(0);
2048  }
static MX matrix_expand(const MX &e, const std::vector< MX > &boundary, const Dict &options)
Definition: mx.cpp:2046

◆ matrix_expand() [2/2]

std::vector< MX > casadi::MX::matrix_expand ( const std::vector< MX > &  e,
const std::vector< MX > &  boundary,
const Dict options 
)
static

Functions called by friend functions defined for this class

Definition at line 2050 of file mx.cpp.

2052  {
2053 
2054  // Create symbols for boundary nodes
2055  std::vector<MX> syms(boundary.size());
2056 
2057  for (casadi_int i=0;i<syms.size();++i) {
2058  syms[i] = MX::sym("x", boundary[i].sparsity());
2059  }
2060 
2061  // Substitute symbols for boundary nodes
2062  std::vector<MX> ret = graph_substitute(e, boundary, syms);
2063 
2064  // Obtain list of dependents
2065  std::vector<MX> v = symvar(veccat(ret));
2066 
2067  // Construct an MXFunction with it
2068  Function f("tmp_matrix_expand", v, ret, Dict{{"max_io", 0}, {"allow_free", true}});
2069 
2070  // Expand to SXFunction
2071  Function s = f.expand("expand_" + f.name(), options);
2072  std::vector<MX> r;
2073  s.call(graph_substitute(v, syms, boundary), r);
2074  return r;
2075  }

References casadi::Function::call(), casadi::Function::expand(), graph_substitute(), sparsity(), casadi::GenericMatrix< MX >::sym(), symvar(), and casadi::SparsityInterface< MatType >::veccat().

◆ mldivide()

MX casadi::MX::mldivide ( const MX a,
const MX b 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 778 of file mx.cpp.

778  {
779  if (a.is_scalar() || b.is_scalar()) return b/a;
780  return solve(a, b);
781  }

References casadi::GenericMatrix< MatType >::is_scalar(), and solve().

◆ mmax()

MX casadi::MX::mmax ( const MX x)
static

Functions called by friend functions defined for GenericExpression

Definition at line 875 of file mx.cpp.

875  {
876  return x->get_mmax();
877  }

References casadi::MXNode::get_mmax().

◆ mmin()

MX casadi::MX::mmin ( const MX x)
static

Functions called by friend functions defined for GenericExpression

Definition at line 871 of file mx.cpp.

871  {
872  return x->get_mmin();
873  }

References casadi::MXNode::get_mmin().

◆ monitor()

MX casadi::MX::monitor ( const std::string &  comment) const

Returns itself, but with the side effect of printing the nonzeros along with a comment

Extra doc: https://github.com/casadi/casadi/wiki/L_rh

Definition at line 750 of file mx.cpp.

750  {
751  return(*this)->get_monitor(comment);
752  }

References casadi::MXNode::get_monitor().

◆ mpower()

static MX casadi::GenericMatrix< MX >::mpower ( const MX x,
const MX y 
)
staticinherited

Functions called by friend functions defined here

◆ mrdivide()

MX casadi::MX::mrdivide ( const MX a,
const MX b 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 773 of file mx.cpp.

773  {
774  if (a.is_scalar() || b.is_scalar()) return b/a;
775  return solve(a.T(), b.T()).T();
776  }
MX T() const
Transpose the matrix.
Definition: mx.cpp:1095

References casadi::GenericMatrix< MatType >::is_scalar(), solve(), and T().

◆ mtimes()

MX casadi::MX::mtimes ( const MX x,
const MX y,
const std::string &  blas = "reference" 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 672 of file mx.cpp.

672  {
673  if (x.is_scalar() || y.is_scalar()) {
674  // Use element-wise multiplication if at least one factor scalar
675  return x*y;
676  } else {
677  MX z = MX::zeros(Sparsity::mtimes(x.sparsity(), y.sparsity()));
678  return mac(x, y, z, blas);
679  }
680  }
static MX mac(const MX &x, const MX &y, const MX &z, const std::string &blas="reference")
Definition: mx.cpp:712
static Sparsity mtimes(const Sparsity &x, const Sparsity &y, const std::string &blas="reference")
Enlarge matrix.
Definition: sparsity.cpp:430

References casadi::GenericMatrix< MatType >::is_scalar(), mac(), casadi::Sparsity::mtimes(), sparsity(), and casadi::GenericMatrix< MX >::zeros().

Referenced by pinv(), solve(), sum1(), and sum2().

◆ n_dep()

casadi_int casadi::MX::n_dep ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qm

Definition at line 787 of file mx.cpp.

787  {
788  return (*this)->n_dep();
789  }

Referenced by casadi::DaeBuilderInternal::create(), and casadi::DaeBuilderInternal::load_fmi_description().

◆ n_nodes()

casadi_int casadi::MX::n_nodes ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1475 of file mx.cpp.

1475  {
1476  Dict opts{{"max_io", 0}, {"cse", false}, {"allow_free", true}};
1477  Function f("tmp_n_nodes", std::vector<MX>{}, {x}, opts);
1478  return f.n_nodes();
1479  }

References casadi::Function::n_nodes().

◆ n_out()

casadi_int casadi::MX::n_out ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qk

Definition at line 898 of file mx.cpp.

898  {
899  return (*this)->nout();
900  }

Referenced by casadi::DaeBuilderInternal::create(), and interpn_linear().

◆ n_primitives()

casadi_int casadi::MX::n_primitives ( ) const

◆ name()

std::string casadi::MX::name ( ) const

◆ nan() [1/3]

MX casadi::MX::nan ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r3

Definition at line 588 of file mx.cpp.

588  {
589  return nan(Sparsity::dense(nrow, ncol));
590  }
static MX nan(const Sparsity &sp)
create a matrix with all nan
Definition: mx.cpp:596

References casadi::Sparsity::dense(), and nan().

◆ nan() [2/3]

MX casadi::MX::nan ( const Sparsity sp)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r3

Definition at line 596 of file mx.cpp.

596  {
597  return create(ConstantMX::create(sp, std::numeric_limits<double>::quiet_NaN()));
598  }

References casadi::ConstantMX::create(), and create().

Referenced by casadi::MXNode::_get_binary(), nan(), and casadi::qpsol_nlp().

◆ nan() [3/3]

MX casadi::MX::nan ( const std::pair< casadi_int, casadi_int > &  rc)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r3

Definition at line 592 of file mx.cpp.

592  {
593  return nan(rc.first, rc.second);
594  }

References nan().

◆ nnz()

casadi_int casadi::GenericMatrix< MX >::nnz
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1an

Definition at line 84 of file generic_matrix.hpp.

1325  {
1326  return sparsity().nnz();
1327  }
casadi_int nnz() const
Get the number of (structural) non-zeros.
Definition: sparsity.cpp:148

◆ nnz_diag()

casadi_int casadi::GenericMatrix< MX >::nnz_diag
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1aq

Definition at line 99 of file generic_matrix.hpp.

1340  {
1341  return sparsity().nnz_diag();
1342  }
casadi_int nnz_diag() const
Number of non-zeros on the diagonal, i.e. the number of elements (i, j) with j==i.
Definition: sparsity.cpp:360

◆ nnz_lower()

casadi_int casadi::GenericMatrix< MX >::nnz_lower
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ao

Definition at line 89 of file generic_matrix.hpp.

1330  {
1331  return sparsity().nnz_lower();
1332  }
casadi_int nnz_lower(bool strictly=false) const
Number of non-zeros in the lower triangular half,.
Definition: sparsity.cpp:352

◆ nnz_upper()

casadi_int casadi::GenericMatrix< MX >::nnz_upper
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ap

Definition at line 94 of file generic_matrix.hpp.

1335  {
1336  return sparsity().nnz_upper();
1337  }
casadi_int nnz_upper(bool strictly=false) const
Number of non-zeros in the upper triangular half,.
Definition: sparsity.cpp:356

◆ norm_0_mul()

static casadi_int casadi::GenericMatrix< MX >::norm_0_mul ( const MX x,
const MX y 
)
inlinestaticinherited

Definition at line 216 of file generic_matrix.hpp.

216  {
217  return Sparsity::norm_0_mul(x.sparsity(), y.sparsity());
218  }

◆ norm_1()

MX casadi::MX::norm_1 ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1296 of file mx.cpp.

1296  {
1297  return x->get_norm_1();
1298  }

References casadi::MXNode::get_norm_1().

◆ norm_2()

MX casadi::MX::norm_2 ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1284 of file mx.cpp.

1284  {
1285  if (x.is_vector()) {
1286  return norm_fro(x);
1287  } else {
1288  return x->get_norm_2();
1289  }
1290  }
static MX norm_fro(const MX &x)
Definition: mx.cpp:1292

References casadi::MXNode::get_norm_2(), casadi::GenericMatrix< MatType >::is_vector(), and norm_fro().

◆ norm_fro()

MX casadi::MX::norm_fro ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1292 of file mx.cpp.

1292  {
1293  return x->get_norm_fro();
1294  }

References casadi::MXNode::get_norm_fro().

Referenced by norm_2().

◆ norm_inf()

MX casadi::MX::norm_inf ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1300 of file mx.cpp.

1300  {
1301  return x->get_norm_inf();
1302  }

References casadi::MXNode::get_norm_inf().

◆ nullspace()

MX casadi::MX::nullspace ( const MX A)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2159 of file mx.cpp.

2159  {
2160  SX A_sx = SX::sym("A", A.sparsity());
2161  Function f("nullspace", {A_sx}, {SX::nullspace(A_sx)});
2162  return f(A).at(0);
2163  }
static Matrix< Scalar > nullspace(const Matrix< Scalar > &x)

References casadi::Matrix< Scalar >::nullspace(), sparsity(), and casadi::GenericMatrix< Matrix< Scalar > >::sym().

◆ numel()

casadi_int casadi::GenericMatrix< MX >::numel
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ar

Definition at line 104 of file generic_matrix.hpp.

1345  {
1346  return sparsity().numel();
1347  }
casadi_int numel() const
The total number of elements, including structural zeros, i.e. size2()*size1()
Definition: sparsity.cpp:132

◆ nz() [1/2]

NonZeros<MX , K> casadi::GenericMatrix< MX >::nz ( const K &  k)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1bc

Definition at line 258 of file generic_matrix.hpp.

258  {
259  return NonZeros<MatType, K>(self(), k);
260  }

◆ nz() [2/2]

const MX casadi::GenericMatrix< MX >::nz ( const K &  k) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1bb

Definition at line 248 of file generic_matrix.hpp.

248  {
249  MatType ret;
250  self().get_nz(ret, false, k);
251  return ret;
252  }

◆ nzref()

MX casadi::MX::nzref ( const Sparsity sp,
const std::vector< casadi_int > &  nz 
) const

Intended for writing unittests

Extra doc: https://github.com/casadi/casadi/wiki/L_2er

Definition at line 149 of file mx.cpp.

149  {
150  return (*this)->get_nzref(sp, nz);
151  }

References casadi::MXNode::get_nzref(), and casadi::GenericMatrix< MX >::nz().

◆ ones() [1/3]

static MX casadi::GenericMatrix< MX >::ones ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1di

Definition at line 1302 of file generic_matrix.hpp.

1302  {
1303  return ones(Sparsity::dense(nrow, ncol));
1304  }
static MX ones(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries one.

◆ ones() [2/3]

static MX casadi::GenericMatrix< MX >::ones ( const Sparsity sp)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1di

Definition at line 1305 of file generic_matrix.hpp.

1305 { return MatType(sp, 1, false);}

◆ ones() [3/3]

static MX casadi::GenericMatrix< MX >::ones ( const std::pair< casadi_int, casadi_int > &  rc)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1di

Definition at line 1306 of file generic_matrix.hpp.

1306  {
1307  return ones(rc.first, rc.second);
1308  }

◆ op()

casadi_int casadi::MX::op ( ) const

◆ operator double()

casadi::MX::operator double ( ) const
explicit

Definition at line 835 of file mx.cpp.

835  {
836  return (*this)->to_double();
837  }

References casadi::MXNode::to_double().

◆ operator Matrix< double >()

casadi::MX::operator Matrix< double > ( ) const
explicit

◆ operator()() [1/4]

SubIndex<MX , RR> casadi::GenericMatrix< MX >::operator() ( const RR &  rr)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1bf

Definition at line 286 of file generic_matrix.hpp.

286  {
287  return SubIndex<MatType, RR>(self(), rr);
288  }

◆ operator()() [2/4]

const MX casadi::GenericMatrix< MX >::operator() ( const RR &  rr) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1bd

Definition at line 266 of file generic_matrix.hpp.

266  {
267  MatType ret;
268  self().get(ret, false, rr);
269  return ret;
270  }

◆ operator()() [3/4]

SubMatrix<MX , RR, CC> casadi::GenericMatrix< MX >::operator() ( const RR &  rr,
const CC &  cc 
)
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1bg

Definition at line 294 of file generic_matrix.hpp.

294  {
295  return SubMatrix<MatType, RR, CC>(self(), rr, cc);
296  }

◆ operator()() [4/4]

const MX casadi::GenericMatrix< MX >::operator() ( const RR &  rr,
const CC &  cc 
) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1be

Definition at line 276 of file generic_matrix.hpp.

276  {
277  MatType ret;
278  self().get(ret, false, rr, cc);
279  return ret;
280  }

◆ operator+()

MX casadi::MX::operator+ ( ) const
inline

Definition at line 247 of file mx.hpp.

247 { return *this; }

◆ operator-()

MX casadi::MX::operator- ( ) const

Definition at line 604 of file mx.cpp.

604  {
605  if ((*this)->op()==OP_NEG) {
606  return (*this)->dep(0);
607  } else {
608  return (*this)->get_unary(OP_NEG);
609  }
610  }
@ OP_NEG
Definition: calculus.hpp:66

References casadi::MXNode::dep(), casadi::MXNode::get_unary(), and casadi::OP_NEG.

◆ operator->() [1/2]

MXNode * casadi::MX::operator-> ( )

Extra doc: https://github.com/casadi/casadi/wiki/L_qh

Definition at line 568 of file mx.cpp.

568  {
569  return static_cast<MXNode*>(SharedObject::operator->());
570  }
SharedObjectInternal * operator->() const
Access a member function or object.

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ operator->() [2/2]

const MXNode * casadi::MX::operator-> ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qi

Definition at line 572 of file mx.cpp.

572  {
573  return static_cast<const MXNode*>(SharedObject::operator->());
574  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().

◆ own()

void casadi::GenericShared< SharedObject , SharedObjectInternal >::own ( Internal *  node)
inherited

Assign the node to a node class pointer (or null)

Definition at line 89 of file generic_shared_impl.hpp.

◆ pinv()

MX casadi::MX::pinv ( const MX A,
const std::string &  lsolver = "qr",
const Dict dict = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2139 of file mx.cpp.

2139  {
2140  if (A.size1()>=A.size2()) {
2141  return solve(mtimes(A.T(), A), A.T(), lsolver, dict);
2142  } else {
2143  return solve(mtimes(A, A.T()), A, lsolver, dict).T();
2144  }
2145  }
static MX mtimes(const MX &x, const MX &y, const std::string &blas="reference")
Definition: mx.cpp:672

References mtimes(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), solve(), and T().

◆ polyval()

MX casadi::MX::polyval ( const MX p,
const MX x 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1489 of file mx.cpp.

1489  {
1490  casadi_assert(p.is_dense(), "polynomial coefficients vector must be a vector");
1491  casadi_assert(p.is_column() && p.nnz()>0, "polynomial coefficients must be a vector");
1492  MX ret = p.nz(0);
1493  for (casadi_int i=1; i<p.nnz(); ++i) {
1494  ret = ret*x + p.nz(i);
1495  }
1496  return ret;
1497  }

References casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::nnz(), and casadi::GenericMatrix< MatType >::nz().

◆ primitives()

std::vector< MX > casadi::MX::primitives ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qp

Definition at line 962 of file mx.cpp.

962  {
963  std::vector<MX> ret(n_primitives());
964  std::vector<MX>::iterator it=ret.begin();
965  (*this)->primitives(it);
966  casadi_assert_dev(it==ret.end());
967  return ret;
968  }

References n_primitives().

Referenced by casadi::DaeBuilderInternal::der(), get_nonzeros(), casadi::DaeBuilderInternal::load_fmi_description(), casadi::OptiNode::set_domain(), and casadi::OptiNode::to_function().

◆ print_operator()

std::string casadi::MX::print_operator ( const MX x,
const std::vector< std::string > &  args 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1499 of file mx.cpp.

1499  {
1500  return x->disp(args);
1501  }

References casadi::MXNode::disp().

◆ print_ptr()

void casadi::SharedObject::print_ptr ( std::ostream &  stream = casadi::uout()) const
inherited

Print the pointer to the internal class

Definition at line 43 of file shared_object.cpp.

43  {
44  stream << get();
45  }

References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().

◆ printme()

MX casadi::MX::printme ( const MX b) const

Definition at line 739 of file mx.cpp.

739  {
740  return binary(OP_PRINTME, *this, b);
741  }
@ OP_PRINTME
Definition: calculus.hpp:190

References binary(), and casadi::OP_PRINTME.

◆ project()

MX casadi::MX::project ( const MX x,
const Sparsity sp,
bool  intersect = false 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 906 of file mx.cpp.

906  {
907  try {
908  if (x.is_empty() || (sp==x.sparsity())) {
909  return x;
910  } else {
911  casadi_assert(sp.size()==x.size(), "Cannot project " + x.dim() + " to " + sp.dim());
912  if (intersect) {
913  return x->get_project(sp.intersect(x.sparsity()));
914  } else {
915  return x->get_project(sp);
916  }
917  }
918  } catch (std::exception& e) {
919  CASADI_THROW_ERROR("project", e.what());
920  }
921  }

References casadi::GenericMatrix< MatType >::dim(), casadi::Sparsity::dim(), casadi::MXNode::get_project(), casadi::Sparsity::intersect(), casadi::GenericMatrix< MatType >::is_empty(), casadi::GenericMatrix< MatType >::size(), casadi::Sparsity::size(), and sparsity().

Referenced by densify(), get(), set(), set_nz(), simplify_const_folding(), and simplify_ref_count().

◆ quadratic_coeff()

void casadi::GenericMatrix< MX >::quadratic_coeff ( const MX expr,
const MX var,
MX A,
MX b,
MX c,
bool  check 
)
staticinherited

Definition at line 237 of file generic_matrix.hpp.

1781  {
1782  casadi_assert(expr.is_scalar(), "'quadratic_coeff' only defined for scalar expressions.");
1783  A = hessian(expr, var);
1784  b = substitute(jacobian(expr, var), var, 0).T();
1785  if (check)
1786  casadi_assert(!depends_on(A, var), "'quadratic_coeff' called on non-quadratic expression.");
1787  c = substitute(expr, var, 0);
1788  }
friend bool depends_on(const MX &f, const MX &arg)
Check if expression depends on the argument.
friend MX hessian(const MX &ex, const MX &arg, const Dict &opts=Dict())
Hessian and (optionally) gradient.

◆ rank1()

static MX casadi::GenericMatrix< MX >::rank1 ( const MX A,
const MX alpha,
const MX x,
const MX y 
)
staticinherited

Calculates A + 1/2 * alpha * x*y'

Extra doc: https://github.com/casadi/casadi/wiki/L_1bp

◆ repmat()

MX casadi::MX::repmat ( const MX x,
casadi_int  n,
casadi_int  m = 1 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 2085 of file mx.cpp.

2085  {
2086  if (n==0 && m==0) {
2087  return MX();
2088  } else if (n==0) {
2089  return MX(0, x.size2()*m);
2090  } else if (m==0) {
2091  return MX(x.size1()*n, 0);
2092  } else if (n==1 && m==1) {
2093  return x;
2094  } else {
2095  return x->get_repmat(n, m);
2096  }
2097  }

References casadi::MXNode::get_repmat(), MX(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().

Referenced by binary(), densify(), and set().

◆ repsum() [1/2]

MX casadi::GenericMatrix< MX >::repsum ( const MX x,
casadi_int  n,
casadi_int  m = 1 
)
staticinherited

Definition at line 232 of file generic_matrix.hpp.

1556  {
1557  casadi_assert_dev(x.size1() % n==0);
1558  casadi_assert_dev(x.size2() % m==0);
1559  std::vector< std::vector< MatType> > s =
1560  blocksplit(x, x.size1()/n, x.size2()/m);
1561  MatType sum = 0;
1562  for (casadi_int i=0;i<s.size();++i) {
1563  for (casadi_int j=0;j<s[i].size();++j) {
1564  sum = sum + s[i][j];
1565  }
1566  }
1567  return sum;
1568  }
static std::vector< std::vector< MatType > > blocksplit(const MatType &x, const std::vector< casadi_int > &vert_offset, const std::vector< casadi_int > &horz_offset)
friend MatType sum(const MatType &x)
Returns summation of all elements.

◆ repsum() [2/2]

MX casadi::MX::repsum ( const MX x,
casadi_int  n,
casadi_int  m = 1 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2099 of file mx.cpp.

2099  {
2100  return x->get_repsum(n, m);
2101  }

References casadi::MXNode::get_repsum().

◆ reset_dump_count()

void casadi::MX::reset_dump_count ( )

Definition at line 758 of file mx.cpp.

758  {
759  casadi_assert(op()==OP_DUMP, "reset_dump_count: not a dump node");
760  static_cast<Dump*>(get())->reset_dump_count();
761  }
void reset_dump_count()
Reset the dump counter.
Definition: mx.cpp:758
@ OP_DUMP
Definition: calculus.hpp:212

References get(), op(), and casadi::OP_DUMP.

◆ reset_input()

void casadi::MX::reset_input ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qt

Definition at line 1022 of file mx.cpp.

1022  {
1023  (*this)->reset_input();
1024  }

◆ reshape() [1/2]

MX casadi::MX::reshape ( const MX x,
casadi_int  nrow,
casadi_int  ncol 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1343 of file mx.cpp.

1343  {
1344  // Quick return if trivial
1345  if (nrow==x.size1() && ncol==x.size2()) return x;
1346 
1347  // Reshape the sparsity pattern
1348  return reshape(x, Sparsity::reshape(x.sparsity(), nrow, ncol));
1349  }
static Sparsity reshape(const Sparsity &x, casadi_int nrow, casadi_int ncol)
Enlarge matrix.
Definition: sparsity.cpp:260

References casadi::Sparsity::reshape(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), and sparsity().

Referenced by MX().

◆ reshape() [2/2]

MX casadi::MX::reshape ( const MX x,
const Sparsity sp 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1351 of file mx.cpp.

1351  {
1352  casadi_assert(sp.is_reshape(x.sparsity()), "Reshape mismatch");
1353 
1354  // Quick return if trivial
1355  if (sp==x.sparsity()) return x;
1356 
1357  // Call internal method
1358  return x->get_reshape(sp);
1359  }

References casadi::MXNode::get_reshape(), casadi::Sparsity::is_reshape(), and sparsity().

◆ reverse()

std::vector< std::vector< MX > > casadi::MX::reverse ( const std::vector< MX > &  ex,
const std::vector< MX > &  arg,
const std::vector< std::vector< MX > > &  v,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1980 of file mx.cpp.

1982  {
1983  try {
1984  // Read options
1985  bool always_inline = true;
1986  bool never_inline = false;
1987 
1988 
1989  Dict h_opts;
1990  Dict opts_remainder = extract_from_dict(opts, "helper_options", h_opts);
1991  h_opts["allow_free"] = true;
1992 
1993  for (auto&& op : opts_remainder) {
1994  if (op.first=="always_inline") {
1995  always_inline = op.second;
1996  } else if (op.first=="never_inline") {
1997  never_inline = op.second;
1998  } else {
1999  casadi_error("No such option: " + std::string(op.first));
2000  }
2001  }
2002  // Call internal function on a temporary object
2003  Function temp("reverse_temp", arg, ex, h_opts);
2004  std::vector<std::vector<MX> > ret;
2005  temp->call_reverse(arg, ex, v, ret, always_inline, never_inline);
2006  return ret;
2007  } catch (std::exception& e) {
2008  CASADI_THROW_ERROR("reverse", e.what());
2009  }
2010  }

References casadi::FunctionInternal::call_reverse(), casadi::extract_from_dict(), and op().

Referenced by substitute_inplace().

◆ row() [1/2]

const casadi_int* casadi::GenericMatrix< MX >::row ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b8

Definition at line 197 of file generic_matrix.hpp.

197 { return sparsity().row(); }
const casadi_int * row() const
Get a reference to row-vector,.
Definition: sparsity.cpp:164

◆ row() [2/2]

casadi_int casadi::GenericMatrix< MX >::row ( casadi_int  el) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1b8

Definition at line 200 of file generic_matrix.hpp.

200 { return sparsity().row(el); }

◆ rows()

casadi_int casadi::GenericMatrix< MX >::rows ( ) const
inlineinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1at

Definition at line 114 of file generic_matrix.hpp.

114 {return size1();}

◆ separate_linear()

void casadi::MX::separate_linear ( const MX expr,
const MX sym_lin,
const MX sym_const,
MX expr_const,
MX expr_lin,
MX expr_nonlin 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2936 of file mx.cpp.

2938  {
2939 
2940  std::vector<MX> in = {sym_const, sym_lin};
2941  std::vector<MX> out = {expr};
2942 
2943  Function f("f", in, out, {{"live_variables", false},
2944  {"max_io", 0}, {"allow_free", true}});
2945  MXFunction *ff = f.get<MXFunction>();
2946 
2947  // Each work vector element has (const, lin, nonlin) part
2948  std::vector< std::array<MX, 3> > w(ff->workloc_.size()-1);
2949 
2950  // Split up inputs analogous to symbolic primitives
2951  std::vector<std::vector<MX> > arg_split(in.size());
2952  for (casadi_int i=0; i<in.size(); ++i) arg_split[i] = in[i].split_primitives(in[i]);
2953 
2954  // Allocate storage for split outputs
2955  std::array<std::vector<MX>, 3> res_split;
2956  for (int k=0;k<3;++k) {
2957  res_split[k].resize(expr.n_primitives());
2958  }
2959 
2960  std::vector<std::array<MX, 3> > arg1, res1;
2961 
2962  std::array<MX, 3> res;
2963 
2964  // Loop over computational nodes in forward order
2965  casadi_int alg_counter = 0;
2966  for (auto it=ff->algorithm_.begin(); it!=ff->algorithm_.end(); ++it, ++alg_counter) {
2967  if (it->op == OP_INPUT) {
2968  MX null = MX::zeros(arg_split.at(it->data->ind()).at(it->data->segment()).sparsity());
2969  w[it->res.front()][0] = null;
2970  w[it->res.front()][1] = null;
2971  w[it->res.front()][2] = null;
2972  w[it->res.front()][it->data->ind()] = arg_split.at(it->data->ind()).at(it->data->segment());
2973  } else if (it->op==OP_OUTPUT) {
2974  // Collect the results
2975  for (int i=0;i<3;++i) {
2976  res_split.at(i).at(it->data->segment()) = w[it->arg.front()][i];
2977  }
2978  } else if (it->op==OP_CONST) {
2979  // Fetch constant
2980  w[it->res.front()][0] = it->data;
2981  w[it->res.front()][1] = MX::zeros(it->data->sparsity());
2982  w[it->res.front()][2] = MX::zeros(it->data->sparsity());
2983  } else if (it->op==OP_PARAMETER) {
2984  // Fetch parameter
2985  w[it->res.front()][0] = MX::zeros(it->data->sparsity());
2986  w[it->res.front()][1] = MX::zeros(it->data->sparsity());
2987  w[it->res.front()][2] = it->data;
2988  } else {
2989  // Arguments of the operation
2990  arg1.resize(it->arg.size());
2991  for (casadi_int i=0; i<arg1.size(); ++i) {
2992  casadi_int el = it->arg[i]; // index of the argument
2993  for (int k=0;k<3;++k) {
2994  arg1[i][k] = el<0 ? MX(it->data->dep(i).size()) : w[el][k];
2995  }
2996  }
2997 
2998  // Perform the operation
2999  res1.clear();
3000  res1.resize(it->res.size());
3001  for (casadi_int i=0;i<it->res.size();++i) {
3002  for (int k=0;k<3;++k) {
3003  res1[i][k] = MX::zeros(it->data->sparsity());
3004  }
3005  }
3006  it->data->eval_linear(arg1, res1);
3007 
3008  // Get the result
3009  for (casadi_int i=0; i<res1.size(); ++i) {
3010  casadi_int el = it->res[i]; // index of the output
3011  for (int k=0;k<3;++k) {
3012  if (el>=0) w[el][k] = res1[i][k];
3013  }
3014  }
3015  }
3016  }
3017 
3018  // Join split outputs
3019  for (int k=0;k<3;++k) {
3020  res[k] = expr.join_primitives(res_split[k]);
3021  }
3022  expr_const = res[0];
3023  expr_lin = res[1];
3024  expr_nonlin = res[2];
3025  }
std::vector< MX > split_primitives(const MX &x) const
Split up an expression along symbolic primitives.
Definition: mx.cpp:970

References join_primitives(), MX(), n_primitives(), casadi::OP_CONST, casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, split_primitives(), and casadi::GenericMatrix< MX >::zeros().

◆ serialize()

void casadi::MX::serialize ( SerializingStream s) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qz

Definition at line 859 of file mx.cpp.

859  {
860  (*this)->serialize(s);
861  }

◆ set() [1/7]

void casadi::MX::set ( const MX m,
bool  ind1,
const Matrix< casadi_int > &  rr 
)

Set a submatrix, single argument

Definition at line 320 of file mx.cpp.

320  {
321  // Assert dimensions of assigning matrix
322  if (rr.sparsity() != m.sparsity()) {
323  if (rr.size() == m.size()) {
324  // Remove submatrix to be replaced
325  erase(rr.nonzeros(), ind1);
326 
327  // Find the intersection between rr's and m's sparsity patterns
328  Sparsity sp = rr.sparsity() * m.sparsity();
329 
330  // Project both matrices to this sparsity
331  set(project(m, sp), ind1, Matrix<casadi_int>::project(rr, sp));
332  return;
333  } else if (m.is_scalar()) {
334  // m scalar means "set all"
335  if (m.is_dense()) {
336  set(MX(rr.sparsity(), m), ind1, rr);
337  } else {
338  set(MX(rr.size()), ind1, rr);
339  }
340  return;
341  } else if (rr.size1() == m.size2() && rr.size2() == m.size1()
342  && std::min(m.size1(), m.size2()) == 1) {
343  // m is transposed if necessary
344  set(m.T(), ind1, rr);
345  return;
346  } else {
347  // Error otherwise
348  casadi_error("Dimension mismatch. lhs is " + str(rr.size())
349  + ", while rhs is " + str(m.size()));
350  }
351  }
352 
353  // Dimensions of this
354  casadi_int sz1 = size1(), sz2 = size2(), sz = nnz(), nel = numel(), rrsz = rr.nnz();
355 
356  // Quick return if nothing to set
357  if (rrsz==0) return;
358 
359  // Check bounds
360  casadi_assert_in_range(rr.nonzeros(), -nel+ind1, nel+ind1);
361 
362  // Dense mode
363  if (is_dense() && m.is_dense()) {
364  set_nz(m, ind1, rr);
365  return;
366  }
367 
368  // Construct new sparsity pattern
369  std::vector<casadi_int> new_row=sparsity().get_row(), new_col=sparsity().get_col();
370  std::vector<casadi_int> nz(rr.nonzeros());
371  new_row.reserve(sz+rrsz);
372  new_col.reserve(sz+rrsz);
373  nz.reserve(rrsz);
374  for (std::vector<casadi_int>::iterator i=nz.begin(); i!=nz.end(); ++i) {
375  if (ind1) (*i)--;
376  if (*i<0) *i += nel;
377  new_row.push_back(*i % sz1);
378  new_col.push_back(*i / sz1);
379  }
380  Sparsity sp = Sparsity::triplet(sz1, sz2, new_row, new_col);
381 
382  // If needed, update pattern
383  if (sp != sparsity()) *this = project(*this, sp);
384 
385  // Find the nonzeros corresponding to rr
386  sparsity().get_nz(nz);
387 
388  // Create a nonzero assignment node
389  *this = m->get_nzassign(*this, nz);
390  }
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)
Definition: mx.cpp:616
void set_nz(const MX &m, bool ind1, const Slice &kk)
Definition: mx.cpp:463
void set(const MX &m, bool ind1, const Slice &rr)
Definition: mx.cpp:315
static Matrix< casadi_int > project(const Matrix< casadi_int > &x, const Sparsity &sp, bool intersect=false)
casadi_int get_nz(casadi_int rr, casadi_int cc) const
Get the index of an existing non-zero element.
Definition: sparsity.cpp:246
std::vector< casadi_int > get_col() const
Get the column for each non-zero entry.
Definition: sparsity.cpp:368
static Sparsity triplet(casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, std::vector< casadi_int > &mapping, bool invert_mapping)
Create a sparsity pattern given the nonzeros in sparse triplet form *.
Definition: sparsity.cpp:1143

References erase(), casadi::Sparsity::get_col(), casadi::Sparsity::get_nz(), casadi::MXNode::get_nzassign(), casadi::Sparsity::get_row(), casadi::GenericMatrix< MX >::is_dense(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), MX(), casadi::GenericMatrix< MatType >::nnz(), casadi::GenericMatrix< MX >::nnz(), casadi::Matrix< Scalar >::nonzeros(), casadi::GenericMatrix< MX >::numel(), casadi::GenericMatrix< MX >::nz(), project(), set(), set_nz(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MX >::size1(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MX >::size2(), casadi::GenericMatrix< MatType >::size2(), casadi::Matrix< Scalar >::sparsity(), sparsity(), casadi::str(), T(), and casadi::Sparsity::triplet().

◆ set() [2/7]

void casadi::MX::set ( const MX m,
bool  ind1,
const Matrix< casadi_int > &  rr,
const Matrix< casadi_int > &  cc 
)

Set a submatrix, two arguments

Definition at line 251 of file mx.cpp.

251  {
252  // Row vector rr (e.g. in MATLAB) is transposed to column vector
253  if (rr.size1()==1 && rr.size2()>1) {
254  set(m, ind1, rr.T(), cc);
255  return;
256  }
257 
258  // Row vector cc (e.g. in MATLAB) is transposed to column vector
259  if (cc.size1()==1 && cc.size2()>1) {
260  set(m, ind1, rr, cc.T());
261  return;
262  }
263 
264  // Make sure rr and cc are dense vectors
265  casadi_assert(rr.is_dense() && rr.is_column(),
266  "MX::set: First index not dense vector");
267  casadi_assert(cc.is_dense() && cc.is_column(),
268  "MX::set: Second index not dense vector");
269 
270  // Assert dimensions of assigning matrix
271  if (rr.size1() != m.size1() || cc.size1() != m.size2()) {
272  if (m.is_scalar()) {
273  // m scalar means "set all"
274  set(repmat(m, rr.size1(), cc.size1()), ind1, rr, cc);
275  return;
276  } else if (rr.size1() == m.size2() && cc.size1() == m.size1()
277  && std::min(m.size1(), m.size2()) == 1) {
278  // m is transposed if necessary
279  set(m.T(), ind1, rr, cc);
280  return;
281  } else {
282  // Error otherwise
283  casadi_error("Dimension mismatch. lhs is " + str(rr.size1()) + "-by-"
284  + str(cc.size1()) + ", while rhs is " + str(m.size()));
285  }
286  }
287 
288  // Dimensions
289  casadi_int sz1 = size1(), sz2 = size2();
290 
291  // Report out-of-bounds
292  casadi_assert_in_range(rr.nonzeros(), -sz1+ind1, sz1+ind1);
293  casadi_assert_in_range(cc.nonzeros(), -sz2+ind1, sz2+ind1);
294 
295  // If we are assigning with something sparse, first remove existing entries
296  if (!m.is_dense()) {
297  erase(rr.nonzeros(), cc.nonzeros(), ind1);
298  }
299 
300  // Collect all assignments
301  IM el = IM::zeros(m.sparsity());
302  for (casadi_int j=0; j<el.size2(); ++j) { // Loop over columns of m
303  casadi_int this_j = cc->at(j) - ind1; // Corresponding column in this
304  if (this_j<0) this_j += sz2;
305  for (casadi_int k=el.colind(j); k<el.colind(j+1); ++k) { // Loop over rows of m
306  casadi_int i = m.row(k);
307  casadi_int this_i = rr->at(i) - ind1; // Corresponding row in this
308  if (this_i<0) this_i += sz1;
309  el->at(k) = this_i + this_j*sz1;
310  }
311  }
312  set(m, false, el);
313  }
Matrix< Scalar > T() const
Transpose the matrix.
Matrix< casadi_int > IM
Definition: im_fwd.hpp:31

References casadi::GenericMatrix< MatType >::colind(), erase(), casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::Matrix< Scalar >::nonzeros(), repmat(), casadi::GenericMatrix< MatType >::row(), set(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MX >::size1(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MX >::size2(), casadi::GenericMatrix< MatType >::size2(), sparsity(), casadi::str(), casadi::Matrix< Scalar >::T(), T(), and casadi::GenericMatrix< MatType >::zeros().

◆ set() [3/7]

void casadi::MX::set ( const MX m,
bool  ind1,
const Matrix< casadi_int > &  rr,
const Slice cc 
)

Set a submatrix, two arguments

Definition at line 246 of file mx.cpp.

246  {
247  // Fall back on (IM, IM)
248  set(m, ind1, rr, cc.all(size2(), ind1));
249  }

References casadi::Slice::all(), set(), and casadi::GenericMatrix< MX >::size2().

◆ set() [4/7]

void casadi::MX::set ( const MX m,
bool  ind1,
const Slice rr 
)

Set a submatrix, single argument

Definition at line 315 of file mx.cpp.

315  {
316  // Fall back on IM
317  set(m, ind1, rr.all(size1(), ind1));
318  }

References casadi::Slice::all(), and casadi::GenericMatrix< MX >::size1().

Referenced by set().

◆ set() [5/7]

void casadi::MX::set ( const MX m,
bool  ind1,
const Slice rr,
const Matrix< casadi_int > &  cc 
)

Set a submatrix, two arguments

Definition at line 241 of file mx.cpp.

241  {
242  // Fall back on (IM, IM)
243  set(m, ind1, rr.all(size1(), ind1), cc);
244  }

References casadi::Slice::all(), set(), and casadi::GenericMatrix< MX >::size1().

◆ set() [6/7]

void casadi::MX::set ( const MX m,
bool  ind1,
const Slice rr,
const Slice cc 
)

Set a submatrix, two arguments

Definition at line 236 of file mx.cpp.

236  {
237  // Fall back on (IM, IM)
238  set(m, ind1, rr.all(size1(), ind1), cc.all(size2(), ind1));
239  }

References casadi::Slice::all(), set(), casadi::GenericMatrix< MX >::size1(), and casadi::GenericMatrix< MX >::size2().

◆ set() [7/7]

void casadi::MX::set ( const MX m,
bool  ind1,
const Sparsity sp 
)

Set a submatrix, single argument

Definition at line 392 of file mx.cpp.

392  {
393  casadi_assert(size()==sp.size(),
394  "set(Sparsity sp): shape mismatch. This matrix has shape "
395  + str(size()) + ", but supplied sparsity index has shape "
396  + str(sp.size()) + ".");
397  std::vector<casadi_int> ii = sp.find();
398  if (m.is_scalar()) {
399  (*this)(ii) = densify(m);
400  } else {
401  (*this)(ii) = densify(m(ii));
402  }
403  }

References densify(), casadi::Sparsity::find(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::GenericMatrix< MX >::size(), casadi::Sparsity::size(), and casadi::str().

◆ set_max_depth()

void casadi::MX::set_max_depth ( casadi_int  eq_depth = 1)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_rj

Definition at line 938 of file mx.cpp.

938  {
939  eq_depth_ = eq_depth;
940  }

◆ set_nz() [1/4]

void casadi::MX::set_nz ( const MX m,
bool  ind1,
casadi_int  kk 
)
inline

Set a set of nonzeros

Definition at line 589 of file mx.hpp.

589 { set_nz(m, ind1, Matrix<casadi_int>(kk)); }

References set_nz().

Referenced by set_nz().

◆ set_nz() [2/4]

void casadi::MX::set_nz ( const MX m,
bool  ind1,
const Matrix< casadi_int > &  kk 
)

Set a set of nonzeros

Definition at line 468 of file mx.cpp.

468  {
469  casadi_assert(kk.nnz()==m.nnz() || m.nnz()==1,
470  "MX::set_nz: length of non-zero indices (" + str(kk.nnz()) + ") " +
471  "must match size of rhs (" + str(m.nnz()) + ").");
472 
473  // Assert dimensions of assigning matrix
474  if (kk.sparsity() != m.sparsity()) {
475  if (m.is_scalar()) {
476  // m scalar means "set all"
477  if (!m.is_dense()) return; // Nothing to set
478  set_nz(MX(kk.sparsity(), m), ind1, kk);
479  return;
480  } else if (kk.size() == m.size()) {
481  // Project sparsity if needed
482  set_nz(project(m, kk.sparsity()), ind1, kk);
483  return;
484  } else if (kk.size1() == m.size2() && kk.size2() == m.size1()
485  && std::min(m.size1(), m.size2()) == 1) {
486  // m is transposed if necessary
487  set_nz(m.T(), ind1, kk);
488  return;
489  } else {
490  // Error otherwise
491  casadi_error("Dimension mismatch. lhs is " + str(kk.size())
492  + ", while rhs is " + str(m.size()));
493  }
494  }
495 
496  // Call recursively if points both objects point to the same node
497  if (this==&m) {
498  MX m_copy = m;
499  set_nz(m_copy, ind1, kk);
500  return;
501  }
502 
503  // Check bounds
504  casadi_int sz = nnz();
505  casadi_assert_in_range(kk.nonzeros(), -sz+ind1, sz+ind1);
506 
507  // Quick return if no assignments to be made
508  if (kk.nnz()==0) return;
509 
510  // Handle index-1, negative indices
511  if (ind1 || *std::min_element(kk->begin(), kk->end())<0) {
512  Matrix<casadi_int> kk_mod = kk;
513  for (auto&& i : kk_mod.nonzeros()) {
514  casadi_assert(!(ind1 && i<=0),
515  "Matlab is 1-based, but requested index " + str(i) + ". "
516  "Note that negative slices are disabled in the Matlab interface. "
517  "Possibly you may want to use 'end'.");
518  if (ind1) i--;
519  if (i<0) i += sz;
520  }
521  set_nz(m, false, kk_mod); // Call recursively
522  return;
523  }
524 
525  // Create a nonzero assignment node
526  *this = m->get_nzassign(*this, kk.nonzeros());
527  }

References casadi::MXNode::get_nzassign(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), MX(), casadi::GenericMatrix< MX >::nnz(), casadi::GenericMatrix< MatType >::nnz(), casadi::Matrix< Scalar >::nonzeros(), project(), set_nz(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), casadi::Matrix< Scalar >::sparsity(), sparsity(), casadi::str(), and T().

◆ set_nz() [3/4]

void casadi::MX::set_nz ( const MX m,
bool  ind1,
const MX kk 
)

Set a set of nonzeros

Definition at line 529 of file mx.cpp.

529  {
530  *this = m->get_nzassign(*this, ind1 ? kk-1 : kk);
531  }

References casadi::MXNode::get_nzassign().

◆ set_nz() [4/4]

void casadi::MX::set_nz ( const MX m,
bool  ind1,
const Slice kk 
)

Set a set of nonzeros

Definition at line 463 of file mx.cpp.

463  {
464  // Fallback on IM
465  set_nz(m, ind1, kk.all(nnz(), ind1));
466  }

References casadi::Slice::all(), and casadi::GenericMatrix< MX >::nnz().

Referenced by set(), and set_nz().

◆ set_temp()

void casadi::MX::set_temp ( casadi_int  t) const

Definition at line 894 of file mx.cpp.

894  {
895  (*this)->temp = t;
896  }

◆ shared()

void casadi::MX::shared ( std::vector< MX > &  ex,
std::vector< MX > &  v,
std::vector< MX > &  vdef,
const std::string &  v_prefix,
const std::string &  v_suffix 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1913 of file mx.cpp.

1914  {
1915  // Call new, more generic function
1916  extract(ex, v, vdef, Dict{{"lift_shared", true}, {"lift_calls", false},
1917  {"prefix", v_prefix}, {"suffix", v_suffix}});
1918  }
static void extract(std::vector< MX > &ex, std::vector< MX > &v, std::vector< MX > &vdef, const Dict &opts=Dict())
Definition: mx.cpp:1740

References extract().

◆ simplify()

MX casadi::MX::simplify ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1311 of file mx.cpp.

1311  {
1312  return x;
1313  }

◆ simplify_combine_terms()

bool casadi::MX::simplify_combine_terms ( std::vector< MX > &  arg,
std::vector< MX > &  res,
const Dict opts = Dict() 
)
static

Definition at line 1304 of file mx.cpp.

1306  {
1307  // No term-combining available for MX; leave the graph untouched
1308  return false;
1309  }

◆ simplify_const_folding()

bool casadi::MX::simplify_const_folding ( std::vector< MX > &  arg,
std::vector< MX > &  res,
const Dict opts = Dict() 
)
static

Definition at line 2388 of file mx.cpp.

2390  {
2391  simplify_const_folding_order(arg, res, opts);
2392  Dict temp_opts = {{"live_variables", false},
2393  {"max_io", 0},
2394  {"cse", false},
2395  {"allow_free", true}};
2396  Function f("temp", arg, res, temp_opts);
2397  MXFunction *ff = f.get<MXFunction>();
2398  const std::vector<casadi_int>& workloc_ = ff->workloc_;
2399  const auto& algorithm_ = ff->algorithm_;
2400 
2401  // Data structures for numeric evaluation
2402  std::vector<double> w_vec(f.sz_w());
2403  double* w = get_ptr(w_vec);
2404  std::vector<casadi_int> iw_vec(f.sz_iw());
2405  casadi_int* iw = get_ptr(iw_vec);
2406  std::vector<const double*> arg_num_vec(f.sz_arg());
2407  const double** arg_num = get_ptr(arg_num_vec);
2408  std::vector<double*> res_num_vec(f.sz_res());
2409  double** res_num = get_ptr(res_num_vec);
2410 
2411  // Is the work vector entry numeric?
2412  std::vector<bool> is_numeric(workloc_.size()-1);
2413 
2414  // Data structures for symbolic evaluation
2415 
2416  // Symbolic work, non-differentiated
2417  std::vector<MX> swork(workloc_.size()-1);
2418 
2419  // Split up inputs analogous to symbolic primitives
2420  std::vector<std::vector<MX> > arg_split(arg.size());
2421  for (casadi_int i=0; i<arg.size(); ++i) arg_split[i] = arg[i].split_primitives(arg[i]);
2422 
2423  // Allocate storage for split outputs
2424  std::vector<std::vector<MX> > res_split(res.size());
2425  for (casadi_int i=0; i<res.size(); ++i) res_split[i].resize(res[i].n_primitives());
2426 
2427  std::vector<MX> arg1, res1;
2428 
2429  std::unordered_multimap< std::size_t, std::pair<MX, DM> > cache;
2430 
2431  bool performed_folding = false;
2432 
2433  // Loop over computational nodes in forward order
2434  for (auto it=algorithm_.begin(); it!=algorithm_.end(); ++it) {
2435  if (it->op == OP_INPUT) {
2436  swork[it->res.front()] = project(arg_split.at(it->data->ind()).at(it->data->segment()),
2437  it->data.sparsity(), true);
2438  is_numeric[it->res.front()] = false;
2439  } else if (it->op==OP_OUTPUT) {
2440  // Collect the results
2441  MX& target = res_split.at(it->data->ind()).at(it->data->segment());
2442  casadi_int el = it->arg.front();
2443  if (is_numeric[el] && !it->data->dep().is_constant()) {
2444  target = get_const(it->data->dep().sparsity(), w + workloc_[el], cache);
2445  } else {
2446  target = swork[el];
2447  }
2448  } else if (it->op==OP_PARAMETER) {
2449  // Fetch parameter
2450  swork[it->res.front()] = it->data;
2451  is_numeric[it->res.front()] = false;
2452  } else {
2453  // Arguments of the operation
2454  arg1.resize(it->arg.size());
2455 
2456  // Is current algel numeric?
2457  bool numeric = true;
2458 
2459  // Loop over algel inputs
2460  for (casadi_int i=0; i<arg1.size(); ++i) {
2461  casadi_int el = it->arg[i];
2462  if (el<0) {
2463  // Populate arg1 vector
2464  arg1[i] = MX(it->data->dep(i).size());
2465  } else {
2466  // Populate arg1 vector
2467  arg1[i] = swork[el];
2468  // Can only be numeric if arguments are
2469  numeric = numeric && is_numeric[el];
2470  }
2471  }
2472 
2473  if (numeric) {
2474  // Set up arg_num and res_num for numerical evaluation
2475  for (casadi_int i=0; i<it->arg.size(); ++i)
2476  arg_num[i] = it->arg[i]>=0 ? w+workloc_[it->arg[i]] : nullptr;
2477  for (casadi_int i=0; i<it->res.size(); ++i)
2478  res_num[i] = it->res[i]>=0 ? w+workloc_[it->res[i]] : nullptr;
2479 
2480  if (it->data->eval(arg_num, res_num, iw, w)) casadi_error("Evaluation error");
2481  performed_folding = true;
2482  } else {
2483  // Prepare for symbolic evaluation
2484  for (casadi_int i=0; i<arg1.size(); ++i) {
2485  casadi_int el = it->arg[i];
2486  if (el>=0) {
2487  MX& target = arg1[i];
2488  if (is_numeric[el] && !it->data->dep(i).is_constant()) {
2489  target = get_const(it->data->dep(i).sparsity(), w + workloc_[el], cache);
2490  } else {
2491  target = swork[el];
2492  }
2493  }
2494  }
2495  }
2496 
2497  // Perform the operation
2498  res1.resize(it->res.size());
2499  it->data->eval_mx(arg1, res1);
2500 
2501  // Process results
2502  for (casadi_int i=0; i<res1.size(); ++i) {
2503  casadi_int el = it->res[i]; // index of the output
2504  if (el>=0) {
2505  swork[el] = res1[i]; // store symbolic result
2506  is_numeric[el] = numeric; // store flag
2507  }
2508  }
2509  }
2510  }
2511 
2512  // Join split outputs
2513  for (casadi_int i=0; i<res.size(); ++i) res[i] = res[i].join_primitives(res_split[i]);
2514 
2515  return performed_folding;
2516  }
MX get_const(const Sparsity &sp, const double *v, std::unordered_multimap< std::size_t, std::pair< MX, DM > > &cache)
Definition: mx.cpp:2360
bool simplify_const_folding_order(std::vector< MX > &arg, std::vector< MX > &res, const Dict &opts)
Definition: mx.cpp:2261

References casadi::MXFunction::algorithm_, casadi::MXNode::eval_mx(), casadi::Function::get(), casadi::get_const(), casadi::get_ptr(), join_primitives(), MX(), n_primitives(), casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, project(), casadi::simplify_const_folding_order(), split_primitives(), casadi::Function::sz_arg(), casadi::Function::sz_iw(), casadi::Function::sz_res(), casadi::Function::sz_w(), and casadi::MXFunction::workloc_.

◆ simplify_ref_count()

bool casadi::MX::simplify_ref_count ( std::vector< MX > &  arg,
std::vector< MX > &  res,
const Dict opts = Dict() 
)
static

Definition at line 2518 of file mx.cpp.

2520  {
2521  Dict temp_opts = {{"live_variables", false},
2522  {"max_io", 0},
2523  {"cse", false},
2524  {"allow_free", true}};
2525  Function f("temp", arg, res, temp_opts);
2526  MXFunction *ff = f.get<MXFunction>();
2527  const std::vector<casadi_int>& workloc_ = ff->workloc_;
2528  const auto& algorithm_ = ff->algorithm_;
2529 
2530  std::vector<casadi_int> rwork(workloc_.size()-1);
2531  for (auto it=algorithm_.begin(); it!=algorithm_.end(); ++it) {
2532  if (it->op == OP_INPUT) {
2533  } else if (it->op==OP_OUTPUT) {
2534  rwork[it->arg.front()]++;
2535  } else if (it->op==OP_PARAMETER) {
2536  rwork[it->res.front()]++;
2537  } else {
2538  for (casadi_int i=0; i<it->arg.size(); ++i) {
2539  casadi_int el = it->arg[i];
2540  if (el>=0) {
2541  rwork[el]++;
2542  }
2543  }
2544  }
2545  }
2546 
2547  // Forward pass
2548  {
2549 
2550  // Symbolic work, non-differentiated
2551  std::vector<MX> swork(workloc_.size()-1);
2552 
2553  // Split up inputs analogous to symbolic primitives
2554  std::vector<std::vector<MX> > arg_split(arg.size());
2555  for (casadi_int i=0; i<arg.size(); ++i) arg_split[i] = arg[i].split_primitives(arg[i]);
2556 
2557  // Allocate storage for split outputs
2558  std::vector<std::vector<MX> > res_split(res.size());
2559  for (casadi_int i=0; i<res.size(); ++i) res_split[i].resize(res[i].n_primitives());
2560 
2561  std::vector<MX> arg1, res1;
2562 
2563  // Loop over computational nodes in forward order
2564  for (auto it=algorithm_.begin(); it!=algorithm_.end(); ++it) {
2565  if (it->op == OP_INPUT) {
2566  swork[it->res.front()] = project(arg_split.at(it->data->ind()).at(it->data->segment()),
2567  it->data.sparsity(), true);
2568  } else if (it->op==OP_OUTPUT) {
2569  // Collect the results
2570  res_split.at(it->data->ind()).at(it->data->segment()) = swork[it->arg.front()];
2571  } else if (it->op==OP_PARAMETER) {
2572  // Fetch parameter
2573  swork[it->res.front()] = it->data;
2574  } else {
2575  // Arguments of the operation
2576  arg1.resize(it->arg.size());
2577 
2578  std::vector<bool> unique(it->arg.size(), true);
2579  for (casadi_int i=0; i<arg1.size(); ++i) {
2580  casadi_int el = it->arg[i];
2581  if (el<0) {
2582  arg1[i] = MX(it->data->dep(i).size());
2583  } else {
2584  arg1[i] = swork[el];
2585  if (rwork[el]>1) unique[i] = false;
2586  }
2587  }
2588 
2589  // Perform the operation
2590  res1.resize(it->res.size());
2591  it->data->eval_mx(arg1, res1, unique);
2592 
2593  // Get the result
2594  for (casadi_int i=0; i<res1.size(); ++i) {
2595  casadi_int el = it->res[i]; // index of the output
2596  if (el>=0) {
2597  swork[el] = res1[i];
2598  }
2599  }
2600  }
2601  }
2602 
2603  // Join split outputs
2604  for (casadi_int i=0; i<res.size(); ++i) res[i] = res[i].join_primitives(res_split[i]);
2605  }
2606  return true;
2607  }

References casadi::MXFunction::algorithm_, casadi::Function::get(), join_primitives(), MX(), n_primitives(), casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, project(), split_primitives(), and casadi::MXFunction::workloc_.

◆ size() [1/2]

std::pair< casadi_int, casadi_int > casadi::GenericMatrix< MX >::size
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ax

Definition at line 136 of file generic_matrix.hpp.

1360  {
1361  return sparsity().size();
1362  }
std::pair< casadi_int, casadi_int > size() const
Get the shape.
Definition: sparsity.cpp:152

◆ size() [2/2]

casadi_int casadi::GenericMatrix< MX >::size ( casadi_int  axis) const
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1ay

Definition at line 141 of file generic_matrix.hpp.

1365  {
1366  return sparsity().size(axis);
1367  }

◆ size1()

casadi_int casadi::GenericMatrix< MX >::size1
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1as

Definition at line 109 of file generic_matrix.hpp.

1350  {
1351  return sparsity().size1();
1352  }
casadi_int size1() const
Get the number of rows.
Definition: sparsity.cpp:124

◆ size2()

casadi_int casadi::GenericMatrix< MX >::size2
inherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1au

Definition at line 119 of file generic_matrix.hpp.

1355  {
1356  return sparsity().size2();
1357  }
casadi_int size2() const
Get the number of columns.
Definition: sparsity.cpp:128

◆ skew()

MX casadi::GenericMatrix< MX >::skew ( const MX a)
staticinherited

Definition at line 228 of file generic_matrix.hpp.

1527  {
1528  casadi_assert(a.is_vector() && (a.size1()==3 || a.size2()==3),
1529  "skew(a): Expecting 3-vector, got " + a.dim() + ".");
1530 
1531  MatType x = a(0);
1532  MatType y = a(1);
1533  MatType z = a(2);
1534  return blockcat(std::vector< std::vector<MatType> >({{0, -z, y}, {z, 0, -x}, {-y, x, 0}}));
1535  }
friend MatType blockcat(const std::vector< std::vector< MatType > > &v)
Construct a matrix from a list of list of blocks.

◆ soc()

static MX casadi::GenericMatrix< MX >::soc ( const MX x,
const MX y 
)
staticinherited

Functions called by friend functions defined here

◆ solve() [1/2]

MX casadi::MX::solve ( const MX a,
const MX b 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2115 of file mx.cpp.

2115  {
2116  if (a.is_triu()) {
2117  // A is upper triangular
2118  return a->get_solve_triu(b, false);
2119  } else if (a.is_tril()) {
2120  // A is lower triangular
2121  return a->get_solve_tril(b, false);
2122  } else if (a.sparsity().is_orthonormal()) {
2123  // A is orthonormal -> inv(A)==A.T
2124  MX nz = sparsity_cast(a, Sparsity::dense(a.nnz()));
2125  const Sparsity& Q = a.sparsity();
2126  return mtimes(MX(Q, 1/nz).T(), b);
2127  } else {
2128  // Fall-back to QR factorization
2129  return solve(a, b, "qr");
2130  }
2131  }
static MX sparsity_cast(const MX &x, const Sparsity &sp)
Definition: mx.cpp:1361

References casadi::Sparsity::dense(), casadi::MXNode::get_solve_tril(), casadi::MXNode::get_solve_triu(), casadi::Sparsity::is_orthonormal(), casadi::GenericMatrix< MatType >::is_tril(), casadi::GenericMatrix< MatType >::is_triu(), mtimes(), MX(), casadi::GenericMatrix< MatType >::nnz(), casadi::GenericMatrix< MX >::nz(), casadi::Q, sparsity(), sparsity_cast(), and T().

Referenced by casadi::Nlpsol::get_forward(), casadi::Nlpsol::get_reverse(), inv(), mldivide(), mrdivide(), pinv(), and solve().

◆ solve() [2/2]

MX casadi::MX::solve ( const MX a,
const MX b,
const std::string &  lsolver,
const Dict dict = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2133 of file mx.cpp.

2133  {
2134  if (a.sparsity().is_orthonormal()) return solve(a, b);
2135  Linsol mysolver("tmp_solve", lsolver, a.sparsity(), dict);
2136  return mysolver.solve(a, b, false);
2137  }

References casadi::Sparsity::is_orthonormal(), casadi::Linsol::solve(), solve(), and sparsity().

◆ sparsity()

const Sparsity & casadi::MX::sparsity ( ) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qc

Definition at line 612 of file mx.cpp.

612  {
613  return (*this)->sparsity();
614  }

Referenced by casadi::MXNode::_get_binary(), casadi::Constant< Value >::_get_binary(), casadi::UnaryMX::_get_binary(), casadi::GetNonzeros::ad_forward(), casadi::SetNonzeros< Add >::ad_forward(), casadi::GetNonzeros::ad_reverse(), casadi::KronContract::ad_reverse(), casadi::Solve< Tr >::ad_reverse(), casadi::SparsityCast::ad_reverse(), casadi::DaeBuilderInternal::add(), casadi::Assertion::Assertion(), casadi::BinaryMX< ScX, ScY >::BinaryMX(), casadi::OptiNode::canon_expr(), casadi::Convexify::Convexify(), casadi::GetNonzerosParam::create(), casadi::SetNonzeros< Add >::create(), casadi::GetNonzeros::create(), cumsum(), densify(), det(), diag(), casadi::Diagsplit::Diagsplit(), casadi::Dot::Dot(), casadi::dplesol(), casadi::Dump::Dump(), enlarge(), erase(), casadi::GetNonzeros::eval_mx(), casadi::SetNonzeros< Add >::eval_mx(), expm(), expm_const(), casadi::MXFunction::export_code_body(), casadi::MXFunction::generate_lifted(), get(), casadi::MXNode::get_binary(), casadi::Variable::get_der(), casadi::MXNode::get_dot(), casadi::Nlpsol::get_forward(), casadi::MXNode::get_kron(), casadi::MXNode::get_kron_contract(), casadi::MXNode::get_mac(), casadi::Project::get_nzref(), casadi::Nlpsol::get_reverse(), casadi::HorzRepmat::HorzRepmat(), casadi::HorzRepsum::HorzRepsum(), casadi::Horzsplit::Horzsplit(), casadi::Scpgen::init(), casadi::Kron::Kron(), casadi::KronContract::KronContract(), lift(), casadi::Onnx::load(), casadi::Low::Low(), matrix_expand(), casadi::Monitor::Monitor(), mtimes(), casadi::Multiplication::Multiplication(), MX(), nullspace(), casadi::Horzcat::off(), casadi::Vertcat::off(), casadi::Diagcat::off(), casadi::DaeBuilderInternal::outputs(), casadi::OptiNode::parameter(), casadi::MXFunction::print_arg(), project(), casadi::Rank1::Rank1(), casadi::register_symbol(), reshape(), set(), set_nz(), casadi::SetNonzeros< Add >::SetNonzeros(), casadi::SetNonzerosParam< Add >::SetNonzerosParam(), casadi::simpleIRK(), solve(), casadi::Solve< Tr >::Solve(), casadi::Bilin::sp_forward(), casadi::KronContract::sp_forward(), casadi::Bilin::sp_reverse(), casadi::KronContract::sp_reverse(), casadi::Project::sp_reverse(), sparsity_cast(), casadi::Transpose::Transpose(), casadi::PseudoDenseMultiplication::try_create(), unite(), casadi::OptiNode::variable(), and casadi::Vertsplit::Vertsplit().

◆ sparsity_cast()

MX casadi::MX::sparsity_cast ( const MX x,
const Sparsity sp 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1361 of file mx.cpp.

1361  {
1362  casadi_assert(x.nnz()==sp.nnz(),
1363  "Mismatching nonzero count: " + str(x.nnz()) + " versus " +
1364  str(sp.nnz()) + ".");
1365 
1366  // Quick return if trivial
1367  if (sp==x.sparsity()) return x;
1368 
1369  // Call internal method
1370  return x->get_sparsity_cast(sp);
1371  }

References casadi::MXNode::get_sparsity_cast(), casadi::GenericMatrix< MatType >::nnz(), casadi::Sparsity::nnz(), sparsity(), and casadi::str().

Referenced by solve().

◆ split_primitives() [1/3]

std::vector< DM > casadi::MX::split_primitives ( const DM x) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qq

Definition at line 986 of file mx.cpp.

986  {
987  std::vector<DM> ret(n_primitives());
988  std::vector<DM>::iterator it=ret.begin();
989  (*this)->split_primitives(x, it);
990  casadi_assert_dev(it==ret.end());
991  return ret;
992  }

References n_primitives().

◆ split_primitives() [2/3]

std::vector< MX > casadi::MX::split_primitives ( const MX x) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qq

Definition at line 970 of file mx.cpp.

970  {
971  std::vector<MX> ret(n_primitives());
972  std::vector<MX>::iterator it=ret.begin();
973  (*this)->split_primitives(x, it);
974  casadi_assert_dev(it==ret.end());
975  return ret;
976  }

References n_primitives().

Referenced by extract_parametric(), casadi::DaeBuilderInternal::load_fmi_description(), separate_linear(), simplify_const_folding(), and simplify_ref_count().

◆ split_primitives() [3/3]

std::vector< SX > casadi::MX::split_primitives ( const SX x) const

Extra doc: https://github.com/casadi/casadi/wiki/L_qq

Definition at line 978 of file mx.cpp.

978  {
979  std::vector<SX> ret(n_primitives());
980  std::vector<SX>::iterator it=ret.begin();
981  (*this)->split_primitives(x, it);
982  casadi_assert_dev(it==ret.end());
983  return ret;
984  }

References n_primitives().

◆ sprank()

static casadi_int casadi::GenericMatrix< MX >::sprank ( const MX x)
inlinestaticinherited

Definition at line 215 of file generic_matrix.hpp.

215 { return Sparsity::sprank(x.sparsity());}

◆ stop_diff() [1/2]

MX casadi::MX::stop_diff ( const MX expr,
casadi_int  order 
)
static

Functions called by friend functions defined for this class

Definition at line 3027 of file mx.cpp.

3027  {
3028  std::vector<MX> s = symvar(expr);
3029  MX x = veccat(s);
3030  Dict options;
3031  options["never_inline"] = true;
3032 
3033  Dict inline_options;
3034  inline_options["never_inline"] = false;
3035  inline_options["always_inline"] = true;
3036  Dict der_options = Dict{{"forward_options", inline_options},
3037  {"reverse_options", inline_options},
3038  {"jacobian_options", inline_options}};
3039  if (order==1) {
3040  options["is_diff_in"] = std::vector<bool>{false};
3041  options["is_diff_out"] = std::vector<bool>{true};
3042  options = combine(options, der_options);
3043  } else if (order==2) {
3044  options["der_options"] = der_options;
3045  options["forward_options"] = Dict{{"is_diff_in", std::vector<bool>{false, true, true} },
3046  {"is_diff_out", std::vector<bool>{true}}};
3047  options["reverse_options"] = Dict{{"is_diff_in", std::vector<bool>{false, true, true} },
3048  {"is_diff_out", std::vector<bool>{true}}};
3049  options["jacobian_options"] = Dict{{"is_diff_in", std::vector<bool>{false, true} },
3050  {"is_diff_out", std::vector<bool>{false}}};
3051  } else {
3052  casadi_error("stop_diff: order must be 1 or 2, got " + str(order) + ".");
3053  }
3054 
3055  Function FS("FS", {x}, {expr}, {"x"}, {"z"}, options);
3056  return FS(std::vector<MX>{x})[0];
3057  }
Dict combine(const Dict &first, const Dict &second, bool recurse)
Combine two dicts. First has priority.

References casadi::combine(), casadi::str(), symvar(), and casadi::SparsityInterface< MatType >::veccat().

◆ stop_diff() [2/2]

MX casadi::MX::stop_diff ( const MX expr,
const MX var,
casadi_int  order 
)
static

Functions called by friend functions defined for this class

Definition at line 3059 of file mx.cpp.

3059  {
3060  casadi_warning("stop_diff(expr, var, order) is not well tested.");
3061  std::vector<MX> xv = symvar(var);
3062  std::vector<MX> s = symvar(expr);
3063  std::vector<MX> yv = difference(s, xv);
3064 
3065  MX x = veccat(xv);
3066  MX y = veccat(yv);
3067 
3068  Dict options;
3069  options["never_inline"] = true;
3070 
3071  Dict inline_options;
3072  inline_options["never_inline"] = false;
3073  inline_options["always_inline"] = true;
3074  Dict der_options = Dict{{"forward_options", inline_options},
3075  {"reverse_options", inline_options},
3076  {"jacobian_options", inline_options}};
3077  if (order==1) {
3078  options["is_diff_in"] = std::vector<bool>{false, true};
3079  options["is_diff_out"] = std::vector<bool>{true};
3080  options = combine(options, der_options);
3081  } else if (order==2) {
3082  options["der_options"] = der_options;
3083  options["forward_options"] = Dict{{"is_diff_in",
3084  std::vector<bool>{false, true, false, true, true} },
3085  {"is_diff_out", std::vector<bool>{true}}};
3086  options["reverse_options"] = Dict{{"is_diff_in",
3087  std::vector<bool>{false, true, false, true}},
3088  {"is_diff_out", std::vector<bool>{false, true}}};
3089  options["jacobian_options"] = Dict{{"is_diff_in", std::vector<bool>{false, true, true}},
3090  {"is_diff_out", std::vector<bool>{true}}};
3091  } else {
3092  casadi_error("stop_diff: order must be 1 or 2, got " + str(order) + ".");
3093  }
3094 
3095  Function FS("FS", {x, y}, {expr}, {"x", "y"}, {"z"}, options);
3096  return FS(std::vector<MX>{x, y})[0];
3097  }
static std::vector< MX > difference(const std::vector< MX > &a, const std::vector< MX > &b)
Definition: mx.cpp:3099

References casadi::combine(), difference(), casadi::str(), symvar(), and casadi::SparsityInterface< MatType >::veccat().

◆ substitute() [1/2]

MX casadi::MX::substitute ( const MX ex,
const MX v,
const MX vdef 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1525 of file mx.cpp.

1525  {
1526  return substitute(std::vector<MX>{ex}, std::vector<MX>{v}, std::vector<MX>{vdef}).front();
1527  }
static MX substitute(const MX &ex, const MX &v, const MX &vdef)
Definition: mx.cpp:1525

Referenced by casadi::DaeBuilderInternal::transition().

◆ substitute() [2/2]

std::vector< MX > casadi::MX::substitute ( const std::vector< MX > &  ex,
const std::vector< MX > &  v,
const std::vector< MX > &  vdef 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1529 of file mx.cpp.

1530  {
1531  // Assert consistent dimensions
1532  casadi_assert_dev(v.size()==vdef.size());
1533 
1534  // Quick return if all equal
1535  bool all_equal = true;
1536  for (casadi_int k=0; k<v.size(); ++k) {
1537  if (v[k].size()!=vdef[k].size() || !is_equal(v[k], vdef[k])) {
1538  all_equal = false;
1539  break;
1540  }
1541  }
1542  if (all_equal) return ex;
1543 
1544  // Otherwise, evaluate symbolically
1545  Function F("tmp_substitute", v, ex, Dict{{"max_io", 0}, {"allow_free", true}});
1546  std::vector<MX> ret;
1547  F.call(vdef, ret, true);
1548  return ret;
1549  }

References casadi::Function::call(), is_equal(), and casadi::GenericMatrix< MX >::size().

◆ substitute_inplace()

void casadi::MX::substitute_inplace ( const std::vector< MX > &  v,
std::vector< MX > &  vdef,
std::vector< MX > &  ex,
bool  reverse 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1503 of file mx.cpp.

1504  {
1505  casadi_assert(v.size()==vdef.size(),
1506  "Mismatch in the number of expression to substitute.");
1507  for (casadi_int k=0; k<v.size(); ++k) {
1508  casadi_assert(v[k].is_symbolic(),
1509  "Variable " + str(k) + " is not symbolic");
1510  casadi_assert(v[k].size() == vdef[k].size(),
1511  "Inconsistent shape for variable " + str(k) + ".");
1512  }
1513  casadi_assert(reverse==false, "Not implemented");
1514 
1515  // quick return if nothing to replace
1516  if (v.empty()) return;
1517 
1518  // implemented in MXFunction
1519  std::vector<MX> f_out = vdef;
1520  f_out.insert(f_out.end(), ex.begin(), ex.end());
1521  Function temp("tmp_substitute_inplace", {v}, f_out, Dict{{"max_io", 0}, {"allow_free", true}});
1522  temp.get<MXFunction>()->substitute_inplace(vdef, ex);
1523  }
static void substitute_inplace(const std::vector< MX > &v, std::vector< MX > &vdef, std::vector< MX > &ex, bool reverse)
Definition: mx.cpp:1503
static std::vector< std::vector< MX > > reverse(const std::vector< MX > &ex, const std::vector< MX > &arg, const std::vector< std::vector< MX > > &v, const Dict &opts=Dict())
Definition: mx.cpp:1980
bool is_symbolic() const
Check if symbolic.
Definition: mx.cpp:795

References casadi::Function::get(), is_symbolic(), reverse(), casadi::GenericMatrix< MX >::size(), and casadi::str().

◆ sum1()

MX casadi::MX::sum1 ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1485 of file mx.cpp.

1485  {
1486  return mtimes(MX::ones(1, x.size1()), x);
1487  }

References mtimes(), casadi::GenericMatrix< MX >::ones(), and casadi::GenericMatrix< MatType >::size1().

◆ sum2()

MX casadi::MX::sum2 ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1481 of file mx.cpp.

1481  {
1482  return mtimes(x, MX::ones(x.size2(), 1));
1483  }

References mtimes(), casadi::GenericMatrix< MX >::ones(), and casadi::GenericMatrix< MatType >::size2().

◆ sumsqr()

static MX casadi::GenericMatrix< MX >::sumsqr ( const MX x)
inlinestaticinherited

Definition at line 225 of file generic_matrix.hpp.

225 { return dot(x, x);}
friend MX dot(const MX &x, const MX &y)
Inner product of two matrices.

◆ swap()

Definition at line 105 of file generic_shared_impl.hpp.

131  {
132  GenericShared<Shared, Internal> temp = *this;
133  *this = other;
134  other = temp;
135  }

◆ sym() [1/7]

static std::vector<MX > casadi::GenericMatrix< MX >::sym ( const std::string &  name,
casadi_int  nrow,
casadi_int  ncol,
casadi_int  p 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1de

Definition at line 1261 of file generic_matrix.hpp.

1262  {
1263  return sym(name, Sparsity::dense(nrow, ncol), p);
1264  }

◆ sym() [2/7]

static std::vector<std::vector<MX > > casadi::GenericMatrix< MX >::sym ( const std::string &  name,
casadi_int  nrow,
casadi_int  ncol,
casadi_int  p,
casadi_int  r 
)
inlinestaticinherited

with nrow-by-ncol symbolic primitives

Extra doc: https://github.com/casadi/casadi/wiki/L_1dg

Definition at line 1280 of file generic_matrix.hpp.

1280  {
1281  return sym(name, Sparsity::dense(nrow, ncol), p, r);
1282  }

◆ sym() [3/7]

static MX casadi::GenericMatrix< MX >::sym ( const std::string &  name,
casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1da

Definition at line 1233 of file generic_matrix.hpp.

1233  {
1234  return sym(name, Sparsity::dense(nrow, ncol));
1235  }

◆ sym() [4/7]

static MX casadi::GenericMatrix< MX >::sym ( const std::string &  name,
const Sparsity sp 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1dc

Definition at line 1247 of file generic_matrix.hpp.

1247  {
1248  return MatType::_sym(name, sp);
1249  }

◆ sym() [5/7]

std::vector< MX > casadi::GenericMatrix< MX >::sym ( const std::string &  name,
const Sparsity sp,
casadi_int  p 
)
staticinherited

with symbolic primitives of given sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1dd

Definition at line 1256 of file generic_matrix.hpp.

1383  {
1384  std::vector<MatType> ret(p);
1385  std::stringstream ss;
1386  for (casadi_int k=0; k<p; ++k) {
1387  ss.str("");
1388  ss << name << k;
1389  ret[k] = sym(ss.str(), sp);
1390  }
1391  return ret;
1392  }

◆ sym() [6/7]

std::vector< std::vector< MX > > casadi::GenericMatrix< MX >::sym ( const std::string &  name,
const Sparsity sp,
casadi_int  p,
casadi_int  r 
)
staticinherited

symbolic primitives with given sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1df

Definition at line 1272 of file generic_matrix.hpp.

1397  {
1398  std::vector<std::vector<MatType> > ret(r);
1399  for (casadi_int k=0; k<r; ++k) {
1400  std::stringstream ss;
1401  ss << name << "_" << k;
1402  ret[k] = sym(ss.str(), sp, p);
1403  }
1404  return ret;
1405  }

◆ sym() [7/7]

static MX casadi::GenericMatrix< MX >::sym ( const std::string &  name,
const std::pair< casadi_int, casadi_int > &  rc 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1db

Definition at line 1240 of file generic_matrix.hpp.

1240  {
1241  return sym(name, rc.first, rc.second);
1242  }

◆ symvar()

std::vector< MX > casadi::MX::symvar ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2041 of file mx.cpp.

2041  {
2042  Function f("f", std::vector<MX>{}, {x}, {{"allow_free", true}});
2043  return f.free_mx();
2044  }

References casadi::Function::free_mx().

Referenced by conditional(), if_else(), matrix_expand(), casadi::OptiNode::set_initial(), casadi::OptiNode::set_linear_scale(), casadi::OptiNode::set_value(), stop_diff(), casadi::OptiNode::symvar(), transform(), and casadi::OptiNode::update_user_dict().

◆ T()

MX casadi::MX::T ( ) const

◆ tangent()

static MX casadi::GenericMatrix< MX >::tangent ( const MX ex,
const MX arg,
const Dict opts = Dict() 
)
staticinherited

Functions called by friend functions defined here

◆ test_cast()

bool casadi::MX::test_cast ( const SharedObjectInternal ptr)
static

Definition at line 1099 of file mx.cpp.

1099  {
1100  return dynamic_cast<const MXNode*>(ptr)!=nullptr;
1101  }

◆ trace()

MX casadi::MX::trace ( const MX x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1455 of file mx.cpp.

1455  {
1456  casadi_assert(x.is_square(), "trace: must be square");
1457  MX res(0);
1458  for (casadi_int i=0; i < x.size2(); i ++) {
1459  res += x(i, i);
1460  }
1461  return res;
1462  }

References casadi::GenericMatrix< MatType >::is_square(), and casadi::GenericMatrix< MatType >::size2().

◆ transform() [1/4]

MX casadi::MX::transform ( const MX x,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1315 of file mx.cpp.

1315  {
1316  return transform(std::vector<MX>{x}, opts).at(0);
1317  }
static MX transform(const MX &x, const Dict &opts=Dict())
Definition: mx.cpp:1315

Referenced by transform().

◆ transform() [2/4]

MX casadi::MX::transform ( const MX x,
const std::vector< std::vector< GenericType > > &  passes,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1319 of file mx.cpp.

1320  {
1321  return transform(std::vector<MX>{x}, passes, opts).at(0);
1322  }

References transform().

◆ transform() [3/4]

std::vector< MX > casadi::MX::transform ( const std::vector< MX > &  x,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1324 of file mx.cpp.

1324  {
1325  // Route through Function::transform; inputs are the free variables across all of x
1326  std::vector<MX> arg = symvar(veccat(x));
1327  Function f("transform", arg, x,
1328  {{"allow_free", true}, {"allow_duplicate_io_names", true}});
1329  f = f.transform(opts);
1330  return f(arg);
1331  }

References symvar(), casadi::Function::transform(), and casadi::SparsityInterface< MatType >::veccat().

◆ transform() [4/4]

std::vector< MX > casadi::MX::transform ( const std::vector< MX > &  x,
const std::vector< std::vector< GenericType > > &  passes,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1333 of file mx.cpp.

1334  {
1335  // Route through Function::transform; inputs are the free variables across all of x
1336  std::vector<MX> arg = symvar(veccat(x));
1337  Function f("transform", arg, x,
1338  {{"allow_free", true}, {"allow_duplicate_io_names", true}});
1339  f = f.transform(passes, opts);
1340  return f(arg);
1341  }

References symvar(), casadi::Function::transform(), and casadi::SparsityInterface< MatType >::veccat().

◆ tril()

static MX casadi::GenericMatrix< MX >::tril ( const MX x,
bool  includeDiagonal = true 
)
inlinestaticinherited

Definition at line 219 of file generic_matrix.hpp.

219  {
220  return project(x, Sparsity::tril(x.sparsity(), includeDiagonal));
221  }
friend MX project(const MX &A, const Sparsity &sp, bool intersect=false)
Create a new matrix with a given sparsity pattern but with the.

◆ tril2symm()

MX casadi::GenericMatrix< MX >::tril2symm ( const MX x)
staticinherited

Definition at line 230 of file generic_matrix.hpp.

1547  {
1548  casadi_assert(x.is_square(),
1549  "Shape error in tril2symm. Expecting square shape but got " + x.dim());
1550  casadi_assert(x.nnz_upper()-x.nnz_diag()==0,
1551  "Sparsity error in tril2symm. Found above-diagonal entries in argument: " + x.dim());
1552  return x + x.T() - diag(diag(x));
1553  }
friend MX diag(const MX &A)
Get the diagonal of a matrix or construct a diagonal.

◆ triu()

static MX casadi::GenericMatrix< MX >::triu ( const MX x,
bool  includeDiagonal = true 
)
inlinestaticinherited

Definition at line 222 of file generic_matrix.hpp.

222  {
223  return project(x, Sparsity::triu(x.sparsity(), includeDiagonal));
224  }

◆ triu2symm()

MX casadi::GenericMatrix< MX >::triu2symm ( const MX x)
staticinherited

Definition at line 231 of file generic_matrix.hpp.

1571  {
1572  casadi_assert(x.is_square(),
1573  "Shape error in triu2symm. Expecting square shape but got " + x.dim());
1574  casadi_assert(x.nnz_lower()-x.nnz_diag()==0,
1575  "Sparsity error in triu2symm. Found below-diagonal entries in argument: " + x.dim());
1576  return x + x.T() - diag(diag(x));
1577  }

◆ type_name()

static std::string casadi::MX::type_name ( )
inlinestatic

Extra doc: https://github.com/casadi/casadi/wiki/L_pz

Definition at line 97 of file mx.hpp.

97 {return "MX";}

◆ unary()

MX casadi::MX::unary ( casadi_int  op,
const MX x,
bool  unique = false 
)
static

Extra doc: https://github.com/casadi/casadi/wiki/L_r1

Definition at line 560 of file mx.cpp.

560  {
561  return x->get_unary(Operation(op), unique);
562  }
Operation
Enum for quick access to any node.
Definition: calculus.hpp:60

References casadi::MXNode::get_unary(), and op().

Referenced by casadi::UnaryMX::eval_mx().

◆ unite()

MX casadi::MX::unite ( const MX A,
const MX B 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 1429 of file mx.cpp.

1429  {
1430  // Join the sparsity patterns
1431  std::vector<unsigned char> mapping;
1432  Sparsity sp = A.sparsity().unite(B.sparsity(), mapping);
1433 
1434  // Split up the mapping
1435  std::vector<casadi_int> nzA, nzB;
1436 
1437  // Copy sparsity
1438  for (casadi_int k=0; k<mapping.size(); ++k) {
1439  if (mapping[k]==1) {
1440  nzA.push_back(k);
1441  } else if (mapping[k]==2) {
1442  nzB.push_back(k);
1443  } else {
1444  throw CasadiException("Pattern intersection not empty");
1445  }
1446  }
1447 
1448  // Create mapping
1449  MX ret = MX::zeros(sp);
1450  ret = A->get_nzassign(ret, nzA);
1451  ret = B->get_nzassign(ret, nzB);
1452  return ret;
1453  }
Sparsity unite(const Sparsity &y, std::vector< unsigned char > &mapping) const
Union of two sparsity patterns.
Definition: sparsity.cpp:409

References casadi::MXNode::get_nzassign(), mapping(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::sparsity(), sparsity(), casadi::Sparsity::unite(), and casadi::GenericMatrix< MX >::zeros().

◆ vertcat()

MX casadi::MX::vertcat ( const std::vector< MX > &  x)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1165 of file mx.cpp.

1165  {
1166  // Check dimensions
1167  if (x.size()>1) {
1168  std::vector<MX> ne = trim_empty(x, true);
1169  for (casadi_int i=0;i<ne.size();i++) {
1170  casadi_assert(ne[i].size2()==ne[0].size2(),
1171  "vertcat dimension mismatch x[" + str(i) + "]:" + ne[i].dim() +
1172  " and x[0]: " + ne[0].dim() + ".");
1173  }
1174  }
1175 
1176  if (x.empty()) {
1177  return MX(0, 1);
1178  } else if (x.size()==1) {
1179  return x.front();
1180  } else if (has_empty(x)) {
1181  std::vector<MX> ret = trim_empty(x);
1182  if (ret.empty()) {
1183  // We still want vertcat(zeros(5,0),zeros(5,0)) -> zeros(10,0)
1184  ret = trim_empty(x, true);
1185  casadi_int s = 0;
1186  casadi_int ncol = 0;
1187  for (casadi_int i=0;i<ret.size();++i) {
1188  s+= ret[i].size1();
1189  casadi_assert_dev(ncol==0 || ret[i].size2()==ncol);
1190  ncol = ret[i].size2();
1191  }
1192  return MX::zeros(s, ncol);
1193  } else {
1194  return vertcat(ret);
1195  }
1196  } else if (!x.front().is_column()) {
1197  // Vertcat operation only supports vectors, rewrite using horzcat
1198  std::vector<MX> xT = x;
1199  for (std::vector<MX>::iterator i=xT.begin(); i!=xT.end(); ++i) *i = i->T();
1200  return horzcat(xT).T();
1201  } else {
1202  return x.front()->get_vertcat(x);
1203  }
1204  }
virtual MX get_vertcat(const std::vector< MX > &x) const
Create a vertical concatenation node (vectors only)
Definition: mx_node.cpp:1170

References casadi::GenericMatrix< MX >::dim(), casadi::MXNode::get_vertcat(), casadi::has_empty(), horzcat(), MX(), casadi::GenericExpression< MX >::ne(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MX >::size2(), casadi::str(), T(), casadi::trim_empty(), and casadi::GenericMatrix< MX >::zeros().

Referenced by blockcat(), casadi::Nlpsol::get_forward(), casadi::Nlpsol::get_reverse(), casadi::Blocksqp::init(), and linspace().

◆ vertsplit()

std::vector< MX > casadi::MX::vertsplit ( const MX x,
const std::vector< casadi_int > &  offset 
)
static

Functions called by friend functions defined for SparsityInterface

Definition at line 1240 of file mx.cpp.

1240  {
1241  if (x.is_column()) {
1242  // Consistency check
1243  casadi_assert_dev(!offset.empty());
1244  casadi_assert_dev(offset.front()==0);
1245  casadi_assert_dev(offset.back()==x.size1());
1246  casadi_assert_dev(is_monotone(offset));
1247 
1248  // Trivial return if possible
1249  if (offset.size()==1) {
1250  return std::vector<MX>();
1251  } else if (offset.size()==2) {
1252  return std::vector<MX>(1, x);
1253  } else {
1254  return x->get_vertsplit(offset);
1255  }
1256  } else {
1257  std::vector<MX> ret = horzsplit(x.T(), offset);
1258  for (auto&& e : ret) e = e.T();
1259  return ret;
1260  }
1261  }
static std::vector< MX > horzsplit(const MX &x, const std::vector< casadi_int > &offset)
Definition: mx.cpp:1206

References casadi::MXNode::get_vertsplit(), horzsplit(), casadi::GenericMatrix< MatType >::is_column(), casadi::is_monotone(), casadi::SparsityInterface< MatType >::offset(), casadi::GenericMatrix< MatType >::size1(), and T().

◆ weak()

Extra doc: https://github.com/casadi/casadi/wiki/L_aw

Definition at line 130 of file generic_shared_impl.hpp.

143  {
144  return (*this)->weak();
145  }

◆ which_depends()

std::vector< bool > casadi::MX::which_depends ( const MX expr,
const MX var,
casadi_int  order = 1,
bool  tr = false 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 2012 of file mx.cpp.

2012  {
2013  return _which_depends(expr, var, order, tr);
2014  }
std::vector< bool > _which_depends(const MatType &expr, const MatType &var, casadi_int order, bool tr)

References casadi::_which_depends().

◆ which_function()

Function casadi::MX::which_function ( ) const

Definition at line 807 of file mx.cpp.

807  {
808  return (*this)->which_function();
809  }

Referenced by casadi::DaeBuilderInternal::create(), cse(), casadi::Onnx::load(), and casadi::BlazingSplineFunction::merge().

◆ which_output()

casadi_int casadi::MX::which_output ( ) const

Definition at line 819 of file mx.cpp.

819  {
820  return (*this)->which_output();
821  }

Referenced by casadi::DaeBuilderInternal::create(), cse(), and casadi::DaeBuilderInternal::jac_vdef_v_from_calls().

◆ zeros() [1/3]

static MX casadi::GenericMatrix< MX >::zeros ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1dh

Definition at line 1289 of file generic_matrix.hpp.

1289  {
1290  return zeros(Sparsity::dense(nrow, ncol));
1291  }

◆ zeros() [2/3]

static MX casadi::GenericMatrix< MX >::zeros ( const Sparsity sp)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1dh

Definition at line 1292 of file generic_matrix.hpp.

1292 { return MatType(sp, 0, false);}

◆ zeros() [3/3]

static MX casadi::GenericMatrix< MX >::zeros ( const std::pair< casadi_int, casadi_int > &  rc)
inlinestaticinherited

Extra doc: https://github.com/casadi/casadi/wiki/L_1dh

Definition at line 1293 of file generic_matrix.hpp.

1293  {
1294  return zeros(rc.first, rc.second);
1295  }

The documentation for this class was generated from the following files: