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 80 of file mx.hpp.
|
| MX () |
| Default constructor. More...
|
|
| MX (casadi_int nrow, casadi_int ncol) |
| 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 (double x) |
| Create scalar constant (also implicit type conversion) More...
|
|
| MX (const Matrix< double > &x) |
| Create sparse matrix constant (also implicit type conversion) 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...
|
|
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 | 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_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...
|
|
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< MX > | primitives () const |
| Get primitives. 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 zero (note that false negative answers are possible) More...
|
|
bool | is_minus_one () const |
| check if zero (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_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...
|
|
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 | 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 |
| Evaluate the MX node with new symbolic dependencies. 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...
|
|
Sparsity | sparsity () const |
| Get the sparsity pattern. 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...
|
|
bool | is_null () const |
| Is a null pointer? More...
|
|
casadi_int | __hash__ () const |
| Returns a number that is unique for a given Node. More...
|
|
|
std::vector< MX > | split_primitives (const MX &x) const |
| Split up an expression along symbolic primitives. More...
|
|
std::vector< SX > | split_primitives (const SX &x) const |
| Split up an expression along symbolic primitives. More...
|
|
std::vector< DM > | split_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) |
|
|
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...
|
|
casadi_int | row (casadi_int el) 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 std::string | type_name () |
| Get type name. More...
|
|
static MX | deserialize (DeserializingStream &s) |
| Deserialize with type disambiguation. More...
|
|
static MX | eye (casadi_int n) |
| Identity matrix. More...
|
|
static DM | bspline_dual (const std::vector< double > &x, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > °ree, const Dict &opts=Dict()) |
|
static MX | 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< MX > | get_input (const Function &f) |
| Get function inputs. More...
|
|
static std::vector< MX > | get_free (const Function &f) |
| Get free variables. More...
|
|
static MX | logsumexp (const MX &x) |
|
|
static MX | binary (casadi_int op, const MX &x, const MX &y) |
| Create nodes by their ID. More...
|
|
static MX | unary (casadi_int op, const MX &x) |
| 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 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...
|
|
|
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< MX > | sym (const std::string &name, const Sparsity &sp, casadi_int p) |
| Create a vector of length p with with matrices. More...
|
|
static std::vector< MX > | sym (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...
|
|
|
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...
|
|
std::vector< MX > | graph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef) |
| Substitute multiple expressions in graph. More...
|
|
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< MX > | matrix_expand (const std::vector< MX > &e, const std::vector< MX > &boundary=std::vector< MX >(), const Dict &options=Dict()) |
| Expand MX graph to SXFunction call. More...
|
|
MX | bspline (const MX &x, const DM &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > °ree, casadi_int m, const Dict &opts=Dict()) |
|
MX | bspline (const MX &x, const MX &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > °ree, 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 > °ree, 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< MX > | difference (const std::vector< MX > &a, const std::vector< MX > &b) |
|