MX - Matrix expression. More...
#include <mx.hpp>
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.
Each node is a matrix-valued operation (symbolic primitive, constant, binary operation, concatenation, matrix product, call to a Function, ...), so an expression such as A+1 is a small number of nodes regardless of the matrix sizes. The graph is immutable: every operation creates new nodes. Symbolic primitives are created with MX.sym; MX(...) creates constants.
>>> x = MX.sym("x", 2)
>>> A = MX.sym("A", 2, 2)
>>> e = A @ x + 1
>>> e
MX((ones(2x1)+mac(A,x,zeros(2x1))))
>>> e.shape, e.n_dep(), e.is_symbolic()
((2, 1), 2, False)
>>> f = Function("f", [A, x], [e])
>>> f(DM([[1, 2], [3, 4]]), DM([1, 1]))
DM([4, 8])
>> x = MX.sym('x', 2); A = MX.sym('A', 2, 2);
>> e = A*x + 1;
>> e
(ones(2x1)+mac(A,x,zeros(2x1)))
>> size(e), e.n_dep(), e.is_symbolic()
2 1
2
0
>> f = Function('f', {A, x}, {e});
>> f(DM([1 2; 3 4]), DM([1; 1]))
[4, 8]
julia> x = ca.MX.sym("x", 2); A = ca.MX.sym("A", 2, 2);
julia> e = A * x + 1;
julia> e
MX((ones(2x1)+mac(A,x,zeros(2x1))))
julia> size(e), ca.n_dep(e), ca.is_symbolic(e)
((2, 1), 2, false)
julia> f = ca.Function("f", [A, x], [e]);
julia> f([1 2; 3 4], [1, 1])
DM([4, 8])
Extra doc: https://github.com/casadi/casadi/wiki/L_py

Public Types | |
| typedef std::map< std::string, MX > | MXDict |
| Readability typedef. More... | |
| using | internal_base_type = SharedObjectInternal |
| using | base_type = SharedObject |
Public Member Functions | |
| MX () | |
| Default constructor: a 0-by-0 constant. More... | |
| MX (casadi_int nrow, casadi_int ncol) | |
| Create a sparse matrix with all structural zeros. More... | |
| MX (const Sparsity &sp) | |
| Create a constant with a given sparsity pattern and all nonzeros equal to one. More... | |
| MX (const Sparsity &sp, const MX &val) | |
| Construct a matrix with a given sparsity pattern and given nonzeros. More... | |
| MX (const Sparsity &sp, const std::string &fname) | |
| Construct a constant whose nonzeros are read from a text file. More... | |
| MX (const Matrix< double > &val, const std::string &name) | |
| Construct a named constant that generated code exposes as a modifiable pool. More... | |
| MX (double x) | |
| Create a 1-by-1 constant (also used for implicit conversion from a number) More... | |
| MX (const Matrix< double > &x) | |
| Create a constant from a DM (also used for implicit conversion) More... | |
| bool | __nonzero__ () const |
| Truth value of a 1-by-1 constant. More... | |
| Sparsity | get_sparsity () const |
| Get an owning reference to the sparsity pattern. More... | |
| std::vector< MX > | get_nonzeros () const |
| Get the nonzeros as a list of 1-by-1 expressions. 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 elements (leaving structural zeros in their 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 |
| Unary minus. More... | |
| MX | operator+ () const |
| Unary plus: returns the expression itself. More... | |
| MX | inv () const |
| Element-wise inverse, 1/x. More... | |
| MX | dep (casadi_int ch=0) const |
Get the ch-th dependency (child node) of this node. More... | |
| casadi_int | n_out () const |
| Number of outputs of this node. More... | |
| MX | get_output (casadi_int oind) const |
| Get an output of a multiple-output node. More... | |
| casadi_int | n_dep () const |
| Get the number of dependencies (child nodes) of this node. More... | |
| std::string | name () const |
| Get the name of a symbolic primitive. More... | |
| operator double () const | |
| Get the value of a 1-by-1 constant node (float conversion) More... | |
| operator Matrix< double > () const | |
| Get the value of a constant node as a DM. More... | |
| bool | is_symbolic () const |
| Check if the node is a symbolic primitive (created by MX.sym) More... | |
| bool | is_constant () const |
| Check if the node is a constant. More... | |
| bool | is_integer () const |
| Check if the node is a constant with integer-valued nonzeros. More... | |
| bool | is_doubled () const |
| Check if the node is the sum of two equal expressions, or 2*x. More... | |
| bool | is_call () const |
| Check if the node is a call to a Function. More... | |
| Function | which_function () const |
| Get the Function of a call node. More... | |
| bool | is_output () const |
| Check if the node selects one output of a multiple-output node. More... | |
| bool | has_output () const |
| Check if this is a multiple-output node. More... | |
| casadi_int | which_output () const |
| Get the output index of an OutputNode. More... | |
| bool | is_op (casadi_int op) const |
| Check if the node is a certain operation. More... | |
| bool | is_multiplication () const |
| Check if the node is a matrix product (mtimes) More... | |
| bool | is_commutative () const |
| Check if a binary operation is commutative. More... | |
| bool | is_norm () const |
| Check if the node is a norm (norm_1, norm_2, norm_inf or norm_fro) More... | |
| bool | is_valid_input () const |
| Check if the expression can be used as a Function input. More... | |
| casadi_int | n_primitives () const |
| Get the number of symbolic primitives in a valid Function input. More... | |
| std::vector< MX > | primitives () const |
| Get the symbolic primitives of a valid Function input. More... | |
| bool | is_eye () const |
| Check if the node is a constant identity matrix. More... | |
| bool | is_zero () const |
| Check if the node is a constant zero (false negatives are possible) More... | |
| bool | is_one () const |
| Check if the node is a constant with all nonzeros one (false negatives possible) More... | |
| bool | is_minus_one () const |
| Check if the node is a constant with all nonzeros -1 (false negatives possible) More... | |
| bool | is_half () const |
| Check if the node is a constant with all nonzeros 0.5 (false negatives possible) More... | |
| bool | is_value (double val) const |
Check if the node is a constant with all nonzeros equal to val. More... | |
| bool | is_inf () const |
| Check if the node is a constant with all nonzeros +inf (false negatives possible) More... | |
| bool | is_minus_inf () const |
| Check if the node is a constant with all nonzeros -inf (false negatives possible) More... | |
| bool | is_transpose () const |
| Check if the node is a transpose operation. More... | |
| bool | is_regular () const |
| Check that a constant node contains neither NaN nor Inf. More... | |
| bool | is_binary () const |
| Check if the node is an elementwise binary operation. More... | |
| bool | is_nonnegative () const |
| Check if a value is always nonnegative (false negatives are allowed) More... | |
| bool | is_unary () const |
| Check if the node is an elementwise unary operation. More... | |
| casadi_int | op () const |
| Get the operation type of the node. More... | |
| Dict | info () const |
| Obtain information about the node as a dictionary. More... | |
| void | serialize (SerializingStream &s) const |
| Serialize the expression to a stream. More... | |
| MX | printme (const MX &b) const |
| Return the expression with the side effect of printing its value with a tag. More... | |
| MX | attachAssert (const MX &y, const std::string &fail_message="") const |
| Return the expression with a run-time assertion attached. More... | |
| MX | monitor (const std::string &comment) const |
| Return the expression with the side effect of printing its value. More... | |
| MX | dump (const std::string &base_filename, const Dict &opts=Dict()) const |
| Return the expression with the side effect of writing its value to a file. More... | |
| void | reset_dump_count () |
| Reset the file counter of a dump node; raises an error on any other node. More... | |
| MX | T () const |
| Transpose the matrix. More... | |
| Matrix< casadi_int > | mapping () const |
| Get the nonzero mapping 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 |
| Re-apply the operation of this node to new dependencies. More... | |
| casadi_int | nnz () const |
| Get the number of structural nonzeros. More... | |
| casadi_int | nnz_lower () const |
| Get the number of structural nonzeros on or below the diagonal. More... | |
| casadi_int | nnz_upper () const |
| Get the number of structural nonzeros on or above the diagonal. More... | |
| casadi_int | nnz_diag () const |
| Get the number of structural nonzeros on the diagonal. More... | |
| casadi_int | numel () const |
| Get the number of elements, size1()*size2() 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 (same as size1()) 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 (same as size2()) 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 as a pair (number of rows, number of columns) More... | |
| casadi_int | size (casadi_int axis) const |
| Get the size along a particular dimension. More... | |
| bool | is_empty (bool both=false) const |
| Check if the matrix is empty, i.e. if one of the dimensions is zero. More... | |
| bool | is_dense () const |
| Check if the matrix is dense, i.e. nnz() equals numel() More... | |
| bool | is_scalar (bool scalar_and_dense=false) const |
| Check if the matrix is scalar, i.e. 1-by-1. More... | |
| bool | is_square () const |
| Check if the matrix is square, i.e. size1() equals size2() 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... | |
| 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... | |
| std::vector< MX > | split_primitives (const MX &x) const |
| Split a value along the symbolic primitives of this expression. More... | |
| std::vector< SX > | split_primitives (const SX &x) const |
| Split a value along the symbolic primitives of this expression. More... | |
| std::vector< DM > | split_primitives (const DM &x) const |
| Split a value along the symbolic primitives of this expression. More... | |
| MX | join_primitives (const std::vector< MX > &v) const |
| Join values along the symbolic primitives of this expression. More... | |
| SX | join_primitives (const std::vector< SX > &v) const |
| Join values along the symbolic primitives of this expression. More... | |
| DM | join_primitives (const std::vector< DM > &v) const |
| Join values along the symbolic primitives of this expression. More... | |
| void | get (MX &m, bool ind1, const Slice &rr) const |
| Get a submatrix by linear index (what x[k] does) More... | |
| void | get (MX &m, bool ind1, const Matrix< casadi_int > &rr) const |
| Get a submatrix by linear index (what x[k] does) More... | |
| void | get (MX &m, bool ind1, const Sparsity &sp) const |
| Get a submatrix by linear index (what x[k] does) More... | |
| void | get (MX &m, bool ind1, const MX &rr) const |
| Get a submatrix by linear index (what x[k] does) More... | |
| void | get (MX &m, bool ind1, const casadi_int rr) const |
| Get a submatrix by linear index (what x[k] does) More... | |
| void | get (MX &m, bool ind1, const Slice &rr, const Slice &cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, const Slice &rr, casadi_int cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, casadi_int rr, const Slice &cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, casadi_int rr, casadi_int cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, const MX &rr, const Slice &cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, const Slice &rr, const MX &cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | get (MX &m, bool ind1, const MX &rr, const MX &cc) const |
| Get a submatrix by row and column index (what x[i, j] does) More... | |
| void | set (const MX &m, bool ind1, const Slice &rr) |
| Assign to a submatrix by linear index (what x[k] = m does) More... | |
| void | set (const MX &m, bool ind1, const Matrix< casadi_int > &rr) |
| Assign to a submatrix by linear index (what x[k] = m does) More... | |
| void | set (const MX &m, bool ind1, const Sparsity &sp) |
| Assign to a submatrix by linear index (what x[k] = m does) More... | |
| void | set (const MX &m, bool ind1, const Slice &rr, const Slice &cc) |
| Assign to a submatrix by row and column index (what x[i, j] = m does) More... | |
| void | set (const MX &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc) |
| Assign to a submatrix by row and column index (what x[i, j] = m does) More... | |
| void | set (const MX &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc) |
| Assign to a submatrix by row and column index (what x[i, j] = m does) More... | |
| void | set (const MX &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc) |
| Assign to a submatrix by row and column index (what x[i, j] = m does) More... | |
| void | get_nz (MX &m, bool ind1, const Slice &kk) const |
| Get a set of nonzeros (what x.nz[k] does) More... | |
| void | get_nz (MX &m, bool ind1, const Matrix< casadi_int > &kk) const |
| Get a set of nonzeros (what x.nz[k] does) More... | |
| void | get_nz (MX &m, bool ind1, const MX &kk) const |
| Get a set of nonzeros (what x.nz[k] does) More... | |
| void | get_nz (MX &m, bool ind1, casadi_int kk) const |
| Get a set of nonzeros (what x.nz[k] does) More... | |
| void | get_nz (MX &m, bool ind1, const MX &inner, const Slice &outer) const |
| Get a set of nonzeros (what x.nz[k] does) More... | |
| void | get_nz (MX &m, bool ind1, const Slice &inner, const MX &outer) const |
| Get a set of nonzeros (what x.nz[k] does) More... | |
| void | get_nz (MX &m, bool ind1, const MX &inner, const MX &outer) const |
| Get a set of nonzeros (what x.nz[k] does) More... | |
| void | set_nz (const MX &m, bool ind1, const Slice &kk) |
| Assign to a set of nonzeros (what x.nz[k] = m does) More... | |
| void | set_nz (const MX &m, bool ind1, const Matrix< casadi_int > &kk) |
| Assign to a set of nonzeros (what x.nz[k] = m does) More... | |
| void | set_nz (const MX &m, bool ind1, const MX &kk) |
| Assign to a set of nonzeros (what x.nz[k] = m does) More... | |
| void | set_nz (const MX &m, bool ind1, casadi_int kk) |
| Assign to a set of nonzeros (what x.nz[k] = m does) 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... | |
| 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 Public Member Functions | |
| static std::string | type_name () |
| Get type name. More... | |
| static MX | deserialize (DeserializingStream &s) |
| Deserialize an expression from a stream, with type disambiguation. More... | |
| static MX | eye (casadi_int n) |
Identity matrix constant of size n-by- with a diagonal sparsity pattern. 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 > °ree, const Dict &opts=Dict()) |
| Evaluate the B-spline basis functions at given points. More... | |
| static MX | interpn_linear (const std::vector< MX > &x, const MX &v, const std::vector< MX > &xq, const Dict &opts=Dict()) |
| Low-level inlined multilinear interpolation. More... | |
| static void | set_max_depth (casadi_int eq_depth=1) |
| Set the depth to which equalities are checked for simplifications. More... | |
| static casadi_int | get_max_depth () |
| Get the depth to which equalities are checked for simplifications. More... | |
| static bool | test_cast (const SharedObjectInternal *ptr) |
| Check if a SharedObjectInternal pointer refers to an MX node (C++ only) More... | |
| static std::vector< MX > | get_input (const Function &f) |
| Get the symbolic inputs of a Function, as MX. More... | |
| static std::vector< MX > | get_free (const Function &f) |
| Get the free variables of a Function. More... | |
| 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 an elementwise binary or unary node from an operation code. More... | |
| static MX | unary (casadi_int op, const MX &x, bool unique=false) |
| Create an elementwise binary or unary node from an operation code. More... | |
| static MX | inf (const Sparsity &sp) |
| Create a constant with all nonzeros +inf. More... | |
| static MX | inf (casadi_int nrow=1, casadi_int ncol=1) |
| Create a constant with all nonzeros +inf. More... | |
| static MX | inf (const std::pair< casadi_int, casadi_int > &rc) |
| Create a constant with all nonzeros +inf. More... | |
| static MX | nan (const Sparsity &sp) |
| Create a constant with all nonzeros NaN. More... | |
| static MX | nan (casadi_int nrow=1, casadi_int ncol=1) |
| Create a constant with all nonzeros NaN. More... | |
| static MX | nan (const std::pair< casadi_int, casadi_int > &rc) |
| Create a constant with all nonzeros 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) |
| Compute a dense tensor contraction in Einstein notation. 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) |
| Compute a dense tensor contraction in Einstein notation. 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, as a pair (nrow, ncol) 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 list of length p of symbolic primitives with a given sparsity. More... | |
| static std::vector< MX > | sym (const std::string &name, casadi_int nrow, casadi_int ncol, casadi_int p) |
| Create a list of length p of 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 list of length r of lists of length p of symbolic primitives. 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 list of length r of lists of length p of nrow-by-ncol symbolic primitives. 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... | |
Friends | |
| MX | find (const MX &x) |
| Find the index of the first nonzero entry of a vector. More... | |
| MX | low (const MX &v, const MX &p, const Dict &options=Dict()) |
| Find the interval of a sorted grid that contains each query value. More... | |
| MX | graph_substitute (const MX &ex, const std::vector< MX > &v, const std::vector< MX > &vdef) |
| Substitute nodes in the expression graph, by node identity. More... | |
| MX | graph_substitute (const MX &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated) |
| std::vector< MX > | graph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef) |
| Substitute nodes in several expressions at once, by node identity. More... | |
| std::vector< MX > | graph_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 an MX expression into a call to an SX Function. More... | |
| std::vector< MX > | matrix_expand (const std::vector< MX > &e, const std::vector< MX > &boundary=std::vector< MX >(), const Dict &options=Dict()) |
| Expand several MX expressions into one call to an SX Function. 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()) |
| Evaluate a tensor-product B-spline with fixed coefficients. More... | |
| 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()) |
| Evaluate a B-spline whose coefficients are an expression. More... | |
| MX | bspline (const MX &x, const MX &coeffs, const std::vector< MX > &knots, const std::vector< casadi_int > °ree, casadi_int m, const Dict &opts=Dict()) |
| Evaluate a B-spline whose knots and coefficients are expressions. More... | |
| 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()) |
| Evaluate the B-spline basis functions at given points, see MX::bspline_dual. More... | |
| MX | convexify (const MX &H, const Dict &opts=Dict()) |
| Make a symmetric matrix positive definite at evaluation time. More... | |
| MX | lift (const MX &x, const MX &x_guess) |
| Lift the expression. More... | |
| MX | inv_node (const MX &x) |
| Symbolic matrix inverse node. More... | |
| DM | evalf (const MX &expr) |
| Evaluate an expression without free symbols numerically. More... | |
| MX | stop_diff (const MX &expr, casadi_int order) |
| Stop derivatives of an expression with respect to all its symbolic variables. More... | |
| MX | no_grad (const MX &expr) |
| Treat an expression as constant for differentiation (stop first derivatives) More... | |
| MX | no_hess (const MX &expr) |
| Stop second derivatives of an expression wrt all its symbolic variables. More... | |
| MX | stop_diff (const MX &expr, const MX &var, casadi_int order) |
| Stop derivatives of an expression wrt a selected set of symbolic variables. More... | |
| std::vector< MX > | difference (const std::vector< MX > &a, const std::vector< MX > &b) |
Return all elements of a that do not occur in b, preserving order. More... | |
|
inherited |
Definition at line 103 of file shared_object.hpp.
|
inherited |
Definition at line 102 of file shared_object.hpp.
| typedef std::map<std::string, MX> casadi::MX::MXDict |
| casadi::MX::MX | ( | ) |
The result is an empty constant, not a symbolic primitive (use MX.sym for that).
>>> MX(), MX().shape, MX().is_constant() (MX(0x0), (0, 0), True)
>> MX(), size(MX()), MX().is_constant() 0x0 0 0 1
julia> ca.MX(), size(ca.MX()), ca.is_constant(ca.MX()) (0x0, (0, 0), true)
Extra doc: https://github.com/casadi/casadi/wiki/L_q0
| casadi::MX::MX | ( | casadi_int | nrow, |
| casadi_int | ncol | ||
| ) |
The result is a constant of shape nrow-by- any nonzeros. It is the usual starting point for building a matrix by assignment: assigning to an element grows the sparsity pattern.ncol without
>>> Z = MX(2, 3)
>>> Z, Z.nnz(), Z.is_zero()
(MX(zeros(2x3,0nz)), 0, True)
>>> Z[1, 2] = MX.sym("x")
>>> Z.sparsity()
Sparsity(2x3,1nz)
>> Z = MX(2, 3);
>> Z, Z.nnz(), Z.is_zero()
zeros(2x3,0nz)
0
1
>> Z(2, 3) = MX.sym('x');
>> Z.sparsity()
2x3,1nz
julia> Z = ca.MX(2, 3);
julia> Z, ca.nnz(Z), ca.is_zero(Z)
(zeros(2x3,0nz), 0, true)
julia> Z[2, 3] = ca.MX.sym("x");
julia> ca.sparsity(Z)
Sparsity(2x3,1nz)
Extra doc: https://github.com/casadi/casadi/wiki/L_q1
|
explicit |
Same as MX::ones(sp).
>>> MX(Sparsity.lower(2)) MX(ones(2x2,3nz)) >>> evalf(MX(Sparsity.lower(2))) DM( [[1, 00], [1, 1]])
>> MX(Sparsity.lower(2)) ones(2x2,3nz) >> evalf(MX(Sparsity.lower(2))) [[1, 00], [1, 1]]
julia> ca.MX(ca.Sparsity.lower(2)) MX(ones(2x2,3nz)) julia> ca.evalf(ca.MX(ca.Sparsity.lower(2))) DM( [[1, 00], [1, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_q3
| sp | Sparsity pattern of the result |
| val | Either a scalar, which is repeated over all nonzeros of sp, or a column vector with exactly sp.nnz() entries, which become the nonzeros of the result in column-major order. A matrix whose shape is a reshape of sp is reshaped. Anything else is an error. |
val may be symbolic; the result is then an expression, not a constant.
>>> v = MX.sym("v", 3)
>>> L = MX(Sparsity.lower(2), v)
>>> L.sparsity(), L.is_constant()
(Sparsity(2x2,3nz), False)
>>> Function("f", [v], [L])(DM([1, 2, 3]))
DM(
[[1, 00],
[2, 3]])
>>> evalf(MX(Sparsity.lower(2), MX(7)))
DM(
[[7, 00],
[7, 7]])
>> v = MX.sym('v', 3);
>> L = MX(Sparsity.lower(2), v);
>> L.sparsity(), L.is_constant()
2x2,3nz
0
>> f = Function('f', {v}, {L});
>> f(DM([1; 2; 3]))
[[1, 00],
[2, 3]]
>> evalf(MX(Sparsity.lower(2), MX(7)))
[[7, 00],
[7, 7]]
julia> v = ca.MX.sym("v", 3);
julia> L = ca.MX(ca.Sparsity.lower(2), v);
julia> ca.sparsity(L), ca.is_constant(L)
(2x2,3nz, false)
julia> ca.Function("f", [v], [L])([1, 2, 3])
DM(
[[1, 00],
[2, 3]])
julia> ca.evalf(ca.MX(ca.Sparsity.lower(2), ca.MX(7)))
DM(
[[7, 00],
[7, 7]])
Extra doc: https://github.com/casadi/casadi/wiki/L_q4
| casadi::MX::MX | ( | const Sparsity & | sp, |
| const std::string & | fname | ||
| ) |
The file must contain exactly sp.nnz() whitespace-separated numbers, giving the nonzeros in column-major order; otherwise an error is raised. In generated C code the file is read at initialization time rather than embedded in the source. The node cannot be converted with to_DM.
| fname | Path of the file, read when the constructor runs |
>>> try:
... MX(Sparsity.lower(2), "no_such_file.txt")
... except Exception as e:
... print("Cannot open file" in str(e))
True
>> try, MX(Sparsity.lower(2), 'no_such_file.txt'); catch e, disp('cannot open file'); end
cannot open file
julia> try
ca.MX(ca.Sparsity.lower(2), "no_such_file.txt")
catch e
println(occursin("Cannot open file", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_q5
| casadi::MX::MX | ( | const Matrix< double > & | val, |
| const std::string & | name | ||
| ) |
Behaves like the constant val during evaluation. In generated C code the nonzeros are placed in a named double pool so that they can be changed after compilation. The node cannot be converted with to_DM.
>>> p = MX(DM([1, 2]), "p")
>>> p, p.is_constant()
(MX(constant_pool('p'): [1, 2]), True)
>>> evalf(2*p)
DM([2, 4])
>> p = MX(DM([1; 2]), 'p');
>> p, p.is_constant()
constant_pool('p'): [1, 2]
1
>> evalf(2*p)
[2, 4]
julia> p = ca.MX(ca.DM([1, 2]), "p");
julia> p, ca.is_constant(p)
(constant_pool('p'): [1, 2], true)
julia> ca.evalf(2 * p)
DM([2, 4])
Extra doc: https://github.com/casadi/casadi/wiki/L_2aa
| casadi::MX::MX | ( | double | x | ) |
>>> c = MX(3.5) >>> c, c.is_constant(), c.shape, float(c) (MX(3.5), True, (1, 1), 3.5)
>> c = MX(3.5); >> c, c.is_constant(), size(c), c.to_double() 3.5 1 1 1 3.5000
julia> c = ca.MX(3.5); julia> c, ca.is_constant(c), size(c), Float64(c) (3.5, true, (1, 1), 3.5)
Extra doc: https://github.com/casadi/casadi/wiki/L_q6
| casadi::MX::MX | ( | const Matrix< double > & | x | ) |
The sparsity pattern of x is kept. Numbers and numeric arrays are accepted through the DM conversion. SX cannot be converted to MX this way.
>>> c = MX(DM(Sparsity.diag(2), [1, 2])) >>> c.sparsity(), c.is_constant() (Sparsity(2x2,2nz), True) >>> MX([1, 2, 3]).shape (3, 1) >>> MX(np.array([[1, 2], [3, 4]])) MX( [[1, 2], [3, 4]])
>> c = MX(DM(Sparsity.diag(2), [1; 2])); >> c.sparsity(), c.is_constant() 2x2,2nz 1 >> size(MX([1; 2; 3])) 3 1 >> MX([1 2; 3 4]) [[1, 2], [3, 4]]
julia> c = ca.MX(ca.DM(ca.Sparsity.diag(2), [1, 2])); julia> ca.sparsity(c), ca.is_constant(c) (2x2,2nz, true) julia> size(ca.MX([1, 2, 3])) (3, 1) julia> ca.MX([1 2; 3 4]) MX( [[1, 2], [3, 4]])
Extra doc: https://github.com/casadi/casadi/wiki/L_q8
|
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.
| bool casadi::MX::__nonzero__ | ( | ) | const |
Nonzero constants are true, zero is false. Symbolic expressions and non-scalar constants raise an error: use a Function or evalf to evaluate first.
>>> bool(MX(2)), bool(MX(0))
(True, False)
>>> try:
... bool(MX.sym("x"))
... except Exception as e:
... print("Can only determine truth value of a numeric MX" in str(e))
True
julia> Bool(ca.MX(1)), Bool(ca.MX(0))
(true, false)
julia> try
Bool(ca.MX.sym("x"))
catch e
println(occursin("constant scalar", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2pp
The result is equal to this expression, but when it is evaluated the scalar expression y is evaluated too and a runtime error with fail_message is raised unless y equals 1. Useful to check preconditions inside a Function. A non-scalar y raises an error at construction.
>>> x = MX.sym("x")
>>> e = x.attachAssert(x > 0, "x must be positive")
>>> e
MX(assertion(x, (0<x)))
>>> f = Function("f", [x], [e])
>>> f(1)
DM(1)
>>> try:
... f(-1)
... except Exception as e:
... print("Assertion error: x must be positive" in str(e))
True
>> x = MX.sym('x');
>> e = x.attachAssert(x > 0, 'x must be positive');
>> e
assertion(x, (0<x))
>> f = Function('f', {x}, {e});
>> f(1)
1
>> try, f(-1); catch err, disp('assertion error'); end
assertion error
julia> x = ca.MX.sym("x");
julia> e = ca.attachAssert(x, x > 0, "x must be positive");
julia> e
MX(assertion(x, (0<x)))
julia> f = ca.Function("f", [x], [e]);
julia> f(1)
DM(1)
julia> try
f(-1)
catch err
println(occursin("Assertion error: x must be positive", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_rg
|
staticinherited |
x and y must be vectors (row vectors are transposed, sparse vectors densified) with x.numel() == A.size1() and y.numel() == A.size2(); otherwise an error is raised. The result is scalar. When y is omitted, the quadratic form x^T A x is calculated.
>>> A = DM([[1, 2], [3, 4]])
>>> bilin(A, DM([1, 1]), DM([1, 2]))
DM(16)
>>> bilin(A, DM([1, 1]))
DM(10)
>>> bilin(MX.sym("A", 2, 2), MX.sym("x", 2), MX.sym("y", 2))
MX(bilin(A, x, y))
>> A = DM([1 2; 3 4]);
>> bilin(A, DM([1; 1]), DM([1; 2]))
16
>> bilin(A, DM([1; 1]))
10
>> bilin(MX.sym('A', 2, 2), MX.sym('x', 2), MX.sym('y', 2))
bilin(A, x, y)
julia> A = ca.DM([1 2; 3 4]);
julia> ca.bilin(A, ca.DM([1, 1]), ca.DM([1, 2]))
DM(16)
julia> ca.bilin(A, ca.DM([1, 1]))
DM(10)
julia> ca.bilin(ca.MX.sym("A", 2, 2), ca.MX.sym("x", 2), ca.MX.sym("y", 2))
MX(bilin(A, x, y))
Extra doc: https://github.com/casadi/casadi/wiki/L_1bo
|
static |
Low-level constructors behind the operators: MX.binary(OP_ADD, x, y) is x + y. Operands must have the same shape, or one of them is a scalar, or one is a horizontal repetition of the other (which is repmat-ed). The usual simplifications are applied. An invalid operation code is not checked.
| op | One of the OP_* constants |
| unique_x,unique_y | Internal hints for in-place simplification; leave false |
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> MX.binary(OP_ADD, x, y), MX.unary(OP_SIN, x)
(MX((x+y)), MX(sin(x)))
>>> MX.binary(OP_ADD, MX.sym("V", 2, 4), MX.sym("W", 2, 2))
MX((V+repmat(W, 2)))
>>> try:
... MX.binary(OP_ADD, MX.sym("v", 2), MX.sym("w", 3))
... except Exception as e:
... print("Dimension mismatch" in str(e))
True
>> x = MX.sym('x'); y = MX.sym('y');
>> MX.binary(OP_ADD, x, y), MX.unary(OP_SIN, x)
(x+y)
sin(x)
>> MX.binary(OP_ADD, MX.sym('V', 2, 4), MX.sym('W', 2, 2))
(V+repmat(W, 2))
>> v = MX.sym('v', 2); w = MX.sym('w', 3);
>> try, MX.binary(OP_ADD, v, w); catch e, disp('dimension mismatch'); end
dimension mismatch
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> ca.MX.binary(ca.OP_ADD, x, y), ca.MX.unary(ca.OP_SIN, x)
((x+y), sin(x))
julia> ca.MX.binary(ca.OP_ADD, ca.MX.sym("V", 2, 4), ca.MX.sym("W", 2, 2))
MX((V+repmat(W, 2)))
julia> try
ca.MX.binary(ca.OP_ADD, ca.MX.sym("v", 2), ca.MX.sym("w", 3))
catch e
println(occursin("Dimension mismatch", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_r1
|
static |
Returns the sparse matrix of basis function values such that bspline_dual(x, knots, degree) @ coeffs equals bspline(x, coeffs, knots, degree, 1) at the same points. Each row corresponds to one evaluation point and each row sums to one inside the knot range. Used to fit coefficients to data.
| x | Evaluation points, flattened: n_points * n_dims numbers, point by point |
| knots | One knot vector per dimension |
| degree | Degree per dimension |
| opts | "lookup_mode": list with one of "linear", "exact", "binary" per dimension |
>>> knots = [[0, 0, 0, 0, 1, 2, 3, 3, 3, 3]] >>> B = MX.bspline_dual([0.5, 1.5], knots, [3]) >>> B.shape, sum2(B) ((2, 6), DM([1, 1])) >>> B @ DM(range(6)) DM([1.17708, 2.5])
>> knots = {[0 0 0 0 1 2 3 3 3 3]};
>> B = MX.bspline_dual([0.5, 1.5], knots, 3);
>> size(B), sum2(B)
2 6
[1, 1]
>> B * DM((0:5)')
[1.17708, 2.5]
julia> knots = [[0, 0, 0, 0, 1, 2, 3, 3, 3, 3]]; julia> B = ca.MX.bspline_dual([0.5, 1.5], knots, [3]); julia> size(B), sum(B, dims=2) ((2, 6), [1, 1]) julia> B * ca.DM(0:5) DM([1.17708, 2.5])
Extra doc: https://github.com/casadi/casadi/wiki/L_2qg
|
inherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_au
|
inlineinherited |
The pattern is stored in compressed column format: colind has size2()+1 entries, the nonzeros of column j are the entries colind(j) up to colind(j+1) (exclusive), and row(el) is the row index of nonzero el. Without argument, the full vectors are returned. Out-of-range indices raise an error.
>>> x = DM(Sparsity.diag(2), [5, 6]) >>> x.row(), x.colind() ([0, 1], [0, 1, 2]) >>> x.row(1), x.colind(2) (1, 2)
>> x = DM(Sparsity.diag(2), [5; 6]);
>> x.row(), x.colind()
0 1
0 1 2
>> fprintf('%d %d\n', x.row(1), x.colind(2))
1 2
julia> x = ca.DM(ca.Sparsity.diag(2), [5, 6]); julia> ca.row(x), ca.colind(x) ([0, 1], [0, 1, 2]) julia> ca.row(x, 1), ca.colind(x, 2) (1, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b8
Definition at line 609 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1av
Definition at line 295 of file generic_matrix.hpp.
|
inherited |
Definition at line 112 of file generic_shared_impl.hpp.
| MX casadi::MX::dep | ( | casadi_int | ch = 0 | ) | const |
Together with n_dep, op and is_op this allows walking the expression graph. Symbolic primitives and constants have no dependencies.
| ch | Index in [0, n_dep()); out of range raises an error |
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> e = x*y + 1
>>> e.n_dep(), e.dep(0), e.dep(1)
(2, MX(1), MX((x*y)))
>>> e.dep(1).dep(0), x.n_dep()
(MX(x), 0)
>> x = MX.sym('x'); y = MX.sym('y');
>> e = x*y + 1;
>> e.n_dep(), e.dep(0), e.dep(1)
2
1
(x*y)
>> e.dep(1).dep(0), x.n_dep()
x
0
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> e = x * y + 1;
julia> ca.n_dep(e), ca.dep(e, 0), ca.dep(e, 1)
(2, 1, (x*y))
julia> ca.dep(ca.dep(e, 1), 0), ca.n_dep(x)
(x, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_qj
|
static |
Counterpart of serialize; use StringDeserializer.unpack from Python.
Extra doc: https://github.com/casadi/casadi/wiki/L_r0
|
inherited |
The representation is e.g. "4x5" or, with with_nz true, "4x5,10nz".
>>> DM.eye(3).dim(), DM.eye(3).dim(True), DM.ones(3, 3).dim(True)
('3x3', '3x3,3nz', '3x3,9nz')
>> fprintf('%s %s %s\n', DM.eye(3).dim(), DM.eye(3).dim(true), DM.ones(3, 3).dim(true))
3x3 3x3,3nz 3x3,9nz
julia> ca.dim(ca.DM.eye(3)), ca.dim(ca.DM.eye(3), true), ca.dim(ca.DM.ones(3, 3), true)
("3x3", "3x3,3nz", "3x3,9nz")
Extra doc: https://github.com/casadi/casadi/wiki/L_1aw
|
inherited |
Each evaluation writes the value to a new file named after base_filename and a running counter. The value is unchanged. A matrix without nonzeros is returned as is.
| base_filename | Prefix of the file names |
| opts | "dir" (directory, default "."), "format" (file format, default "mtx", Matrix Market), "verbose" (print the file name on each dump, default false). Unknown keys raise an error. |
Extra doc: https://github.com/casadi/casadi/wiki/L_2f9
|
static |
Computes C_c += A_a * B_b, where a, b and c are index labels in Einstein notation: a label appearing in both a and b is summed over, the remaining labels index the result. Tensors are passed as flat column vectors in column-major (Fortran) order together with their dimensions. Labels are encoded as strictly negative integers. For the matrix product C_ij = A_ik B_kj one writes a = [-1, -3], b = [-3, -2], c = [-1, -2].
| A,B | Dense column vectors with product(dim_a), product(dim_b) entries |
| C | Optional accumulator with product(dim_c) entries, added to the result; when omitted the result starts from zero |
| dim_a,dim_b,dim_c | Tensor dimensions |
| a,b,c | Negative labels, one per dimension |
Inconsistent dimensions or labels are not validated with a user-facing message. Also available for SX and DM.
>>> A = MX.sym("A", 6)
>>> B = MX.sym("B", 6)
>>> C = einstein(A, B, [2, 3], [3, 2], [2, 2], [-1, -3], [-3, -2], [-1, -2])
>>> C.shape
(4, 1)
>>> f = Function("f", [A, B], [C])
>>> f(DM(range(1, 7)), DM(range(1, 7)))
DM([22, 28, 49, 64])
>>> reshape(DM(range(1, 7)), 2, 3) @ reshape(DM(range(1, 7)), 3, 2)
DM(
[[22, 49],
[28, 64]])
>> A = MX.sym('A', 6); B = MX.sym('B', 6);
>> C = einstein(A, B, [2 3], [3 2], [2 2], [-1 -3], [-3 -2], [-1 -2]);
>> size(C)
4 1
>> f = Function('f', {A, B}, {C});
>> f(DM((1:6)'), DM((1:6)'))
[22, 28, 49, 64]
>> reshape(DM((1:6)'), 2, 3) * reshape(DM((1:6)'), 3, 2)
[[22, 49],
[28, 64]]
julia> A = ca.MX.sym("A", 6); B = ca.MX.sym("B", 6);
julia> C = ca.einstein(A, B, [2, 3], [3, 2], [2, 2], [-1, -3], [-3, -2], [-1, -2]);
julia> size(C)
(4, 1)
julia> f = ca.Function("f", [A, B], [C]);
julia> f(1:6, 1:6)
DM([22, 28, 49, 64])
julia> reshape(ca.DM(1:6), 2, 3) * reshape(ca.DM(1:6), 3, 2)
DM(
[[22, 49],
[28, 64]])
Extra doc: https://github.com/casadi/casadi/wiki/L_r5
|
static |
Computes C_c += A_a * B_b, where a, b and c are index labels in Einstein notation: a label appearing in both a and b is summed over, the remaining labels index the result. Tensors are passed as flat column vectors in column-major (Fortran) order together with their dimensions. Labels are encoded as strictly negative integers. For the matrix product C_ij = A_ik B_kj one writes a = [-1, -3], b = [-3, -2], c = [-1, -2].
| A,B | Dense column vectors with product(dim_a), product(dim_b) entries |
| C | Optional accumulator with product(dim_c) entries, added to the result; when omitted the result starts from zero |
| dim_a,dim_b,dim_c | Tensor dimensions |
| a,b,c | Negative labels, one per dimension |
Inconsistent dimensions or labels are not validated with a user-facing message. Also available for SX and DM.
>>> A = MX.sym("A", 6)
>>> B = MX.sym("B", 6)
>>> C = einstein(A, B, [2, 3], [3, 2], [2, 2], [-1, -3], [-3, -2], [-1, -2])
>>> C.shape
(4, 1)
>>> f = Function("f", [A, B], [C])
>>> f(DM(range(1, 7)), DM(range(1, 7)))
DM([22, 28, 49, 64])
>>> reshape(DM(range(1, 7)), 2, 3) @ reshape(DM(range(1, 7)), 3, 2)
DM(
[[22, 49],
[28, 64]])
>> A = MX.sym('A', 6); B = MX.sym('B', 6);
>> C = einstein(A, B, [2 3], [3 2], [2 2], [-1 -3], [-3 -2], [-1 -2]);
>> size(C)
4 1
>> f = Function('f', {A, B}, {C});
>> f(DM((1:6)'), DM((1:6)'))
[22, 28, 49, 64]
>> reshape(DM((1:6)'), 2, 3) * reshape(DM((1:6)'), 3, 2)
[[22, 49],
[28, 64]]
julia> A = ca.MX.sym("A", 6); B = ca.MX.sym("B", 6);
julia> C = ca.einstein(A, B, [2, 3], [3, 2], [2, 2], [-1, -3], [-3, -2], [-1, -2]);
julia> size(C)
(4, 1)
julia> f = ca.Function("f", [A, B], [C]);
julia> f(1:6, 1:6)
DM([22, 28, 49, 64])
julia> reshape(ca.DM(1:6), 2, 3) * reshape(ca.DM(1:6), 3, 2)
DM(
[[22, 49],
[28, 64]])
Extra doc: https://github.com/casadi/casadi/wiki/L_r5
| 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 |
||
| ) |
Makes the matrix nrow-by- inserting empty rows and columns, keeping the existing nonzeros. Modifies the expression in place.ncol by
| nrow | New number of rows |
| ncol | New number of columns |
| rr | Rows of the new matrix that receive the existing rows; one entry per existing row |
| cc | Columns of the new matrix that receive the existing columns; one entry per existing column |
| ind1 | True for 1-based indices (MATLAB), default 0-based |
>>> B = MX.sym("B", 2, 2)
>>> B.enlarge(3, 3, [0, 2], [0, 2])
>>> B.shape, B.nnz(), B.sparsity().row()
((3, 3), 4, [0, 2, 0, 2])
>> B = MX.sym('B', 2, 2);
>> B.enlarge(3, 3, [1, 3], [1, 3], true);
>> size(B), B.nnz(), B.sparsity().row()
3 3
4
0 2 0 2
julia> B = ca.MX.sym("B", 2, 2);
julia> ca.enlarge(B, 3, 3, [0, 2], [0, 2]);
julia> size(B), ca.nnz(B), ca.row(ca.sparsity(B))
((3, 3), 4, [0, 2, 0, 2])
Extra doc: https://github.com/casadi/casadi/wiki/L_qg
| void casadi::MX::erase | ( | const std::vector< casadi_int > & | rr, |
| bool | ind1 = false |
||
| ) |
Same as the two-index overload, but rr holds linear (column-major) element indices.
>>> B = MX.sym("B", 3, 3)
>>> B.erase([0, 4])
>>> B.sparsity()
Sparsity(3x3,7nz)
>> B = MX.sym('B', 3, 3);
>> B.erase([1, 5], true);
>> B.sparsity()
3x3,7nz
julia> B = ca.MX.sym("B", 3, 3);
julia> ca.erase(B, [0, 4]);
julia> ca.sparsity(B)
Sparsity(3x3,7nz)
Extra doc: https://github.com/casadi/casadi/wiki/L_qf
| void casadi::MX::erase | ( | const std::vector< casadi_int > & | rr, |
| const std::vector< casadi_int > & | cc, | ||
| bool | ind1 = false |
||
| ) |
Removes the nonzeros at the intersection of rows rr and columns cc from the sparsity pattern. The shape is unchanged. Modifies the expression in place by replacing it with a new node that references the remaining nonzeros.
| rr | Row indices to erase; out-of-range values raise an error |
| cc | Column indices to erase |
| ind1 | True for 1-based indices (MATLAB), default 0-based |
>>> B = MX.sym("B", 3, 3)
>>> B.erase([0], [1])
>>> B.sparsity(), B.shape
(Sparsity(3x3,8nz), (3, 3))
>> B = MX.sym('B', 3, 3);
>> B.erase(1, 2, true);
>> B.sparsity(), size(B)
3x3,8nz
3 3
julia> B = ca.MX.sym("B", 3, 3);
julia> ca.erase(B, [0], [1]);
julia> ca.sparsity(B), size(B)
(3x3,8nz, (3, 3))
Extra doc: https://github.com/casadi/casadi/wiki/L_qe
| void casadi::MX::eval_mx | ( | const std::vector< MX > & | arg, |
| std::vector< MX > & | res, | ||
| const std::vector< bool > & | unique = std::vector< bool >() |
||
| ) | const |
Creates the same operation as this node, applied to arg instead of the node's own dependencies, with the usual simplifications. arg must have exactly n_dep() entries of matching shapes; a mismatch is a developer error. Symbolic primitives and constants return the node itself. Call nodes are re-called with the new arguments; OutputNodes cannot be evaluated this way. Mainly useful for writing graph transformations.
| arg | New dependencies |
| unique | Internal hints that the arguments are not referenced elsewhere; leave empty |
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> (x * y).eval_mx([MX(2), MX(3)]), (x + y).eval_mx([y, x])
([MX(6)], [MX((y+x))])
>>> MX.sym("v", 3)[1].eval_mx([MX([4, 5, 6])])
[MX([4, 5, 6][1])]
>> x = MX.sym('x'); y = MX.sym('y');
>> e = x * y; r = e.eval_mx({MX(2), MX(3)});
>> numel(r), r{1}
1
6
>> e = x + y; r = e.eval_mx({y, x});
>> r{1}
(y+x)
>> v = MX.sym('v', 3); e = v(2); r = e.eval_mx({MX([4; 5; 6])});
>> r{1}
[4, 5, 6][1]
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> ca.eval_mx(x * y, [ca.MX(2), ca.MX(3)]), ca.eval_mx(x + y, [y, x])
(MX[6], MX[(y+x)])
julia> ca.eval_mx(ca.MX.sym("v", 3)[2], [ca.MX([4, 5, 6])])
1-element Vector{MX}:
MX([4, 5, 6][1])
Extra doc: https://github.com/casadi/casadi/wiki/L_rn
|
static |
>>> MX.eye(2), MX.eye(2).is_eye() (MX(ones(2x2,2nz)), True)
>> MX.eye(2), MX.eye(2).is_eye() ones(2x2,2nz) 1
julia> ca.MX.eye(2), ca.is_eye(ca.MX.eye(2)) (ones(2x2,2nz), true)
Extra doc: https://github.com/casadi/casadi/wiki/L_r4
|
inline |
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
|
inline |
Backs single-index subscripting. Elements are addressed in column-major order over all numel() entries, including structural zeros. Indices may be negative (counted from the end); out-of-range indices raise an error. The result is a new GetNonzeros node referencing the selected nonzeros of this expression; a structural zero is returned as an empty-sparsity constant. Accepted index types: integer, slice, list of integers, list of booleans (mask), integer DM, Sparsity pattern of the same shape (returns the projection on that pattern) and MX (a symbolic index into the nonzeros of a dense expression, evaluated at run time with truncation and NaN for out-of-range values).
| ind1 | True for 1-based indices (MATLAB), false for 0-based |
| rr | Element indices |
>>> X = MX.sym("X", 3, 3)
>>> X[4], X[-1], X[[0, 4]], X[1:3].shape
(MX(X[4]), MX(X[8]), MX(X[:8:4]), (2, 1))
>>> try:
... X[9]
... except Exception as e:
... print("Out of bounds" in str(e))
True
>>> S = MX.sym("S", Sparsity.lower(2))
>>> S[2], S[2].nnz()
(MX(00), 0)
>>> X[Sparsity.lower(3)]
MX(project(X))
>>> k = MX.sym("k")
>>> v = MX.sym("v", 4)
>>> v[k], Function("f", [v, k], [v[k]])(DM([10, 20, 30, 40]), 1.7)
(MX(v[k]), DM(20))
>> X = MX.sym('X', 3, 3);
>> a = X(5); b = X(end); c = X([1, 5]); d = X([2; 3]);
>> a, b, c, size(d)
X[4]
X[8]
X[:8:4]
2 1
>> try, X(10); catch e, disp('out of bounds'); end
out of bounds
>> S = MX.sym('S', Sparsity.lower(2));
>> e = S(3);
>> e, e.nnz()
00
0
>> X(Sparsity.lower(3))
project(X)
>> k = MX.sym('k'); v = MX.sym('v', 4);
>> f = Function('f', {v, k}, {v(k)});
>> v(k), f(DM([10; 20; 30; 40]), 2.7)
v[(k-1)]
20
julia> X = ca.MX.sym("X", 3, 3);
julia> X[5], X[end], X[[1, 5]], size(X[2:3])
(X[4], X[8], X[[0, 4]], (2, 1))
julia> try
X[10]
catch e
println(e isa BoundsError)
end
true
julia> S = ca.MX.sym("S", ca.Sparsity.lower(2));
julia> S[3], ca.nnz(S[3])
(00, 0)
julia> X[ca.Sparsity.lower(3)]
MX(project(X))
julia> k = ca.MX.sym("k"); v = ca.MX.sym("v", 4);
julia> v[k]
MX(v[(k-1)])
julia> ca.Function("f", [v, k], [v[k]])([10, 20, 30, 40], 2.7)
DM(20)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qa
Backs single-index subscripting. Elements are addressed in column-major order over all numel() entries, including structural zeros. Indices may be negative (counted from the end); out-of-range indices raise an error. The result is a new GetNonzeros node referencing the selected nonzeros of this expression; a structural zero is returned as an empty-sparsity constant. Accepted index types: integer, slice, list of integers, list of booleans (mask), integer DM, Sparsity pattern of the same shape (returns the projection on that pattern) and MX (a symbolic index into the nonzeros of a dense expression, evaluated at run time with truncation and NaN for out-of-range values).
| ind1 | True for 1-based indices (MATLAB), false for 0-based |
| rr | Element indices |
>>> X = MX.sym("X", 3, 3)
>>> X[4], X[-1], X[[0, 4]], X[1:3].shape
(MX(X[4]), MX(X[8]), MX(X[:8:4]), (2, 1))
>>> try:
... X[9]
... except Exception as e:
... print("Out of bounds" in str(e))
True
>>> S = MX.sym("S", Sparsity.lower(2))
>>> S[2], S[2].nnz()
(MX(00), 0)
>>> X[Sparsity.lower(3)]
MX(project(X))
>>> k = MX.sym("k")
>>> v = MX.sym("v", 4)
>>> v[k], Function("f", [v, k], [v[k]])(DM([10, 20, 30, 40]), 1.7)
(MX(v[k]), DM(20))
>> X = MX.sym('X', 3, 3);
>> a = X(5); b = X(end); c = X([1, 5]); d = X([2; 3]);
>> a, b, c, size(d)
X[4]
X[8]
X[:8:4]
2 1
>> try, X(10); catch e, disp('out of bounds'); end
out of bounds
>> S = MX.sym('S', Sparsity.lower(2));
>> e = S(3);
>> e, e.nnz()
00
0
>> X(Sparsity.lower(3))
project(X)
>> k = MX.sym('k'); v = MX.sym('v', 4);
>> f = Function('f', {v, k}, {v(k)});
>> v(k), f(DM([10; 20; 30; 40]), 2.7)
v[(k-1)]
20
julia> X = ca.MX.sym("X", 3, 3);
julia> X[5], X[end], X[[1, 5]], size(X[2:3])
(X[4], X[8], X[[0, 4]], (2, 1))
julia> try
X[10]
catch e
println(e isa BoundsError)
end
true
julia> S = ca.MX.sym("S", ca.Sparsity.lower(2));
julia> S[3], ca.nnz(S[3])
(00, 0)
julia> X[ca.Sparsity.lower(3)]
MX(project(X))
julia> k = ca.MX.sym("k"); v = ca.MX.sym("v", 4);
julia> v[k]
MX(v[(k-1)])
julia> ca.Function("f", [v, k], [v[k]])([10, 20, 30, 40], 2.7)
DM(20)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qa
| void casadi::MX::get | ( | MX & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | rr, | ||
| const Matrix< casadi_int > & | cc | ||
| ) | const |
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs single-index subscripting. Elements are addressed in column-major order over all numel() entries, including structural zeros. Indices may be negative (counted from the end); out-of-range indices raise an error. The result is a new GetNonzeros node referencing the selected nonzeros of this expression; a structural zero is returned as an empty-sparsity constant. Accepted index types: integer, slice, list of integers, list of booleans (mask), integer DM, Sparsity pattern of the same shape (returns the projection on that pattern) and MX (a symbolic index into the nonzeros of a dense expression, evaluated at run time with truncation and NaN for out-of-range values).
| ind1 | True for 1-based indices (MATLAB), false for 0-based |
| rr | Element indices |
>>> X = MX.sym("X", 3, 3)
>>> X[4], X[-1], X[[0, 4]], X[1:3].shape
(MX(X[4]), MX(X[8]), MX(X[:8:4]), (2, 1))
>>> try:
... X[9]
... except Exception as e:
... print("Out of bounds" in str(e))
True
>>> S = MX.sym("S", Sparsity.lower(2))
>>> S[2], S[2].nnz()
(MX(00), 0)
>>> X[Sparsity.lower(3)]
MX(project(X))
>>> k = MX.sym("k")
>>> v = MX.sym("v", 4)
>>> v[k], Function("f", [v, k], [v[k]])(DM([10, 20, 30, 40]), 1.7)
(MX(v[k]), DM(20))
>> X = MX.sym('X', 3, 3);
>> a = X(5); b = X(end); c = X([1, 5]); d = X([2; 3]);
>> a, b, c, size(d)
X[4]
X[8]
X[:8:4]
2 1
>> try, X(10); catch e, disp('out of bounds'); end
out of bounds
>> S = MX.sym('S', Sparsity.lower(2));
>> e = S(3);
>> e, e.nnz()
00
0
>> X(Sparsity.lower(3))
project(X)
>> k = MX.sym('k'); v = MX.sym('v', 4);
>> f = Function('f', {v, k}, {v(k)});
>> v(k), f(DM([10; 20; 30; 40]), 2.7)
v[(k-1)]
20
julia> X = ca.MX.sym("X", 3, 3);
julia> X[5], X[end], X[[1, 5]], size(X[2:3])
(X[4], X[8], X[[0, 4]], (2, 1))
julia> try
X[10]
catch e
println(e isa BoundsError)
end
true
julia> S = ca.MX.sym("S", ca.Sparsity.lower(2));
julia> S[3], ca.nnz(S[3])
(00, 0)
julia> X[ca.Sparsity.lower(3)]
MX(project(X))
julia> k = ca.MX.sym("k"); v = ca.MX.sym("v", 4);
julia> v[k]
MX(v[(k-1)])
julia> ca.Function("f", [v, k], [v[k]])([10, 20, 30, 40], 2.7)
DM(20)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qa
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs single-index subscripting. Elements are addressed in column-major order over all numel() entries, including structural zeros. Indices may be negative (counted from the end); out-of-range indices raise an error. The result is a new GetNonzeros node referencing the selected nonzeros of this expression; a structural zero is returned as an empty-sparsity constant. Accepted index types: integer, slice, list of integers, list of booleans (mask), integer DM, Sparsity pattern of the same shape (returns the projection on that pattern) and MX (a symbolic index into the nonzeros of a dense expression, evaluated at run time with truncation and NaN for out-of-range values).
| ind1 | True for 1-based indices (MATLAB), false for 0-based |
| rr | Element indices |
>>> X = MX.sym("X", 3, 3)
>>> X[4], X[-1], X[[0, 4]], X[1:3].shape
(MX(X[4]), MX(X[8]), MX(X[:8:4]), (2, 1))
>>> try:
... X[9]
... except Exception as e:
... print("Out of bounds" in str(e))
True
>>> S = MX.sym("S", Sparsity.lower(2))
>>> S[2], S[2].nnz()
(MX(00), 0)
>>> X[Sparsity.lower(3)]
MX(project(X))
>>> k = MX.sym("k")
>>> v = MX.sym("v", 4)
>>> v[k], Function("f", [v, k], [v[k]])(DM([10, 20, 30, 40]), 1.7)
(MX(v[k]), DM(20))
>> X = MX.sym('X', 3, 3);
>> a = X(5); b = X(end); c = X([1, 5]); d = X([2; 3]);
>> a, b, c, size(d)
X[4]
X[8]
X[:8:4]
2 1
>> try, X(10); catch e, disp('out of bounds'); end
out of bounds
>> S = MX.sym('S', Sparsity.lower(2));
>> e = S(3);
>> e, e.nnz()
00
0
>> X(Sparsity.lower(3))
project(X)
>> k = MX.sym('k'); v = MX.sym('v', 4);
>> f = Function('f', {v, k}, {v(k)});
>> v(k), f(DM([10; 20; 30; 40]), 2.7)
v[(k-1)]
20
julia> X = ca.MX.sym("X", 3, 3);
julia> X[5], X[end], X[[1, 5]], size(X[2:3])
(X[4], X[8], X[[0, 4]], (2, 1))
julia> try
X[10]
catch e
println(e isa BoundsError)
end
true
julia> S = ca.MX.sym("S", ca.Sparsity.lower(2));
julia> S[3], ca.nnz(S[3])
(00, 0)
julia> X[ca.Sparsity.lower(3)]
MX(project(X))
julia> k = ca.MX.sym("k"); v = ca.MX.sym("v", 4);
julia> v[k]
MX(v[(k-1)])
julia> ca.Function("f", [v, k], [v[k]])([10, 20, 30, 40], 2.7)
DM(20)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qa
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs two-index subscripting. rr and cc select rows and columns (integer, slice, list, integer DM); the result has shape len(rr)-by-len(cc) and the corresponding part of the sparsity pattern. Out-of-range indices raise an error. An MX index is only allowed for dense expressions and selects at run time.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1], X[1, :].shape, X[[0, 2], [0, 2]].shape
(MX(X[3]), (1, 3), (2, 2))
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S[:, 0].sparsity(), S[0, 2].nnz()
(Sparsity(3x1), 0)
>>> k = MX.sym("k")
>>> X[k, 1]
MX(X[(k;3:6:3)])
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(2, :); c = X([1 3], [1 3]);
>> a, size(b), size(c)
X[3]
1 3
2 2
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S(:, 1); b = S(1, 3);
>> a.sparsity(), b.nnz()
3x1
0
>> k = MX.sym('k');
>> X(k, 2)
X[((k-1);3)]
julia> X = ca.MX.sym("X", 3, 3);
julia> X[1, 2], size(X[2, :]), size(X[[1, 3], [1, 3]])
(X[3], (1, 3), (2, 2))
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> ca.sparsity(S[:, 1]), ca.nnz(S[1, 3])
(3x1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qb
Backs single-index subscripting. Elements are addressed in column-major order over all numel() entries, including structural zeros. Indices may be negative (counted from the end); out-of-range indices raise an error. The result is a new GetNonzeros node referencing the selected nonzeros of this expression; a structural zero is returned as an empty-sparsity constant. Accepted index types: integer, slice, list of integers, list of booleans (mask), integer DM, Sparsity pattern of the same shape (returns the projection on that pattern) and MX (a symbolic index into the nonzeros of a dense expression, evaluated at run time with truncation and NaN for out-of-range values).
| ind1 | True for 1-based indices (MATLAB), false for 0-based |
| rr | Element indices |
>>> X = MX.sym("X", 3, 3)
>>> X[4], X[-1], X[[0, 4]], X[1:3].shape
(MX(X[4]), MX(X[8]), MX(X[:8:4]), (2, 1))
>>> try:
... X[9]
... except Exception as e:
... print("Out of bounds" in str(e))
True
>>> S = MX.sym("S", Sparsity.lower(2))
>>> S[2], S[2].nnz()
(MX(00), 0)
>>> X[Sparsity.lower(3)]
MX(project(X))
>>> k = MX.sym("k")
>>> v = MX.sym("v", 4)
>>> v[k], Function("f", [v, k], [v[k]])(DM([10, 20, 30, 40]), 1.7)
(MX(v[k]), DM(20))
>> X = MX.sym('X', 3, 3);
>> a = X(5); b = X(end); c = X([1, 5]); d = X([2; 3]);
>> a, b, c, size(d)
X[4]
X[8]
X[:8:4]
2 1
>> try, X(10); catch e, disp('out of bounds'); end
out of bounds
>> S = MX.sym('S', Sparsity.lower(2));
>> e = S(3);
>> e, e.nnz()
00
0
>> X(Sparsity.lower(3))
project(X)
>> k = MX.sym('k'); v = MX.sym('v', 4);
>> f = Function('f', {v, k}, {v(k)});
>> v(k), f(DM([10; 20; 30; 40]), 2.7)
v[(k-1)]
20
julia> X = ca.MX.sym("X", 3, 3);
julia> X[5], X[end], X[[1, 5]], size(X[2:3])
(X[4], X[8], X[[0, 4]], (2, 1))
julia> try
X[10]
catch e
println(e isa BoundsError)
end
true
julia> S = ca.MX.sym("S", ca.Sparsity.lower(2));
julia> S[3], ca.nnz(S[3])
(00, 0)
julia> X[ca.Sparsity.lower(3)]
MX(project(X))
julia> k = ca.MX.sym("k"); v = ca.MX.sym("v", 4);
julia> v[k]
MX(v[(k-1)])
julia> ca.Function("f", [v, k], [v[k]])([10, 20, 30, 40], 2.7)
DM(20)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qa
|
inlineinherited |
The pattern is stored in compressed column format: colind has size2()+1 entries, the nonzeros of column j are the entries colind(j) up to colind(j+1) (exclusive), and row(el) is the row index of nonzero el. Without argument, the full vectors are returned. Out-of-range indices raise an error.
>>> x = DM(Sparsity.diag(2), [5, 6]) >>> x.row(), x.colind() ([0, 1], [0, 1, 2]) >>> x.row(1), x.colind(2) (1, 2)
>> x = DM(Sparsity.diag(2), [5; 6]);
>> x.row(), x.colind()
0 1
0 1 2
>> fprintf('%d %d\n', x.row(1), x.colind(2))
1 2
julia> x = ca.DM(ca.Sparsity.diag(2), [5, 6]); julia> ca.row(x), ca.colind(x) ([0, 1], [0, 1, 2]) julia> ca.row(x, 1), ca.colind(x, 2) (1, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b8
Definition at line 603 of file generic_matrix.hpp.
Same as f.free_mx(): the symbolic primitives that occur in the outputs of an MX Function without being an input. Such a Function can only be created with the option "allow_free" and cannot be evaluated until the free variables are bound.
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> f = Function("f", [x], [x + y], {"allow_free": True})
>>> MX.get_free(f), MX.get_free(Function("g", [x], [x]))
([MX(y)], [])
>>> try:
... Function("f", [x], [x + y])
... except Exception as e:
... print("variables [y] are free" in str(e))
True
>> x = MX.sym('x'); y = MX.sym('y');
>> f = Function('f', {x}, {x + y}, struct('allow_free', true));
>> v = MX.get_free(f);
>> numel(v), v{1}
1
y
>> numel(MX.get_free(Function('g', {x}, {x})))
0
>> try, Function('f', {x}, {x + y}); catch e, disp('free variables'); end
free variables
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> f = ca.Function("f", [x], [x + y], Dict("allow_free" => true));
julia> ca.MX.get_free(f), ca.MX.get_free(ca.Function("g", [x], [x]))
(MX[y], MX[])
julia> try
ca.Function("f", [x], [x + y])
catch e
println(occursin("variables [y] are free", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_rm
Same as f.mx_in(). For an MX Function these are the original input expressions; for other Functions fresh symbols with the input names and sparsities.
>>> x = MX.sym("x")
>>> f = Function("f", [x], [2*x])
>>> MX.get_input(f), is_equal(MX.get_input(f)[0], x)
([MX(x)], True)
>> x = MX.sym('x');
>> f = Function('f', {x}, {2*x});
>> v = MX.get_input(f);
>> numel(v), v{1}, is_equal(v{1}, x)
1
x
1
julia> x = ca.MX.sym("x");
julia> f = ca.Function("f", [x], [2 * x]);
julia> ca.MX.get_input(f), ca.is_equal(ca.MX.get_input(f)[1], x)
(MX[x], true)
Extra doc: https://github.com/casadi/casadi/wiki/L_rl
|
static |
Extra doc: https://github.com/casadi/casadi/wiki/L_rk
| std::vector<MX> casadi::MX::get_nonzeros | ( | ) | const |
Since an MX is not a container, each entry is an expression that selects one nonzero of this expression. When the expression satisfies is_valid_input, the entries are the scalar primitives themselves: for vertcat(x, y) with scalar symbols x and y the result is [x, y]. The list has nnz() entries, in column-major order.
Extra doc: https://github.com/casadi/casadi/wiki/L_2bh
|
inline |
Indexes the nnz() nonzeros directly, skipping structural zeros, in column-major order. Negative indices count from the end; out-of-range indices raise an error. An MX index (or an inner/outer pair of indices) creates a parametric lookup that is resolved at evaluation time; such a node has no derivative with respect to the index. For dense expressions x[k] and x.nz[k] coincide.
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S.nz[1], S.nz[:].shape, len(S.nz)
(MX(S[1]), (6, 1), 6)
>>> k = MX.sym("k")
>>> S.nz[k]
MX(S[k])
>>> MX.sym("x", 2, 2).nz[[]].shape
(0, 1)
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S.get_nz(true, 2); b = S.get_nz(true, Slice());
>> a, size(b), S.nnz()
S[1]
6 1
6
>> k = MX.sym('k');
>> S.get_nz(true, k)
S[(k-1)]
>> size(MX.sym('x', 2, 2).get_nz(true, []))
0 0
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> S.nz[2], size(S.nz[:]), length(S.nz)
(S[1], (6, 1), 6)
julia> k = ca.MX.sym("k");
julia> S.nz[k]
MX(S[(k-1)])
julia> size(ca.MX.sym("x", 2, 2).nz[Int[]])
(0, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qe
Indexes the nnz() nonzeros directly, skipping structural zeros, in column-major order. Negative indices count from the end; out-of-range indices raise an error. An MX index (or an inner/outer pair of indices) creates a parametric lookup that is resolved at evaluation time; such a node has no derivative with respect to the index. For dense expressions x[k] and x.nz[k] coincide.
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S.nz[1], S.nz[:].shape, len(S.nz)
(MX(S[1]), (6, 1), 6)
>>> k = MX.sym("k")
>>> S.nz[k]
MX(S[k])
>>> MX.sym("x", 2, 2).nz[[]].shape
(0, 1)
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S.get_nz(true, 2); b = S.get_nz(true, Slice());
>> a, size(b), S.nnz()
S[1]
6 1
6
>> k = MX.sym('k');
>> S.get_nz(true, k)
S[(k-1)]
>> size(MX.sym('x', 2, 2).get_nz(true, []))
0 0
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> S.nz[2], size(S.nz[:]), length(S.nz)
(S[1], (6, 1), 6)
julia> k = ca.MX.sym("k");
julia> S.nz[k]
MX(S[(k-1)])
julia> size(ca.MX.sym("x", 2, 2).nz[Int[]])
(0, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qe
Indexes the nnz() nonzeros directly, skipping structural zeros, in column-major order. Negative indices count from the end; out-of-range indices raise an error. An MX index (or an inner/outer pair of indices) creates a parametric lookup that is resolved at evaluation time; such a node has no derivative with respect to the index. For dense expressions x[k] and x.nz[k] coincide.
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S.nz[1], S.nz[:].shape, len(S.nz)
(MX(S[1]), (6, 1), 6)
>>> k = MX.sym("k")
>>> S.nz[k]
MX(S[k])
>>> MX.sym("x", 2, 2).nz[[]].shape
(0, 1)
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S.get_nz(true, 2); b = S.get_nz(true, Slice());
>> a, size(b), S.nnz()
S[1]
6 1
6
>> k = MX.sym('k');
>> S.get_nz(true, k)
S[(k-1)]
>> size(MX.sym('x', 2, 2).get_nz(true, []))
0 0
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> S.nz[2], size(S.nz[:]), length(S.nz)
(S[1], (6, 1), 6)
julia> k = ca.MX.sym("k");
julia> S.nz[k]
MX(S[(k-1)])
julia> size(ca.MX.sym("x", 2, 2).nz[Int[]])
(0, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qe
Indexes the nnz() nonzeros directly, skipping structural zeros, in column-major order. Negative indices count from the end; out-of-range indices raise an error. An MX index (or an inner/outer pair of indices) creates a parametric lookup that is resolved at evaluation time; such a node has no derivative with respect to the index. For dense expressions x[k] and x.nz[k] coincide.
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S.nz[1], S.nz[:].shape, len(S.nz)
(MX(S[1]), (6, 1), 6)
>>> k = MX.sym("k")
>>> S.nz[k]
MX(S[k])
>>> MX.sym("x", 2, 2).nz[[]].shape
(0, 1)
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S.get_nz(true, 2); b = S.get_nz(true, Slice());
>> a, size(b), S.nnz()
S[1]
6 1
6
>> k = MX.sym('k');
>> S.get_nz(true, k)
S[(k-1)]
>> size(MX.sym('x', 2, 2).get_nz(true, []))
0 0
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> S.nz[2], size(S.nz[:]), length(S.nz)
(S[1], (6, 1), 6)
julia> k = ca.MX.sym("k");
julia> S.nz[k]
MX(S[(k-1)])
julia> size(ca.MX.sym("x", 2, 2).nz[Int[]])
(0, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qe
Indexes the nnz() nonzeros directly, skipping structural zeros, in column-major order. Negative indices count from the end; out-of-range indices raise an error. An MX index (or an inner/outer pair of indices) creates a parametric lookup that is resolved at evaluation time; such a node has no derivative with respect to the index. For dense expressions x[k] and x.nz[k] coincide.
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S.nz[1], S.nz[:].shape, len(S.nz)
(MX(S[1]), (6, 1), 6)
>>> k = MX.sym("k")
>>> S.nz[k]
MX(S[k])
>>> MX.sym("x", 2, 2).nz[[]].shape
(0, 1)
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S.get_nz(true, 2); b = S.get_nz(true, Slice());
>> a, size(b), S.nnz()
S[1]
6 1
6
>> k = MX.sym('k');
>> S.get_nz(true, k)
S[(k-1)]
>> size(MX.sym('x', 2, 2).get_nz(true, []))
0 0
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> S.nz[2], size(S.nz[:]), length(S.nz)
(S[1], (6, 1), 6)
julia> k = ca.MX.sym("k");
julia> S.nz[k]
MX(S[(k-1)])
julia> size(ca.MX.sym("x", 2, 2).nz[Int[]])
(0, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qe
Indexes the nnz() nonzeros directly, skipping structural zeros, in column-major order. Negative indices count from the end; out-of-range indices raise an error. An MX index (or an inner/outer pair of indices) creates a parametric lookup that is resolved at evaluation time; such a node has no derivative with respect to the index. For dense expressions x[k] and x.nz[k] coincide.
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S.nz[1], S.nz[:].shape, len(S.nz)
(MX(S[1]), (6, 1), 6)
>>> k = MX.sym("k")
>>> S.nz[k]
MX(S[k])
>>> MX.sym("x", 2, 2).nz[[]].shape
(0, 1)
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S.get_nz(true, 2); b = S.get_nz(true, Slice());
>> a, size(b), S.nnz()
S[1]
6 1
6
>> k = MX.sym('k');
>> S.get_nz(true, k)
S[(k-1)]
>> size(MX.sym('x', 2, 2).get_nz(true, []))
0 0
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> S.nz[2], size(S.nz[:]), length(S.nz)
(S[1], (6, 1), 6)
julia> k = ca.MX.sym("k");
julia> S.nz[k]
MX(S[(k-1)])
julia> size(ca.MX.sym("x", 2, 2).nz[Int[]])
(0, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qe
Indexes the nnz() nonzeros directly, skipping structural zeros, in column-major order. Negative indices count from the end; out-of-range indices raise an error. An MX index (or an inner/outer pair of indices) creates a parametric lookup that is resolved at evaluation time; such a node has no derivative with respect to the index. For dense expressions x[k] and x.nz[k] coincide.
>>> S = MX.sym("S", Sparsity.lower(3))
>>> S.nz[1], S.nz[:].shape, len(S.nz)
(MX(S[1]), (6, 1), 6)
>>> k = MX.sym("k")
>>> S.nz[k]
MX(S[k])
>>> MX.sym("x", 2, 2).nz[[]].shape
(0, 1)
>> S = MX.sym('S', Sparsity.lower(3));
>> a = S.get_nz(true, 2); b = S.get_nz(true, Slice());
>> a, size(b), S.nnz()
S[1]
6 1
6
>> k = MX.sym('k');
>> S.get_nz(true, k)
S[(k-1)]
>> size(MX.sym('x', 2, 2).get_nz(true, []))
0 0
julia> S = ca.MX.sym("S", ca.Sparsity.lower(3));
julia> S.nz[2], size(S.nz[:]), length(S.nz)
(S[1], (6, 1), 6)
julia> k = ca.MX.sym("k");
julia> S.nz[k]
MX(S[(k-1)])
julia> size(ca.MX.sym("x", 2, 2).nz[Int[]])
(0, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qe
| MX casadi::MX::get_output | ( | casadi_int | oind | ) | const |
For a multiple-output node (a Function call), returns the OutputNode selecting output oind. For any other node only oind == 0 is valid and the node itself is returned.
>>> a = SX.sym("a")
>>> f = Function("f", [a], [a + 1, 2*a])
>>> x = MX.sym("x")
>>> r0, r1 = f(x, )
>>> call = r0.dep(0)
>>> call.get_output(1), is_equal(call.get_output(0), r0)
(MX(f(x){1}), True)
>>> x.get_output(0)
MX(x)
>> a = SX.sym('a');
>> f = Function('f', {a}, {a + 1, 2*a});
>> x = MX.sym('x');
>> [r0, r1] = f(x);
>> call = r0.dep(0);
>> call.get_output(1), is_equal(call.get_output(0), r0)
f(x){1}
1
>> x.get_output(0)
x
julia> a = ca.SX.sym("a");
julia> f = ca.Function("f", [a], [a + 1, 2 * a]);
julia> x = ca.MX.sym("x");
julia> r0, r1 = f(x);
julia> call = ca.dep(r0, 0);
julia> ca.get_output(call, 1), ca.is_equal(ca.get_output(call, 0), r0)
(f(x){1}, true)
julia> ca.get_output(x, 0)
MX(x)
Extra doc: https://github.com/casadi/casadi/wiki/L_ql
|
inlineinherited |
The pattern is stored in compressed column format: colind has size2()+1 entries, the nonzeros of column j are the entries colind(j) up to colind(j+1) (exclusive), and row(el) is the row index of nonzero el. Without argument, the full vectors are returned. Out-of-range indices raise an error.
>>> x = DM(Sparsity.diag(2), [5, 6]) >>> x.row(), x.colind() ([0, 1], [0, 1, 2]) >>> x.row(1), x.colind(2) (1, 2)
>> x = DM(Sparsity.diag(2), [5; 6]);
>> x.row(), x.colind()
0 1
0 1 2
>> fprintf('%d %d\n', x.row(1), x.colind(2))
1 2
julia> x = ca.DM(ca.Sparsity.diag(2), [5, 6]); julia> ca.row(x), ca.colind(x) ([0, 1], [0, 1, 2]) julia> ca.row(x, 1), ca.colind(x, 2) (1, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b8
Definition at line 602 of file generic_matrix.hpp.
|
inline |
Extra doc: https://github.com/casadi/casadi/wiki/L_qd
|
inlineinherited |
Definition at line 91 of file shared_object.hpp.
|
staticinherited |
Functions called by friend functions defined here
| bool casadi::MX::has_output | ( | ) | const |
True for the call node of a Function with several outputs. Such a node cannot be used directly in expressions; select an output with get_output.
>>> a = SX.sym("a")
>>> f = Function("f", [a], [a + 1, 2*a])
>>> x = MX.sym("x")
>>> r0, r1 = f(x, )
>>> r0.dep(0).has_output(), r0.has_output(), x.has_output()
(True, False, False)
>> a = SX.sym('a');
>> f = Function('f', {a}, {a + 1, 2*a});
>> x = MX.sym('x');
>> [r0, r1] = f(x);
>> call = r0.dep(0);
>> call.has_output(), r0.has_output(), x.has_output()
1
0
0
julia> a = ca.SX.sym("a");
julia> f = ca.Function("f", [a], [a + 1, 2 * a]);
julia> x = ca.MX.sym("x");
julia> r0, r1 = f(x);
julia> ca.has_output(ca.dep(r0, 0)), ca.has_output(r0), ca.has_output(x)
(true, false, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_284
|
static |
Dense nrow-by-(default 1-by-1), or with the given sparsity pattern.ncol
>>> MX.inf(), MX.inf(2, 1), MX.inf(Sparsity.lower(2)) (MX(inf), MX(inf(2x1)), MX(inf(2x2,3nz)))
>> MX.inf(), MX.inf(2, 1), MX.inf(Sparsity.lower(2)) inf inf(2x1) inf(2x2,3nz)
julia> ca.MX.inf(), ca.MX.inf(2, 1), ca.MX.inf(ca.Sparsity.lower(2)) (inf, inf(2x1), inf(2x2,3nz))
Extra doc: https://github.com/casadi/casadi/wiki/L_r2
Dense nrow-by-(default 1-by-1), or with the given sparsity pattern.ncol
>>> MX.inf(), MX.inf(2, 1), MX.inf(Sparsity.lower(2)) (MX(inf), MX(inf(2x1)), MX(inf(2x2,3nz)))
>> MX.inf(), MX.inf(2, 1), MX.inf(Sparsity.lower(2)) inf inf(2x1) inf(2x2,3nz)
julia> ca.MX.inf(), ca.MX.inf(2, 1), ca.MX.inf(ca.Sparsity.lower(2)) (inf, inf(2x1), inf(2x2,3nz))
Extra doc: https://github.com/casadi/casadi/wiki/L_r2
|
static |
Dense nrow-by-(default 1-by-1), or with the given sparsity pattern.ncol
>>> MX.inf(), MX.inf(2, 1), MX.inf(Sparsity.lower(2)) (MX(inf), MX(inf(2x1)), MX(inf(2x2,3nz)))
>> MX.inf(), MX.inf(2, 1), MX.inf(Sparsity.lower(2)) inf inf(2x1) inf(2x2,3nz)
julia> ca.MX.inf(), ca.MX.inf(2, 1), ca.MX.inf(ca.Sparsity.lower(2)) (inf, inf(2x1), inf(2x2,3nz))
Extra doc: https://github.com/casadi/casadi/wiki/L_r2
| Dict casadi::MX::info | ( | ) | const |
The contents depend on the node type; most nodes return an empty dictionary. For example, a slicing node reports the slice it takes.
>>> X = MX.sym("X", 2, 2)
>>> X[0, 1].info()
{'slice': {'start': 2, 'step': 1, 'stop': 3}}
>>> X.info()
{}
>> X = MX.sym('X', 2, 2);
>> e = X(1, 2); s = e.info();
>> s.slice
start: 2
step: 1
stop: 3
>> isempty(fieldnames(X.info()))
1
julia> X = ca.MX.sym("X", 3, 3);
julia> ca.info(X[1, 2])
Dict{String, Any} with 1 entry:
"slice" => Dict{String, Any}("step"=>1, "stop"=>4, "start"=>3)
julia> ca.info(X)
Dict{String, Any}()
Extra doc: https://github.com/casadi/casadi/wiki/L_2q9
|
static |
Builds the interpolation as explicit MX operations (low, nonzero lookups and arithmetic) instead of an interpolant Function, so that the grid and values can be symbolic. Usually you want interpolant('name', 'linear', ...) instead. Extrapolates linearly outside the grid.
| x | Grid points, one vector per dimension |
| v | Values on the grid, flattened in column-major order over the grid; its length must be an integer multiple m of the number of grid points, giving m outputs per query point |
| xq | Query coordinates, one vector per dimension, all of the same length nq |
| opts | "lookup_mode": list with one of "linear", "exact", "binary", "auto" (default) per dimension, see low |
>>> g = MX.sym("g", 3)
>>> v = MX.sym("v", 3)
>>> xq = MX.sym("xq", 2)
>>> e = MX.interpn_linear([g], v, [xq])
>>> f = Function("f", [g, v, xq], [e])
>>> f(DM([0, 1, 2]), DM([0, 10, 40]), DM([0.5, 3]))
DM([5, 70])
>>> try:
... MX.interpn_linear([g], MX.sym("w", 4), [xq])
... except Exception as e:
... print("Dimension mismatch" in str(e))
True
>> g = MX.sym('g', 3); v = MX.sym('v', 3); xq = MX.sym('xq', 2);
>> e = MX.interpn_linear({g}, v, {xq});
>> f = Function('f', {g, v, xq}, {e});
>> f(DM([0; 1; 2]), DM([0; 10; 40]), DM([0.5; 3]))
[5, 70]
>> w = MX.sym('w', 4);
>> try, MX.interpn_linear({g}, w, {xq}); catch e, disp('dimension mismatch'); end
dimension mismatch
julia> g = ca.MX.sym("g", 3); v = ca.MX.sym("v", 3); xq = ca.MX.sym("xq", 2);
julia> ex = ca.MX.interpn_linear([g], v, [xq]);
julia> f = ca.Function("f", [g, v, xq], [ex]);
julia> f([0, 1, 2], [0, 10, 40], [0.5, 3])
DM([5, 70])
julia> try
ca.MX.interpn_linear([g], ca.MX.sym("w", 4), [xq])
catch e
println(occursin("Dimension mismatch", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_r6
| MX casadi::MX::inv | ( | ) | const |
Not the matrix inverse: use inv or inv_node for that. Applied twice it returns the original node. Not available in MATLAB and Julia, where inv is the matrix inverse; use 1./x there.
>>> A = MX.sym("A", 2, 2)
>>> A.inv(), A.inv().inv()
(MX((1./A)), MX(A))
>>> evalf(MX(4).inv())
DM(0.25)
Extra doc: https://github.com/casadi/casadi/wiki/L_2dz
| bool casadi::MX::is_binary | ( | ) | const |
Elementwise operations with two operands (OP_ADD, OP_MUL, OP_POW, comparisons, ...). Matrix products, concatenations and calls are not binary nodes. Note that x + x and x*x are stored as unary nodes (doubling, square).
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> A = MX.sym("A", 2, 2)
>>> (x + y).is_binary(), (x**y).is_binary(), (A @ A).is_binary(), (x + x).is_binary()
(True, True, False, False)
>> x = MX.sym('x'); y = MX.sym('y'); A = MX.sym('A', 2, 2);
>> a = x + y; b = x^y; c = A*A; d = x + x;
>> a.is_binary(), b.is_binary(), c.is_binary(), d.is_binary()
1
1
0
0
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y"); A = ca.MX.sym("A", 2, 2);
julia> ca.is_binary(x + y), ca.is_binary(x^y), ca.is_binary(A * A), ca.is_binary(x + x)
(true, true, false, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2q6
| bool casadi::MX::is_call | ( | ) | const |
A call to a Function with several outputs is a single call node; the values you get back from calling the Function are OutputNodes that reference it (see is_output). MX Functions are inlined when called with MX arguments unless never_inline is set, so no call node appears in that case.
>>> a = SX.sym("a")
>>> f = Function("f", [a], [a + 1, 2*a])
>>> x = MX.sym("x")
>>> r0, r1 = f(x, )
>>> r0.is_call(), r0.is_output(), r0.dep(0).is_call()
(False, True, True)
>>> r0.dep(0).which_function().name()
'f'
>> a = SX.sym('a');
>> f = Function('f', {a}, {a + 1, 2*a});
>> x = MX.sym('x');
>> [r0, r1] = f(x);
>> call = r0.dep(0);
>> r0.is_call(), r0.is_output(), call.is_call()
0
1
1
>> call.which_function().name()
f
julia> a = ca.SX.sym("a");
julia> f = ca.Function("f", [a], [a + 1, 2 * a]);
julia> x = ca.MX.sym("x");
julia> r0, r1 = f(x);
julia> ca.is_call(r0), ca.is_output(r0), ca.is_call(ca.dep(r0, 0))
(false, true, true)
julia> ca.name(ca.which_function(ca.dep(r0, 0)))
"f"
Extra doc: https://github.com/casadi/casadi/wiki/L_2px
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1b5
Definition at line 517 of file generic_matrix.hpp.
| bool casadi::MX::is_commutative | ( | ) | const |
Unary operations count as commutative. Any other node raises an error.
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> (x + y).is_commutative(), (x - y).is_commutative()
(True, False)
>> x = MX.sym('x'); y = MX.sym('y');
>> a = x + y; b = x - y;
>> a.is_commutative(), b.is_commutative()
1
0
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> ca.is_commutative(x + y), ca.is_commutative(x - y)
(true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2q3
| bool casadi::MX::is_constant | ( | ) | const |
True only for constant nodes. Operations between constants are folded into a new constant where possible, but an expression without symbols is not constant in general (e.g. a Function call with constant arguments); use evalf to evaluate it.
>>> MX(1).is_constant(), MX(2, 2).is_constant(), MX.sym("x").is_constant()
(True, True, False)
>>> (MX(1) + MX(2)).is_constant()
True
>> MX(1).is_constant(), MX(2, 2).is_constant(), MX.sym('x').is_constant()
1
1
0
>> e = MX(1) + MX(2);
>> e.is_constant()
1
julia> ca.is_constant(ca.MX(1)), ca.is_constant(ca.MX(2, 2)), ca.is_constant(ca.MX.sym("x"))
(true, true, false)
julia> ca.is_constant(ca.MX(1) + ca.MX(2))
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2pv
|
inlineinherited |
Based on the sparsity pattern only: stored numerical zeros still count as nonzeros. Empty matrices are dense.
>>> DM.zeros(2, 2).is_dense(), DM(2, 2).is_dense(), DM(0, 3).is_dense() (True, False, True)
>> Z = DM.zeros(2, 2);
>> fprintf('%d %d %d\n', Z.is_dense(), DM(2, 2).is_dense(), DM(0, 3).is_dense())
1 0 1
julia> ca.is_dense(ca.DM.zeros(2, 2)), ca.is_dense(ca.DM(2, 2)), ca.is_dense(ca.DM(0, 3)) (true, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b0
Definition at line 434 of file generic_matrix.hpp.
| bool casadi::MX::is_doubled | ( | ) | const |
True for x + x (which is stored as a doubling node) and for 2*x, and for a sum whose two operands compare equal up to get_max_depth.
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> (x + x).is_doubled(), (2*x).is_doubled(), (x + y).is_doubled()
(True, True, False)
>> x = MX.sym('x'); y = MX.sym('y');
>> a = x + x; b = 2*x; c = x + y;
>> a.is_doubled(), b.is_doubled(), c.is_doubled()
1
1
0
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> ca.is_doubled(x + x), ca.is_doubled(2 * x), ca.is_doubled(x + y)
(true, true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2e0
|
inlineinherited |
With both true, only a 0-by-0 matrix counts as empty.
>>> DM(0, 3).is_empty(), DM(0, 3).is_empty(True), DM(0, 0).is_empty(True) (True, False, True) >>> DM(1, 1).is_empty() False
>> E = DM(0, 3);
>> fprintf('%d %d %d\n', E.is_empty(), E.is_empty(true), DM(0, 0).is_empty(true))
1 0 1
>> DM(1, 1).is_empty()
0
julia> E = ca.DM(0, 3); julia> ca.is_empty(E), ca.is_empty(E, true), ca.is_empty(ca.DM(0, 0), true) (true, false, true) julia> ca.is_empty(ca.DM(1, 1)) false
Extra doc: https://github.com/casadi/casadi/wiki/L_1az
Definition at line 402 of file generic_matrix.hpp.
| bool casadi::MX::is_eye | ( | ) | const |
Only recognizes constants created as an identity (MX.eye, DM.eye); a dense constant that happens to equal the identity is not detected. A 1-by-1 constant one counts.
>>> MX.eye(2).is_eye(), MX(DM([[1, 0], [0, 1]])).is_eye(), MX(1).is_eye() (True, False, True)
>> MX.eye(2).is_eye(), MX(DM([1 0; 0 1])).is_eye(), MX(1).is_eye() 1 0 1
julia> ca.is_eye(ca.MX.eye(2)), ca.is_eye(ca.MX([1 0; 0 1])), ca.is_eye(ca.MX(1)) (true, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_qu
| bool casadi::MX::is_half | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_2ep
| bool casadi::MX::is_inf | ( | ) | const |
>>> MX.inf().is_inf(), MX.inf(2, 2).is_inf(), MX(1).is_inf() (True, True, False)
>> MX.inf().is_inf(), MX.inf(2, 2).is_inf(), MX(1).is_inf() 1 1 0
julia> ca.is_inf(ca.MX.inf()), ca.is_inf(ca.MX.inf(2, 2)), ca.is_inf(ca.MX(1)) (true, true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2e1
| bool casadi::MX::is_integer | ( | ) | const |
False for non-constant nodes.
>>> MX(3).is_integer(), MX(3.5).is_integer(), MX.sym("x").is_integer()
(True, False, False)
>> MX(3).is_integer(), MX(3.5).is_integer(), MX.sym('x').is_integer()
1
0
0
julia> ca.is_integer(ca.MX(3)), ca.is_integer(ca.MX(3.5)), ca.is_integer(ca.MX.sym("x"))
(true, false, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2pw
| bool casadi::MX::is_minus_inf | ( | ) | const |
>>> (-MX.inf()).is_minus_inf(), MX.inf().is_minus_inf() (True, False)
>> m = -MX.inf(); >> m.is_minus_inf(), MX.inf().is_minus_inf() 1 0
julia> ca.is_minus_inf(-ca.MX.inf()), ca.is_minus_inf(ca.MX.inf()) (true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2e2
| bool casadi::MX::is_minus_one | ( | ) | const |
>>> MX(-1).is_minus_one(), (-MX(1)).is_minus_one(), MX(1).is_minus_one() (True, True, False)
>> m = -MX(1); >> MX(-1).is_minus_one(), m.is_minus_one(), MX(1).is_minus_one() 1 1 0
julia> ca.is_minus_one(ca.MX(-1)), ca.is_minus_one(-ca.MX(1)), ca.is_minus_one(ca.MX(1)) (true, true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_qx
| bool casadi::MX::is_multiplication | ( | ) | const |
Elementwise multiplication does not count.
>>> A = MX.sym("A", 2, 2)
>>> (A @ A).is_multiplication(), (A * A).is_multiplication()
(True, False)
>> A = MX.sym('A', 2, 2);
>> a = A*A; b = A.*A;
>> a.is_multiplication(), b.is_multiplication()
1
0
julia> A = ca.MX.sym("A", 2, 2);
julia> ca.is_multiplication(A * A), ca.is_multiplication(A .* A)
(true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2q2
| bool casadi::MX::is_nonnegative | ( | ) | const |
Recognizes nonnegative constants and operations with a nonnegative range such as squares, absolute values, exponentials and square roots.
>>> x = MX.sym("x")
>>> (x**2).is_nonnegative(), fabs(x).is_nonnegative(), exp(x).is_nonnegative()
(True, True, True)
>>> x.is_nonnegative(), MX(-3).is_nonnegative(), MX(0).is_nonnegative()
(False, False, True)
>> x = MX.sym('x');
>> a = x^2; b = abs(x); c = exp(x);
>> a.is_nonnegative(), b.is_nonnegative(), c.is_nonnegative()
1
1
1
>> x.is_nonnegative(), MX(-3).is_nonnegative(), MX(0).is_nonnegative()
0
0
1
julia> x = ca.MX.sym("x");
julia> ca.is_nonnegative(x^2), ca.is_nonnegative(abs(x)), ca.is_nonnegative(exp(x))
(true, true, true)
julia> ca.is_nonnegative(x), ca.is_nonnegative(ca.MX(-3)), ca.is_nonnegative(ca.MX(0))
(false, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_2e3
| bool casadi::MX::is_norm | ( | ) | const |
>>> A = MX.sym("A", 2, 2)
>>> norm_2(A).is_norm(), norm_fro(A).is_norm(), sqrt(dot(A, A)).is_norm()
(True, True, False)
>> A = MX.sym('A', 2, 2);
>> a = norm_2(A); b = norm_fro(A); c = sqrt(dot(A, A));
>> a.is_norm(), b.is_norm(), c.is_norm()
1
1
0
julia> A = ca.MX.sym("A", 2, 2);
julia> ca.is_norm(ca.norm_2(A)), ca.is_norm(ca.norm_fro(A)), ca.is_norm(sqrt(ca.dot(A, A)))
(true, true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2q4
|
inherited |
Definition at line 116 of file generic_shared_impl.hpp.
| bool casadi::MX::is_one | ( | ) | const |
Structural zeros are ignored: MX(Sparsity.lower(2)) is not "one" because it has structural zeros that would be zero when densified.
>>> MX(1).is_one(), MX.ones(2, 2).is_one(), MX(Sparsity.lower(2)).is_one() (True, True, False)
>> MX(1).is_one(), MX.ones(2, 2).is_one(), MX(Sparsity.lower(2)).is_one() 1 1 0
julia> ca.is_one(ca.MX(1)), ca.is_one(ca.MX.ones(2, 2)),
ca.is_one(ca.MX(ca.Sparsity.lower(2)))
(true, true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_qw
| bool casadi::MX::is_op | ( | casadi_int | op | ) | const |
| op | One of the OP_* constants (OP_ADD, OP_SIN, OP_CALL, OP_GETNONZEROS, ...) |
>>> x = MX.sym("x", 2)
>>> (x + 1).is_op(OP_ADD), sin(x).is_op(OP_SIN), x.is_op(OP_PARAMETER)
(True, True, True)
>>> x[0].is_op(OP_GETNONZEROS), MX(1).is_op(OP_CONST)
(True, True)
>> x = MX.sym('x', 2);
>> a = x + 1; b = sin(x);
>> a.is_op(OP_ADD), b.is_op(OP_SIN), x.is_op(OP_PARAMETER)
1
1
1
>> c = x(1);
>> c.is_op(OP_GETNONZEROS), MX(1).is_op(OP_CONST)
1
1
julia> x = ca.MX.sym("x", 2);
julia> ca.is_op(x + 1, ca.OP_ADD), ca.is_op(sin.(x), ca.OP_SIN),
ca.is_op(x, ca.OP_PARAMETER)
(true, true, true)
julia> ca.is_op(x[1], ca.OP_GETNONZEROS), ca.is_op(ca.MX(1), ca.OP_CONST)
(true, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_2q1
| bool casadi::MX::is_output | ( | ) | const |
The expressions obtained by calling a Function with several outputs are OutputNodes: they have one dependency, the call node, and which_output gives the index.
>>> a = SX.sym("a")
>>> f = Function("f", [a], [a + 1, 2*a])
>>> x = MX.sym("x")
>>> r0, r1 = f(x, )
>>> r1, r1.is_output(), r1.which_output(), r1.dep(0)
(MX(f(x){1}), True, 1, MX(f(x)))
>>> x.is_output(), (x + 1).is_output()
(False, False)
>> a = SX.sym('a');
>> f = Function('f', {a}, {a + 1, 2*a});
>> x = MX.sym('x');
>> [r0, r1] = f(x);
>> r1, r1.is_output(), r1.which_output(), r1.dep(0)
f(x){1}
1
1
f(x)
>> e = x + 1;
>> x.is_output(), e.is_output()
0
0
julia> a = ca.SX.sym("a");
julia> f = ca.Function("f", [a], [a + 1, 2 * a]);
julia> x = ca.MX.sym("x");
julia> r0, r1 = f(x);
julia> r1, ca.is_output(r1), ca.which_output(r1), ca.dep(r1, 0)
(f(x){1}, true, 1, f(x))
julia> ca.is_output(x), ca.is_output(x + 1)
(false, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2pz
| bool casadi::MX::is_regular | ( | ) | const |
Only defined for constant nodes; a symbolic expression raises an error.
>>> MX(1).is_regular(), MX.inf().is_regular(), MX(DM([1, float("nan")])).is_regular()
(True, False, False)
>>> try:
... MX.sym("x").is_regular()
... except Exception as e:
... print("Cannot check regularity for symbolic MX" in str(e))
True
>> MX(1).is_regular(), MX.inf().is_regular()
1
0
>> MX(DM([1; nan])).is_regular()
0
>> try, MX.sym('x').is_regular(); catch e, disp('error'); end
error
julia> ca.is_regular(ca.MX(1)), ca.is_regular(ca.MX.inf()), ca.is_regular(ca.MX([1, NaN]))
(true, false, false)
julia> try
ca.is_regular(ca.MX.sym("x"))
catch e
println(occursin("Cannot check regularity", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2q5
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1b4
Definition at line 512 of file generic_matrix.hpp.
|
inherited |
| scalar_and_dense | When true, a 1-by-1 matrix with a structural zero does not count |
>>> x = SX.sym("x", Sparsity(1, 1))
>>> x.is_scalar(), x.is_scalar(True), SX.sym("y").is_scalar(True)
(True, False, True)
>> x = SX.sym('x', Sparsity(1, 1));
>> fprintf('%d %d %d\n', x.is_scalar(), x.is_scalar(true), SX.sym('y').is_scalar(true))
1 0 1
julia> x = ca.SX.sym("x", ca.Sparsity(1, 1));
julia> ca.is_scalar(x), ca.is_scalar(x, true), ca.is_scalar(ca.SX.sym("y"), true)
(true, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b1
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1b2
Definition at line 470 of file generic_matrix.hpp.
| bool casadi::MX::is_symbolic | ( | ) | const |
False for any expression built from primitives, including concatenations of primitives (use is_valid_input for those). A symbol without nonzeros, e.g. MX.sym("x", 2, 0), is stored as an empty constant and is not symbolic.
>>> x = MX.sym("x")
>>> x.is_symbolic(), (x + 1).is_symbolic(), vertcat(x, x).is_symbolic()
(True, False, False)
>>> MX.sym("e", 2, 0).is_symbolic()
False
>> x = MX.sym('x'); e = x + 1; v = vertcat(x, x);
>> x.is_symbolic(), e.is_symbolic(), v.is_symbolic()
1
0
0
>> MX.sym('e', 2, 0).is_symbolic()
0
julia> x = ca.MX.sym("x");
julia> ca.is_symbolic(x), ca.is_symbolic(x + 1), ca.is_symbolic([x; x])
(true, false, false)
julia> ca.is_symbolic(ca.MX.sym("e", 2, 0))
false
Extra doc: https://github.com/casadi/casadi/wiki/L_2pu
| bool casadi::MX::is_transpose | ( | ) | const |
The transpose of a scalar is the scalar itself and that of a vector is a reshape, so only transposes of genuine matrices create a transpose node.
>>> A = MX.sym("A", 2, 2)
>>> A.T.is_transpose(), A.is_transpose(), MX.sym("v", 2).T.is_transpose()
(True, False, False)
>> A = MX.sym('A', 2, 2); At = A'; vt = MX.sym('v', 2)';
>> At.is_transpose(), A.is_transpose(), vt.is_transpose()
1
0
0
julia> A = ca.MX.sym("A", 2, 2);
julia> ca.is_transpose(A'), ca.is_transpose(A), ca.is_transpose(ca.MX.sym("v", 2)')
(true, false, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_qy
|
inlineinherited |
Decided on the sparsity pattern alone, see is_triu.
Extra doc: https://github.com/casadi/casadi/wiki/L_1b7
Definition at line 560 of file generic_matrix.hpp.
|
inlineinherited |
Decided on the sparsity pattern alone: all structural nonzeros must lie on or above the diagonal. A dense matrix with numerical zeros below the diagonal is not upper triangular. Also defined for non-square matrices.
>>> DM(Sparsity.upper(3), 1).is_triu(), DM.zeros(2, 2).is_triu(), DM(2, 2).is_triu() (True, False, True)
>> U = DM(Sparsity.upper(3), 1);
>> fprintf('%d %d %d\n', U.is_triu(), DM.zeros(2, 2).is_triu(), DM(2, 2).is_triu())
1 0 1
julia> U = ca.DM(ca.Sparsity.upper(3), 1); julia> ca.is_triu(U), ca.is_triu(ca.DM.zeros(2, 2)), ca.is_triu(ca.DM(2, 2)) (true, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b6
Definition at line 551 of file generic_matrix.hpp.
| bool casadi::MX::is_unary | ( | ) | const |
OP_SIN, OP_NEG, OP_SQ, ... Transposes, reshapes and projections are not unary nodes even though they have one dependency.
>>> x = MX.sym("x")
>>> A = MX.sym("A", 2, 2)
>>> sin(x).is_unary(), (-x).is_unary(), x.is_unary(), A.T.is_unary()
(True, True, False, False)
>> x = MX.sym('x'); A = MX.sym('A', 2, 2);
>> a = sin(x); b = -x; c = A';
>> a.is_unary(), b.is_unary(), x.is_unary(), c.is_unary()
1
1
0
0
julia> x = ca.MX.sym("x"); A = ca.MX.sym("A", 2, 2);
julia> ca.is_unary(sin(x)), ca.is_unary(-x), ca.is_unary(x), ca.is_unary(A')
(true, true, false, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_2q7
| bool casadi::MX::is_valid_input | ( | ) | const |
Valid inputs are symbolic primitives, reshapes and transposes of them, and (nested) concatenations of valid inputs. Constants without nonzeros are also accepted. An expression that is not a valid input raises an error when passed as a Function input.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> vertcat(x, y).is_valid_input(), vertcat(x, y).T.is_valid_input()
(True, True)
>>> (x + 1).is_valid_input(), MX(1).is_valid_input(), MX(2, 2).is_valid_input()
(False, False, True)
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> v = [x; y]; vt = v';
>> v.is_valid_input(), vt.is_valid_input()
1
1
>> e = x + 1;
>> e.is_valid_input(), MX(1).is_valid_input(), MX(2, 2).is_valid_input()
0
0
1
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> ca.is_valid_input([x; y]), ca.is_valid_input([x; y]')
(true, true)
julia> ca.is_valid_input(x + 1), ca.is_valid_input(ca.MX(1)), ca.is_valid_input(ca.MX(2, 2))
(false, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_qn
| bool casadi::MX::is_value | ( | double | val | ) | const |
False negatives are possible: only constant nodes are inspected; symbolic expressions always give false.
>>> MX(3).is_value(3), MX(DM([3, 3])).is_value(3), MX(DM([3, 4])).is_value(3)
(True, True, False)
>>> MX.sym("x").is_value(3)
False
>> MX(3).is_value(3), MX(DM([3; 3])).is_value(3)
1
1
>> MX(DM([3; 4])).is_value(3)
0
>> MX.sym('x').is_value(3)
0
julia> ca.is_value(ca.MX(3), 3), ca.is_value(ca.MX([3, 3]), 3),
ca.is_value(ca.MX([3, 4]), 3)
(true, true, false)
julia> ca.is_value(ca.MX.sym("x"), 3)
false
Extra doc: https://github.com/casadi/casadi/wiki/L_2eq
|
inlineinherited |
True when size1() or size2() is one, so scalars and n-by-1 or 1-by-n empties count. A 0-by-0 matrix does not.
>>> DM(3, 1).is_vector(), DM(1, 3).is_vector(), DM(1, 1).is_vector() (True, True, True) >>> DM(3, 3).is_vector(), DM(0, 1).is_vector(), DM(0, 0).is_vector() (False, True, False)
>> fprintf('%d %d %d\n', DM(3, 1).is_vector(), DM(1, 3).is_vector(), DM(1, 1).is_vector())
1 1 1
>> fprintf('%d %d %d\n', DM(3, 3).is_vector(), DM(0, 1).is_vector(), DM(0, 0).is_vector())
0 1 0
julia> ca.is_vector(ca.DM(3, 1)), ca.is_vector(ca.DM(1, 3)), ca.is_vector(ca.DM(1, 1)) (true, true, true) julia> ca.is_vector(ca.DM(3, 3)), ca.is_vector(ca.DM(0, 1)), ca.is_vector(ca.DM(0, 0)) (false, true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b3
Definition at line 507 of file generic_matrix.hpp.
| bool casadi::MX::is_zero | ( | ) | const |
True for constants with all nonzeros zero and for any matrix without nonzeros, whether symbolic or not. Expressions that simplify to zero (x - x, 0*x) are folded to a constant at construction and therefore report true.
>>> x = MX.sym("x")
>>> MX(0).is_zero(), MX(2, 2).is_zero(), (x - x).is_zero(), x.is_zero()
(True, True, True, False)
>>> MX.sym("e", 2, 0).is_zero()
True
>> x = MX.sym('x'); e = x - x;
>> MX(0).is_zero(), MX(2, 2).is_zero(), e.is_zero(), x.is_zero()
1
1
1
0
>> MX.sym('e', 2, 0).is_zero()
1
julia> x = ca.MX.sym("x");
julia> ca.is_zero(ca.MX(0)), ca.is_zero(ca.MX(2, 2)), ca.is_zero(x - x), ca.is_zero(x)
(true, true, true, false)
julia> ca.is_zero(ca.MX.sym("e", 2, 0))
true
Extra doc: https://github.com/casadi/casadi/wiki/L_qv
Inverse of split_primitives: v holds one value per primitive, with the shape of that primitive, and the result has the shape of this expression. A wrong number of pieces raises an error.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> X = vertcat(x, y)
>>> X.join_primitives([DM([1, 2]), DM([3, 4, 5])])
DM([1, 2, 3, 4, 5])
>>> try:
... X.join_primitives([DM([1, 2])])
... except Exception as e:
... print("Wrong number of primitives" in str(e))
True
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> X = [x; y];
>> X.join_primitives({DM([1; 2]), DM([3; 4; 5])})
[1, 2, 3, 4, 5]
>> try, X.join_primitives({DM([1; 2])}); catch e, disp('wrong number of primitives'); end
wrong number of primitives
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> X = [x; y];
julia> ca.join_primitives(X, [ca.DM([1, 2]), ca.DM([3, 4, 5])])
DM([1, 2, 3, 4, 5])
julia> try
ca.join_primitives(X, [ca.DM([1, 2])])
catch e
println(occursin("Wrong number of primitives", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_qr
Inverse of split_primitives: v holds one value per primitive, with the shape of that primitive, and the result has the shape of this expression. A wrong number of pieces raises an error.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> X = vertcat(x, y)
>>> X.join_primitives([DM([1, 2]), DM([3, 4, 5])])
DM([1, 2, 3, 4, 5])
>>> try:
... X.join_primitives([DM([1, 2])])
... except Exception as e:
... print("Wrong number of primitives" in str(e))
True
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> X = [x; y];
>> X.join_primitives({DM([1; 2]), DM([3; 4; 5])})
[1, 2, 3, 4, 5]
>> try, X.join_primitives({DM([1; 2])}); catch e, disp('wrong number of primitives'); end
wrong number of primitives
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> X = [x; y];
julia> ca.join_primitives(X, [ca.DM([1, 2]), ca.DM([3, 4, 5])])
DM([1, 2, 3, 4, 5])
julia> try
ca.join_primitives(X, [ca.DM([1, 2])])
catch e
println(occursin("Wrong number of primitives", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_qr
Inverse of split_primitives: v holds one value per primitive, with the shape of that primitive, and the result has the shape of this expression. A wrong number of pieces raises an error.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> X = vertcat(x, y)
>>> X.join_primitives([DM([1, 2]), DM([3, 4, 5])])
DM([1, 2, 3, 4, 5])
>>> try:
... X.join_primitives([DM([1, 2])])
... except Exception as e:
... print("Wrong number of primitives" in str(e))
True
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> X = [x; y];
>> X.join_primitives({DM([1; 2]), DM([3; 4; 5])})
[1, 2, 3, 4, 5]
>> try, X.join_primitives({DM([1; 2])}); catch e, disp('wrong number of primitives'); end
wrong number of primitives
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> X = [x; y];
julia> ca.join_primitives(X, [ca.DM([1, 2]), ca.DM([3, 4, 5])])
DM([1, 2, 3, 4, 5])
julia> try
ca.join_primitives(X, [ca.DM([1, 2])])
catch e
println(occursin("Wrong number of primitives", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_qr
|
staticinherited |
Functions called by friend functions defined here
|
staticinherited |
Functions called by friend functions defined here
|
staticinherited |
| Matrix<casadi_int> casadi::MX::mapping | ( | ) | const |
For a slicing node (x[...], x.nz[...]) returns the indices of the nonzeros of the dependency that make up the result; for an assignment node, the target indices. Any other node raises an error.
>>> X = MX.sym("X", 3, 3)
>>> X[0, 1].mapping(), X[:, 1].mapping()
(DM(3), DM([3, 4, 5]))
>>> try:
... X.mapping()
... except Exception as e:
... print("'mapping' not defined" in str(e))
True
>> X = MX.sym('X', 3, 3);
>> a = X(1, 2); b = X(:, 2);
>> a.mapping(), b.mapping()
3
[3, 4, 5]
>> try, X.mapping(); catch e, disp('error'); end
error
julia> X = ca.MX.sym("X", 3, 3);
julia> ca.mapping(X[1, 2]), ca.mapping(X[:, 2])
([3;;], [3; 4; 5;;])
julia> try
ca.mapping(X)
catch e
println(occursin("'mapping' not defined", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_ri
| MX casadi::MX::monitor | ( | const std::string & | comment | ) | const |
When the returned expression is evaluated, comment followed by the nonzeros is printed to standard output. The value is unchanged. A matrix without nonzeros is returned as is.
>>> x = MX.sym("x")
>>> e = x.monitor("value of x")
>>> e, e.is_op(OP_MONITOR)
(MX(monitor(x, value of x)), True)
>> x = MX.sym('x');
>> e = x.monitor('value of x');
>> e, e.is_op(OP_MONITOR)
monitor(x, value of x)
1
julia> x = ca.MX.sym("x");
julia> e = ca.monitor(x, "value of x");
julia> e, ca.is_op(e, ca.OP_MONITOR)
(monitor(x, value of x), true)
Extra doc: https://github.com/casadi/casadi/wiki/L_rh
|
staticinherited |
Functions called by friend functions defined here
| casadi_int casadi::MX::n_dep | ( | ) | const |
Zero for symbolic primitives and constants, one for unary operations and projections, two for binary operations, the number of arguments for concatenations and Function calls.
>>> x = MX.sym("x")
>>> A = MX.sym("A", 2, 2)
>>> x.n_dep(), sin(x).n_dep(), (x + 1).n_dep(), vertcat(x, x, x).n_dep()
(0, 1, 2, 3)
>>> (A @ A).n_dep(), A[0, 0].n_dep(), MX(1).n_dep()
(3, 1, 0)
>> x = MX.sym('x'); A = MX.sym('A', 2, 2);
>> e = x + 1; v = vertcat(x, x, x);
>> x.n_dep(), sin(x).n_dep(), e.n_dep(), v.n_dep()
0
1
2
3
>> P = A*A; a = A(1, 1);
>> P.n_dep(), a.n_dep(), MX(1).n_dep()
3
1
0
julia> x = ca.MX.sym("x"); A = ca.MX.sym("A", 2, 2);
julia> ca.n_dep(x), ca.n_dep(sin(x)), ca.n_dep(x + 1), ca.n_dep([x; x; x])
(0, 1, 2, 3)
julia> ca.n_dep(A * A), ca.n_dep(A[1, 1]), ca.n_dep(ca.MX(1))
(3, 1, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_qm
| casadi_int casadi::MX::n_out | ( | ) | const |
Greater than one only for multiple-output nodes, i.e. a call to a Function with several outputs. Every other node, including the OutputNode that selects one output of such a call, reports 1.
>>> a = SX.sym("a")
>>> f = Function("f", [a], [a + 1, 2*a])
>>> x = MX.sym("x")
>>> r0, r1 = f(x, )
>>> call = r0.dep(0)
>>> call, call.n_out(), r0.n_out()
(MX(f(x)), 2, 1)
>> a = SX.sym('a');
>> f = Function('f', {a}, {a + 1, 2*a});
>> x = MX.sym('x');
>> [r0, r1] = f(x);
>> call = r0.dep(0);
>> call, call.n_out(), r0.n_out()
f(x)
2
1
julia> a = ca.SX.sym("a");
julia> f = ca.Function("f", [a], [a + 1, 2 * a]);
julia> x = ca.MX.sym("x");
julia> r0, r1 = f(x);
julia> call = ca.dep(r0, 0);
julia> call, ca.n_out(call), ca.n_out(r0)
(f(x), 2, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_qk
| casadi_int casadi::MX::n_primitives | ( | ) | const |
For an expression that is not a valid input the count is 1 (the expression itself); check is_valid_input first.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> vertcat(x, y).n_primitives(), x.n_primitives()
(2, 1)
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> v = [x; y];
>> v.n_primitives(), x.n_primitives()
2
1
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> ca.n_primitives([x; y]), ca.n_primitives(x)
(2, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_qo
| std::string casadi::MX::name | ( | ) | const |
Only defined for nodes created by MX.sym; any other node raises an error. Check with is_symbolic first.
>>> x = MX.sym("x", 2)
>>> x.name()
'x'
>>> try:
... (x + 1).name()
... except Exception as e:
... print("'name' not defined" in str(e))
True
>> x = MX.sym('x', 2);
>> x.name()
x
>> e = x + 1;
>> try, e.name(); catch err, disp('error'); end
error
julia> x = ca.MX.sym("x", 2);
julia> ca.name(x)
"x"
julia> try
ca.name(x + 1)
catch e
println(occursin("'name' not defined", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2pr
|
static |
Dense nrow-by-(default 1-by-1), or with the given sparsity pattern.ncol
>>> MX.nan(), MX.nan(Sparsity.lower(2)) (MX(nan), MX(nan(2x2,3nz)))
>> MX.nan(), MX.nan(Sparsity.lower(2)) nan nan(2x2,3nz)
julia> ca.MX.nan(), ca.MX.nan(ca.Sparsity.lower(2)) (nan, nan(2x2,3nz))
Extra doc: https://github.com/casadi/casadi/wiki/L_r3
Dense nrow-by-(default 1-by-1), or with the given sparsity pattern.ncol
>>> MX.nan(), MX.nan(Sparsity.lower(2)) (MX(nan), MX(nan(2x2,3nz)))
>> MX.nan(), MX.nan(Sparsity.lower(2)) nan nan(2x2,3nz)
julia> ca.MX.nan(), ca.MX.nan(ca.Sparsity.lower(2)) (nan, nan(2x2,3nz))
Extra doc: https://github.com/casadi/casadi/wiki/L_r3
|
static |
Dense nrow-by-(default 1-by-1), or with the given sparsity pattern.ncol
>>> MX.nan(), MX.nan(Sparsity.lower(2)) (MX(nan), MX(nan(2x2,3nz)))
>> MX.nan(), MX.nan(Sparsity.lower(2)) nan nan(2x2,3nz)
julia> ca.MX.nan(), ca.MX.nan(ca.Sparsity.lower(2)) (nan, nan(2x2,3nz))
Extra doc: https://github.com/casadi/casadi/wiki/L_r3
|
inherited |
Counts the entries present in the sparsity pattern. Entries that are stored but numerically zero still count; structural zeros (not stored) do not. For a dense matrix this equals numel().
>>> DM.eye(3).nnz(), DM.ones(3, 3).nnz(), DM(3, 3).nnz()
(3, 9, 0)
>>> DM([[1, 0], [0, 2]]).nnz()
4
>>> MX.sym("x", 2, 0).nnz()
0
>> fprintf('%d %d %d\n', DM.eye(3).nnz(), DM.ones(3, 3).nnz(), DM(3, 3).nnz())
3 9 0
>> DM([1 0; 0 2]).nnz()
4
>> MX.sym('x', 2, 0).nnz()
0
julia> ca.nnz(ca.DM.eye(3)), ca.nnz(ca.DM.ones(3, 3)), ca.nnz(ca.DM(3, 3))
(3, 9, 0)
julia> ca.nnz(ca.DM([1 0; 0 2]))
4
julia> ca.nnz(ca.MX.sym("x", 2, 0))
0
Extra doc: https://github.com/casadi/casadi/wiki/L_1an
|
inherited |
Also defined for non-square matrices.
>>> DM.ones(3, 3).nnz_diag(), DM.eye(3).nnz_diag(), DM.ones(2, 3).nnz_diag() (3, 3, 2)
>> A = DM.ones(3, 3); I = DM.eye(3); B = DM.ones(2, 3);
>> fprintf('%d %d %d\n', A.nnz_diag(), I.nnz_diag(), B.nnz_diag())
3 3 2
julia> A = ca.DM.ones(3, 3); I = ca.DM.eye(3); B = ca.DM.ones(2, 3); julia> ca.nnz_diag(A), ca.nnz_diag(I), ca.nnz_diag(B) (3, 3, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1aq
|
inherited |
>>> DM.ones(3, 3).nnz_lower(), DM.eye(3).nnz_lower(), DM.ones(2, 3).nnz_lower() (6, 3, 3)
>> A = DM.ones(3, 3); I = DM.eye(3); B = DM.ones(2, 3);
>> fprintf('%d %d %d\n', A.nnz_lower(), I.nnz_lower(), B.nnz_lower())
6 3 3
julia> A = ca.DM.ones(3, 3); I = ca.DM.eye(3); B = ca.DM.ones(2, 3); julia> ca.nnz_lower(A), ca.nnz_lower(I), ca.nnz_lower(B) (6, 3, 3)
Extra doc: https://github.com/casadi/casadi/wiki/L_1ao
|
inherited |
>>> DM.ones(3, 3).nnz_upper(), DM.eye(3).nnz_upper(), DM.ones(2, 3).nnz_upper() (6, 3, 5)
>> A = DM.ones(3, 3); I = DM.eye(3); B = DM.ones(2, 3);
>> fprintf('%d %d %d\n', A.nnz_upper(), I.nnz_upper(), B.nnz_upper())
6 3 5
julia> A = ca.DM.ones(3, 3); I = ca.DM.eye(3); B = ca.DM.ones(2, 3); julia> ca.nnz_upper(A), ca.nnz_upper(I), ca.nnz_upper(B) (6, 3, 5)
Extra doc: https://github.com/casadi/casadi/wiki/L_1ap
|
inherited |
Counts all entries, structural zeros included.
>>> DM.eye(3).numel(), MX.sym("x", 2, 0).numel(), SX.sym("x").numel()
(9, 0, 1)
>> fprintf('%d %d %d\n', DM.eye(3).numel(), MX.sym('x', 2, 0).numel(), SX.sym('x').numel())
9 0 1
julia> ca.numel(ca.DM.eye(3)), ca.numel(ca.MX.sym("x", 2, 0)), ca.numel(ca.SX.sym("x"))
(9, 0, 1)
julia> length(ca.DM.eye(3))
9
Extra doc: https://github.com/casadi/casadi/wiki/L_1ar
|
inlinestaticinherited |
ones(sp) sets every structural nonzero of sp to one; other entries stay structurally zero.
>>> DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) >>> DM.ones(Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
>> DM.ones(2, 3) [[1, 1, 1], [1, 1, 1]] >> DM.ones(Sparsity.diag(2)) [[1, 00], [00, 1]]
julia> ca.DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) julia> ca.DM.ones(ca.Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1di
Definition at line 5206 of file generic_matrix.hpp.
|
inlinestaticinherited |
ones(sp) sets every structural nonzero of sp to one; other entries stay structurally zero.
>>> DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) >>> DM.ones(Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
>> DM.ones(2, 3) [[1, 1, 1], [1, 1, 1]] >> DM.ones(Sparsity.diag(2)) [[1, 00], [00, 1]]
julia> ca.DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) julia> ca.DM.ones(ca.Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1di
Definition at line 5209 of file generic_matrix.hpp.
|
inlinestaticinherited |
ones(sp) sets every structural nonzero of sp to one; other entries stay structurally zero.
>>> DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) >>> DM.ones(Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
>> DM.ones(2, 3) [[1, 1, 1], [1, 1, 1]] >> DM.ones(Sparsity.diag(2)) [[1, 00], [00, 1]]
julia> ca.DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) julia> ca.DM.ones(ca.Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1di
Definition at line 5210 of file generic_matrix.hpp.
| casadi_int casadi::MX::op | ( | ) | const |
Returns one of the OP_* constants. Every node, not only elementwise operations, has an operation code (OP_PARAMETER, OP_CONST, OP_CALL, OP_MTIMES, OP_GETNONZEROS, ...). Function print_operator shows the symbol of an operation.
>>> x = MX.sym("x")
>>> x.op() == OP_PARAMETER, (x + 1).op() == OP_ADD, MX(1).op() == OP_CONST
(True, True, True)
>>> print_operator(x + 1, ["a", "b"])
'(a+b)'
>> x = MX.sym('x'); e = x + 1;
>> x.op() == OP_PARAMETER, e.op() == OP_ADD, MX(1).op() == OP_CONST
1
1
1
>> print_operator(x + 1, {'a', 'b'})
(a+b)
julia> x = ca.MX.sym("x");
julia> ca.op(x) == ca.OP_PARAMETER, ca.op(x + 1) == ca.OP_ADD,
ca.op(ca.MX(1)) == ca.OP_CONST
(true, true, true)
julia> ca.print_operator(x + 1, ["a", "b"])
"(a+b)"
Extra doc: https://github.com/casadi/casadi/wiki/L_2q8
|
explicit |
Raises an error for symbolic nodes and for constants that are not 1-by-1.
>>> float(MX(2))
2.0
>>> try:
... float(MX.sym("x"))
... except Exception as e:
... print("'to_double' not defined" in str(e))
True
>> MX(2).to_double()
2
>> try, MX.sym('x').to_double(); catch e, disp('error'); end
error
julia> Float64(ca.MX(2))
2.0
julia> try
Float64(ca.MX.sym("x"))
catch e
println(occursin("requires a constant scalar", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2ps
|
explicit |
Only defined for constant nodes (is_constant). For a general expression without free symbols use evalf instead. Not defined for constants created from a file or with a pool name.
>>> MX(DM([[1, 2], [3, 4]])).to_DM()
DM(
[[1, 2],
[3, 4]])
>>> try:
... (MX.sym("x") + 1).to_DM()
... except Exception as e:
... print("'get_DM' not defined" in str(e))
True
>> MX(DM([1 2; 3 4])).to_DM()
[[1, 2],
[3, 4]]
>> e = MX.sym('x') + 1;
>> try, e.to_DM(); catch err, disp('error'); end
error
julia> ca.to_DM(ca.MX(ca.DM([1 2; 3 4])))
DM(
[[1, 2],
[3, 4]])
julia> try
ca.to_DM(ca.MX.sym("x") + 1)
catch e
println(occursin("'get_DM' not defined", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2pt
| MX casadi::MX::operator- | ( | ) | const |
Negating a negation returns the original node.
>>> x = MX.sym("x")
>>> -x, -(-x)
(MX((-x)), MX(x))
>> x = MX.sym('x');
>> -x, -(-x)
(-x)
x
julia> x = ca.MX.sym("x");
julia> -x, -(-x)
((-x), x)
Extra doc: https://github.com/casadi/casadi/wiki/L_2pq
| std::vector<MX> casadi::MX::primitives | ( | ) | const |
Returns the symbolic primitives in the order in which they appear in the concatenation. For an expression that is not a valid input, the expression itself is returned.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> vertcat(x, y).primitives()
[MX(x), MX(y)]
>>> reshape(x, 1, 2).primitives()
[MX(x)]
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> v = [x; y];
>> p = v.primitives();
>> numel(p), p{1}, p{2}
2
x
y
>> p = reshape(x, 1, 2).primitives();
>> numel(p), p{1}
1
x
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> ca.primitives([x; y])
2-element Vector{MX}:
MX(x)
MX(y)
julia> ca.primitives(reshape(x, 1, 2))
1-element Vector{MX}:
MX(x)
Extra doc: https://github.com/casadi/casadi/wiki/L_qp
Returns an expression equal to this one; when it is evaluated, every nonzero is printed to standard output as "|> b : value", where b is a scalar expression evaluated alongside it (an identifier for the print). Useful to trace values inside a Function. The printing is not part of the returned value and not seen by the doctest runner's output capture.
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> e = x.printme(y)
>>> e, e.is_op(OP_PRINTME)
(MX(printme(x,y)), True)
>> x = MX.sym('x'); y = MX.sym('y');
>> e = x.printme(y);
>> e, e.is_op(OP_PRINTME)
printme(x,y)
1
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> e = ca.printme(x, y);
julia> e, ca.is_op(e, ca.OP_PRINTME)
(printme(x,y), true)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qh
|
staticinherited |
Calculates A + alpha * x*y'
| alpha | Scalar; if it is a structural zero, A is returned unchanged |
| x | Vector with x.numel() == A.size1() (row vectors are transposed) |
| y | Vector with y.numel() == A.size2() |
>>> A = DM([[1, 2], [3, 4]])
>>> rank1(A, 2, DM([1, 0]), DM([0, 1]))
DM(
[[1, 4],
[3, 4]])
>>> rank1(MX.sym("A", 2, 2), MX.sym("a"), MX.sym("x", 2), MX.sym("y", 2))
MX(rank1(A, a, x, y))
>> A = DM([1 2; 3 4]);
>> rank1(A, 2, DM([1; 0]), DM([0; 1]))
[[1, 4],
[3, 4]]
>> rank1(MX.sym('A', 2, 2), MX.sym('a'), MX.sym('x', 2), MX.sym('y', 2))
rank1(A, a, x, y)
julia> A = ca.DM([1 2; 3 4]);
julia> ca.rank1(A, 2, ca.DM([1, 0]), ca.DM([0, 1]))
DM(
[[1, 4],
[3, 4]])
julia> ca.rank1(ca.MX.sym("A", 2, 2), ca.MX.sym("a"), ca.MX.sym("x", 2), ca.MX.sym("y", 2))
MX(rank1(A, a, x, y))
Extra doc: https://github.com/casadi/casadi/wiki/L_1bp
| void casadi::MX::reset_dump_count | ( | ) |
|
inlineinherited |
The pattern is stored in compressed column format: colind has size2()+1 entries, the nonzeros of column j are the entries colind(j) up to colind(j+1) (exclusive), and row(el) is the row index of nonzero el. Without argument, the full vectors are returned. Out-of-range indices raise an error.
>>> x = DM(Sparsity.diag(2), [5, 6]) >>> x.row(), x.colind() ([0, 1], [0, 1, 2]) >>> x.row(1), x.colind(2) (1, 2)
>> x = DM(Sparsity.diag(2), [5; 6]);
>> x.row(), x.colind()
0 1
0 1 2
>> fprintf('%d %d\n', x.row(1), x.colind(2))
1 2
julia> x = ca.DM(ca.Sparsity.diag(2), [5, 6]); julia> ca.row(x), ca.colind(x) ([0, 1], [0, 1, 2]) julia> ca.row(x, 1), ca.colind(x, 2) (1, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b8
Definition at line 608 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1at
Definition at line 283 of file generic_matrix.hpp.
| void casadi::MX::serialize | ( | SerializingStream & | s | ) | const |
From Python, serialize through StringSerializer, FileSerializer or pickle within a pickle context; the stream object is not constructed directly.
>>> x = MX.sym("x")
>>> s = StringSerializer()
>>> s.pack(x + 1)
>>> d = StringDeserializer(s.encode())
>>> d.unpack()
MX((1+x))
>> x = MX.sym('x');
>> s = StringSerializer();
>> s.pack(x + 1);
>> d = StringDeserializer(s.encode());
>> d.unpack()
(1+x)
julia> x = ca.MX.sym("x");
julia> s = ca.StringSerializer();
julia> ca.pack(s, x + 1)
julia> d = ca.StringDeserializer(ca.encode(s));
julia> ca.unpack(d)
MX((1+x))
Extra doc: https://github.com/casadi/casadi/wiki/L_qz
Expressions are immutable: assignment rebinds this object to a new SetNonzeros node whose dependencies are the old expression and m. Expressions built earlier from the old value are unaffected, but a second name bound to the same object (Y0 = Y) sees the new node; copy the handle with MX(Y) to keep the old value. The sparsity pattern grows to include the assigned elements; assigning a sparse m first erases the targeted elements. m must have the shape of the index set, be a scalar (broadcast), or be its transpose when the index set is a vector; anything else raises a dimension mismatch error. A Sparsity index assigns to the nonzero positions of that pattern. An MX index is only supported for the nonzero (x.nz[k]) form.
>>> Y = MX.sym("Y", 3, 3)
>>> alias, copy, twice = Y, MX(Y), 2*Y
>>> Y[[4]] = 5
>>> Y, Y.n_dep(), Y.dep(0), Y.dep(1)
(MX((Y[4] = 5)), 2, MX(Y), MX(5))
>>> alias, copy, twice
(MX((Y[4] = 5)), MX(Y), MX((2.*Y)))
>>> Z = MX(3, 3)
>>> Z[[0, 8]] = MX.sym("a", 2)
>>> Z.sparsity()
Sparsity(3x3,2nz)
>>> Y = MX.sym("Y", 3, 3)
>>> Y[Sparsity.lower(3)] = 1
>>> Y
MX((Y[0, 1, 2, 4, 5, 8] = ones(6x1)))
>> Y = MX.sym('Y', 3, 3);
>> alias = Y; copy = MX(Y); twice = 2*Y;
>> Y(5) = 5;
>> Y, Y.n_dep(), Y.dep(0), Y.dep(1)
(Y[4] = 5)
2
Y
5
>> alias, copy, twice
(Y[4] = 5)
Y
(2.*Y)
>> Z = MX(3, 3);
>> Z([1, 9]) = MX.sym('a', 2);
>> Z.sparsity()
3x3,2nz
>> Y = MX.sym('Y', 3, 3);
>> Y(Sparsity.lower(3)) = 1;
>> Y
(Y[0, 1, 2, 4, 5, 8] = ones(6x1))
julia> Y = ca.MX.sym("Y", 3, 3);
julia> alias, copy, twice = Y, ca.MX(Y), 2 * Y;
julia> Y[[5]] = 5;
julia> Y, ca.n_dep(Y), ca.dep(Y, 0), ca.dep(Y, 1)
((Y[4] = 5), 2, Y, 5)
julia> alias, copy, twice
((Y[4] = 5), Y, (2.*Y))
julia> Z = ca.MX(3, 3);
julia> Z[[1, 9]] = ca.MX.sym("a", 2);
julia> ca.sparsity(Z)
Sparsity(3x3,2nz)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qc
| void casadi::MX::set | ( | const MX & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | rr, | ||
| const Matrix< casadi_int > & | cc | ||
| ) |
Same semantics as the single-index form. m must be len(rr)-by-len(cc), a scalar, or the transpose of a vector block.
>>> Y = MX.sym("Y", 3, 3)
>>> Y[:, 0] = MX.sym("c", 1, 3)
>>> Y
MX((Y[:3] = c'))
>>> Y[0:2, 0:2] = 0
>>> Y.sparsity()
Sparsity(3x3)
>>> try:
... Y[:, 0] = MX.sym("d", 2)
... except Exception as e:
... print("Dimension mismatch" in str(e))
True
>> Y = MX.sym('Y', 3, 3);
>> Y(:, 1) = MX.sym('c', 1, 3);
>> Y
(Y[:3] = c')
>> Y(1:2, 1:2) = 0;
>> Y.sparsity()
3x3
>> try, Y(:, 1) = MX.sym('d', 2); catch e, disp('dimension mismatch'); end
dimension mismatch
julia> Y = ca.MX.sym("Y", 3, 3);
julia> Y[:, 1] = ca.MX.sym("c", 1, 3);
julia> Y
MX((Y[:3] = c'))
julia> Y[1:2, 1:2] = 0;
julia> ca.sparsity(Y)
Sparsity(3x3)
julia> try
Y[:, 1] = ca.MX.sym("d", 2)
catch e
println(occursin("Dimension mismatch", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qd
Same semantics as the single-index form. m must be len(rr)-by-len(cc), a scalar, or the transpose of a vector block.
>>> Y = MX.sym("Y", 3, 3)
>>> Y[:, 0] = MX.sym("c", 1, 3)
>>> Y
MX((Y[:3] = c'))
>>> Y[0:2, 0:2] = 0
>>> Y.sparsity()
Sparsity(3x3)
>>> try:
... Y[:, 0] = MX.sym("d", 2)
... except Exception as e:
... print("Dimension mismatch" in str(e))
True
>> Y = MX.sym('Y', 3, 3);
>> Y(:, 1) = MX.sym('c', 1, 3);
>> Y
(Y[:3] = c')
>> Y(1:2, 1:2) = 0;
>> Y.sparsity()
3x3
>> try, Y(:, 1) = MX.sym('d', 2); catch e, disp('dimension mismatch'); end
dimension mismatch
julia> Y = ca.MX.sym("Y", 3, 3);
julia> Y[:, 1] = ca.MX.sym("c", 1, 3);
julia> Y
MX((Y[:3] = c'))
julia> Y[1:2, 1:2] = 0;
julia> ca.sparsity(Y)
Sparsity(3x3)
julia> try
Y[:, 1] = ca.MX.sym("d", 2)
catch e
println(occursin("Dimension mismatch", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qd
Expressions are immutable: assignment rebinds this object to a new SetNonzeros node whose dependencies are the old expression and m. Expressions built earlier from the old value are unaffected, but a second name bound to the same object (Y0 = Y) sees the new node; copy the handle with MX(Y) to keep the old value. The sparsity pattern grows to include the assigned elements; assigning a sparse m first erases the targeted elements. m must have the shape of the index set, be a scalar (broadcast), or be its transpose when the index set is a vector; anything else raises a dimension mismatch error. A Sparsity index assigns to the nonzero positions of that pattern. An MX index is only supported for the nonzero (x.nz[k]) form.
>>> Y = MX.sym("Y", 3, 3)
>>> alias, copy, twice = Y, MX(Y), 2*Y
>>> Y[[4]] = 5
>>> Y, Y.n_dep(), Y.dep(0), Y.dep(1)
(MX((Y[4] = 5)), 2, MX(Y), MX(5))
>>> alias, copy, twice
(MX((Y[4] = 5)), MX(Y), MX((2.*Y)))
>>> Z = MX(3, 3)
>>> Z[[0, 8]] = MX.sym("a", 2)
>>> Z.sparsity()
Sparsity(3x3,2nz)
>>> Y = MX.sym("Y", 3, 3)
>>> Y[Sparsity.lower(3)] = 1
>>> Y
MX((Y[0, 1, 2, 4, 5, 8] = ones(6x1)))
>> Y = MX.sym('Y', 3, 3);
>> alias = Y; copy = MX(Y); twice = 2*Y;
>> Y(5) = 5;
>> Y, Y.n_dep(), Y.dep(0), Y.dep(1)
(Y[4] = 5)
2
Y
5
>> alias, copy, twice
(Y[4] = 5)
Y
(2.*Y)
>> Z = MX(3, 3);
>> Z([1, 9]) = MX.sym('a', 2);
>> Z.sparsity()
3x3,2nz
>> Y = MX.sym('Y', 3, 3);
>> Y(Sparsity.lower(3)) = 1;
>> Y
(Y[0, 1, 2, 4, 5, 8] = ones(6x1))
julia> Y = ca.MX.sym("Y", 3, 3);
julia> alias, copy, twice = Y, ca.MX(Y), 2 * Y;
julia> Y[[5]] = 5;
julia> Y, ca.n_dep(Y), ca.dep(Y, 0), ca.dep(Y, 1)
((Y[4] = 5), 2, Y, 5)
julia> alias, copy, twice
((Y[4] = 5), Y, (2.*Y))
julia> Z = ca.MX(3, 3);
julia> Z[[1, 9]] = ca.MX.sym("a", 2);
julia> ca.sparsity(Z)
Sparsity(3x3,2nz)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qc
Same semantics as the single-index form. m must be len(rr)-by-len(cc), a scalar, or the transpose of a vector block.
>>> Y = MX.sym("Y", 3, 3)
>>> Y[:, 0] = MX.sym("c", 1, 3)
>>> Y
MX((Y[:3] = c'))
>>> Y[0:2, 0:2] = 0
>>> Y.sparsity()
Sparsity(3x3)
>>> try:
... Y[:, 0] = MX.sym("d", 2)
... except Exception as e:
... print("Dimension mismatch" in str(e))
True
>> Y = MX.sym('Y', 3, 3);
>> Y(:, 1) = MX.sym('c', 1, 3);
>> Y
(Y[:3] = c')
>> Y(1:2, 1:2) = 0;
>> Y.sparsity()
3x3
>> try, Y(:, 1) = MX.sym('d', 2); catch e, disp('dimension mismatch'); end
dimension mismatch
julia> Y = ca.MX.sym("Y", 3, 3);
julia> Y[:, 1] = ca.MX.sym("c", 1, 3);
julia> Y
MX((Y[:3] = c'))
julia> Y[1:2, 1:2] = 0;
julia> ca.sparsity(Y)
Sparsity(3x3)
julia> try
Y[:, 1] = ca.MX.sym("d", 2)
catch e
println(occursin("Dimension mismatch", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qd
Same semantics as the single-index form. m must be len(rr)-by-len(cc), a scalar, or the transpose of a vector block.
>>> Y = MX.sym("Y", 3, 3)
>>> Y[:, 0] = MX.sym("c", 1, 3)
>>> Y
MX((Y[:3] = c'))
>>> Y[0:2, 0:2] = 0
>>> Y.sparsity()
Sparsity(3x3)
>>> try:
... Y[:, 0] = MX.sym("d", 2)
... except Exception as e:
... print("Dimension mismatch" in str(e))
True
>> Y = MX.sym('Y', 3, 3);
>> Y(:, 1) = MX.sym('c', 1, 3);
>> Y
(Y[:3] = c')
>> Y(1:2, 1:2) = 0;
>> Y.sparsity()
3x3
>> try, Y(:, 1) = MX.sym('d', 2); catch e, disp('dimension mismatch'); end
dimension mismatch
julia> Y = ca.MX.sym("Y", 3, 3);
julia> Y[:, 1] = ca.MX.sym("c", 1, 3);
julia> Y
MX((Y[:3] = c'))
julia> Y[1:2, 1:2] = 0;
julia> ca.sparsity(Y)
Sparsity(3x3)
julia> try
Y[:, 1] = ca.MX.sym("d", 2)
catch e
println(occursin("Dimension mismatch", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qd
Expressions are immutable: assignment rebinds this object to a new SetNonzeros node whose dependencies are the old expression and m. Expressions built earlier from the old value are unaffected, but a second name bound to the same object (Y0 = Y) sees the new node; copy the handle with MX(Y) to keep the old value. The sparsity pattern grows to include the assigned elements; assigning a sparse m first erases the targeted elements. m must have the shape of the index set, be a scalar (broadcast), or be its transpose when the index set is a vector; anything else raises a dimension mismatch error. A Sparsity index assigns to the nonzero positions of that pattern. An MX index is only supported for the nonzero (x.nz[k]) form.
>>> Y = MX.sym("Y", 3, 3)
>>> alias, copy, twice = Y, MX(Y), 2*Y
>>> Y[[4]] = 5
>>> Y, Y.n_dep(), Y.dep(0), Y.dep(1)
(MX((Y[4] = 5)), 2, MX(Y), MX(5))
>>> alias, copy, twice
(MX((Y[4] = 5)), MX(Y), MX((2.*Y)))
>>> Z = MX(3, 3)
>>> Z[[0, 8]] = MX.sym("a", 2)
>>> Z.sparsity()
Sparsity(3x3,2nz)
>>> Y = MX.sym("Y", 3, 3)
>>> Y[Sparsity.lower(3)] = 1
>>> Y
MX((Y[0, 1, 2, 4, 5, 8] = ones(6x1)))
>> Y = MX.sym('Y', 3, 3);
>> alias = Y; copy = MX(Y); twice = 2*Y;
>> Y(5) = 5;
>> Y, Y.n_dep(), Y.dep(0), Y.dep(1)
(Y[4] = 5)
2
Y
5
>> alias, copy, twice
(Y[4] = 5)
Y
(2.*Y)
>> Z = MX(3, 3);
>> Z([1, 9]) = MX.sym('a', 2);
>> Z.sparsity()
3x3,2nz
>> Y = MX.sym('Y', 3, 3);
>> Y(Sparsity.lower(3)) = 1;
>> Y
(Y[0, 1, 2, 4, 5, 8] = ones(6x1))
julia> Y = ca.MX.sym("Y", 3, 3);
julia> alias, copy, twice = Y, ca.MX(Y), 2 * Y;
julia> Y[[5]] = 5;
julia> Y, ca.n_dep(Y), ca.dep(Y, 0), ca.dep(Y, 1)
((Y[4] = 5), 2, Y, 5)
julia> alias, copy, twice
((Y[4] = 5), Y, (2.*Y))
julia> Z = ca.MX(3, 3);
julia> Z[[1, 9]] = ca.MX.sym("a", 2);
julia> ca.sparsity(Z)
Sparsity(3x3,2nz)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qc
|
static |
Global setting (default 1) used when building expressions: operations such as x - y or x/y test whether their operands are equal up to this depth with is_equal and simplify to 0 or 1 when they are. Depth 0 compares node identity only; each extra level compares the operation and recurses into the dependencies. Larger depths find more simplifications at a cost per created node. Calling without an argument restores the default.
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> MX.get_max_depth(), (x + y) - (x + y)
(1, MX(0))
>>> MX.set_max_depth(0)
>>> (x + y) - (x + y)
MX(((x+y)-(x+y)))
>>> MX.set_max_depth()
>>> MX.get_max_depth()
1
>> x = MX.sym('x'); y = MX.sym('y');
>> MX.get_max_depth(), (x + y) - (x + y)
1
0
>> MX.set_max_depth(0);
>> (x + y) - (x + y)
((x+y)-(x+y))
>> MX.set_max_depth();
>> MX.get_max_depth()
1
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> ca.MX.get_max_depth(), (x + y) - (x + y)
(1, 0)
julia> ca.MX.set_max_depth(0)
julia> (x + y) - (x + y)
MX(((x+y)-(x+y)))
julia> ca.MX.set_max_depth()
julia> ca.MX.get_max_depth()
1
Extra doc: https://github.com/casadi/casadi/wiki/L_rj
|
inline |
Rebinds this object to a SetNonzeros node; the sparsity pattern is unchanged. m must have as many nonzeros as the index set or be a scalar. With an MX index the assignment is parametric and resolved at evaluation time.
>>> Y = MX.sym("Y", 3, 3)
>>> Y.nz[0] = 7
>>> Y
MX((Y[0] = 7))
>>> k = MX.sym("k")
>>> Y.nz[k] = 8
>>> Y, Y.is_op(OP_SETNONZEROS_PARAM)
(MX(((Y[0] = 7)[k] = 8)), True)
>> Y = MX.sym('Y', 3, 3);
>> Y.set_nz(7, true, 1);
>> Y
(Y[0] = 7)
>> k = MX.sym('k');
>> Y.set_nz(8, true, k);
>> Y, Y.is_op(OP_SETNONZEROS_PARAM)
((Y[0] = 7)[(k-1)] = 8)
1
julia> Y = ca.MX.sym("Y", 3, 3);
julia> Y.nz[1] = 7;
julia> Y
MX((Y[0] = 7))
julia> k = ca.MX.sym("k");
julia> Y.nz[k] = 8;
julia> Y
MX(((Y[0] = 7)[(k-1)] = 8))
julia> ca.is_op(Y, ca.OP_SETNONZEROS_PARAM)
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qf
Rebinds this object to a SetNonzeros node; the sparsity pattern is unchanged. m must have as many nonzeros as the index set or be a scalar. With an MX index the assignment is parametric and resolved at evaluation time.
>>> Y = MX.sym("Y", 3, 3)
>>> Y.nz[0] = 7
>>> Y
MX((Y[0] = 7))
>>> k = MX.sym("k")
>>> Y.nz[k] = 8
>>> Y, Y.is_op(OP_SETNONZEROS_PARAM)
(MX(((Y[0] = 7)[k] = 8)), True)
>> Y = MX.sym('Y', 3, 3);
>> Y.set_nz(7, true, 1);
>> Y
(Y[0] = 7)
>> k = MX.sym('k');
>> Y.set_nz(8, true, k);
>> Y, Y.is_op(OP_SETNONZEROS_PARAM)
((Y[0] = 7)[(k-1)] = 8)
1
julia> Y = ca.MX.sym("Y", 3, 3);
julia> Y.nz[1] = 7;
julia> Y
MX((Y[0] = 7))
julia> k = ca.MX.sym("k");
julia> Y.nz[k] = 8;
julia> Y
MX(((Y[0] = 7)[(k-1)] = 8))
julia> ca.is_op(Y, ca.OP_SETNONZEROS_PARAM)
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qf
Rebinds this object to a SetNonzeros node; the sparsity pattern is unchanged. m must have as many nonzeros as the index set or be a scalar. With an MX index the assignment is parametric and resolved at evaluation time.
>>> Y = MX.sym("Y", 3, 3)
>>> Y.nz[0] = 7
>>> Y
MX((Y[0] = 7))
>>> k = MX.sym("k")
>>> Y.nz[k] = 8
>>> Y, Y.is_op(OP_SETNONZEROS_PARAM)
(MX(((Y[0] = 7)[k] = 8)), True)
>> Y = MX.sym('Y', 3, 3);
>> Y.set_nz(7, true, 1);
>> Y
(Y[0] = 7)
>> k = MX.sym('k');
>> Y.set_nz(8, true, k);
>> Y, Y.is_op(OP_SETNONZEROS_PARAM)
((Y[0] = 7)[(k-1)] = 8)
1
julia> Y = ca.MX.sym("Y", 3, 3);
julia> Y.nz[1] = 7;
julia> Y
MX((Y[0] = 7))
julia> k = ca.MX.sym("k");
julia> Y.nz[k] = 8;
julia> Y
MX(((Y[0] = 7)[(k-1)] = 8))
julia> ca.is_op(Y, ca.OP_SETNONZEROS_PARAM)
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qf
Rebinds this object to a SetNonzeros node; the sparsity pattern is unchanged. m must have as many nonzeros as the index set or be a scalar. With an MX index the assignment is parametric and resolved at evaluation time.
>>> Y = MX.sym("Y", 3, 3)
>>> Y.nz[0] = 7
>>> Y
MX((Y[0] = 7))
>>> k = MX.sym("k")
>>> Y.nz[k] = 8
>>> Y, Y.is_op(OP_SETNONZEROS_PARAM)
(MX(((Y[0] = 7)[k] = 8)), True)
>> Y = MX.sym('Y', 3, 3);
>> Y.set_nz(7, true, 1);
>> Y
(Y[0] = 7)
>> k = MX.sym('k');
>> Y.set_nz(8, true, k);
>> Y, Y.is_op(OP_SETNONZEROS_PARAM)
((Y[0] = 7)[(k-1)] = 8)
1
julia> Y = ca.MX.sym("Y", 3, 3);
julia> Y.nz[1] = 7;
julia> Y
MX((Y[0] = 7))
julia> k = ca.MX.sym("k");
julia> Y.nz[k] = 8;
julia> Y
MX(((Y[0] = 7)[(k-1)] = 8))
julia> ca.is_op(Y, ca.OP_SETNONZEROS_PARAM)
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qf
|
static |
|
static |
|
static |
|
inherited |
>>> x = MX.sym("x", 2, 3)
>>> x.size(), x.size(1), x.size(2)
((2, 3), 2, 3)
>> x = MX.sym('x', 2, 3);
>> size(x)
2 3
>> fprintf('%d %d\n', size(x, 1), size(x, 2))
2 3
julia> x = ca.MX.sym("x", 2, 3);
julia> size(x), size(x, 1), size(x, 2)
((2, 3), 2, 3)
Extra doc: https://github.com/casadi/casadi/wiki/L_1ax
|
inherited |
| axis | 1 for the number of rows, 2 for the number of columns; any other value raises an error |
Extra doc: https://github.com/casadi/casadi/wiki/L_1ay
|
inherited |
>>> x = MX.sym("x", 2, 3)
>>> x.size1(), x.size2()
(2, 3)
>> x = MX.sym('x', 2, 3);
>> fprintf('%d %d\n', x.size1(), x.size2())
2 3
julia> x = ca.MX.sym("x", 2, 3);
julia> ca.size1(x), ca.size2(x)
(2, 3)
Extra doc: https://github.com/casadi/casadi/wiki/L_1as
|
inherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1au
|
staticinherited |
Functions called by friend functions defined here
|
inherited |
>>> DM.eye(2).sparsity() Sparsity(2x2,2nz) >>> DM.eye(2).sparsity() == Sparsity.diag(2) True
>> DM.eye(2).sparsity() 2x2,2nz >> DM.eye(2).sparsity() == Sparsity.diag(2) 1
julia> ca.sparsity(ca.DM.eye(2)) Sparsity(2x2,2nz) julia> ca.is_equal(ca.sparsity(ca.DM.eye(2)), ca.Sparsity.diag(2)) true
Extra doc: https://github.com/casadi/casadi/wiki/L_1b9
Uses this expression (a valid Function input, see is_valid_input) as a template: x must have the same shape and is cut into one piece per primitive, each with the shape of that primitive. The typical use is to split a solver result back into the variables it was concatenated from. Works with numeric (DM), SX and MX values. A shape mismatch raises an error.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> X = vertcat(x, y)
>>> X.split_primitives(DM([1, 2, 3, 4, 5]))
[DM([1, 2]), DM([3, 4, 5])]
>>> X.split_primitives(SX.sym("z", 5))
[SX([z_0, z_1]), SX([z_2, z_3, z_4])]
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> X = [x; y];
>> parts = X.split_primitives(DM([1; 2; 3; 4; 5]));
>> parts{1}, parts{2}
[1, 2]
[3, 4, 5]
>> parts = X.split_primitives(SX.sym('z', 5));
>> parts{1}, parts{2}
[z_0, z_1]
[z_2, z_3, z_4]
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> X = [x; y];
julia> ca.split_primitives(X, ca.DM([1, 2, 3, 4, 5]))
2-element Vector{DM}:
DM([1, 2])
DM([3, 4, 5])
julia> ca.split_primitives(X, ca.SX.sym("z", 5))
2-element Vector{SX}:
SX([z_0, z_1])
SX([z_2, z_3, z_4])
Extra doc: https://github.com/casadi/casadi/wiki/L_qq
Uses this expression (a valid Function input, see is_valid_input) as a template: x must have the same shape and is cut into one piece per primitive, each with the shape of that primitive. The typical use is to split a solver result back into the variables it was concatenated from. Works with numeric (DM), SX and MX values. A shape mismatch raises an error.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> X = vertcat(x, y)
>>> X.split_primitives(DM([1, 2, 3, 4, 5]))
[DM([1, 2]), DM([3, 4, 5])]
>>> X.split_primitives(SX.sym("z", 5))
[SX([z_0, z_1]), SX([z_2, z_3, z_4])]
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> X = [x; y];
>> parts = X.split_primitives(DM([1; 2; 3; 4; 5]));
>> parts{1}, parts{2}
[1, 2]
[3, 4, 5]
>> parts = X.split_primitives(SX.sym('z', 5));
>> parts{1}, parts{2}
[z_0, z_1]
[z_2, z_3, z_4]
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> X = [x; y];
julia> ca.split_primitives(X, ca.DM([1, 2, 3, 4, 5]))
2-element Vector{DM}:
DM([1, 2])
DM([3, 4, 5])
julia> ca.split_primitives(X, ca.SX.sym("z", 5))
2-element Vector{SX}:
SX([z_0, z_1])
SX([z_2, z_3, z_4])
Extra doc: https://github.com/casadi/casadi/wiki/L_qq
Uses this expression (a valid Function input, see is_valid_input) as a template: x must have the same shape and is cut into one piece per primitive, each with the shape of that primitive. The typical use is to split a solver result back into the variables it was concatenated from. Works with numeric (DM), SX and MX values. A shape mismatch raises an error.
>>> x = MX.sym("x", 2)
>>> y = MX.sym("y", 3)
>>> X = vertcat(x, y)
>>> X.split_primitives(DM([1, 2, 3, 4, 5]))
[DM([1, 2]), DM([3, 4, 5])]
>>> X.split_primitives(SX.sym("z", 5))
[SX([z_0, z_1]), SX([z_2, z_3, z_4])]
>> x = MX.sym('x', 2); y = MX.sym('y', 3);
>> X = [x; y];
>> parts = X.split_primitives(DM([1; 2; 3; 4; 5]));
>> parts{1}, parts{2}
[1, 2]
[3, 4, 5]
>> parts = X.split_primitives(SX.sym('z', 5));
>> parts{1}, parts{2}
[z_0, z_1]
[z_2, z_3, z_4]
julia> x = ca.MX.sym("x", 2); y = ca.MX.sym("y", 3);
julia> X = [x; y];
julia> ca.split_primitives(X, ca.DM([1, 2, 3, 4, 5]))
2-element Vector{DM}:
DM([1, 2])
DM([3, 4, 5])
julia> ca.split_primitives(X, ca.SX.sym("z", 5))
2-element Vector{SX}:
SX([z_0, z_1])
SX([z_2, z_3, z_4])
Extra doc: https://github.com/casadi/casadi/wiki/L_qq
|
inlinestaticinherited |
>>> SX.sym("x", 1, 1, 2)
[SX(x0), SX(x1)]
>> v = SX.sym('x', 1, 1, 2);
>> v{1}, v{2}
x0
x1
julia> ca.SX.sym("x", 1, 1, 2)
2-element Vector{SX}:
SX(x0)
SX(x1)
Extra doc: https://github.com/casadi/casadi/wiki/L_1de
Definition at line 5063 of file generic_matrix.hpp.
|
inlinestaticinherited |
>>> MX.sym("x", 1, 1, 2, 2)
[[MX(x_00), MX(x_01)], [MX(x_10), MX(x_11)]]
>> v = MX.sym('x', 1, 1, 2, 2);
>> numel(v), v{1}{2}, v{2}{1}
2
x_01
x_10
julia> ca.MX.sym("x", 1, 1, 2, 2)
2-element Vector{Vector{MX}}:
MX[x_00, x_01]
MX[x_10, x_11]
Extra doc: https://github.com/casadi/casadi/wiki/L_1dg
Definition at line 5107 of file generic_matrix.hpp.
|
inlinestaticinherited |
Creates a new, dense symbol; two symbols with the same name are still different symbols. For SX each entry is a separate scalar symbol named name_k (k the column-major index), while an MX symbol is a single node with the given name. Only SX and MX have symbols; DM.sym raises an error.
| name | Name used for printing. For SX, a name of the form "[a,b,c]" assigns individual names to the numel() entries. |
| nrow | Number of rows, default 1 |
| ncol | Number of columns, default 1 |
>>> SX.sym("x"), MX.sym("x", 2, 3).dim()
(SX(x), '2x3')
>>> SX.sym("x", 2, 2)
SX(
[[x_0, x_2],
[x_1, x_3]])
>>> SX.sym("[a,b,c]", 3)
SX([a, b, c])
>>> is_equal(SX.sym("x"), SX.sym("x"))
False
>> SX.sym('x'), MX.sym('x', 2, 3).dim()
x
2x3
>> SX.sym('x', 2, 2)
[[x_0, x_2],
[x_1, x_3]]
>> SX.sym('[a,b,c]', 3)
[a, b, c]
>> is_equal(SX.sym('x'), SX.sym('x'))
0
julia> ca.SX.sym("x"), ca.dim(ca.MX.sym("x", 2, 3))
(x, "2x3")
julia> ca.SX.sym("x", 2, 2)
SX(
[[x_0, x_2],
[x_1, x_3]])
julia> ca.SX.sym("[a,b,c]", 3)
SX([a, b, c])
julia> isequal(ca.SX.sym("x"), ca.SX.sym("x"))
false
Extra doc: https://github.com/casadi/casadi/wiki/L_1da
Definition at line 4948 of file generic_matrix.hpp.
|
inlinestaticinherited |
Only the structural nonzeros of sp become symbolic entries; for SX they are numbered by nonzero index.
>>> SX.sym("p", Sparsity.diag(2))
SX(
[[p_0, 00],
[00, p_1]])
>>> MX.sym("p", Sparsity.diag(2)).dim(True)
'2x2,2nz'
>> SX.sym('p', Sparsity.diag(2))
[[p_0, 00],
[00, p_1]]
>> MX.sym('p', Sparsity.diag(2)).dim(true)
2x2,2nz
julia> ca.SX.sym("p", ca.Sparsity.diag(2))
SX(
[[p_0, 00],
[00, p_1]])
julia> ca.dim(ca.MX.sym("p", ca.Sparsity.diag(2)), true)
"2x2,2nz"
Extra doc: https://github.com/casadi/casadi/wiki/L_1dc
Definition at line 4997 of file generic_matrix.hpp.
|
staticinherited |
The k-th symbol is named name followed by k (no separator).
>>> MX.sym("x", Sparsity.dense(2, 1), 3)
[MX(x0), MX(x1), MX(x2)]
>> v = MX.sym('x', Sparsity.dense(2, 1), 3);
>> numel(v), v{1}, v{3}
3
x0
x2
julia> ca.MX.sym("x", ca.Sparsity.dense(2, 1), 3)
3-element Vector{MX}:
MX(x0)
MX(x1)
MX(x2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1dd
Definition at line 5033 of file generic_matrix.hpp.
|
staticinherited |
with given sparsity. The symbol at outer index i and inner index k is named name_ik.
Extra doc: https://github.com/casadi/casadi/wiki/L_1df
Definition at line 5075 of file generic_matrix.hpp.
|
inlinestaticinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1db
Definition at line 4955 of file generic_matrix.hpp.
| MX casadi::MX::T | ( | ) | const |
In Python use the property x.T. Scalars are returned as is, vectors become a reshape node and matrices a transpose node. Transposing twice returns the original node.
>>> A = MX.sym("A", 2, 3)
>>> A.T, A.T.shape, A.T.T
(MX(A'), (3, 2), MX(A))
>> A = MX.sym('A', 2, 3);
>> At = A';
>> At, size(At), At'
A'
3 2
A
julia> A = ca.MX.sym("A", 2, 3);
julia> A', size(A'), (A')'
(A', (3, 2), A)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qn
|
staticinherited |
Functions called by friend functions defined here
|
static |
|
inlinestatic |
Extra doc: https://github.com/casadi/casadi/wiki/L_pz
Low-level constructors behind the operators: MX.binary(OP_ADD, x, y) is x + y. Operands must have the same shape, or one of them is a scalar, or one is a horizontal repetition of the other (which is repmat-ed). The usual simplifications are applied. An invalid operation code is not checked.
| op | One of the OP_* constants |
| unique_x,unique_y | Internal hints for in-place simplification; leave false |
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> MX.binary(OP_ADD, x, y), MX.unary(OP_SIN, x)
(MX((x+y)), MX(sin(x)))
>>> MX.binary(OP_ADD, MX.sym("V", 2, 4), MX.sym("W", 2, 2))
MX((V+repmat(W, 2)))
>>> try:
... MX.binary(OP_ADD, MX.sym("v", 2), MX.sym("w", 3))
... except Exception as e:
... print("Dimension mismatch" in str(e))
True
>> x = MX.sym('x'); y = MX.sym('y');
>> MX.binary(OP_ADD, x, y), MX.unary(OP_SIN, x)
(x+y)
sin(x)
>> MX.binary(OP_ADD, MX.sym('V', 2, 4), MX.sym('W', 2, 2))
(V+repmat(W, 2))
>> v = MX.sym('v', 2); w = MX.sym('w', 3);
>> try, MX.binary(OP_ADD, v, w); catch e, disp('dimension mismatch'); end
dimension mismatch
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> ca.MX.binary(ca.OP_ADD, x, y), ca.MX.unary(ca.OP_SIN, x)
((x+y), sin(x))
julia> ca.MX.binary(ca.OP_ADD, ca.MX.sym("V", 2, 4), ca.MX.sym("W", 2, 2))
MX((V+repmat(W, 2)))
julia> try
ca.MX.binary(ca.OP_ADD, ca.MX.sym("v", 2), ca.MX.sym("w", 3))
catch e
println(occursin("Dimension mismatch", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_r1
| Function casadi::MX::which_function | ( | ) | const |
Only valid when is_call() is true; raises an error otherwise, also for the OutputNode of a call (use dep(0) to reach the call node).
>>> a = SX.sym("a")
>>> f = Function("f", [a], [2*a])
>>> x = MX.sym("x")
>>> r = f(x)
>>> r.dep(0).which_function().name()
'f'
>>> try:
... r.which_function()
... except Exception as e:
... print("'which_function' not defined" in str(e))
True
>> a = SX.sym('a');
>> f = Function('f', {a}, {2*a});
>> x = MX.sym('x');
>> r = f(x);
>> call = r.dep(0);
>> call.which_function().name()
f
>> try, r.which_function(); catch e, disp('error'); end
error
julia> a = ca.SX.sym("a");
julia> f = ca.Function("f", [a], [2 * a]);
julia> x = ca.MX.sym("x");
julia> r = f(x);
julia> ca.name(ca.which_function(ca.dep(r, 0)))
"f"
julia> try
ca.which_function(r)
catch e
println(occursin("'which_function' not defined", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2py
| casadi_int casadi::MX::which_output | ( | ) | const |
Only valid when is_output() is true; raises an error otherwise.
>>> a = SX.sym("a")
>>> f = Function("f", [a], [a + 1, 2*a])
>>> x = MX.sym("x")
>>> r0, r1 = f(x, )
>>> r0.which_output(), r1.which_output()
(0, 1)
>> a = SX.sym('a');
>> f = Function('f', {a}, {a + 1, 2*a});
>> x = MX.sym('x');
>> [r0, r1] = f(x);
>> r0.which_output(), r1.which_output()
0
1
julia> a = ca.SX.sym("a");
julia> f = ca.Function("f", [a], [a + 1, 2 * a]);
julia> x = ca.MX.sym("x");
julia> r0, r1 = f(x);
julia> ca.which_output(r0), ca.which_output(r1)
(0, 1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2q0
|
inlinestaticinherited |
zeros(nrow, ncol) stores nrow*ncol numerical zeros; zeros(sp) stores a zero at every structural nonzero of sp. To get structural zeros instead, construct from a shape, e.g. DM(2, 2).
>>> DM.zeros(2, 2).nnz(), DM.zeros(Sparsity.diag(2)).nnz(), DM(2, 2).nnz() (4, 2, 0) >>> MX.zeros(2, 3) MX(zeros(2x3))
>> Z = DM.zeros(Sparsity.diag(2));
>> fprintf('%d %d %d\n', DM.zeros(2, 2).nnz(), Z.nnz(), DM(2, 2).nnz())
4 2 0
>> MX.zeros(2, 3)
zeros(2x3)
julia> Z = ca.DM.zeros(ca.Sparsity.diag(2)); julia> ca.nnz(ca.DM.zeros(2, 2)), ca.nnz(Z), ca.nnz(ca.DM(2, 2)) (4, 2, 0) julia> ca.MX.zeros(2, 3) MX(zeros(2x3))
Extra doc: https://github.com/casadi/casadi/wiki/L_1dh
Definition at line 5151 of file generic_matrix.hpp.
|
inlinestaticinherited |
zeros(nrow, ncol) stores nrow*ncol numerical zeros; zeros(sp) stores a zero at every structural nonzero of sp. To get structural zeros instead, construct from a shape, e.g. DM(2, 2).
>>> DM.zeros(2, 2).nnz(), DM.zeros(Sparsity.diag(2)).nnz(), DM(2, 2).nnz() (4, 2, 0) >>> MX.zeros(2, 3) MX(zeros(2x3))
>> Z = DM.zeros(Sparsity.diag(2));
>> fprintf('%d %d %d\n', DM.zeros(2, 2).nnz(), Z.nnz(), DM(2, 2).nnz())
4 2 0
>> MX.zeros(2, 3)
zeros(2x3)
julia> Z = ca.DM.zeros(ca.Sparsity.diag(2)); julia> ca.nnz(ca.DM.zeros(2, 2)), ca.nnz(Z), ca.nnz(ca.DM(2, 2)) (4, 2, 0) julia> ca.MX.zeros(2, 3) MX(zeros(2x3))
Extra doc: https://github.com/casadi/casadi/wiki/L_1dh
Definition at line 5154 of file generic_matrix.hpp.
|
inlinestaticinherited |
zeros(nrow, ncol) stores nrow*ncol numerical zeros; zeros(sp) stores a zero at every structural nonzero of sp. To get structural zeros instead, construct from a shape, e.g. DM(2, 2).
>>> DM.zeros(2, 2).nnz(), DM.zeros(Sparsity.diag(2)).nnz(), DM(2, 2).nnz() (4, 2, 0) >>> MX.zeros(2, 3) MX(zeros(2x3))
>> Z = DM.zeros(Sparsity.diag(2));
>> fprintf('%d %d %d\n', DM.zeros(2, 2).nnz(), Z.nnz(), DM(2, 2).nnz())
4 2 0
>> MX.zeros(2, 3)
zeros(2x3)
julia> Z = ca.DM.zeros(ca.Sparsity.diag(2)); julia> ca.nnz(ca.DM.zeros(2, 2)), ca.nnz(Z), ca.nnz(ca.DM(2, 2)) (4, 2, 0) julia> ca.MX.zeros(2, 3) MX(zeros(2x3))
Extra doc: https://github.com/casadi/casadi/wiki/L_1dh
Definition at line 5155 of file generic_matrix.hpp.