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 MX | ScalarType |
| typedef GenericMatrix< MX > | B |
| Base class. More... | |
| 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 std::pair< casadi_int, casadi_int > &rc) | |
| 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 std::vector< double > &x) | |
| Create vector constant (also implicit type conversion) More... | |
| MX (const Matrix< double > &x) | |
| Create a constant from a DM (also used for implicit conversion) More... | |
| ~MX () | |
| Destructor. More... | |
| const Sparsity & | sparsity () const |
| Get the sparsity pattern. 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 | has_duplicates () const |
| Detect duplicate symbolic primitives in a Function input. More... | |
| void | reset_input () const |
| Reset the marker set by has_duplicates on an input expression. 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... | |
| casadi_int | get_temp () const |
| void | set_temp (casadi_int t) const |
| Set the temporary variable. More... | |
| MXNode * | get () const |
| Get a const pointer to the node. More... | |
| MX | nzref (const Sparsity &sp, const std::vector< casadi_int > &nz) const |
| Low-level access to get_nzref. More... | |
| MX | printme (const MX &b) const |
| 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... | |
| MX (const Sparsity &sp, double val, bool dummy) | |
| Construct constant matrix with a given sparsity and values. More... | |
| casadi_int | nnz () const |
| Get the number of structural 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... | |
| const MX | nz (const K &k) const |
| Get vector nonzero or slice of nonzeros. More... | |
| NonZeros< MX, K > | nz (const K &k) |
| Access vector nonzero or slice of nonzeros. More... | |
| const MX | operator() (const RR &rr) const |
| Get vector element or slice. More... | |
| const MX | operator() (const RR &rr, const CC &cc) const |
| Get Matrix element or slice. More... | |
| SubIndex< MX, RR > | operator() (const RR &rr) |
| Access Matrix elements (one argument) More... | |
| SubMatrix< MX, RR, CC > | operator() (const RR &rr, const CC &cc) |
| Access Matrix elements (two arguments) More... | |
| std::string | class_name () const |
| Get class name. More... | |
| void | disp (std::ostream &stream, bool more=false) const |
| Print a description of the object. More... | |
| std::string | get_str (bool more=false) const |
| Get string representation. More... | |
| void | print_ptr (std::ostream &stream=casadi::uout()) const |
| void | own (SharedObjectInternal *node) |
| void | assign (SharedObjectInternal *node) |
| Assign the node to a node class pointer without reference counting. More... | |
| casadi_int | getCount () const |
| Get the reference count. More... | |
| void | swap (GenericShared &other) |
| Swap content with another instance. More... | |
| std::string | debug_repr () const |
| bool | is_null () const |
| Is a null pointer? More... | |
| casadi_int | __hash__ () const |
| Returns a number that is unique for a given Node. More... | |
| GenericWeakRef< SharedObject, SharedObjectInternal > * | weak () |
| Get a weak reference to the object. More... | |
| MXNode * | operator-> () |
| Access a member of the node. More... | |
| const MXNode * | operator-> () const |
| Const access a member of the 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... | |
| void | ad_forward (const std::vector< std::vector< MX > > &fseed, std::vector< std::vector< MX > > &fsens) const |
| Called from MXFunction. More... | |
| void | ad_reverse (const std::vector< std::vector< MX > > &aseed, std::vector< std::vector< MX > > &asens) const |
| Called from MXFunction. More... | |
| std::vector< casadi_int > | get_row () const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
| std::vector< casadi_int > | get_colind () const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
| const casadi_int * | row () const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
| casadi_int | row (casadi_int el) const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
| const casadi_int * | colind () const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
| casadi_int | colind (casadi_int col) const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
Static Public Member Functions | |
| static std::string | type_name () |
| Get type name. More... | |
| static MX | create (MXNode *node) |
| Create from node. More... | |
| static std::vector< MX > | createMultipleOutput (MXNode *node) |
| Create from node (multiple-outputs) 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 | _sym (const std::string &name, const Sparsity &sp) |
| static MX | logsumexp (const MX &x) |
| static MX | binary (casadi_int op, const MX &x, const MX &y, bool unique_x=false, bool unique_y=false) |
| Create 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 bool | is_equal (const MX &x, const MX &y, casadi_int depth=0) |
| static MX | mmin (const MX &x) |
| static MX | mmax (const MX &x) |
| static MX | horzcat (const std::vector< MX > &x) |
| static MX | diagcat (const std::vector< MX > &x) |
| static MX | vertcat (const std::vector< MX > &x) |
| static std::vector< MX > | horzsplit (const MX &x, const std::vector< casadi_int > &offset) |
| static std::vector< MX > | diagsplit (const MX &x, const std::vector< casadi_int > &offset1, const std::vector< casadi_int > &offset2) |
| static std::vector< MX > | vertsplit (const MX &x, const std::vector< casadi_int > &offset) |
| static MX | blockcat (const std::vector< std::vector< MX > > &v) |
| static MX | mtimes (const MX &x, const MX &y, const std::string &blas="reference") |
| static MX | mac (const MX &x, const MX &y, const MX &z, const std::string &blas="reference") |
| static MX | reshape (const MX &x, casadi_int nrow, casadi_int ncol) |
| static MX | reshape (const MX &x, const Sparsity &sp) |
| static MX | sparsity_cast (const MX &x, const Sparsity &sp) |
| static MX | kron (const MX &x, const MX &b) |
| static MX | kron_contract (const MX &m, const MX &x, bool inner) |
| static MX | repmat (const MX &x, casadi_int n, casadi_int m=1) |
| static MX | linspace (const MX &a, const MX &b, casadi_int nsteps) |
| static MX | jacobian (const MX &f, const MX &x, const Dict &opts=Dict()) |
| static MX | hessian (const MX &f, const MX &x, const Dict &opts=Dict()) |
| static MX | hessian (const MX &f, const MX &x, MX &g, const Dict &opts=Dict()) |
| static std::vector< std::vector< MX > > | forward (const std::vector< MX > &ex, const std::vector< MX > &arg, const std::vector< std::vector< MX > > &v, const Dict &opts=Dict()) |
| static std::vector< std::vector< MX > > | reverse (const std::vector< MX > &ex, const std::vector< MX > &arg, const std::vector< std::vector< MX > > &v, const Dict &opts=Dict()) |
| static std::vector< bool > | which_depends (const MX &expr, const MX &var, casadi_int order=1, bool tr=false) |
| static Sparsity | jacobian_sparsity (const MX &f, const MX &x) |
| static MX | substitute (const MX &ex, const MX &v, const MX &vdef) |
| static std::vector< MX > | substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef) |
| static void | substitute_inplace (const std::vector< MX > &v, std::vector< MX > &vdef, std::vector< MX > &ex, bool reverse) |
| static MX | solve (const MX &a, const MX &b) |
| static MX | solve (const MX &a, const MX &b, const std::string &lsolver, const Dict &dict=Dict()) |
| static MX | inv_minor (const MX &A) |
| static MX | inv_node (const MX &A) |
| static MX | inv (const MX &A, const std::string &lsolver="qr", const Dict &dict=Dict()) |
| static MX | pinv (const MX &A, const std::string &lsolver="qr", const Dict &dict=Dict()) |
| static MX | expm_const (const MX &A, const MX &t) |
| static MX | expm (const MX &A) |
| static casadi_int | n_nodes (const MX &x) |
| static std::string | print_operator (const MX &x, const std::vector< std::string > &args) |
| static void | extract (std::vector< MX > &ex, std::vector< MX > &v, std::vector< MX > &vdef, const Dict &opts=Dict()) |
| static void | shared (std::vector< MX > &ex, std::vector< MX > &v, std::vector< MX > &vdef, const std::string &v_prefix, const std::string &v_suffix) |
| static MX | if_else (const MX &cond, const MX &if_true, const MX &if_false, bool short_circuit=false) |
| static MX | conditional (const MX &ind, const std::vector< MX > &x, const MX &x_default, bool short_circuit=false) |
| static bool | depends_on (const MX &x, const MX &arg) |
| static bool | contains_all (const std::vector< MX > &v, const std::vector< MX > &n) |
| static bool | contains_any (const std::vector< MX > &v, const std::vector< MX > &n) |
| static MX | simplify (const MX &x) |
| static MX | transform (const MX &x, const Dict &opts=Dict()) |
| static MX | transform (const MX &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict()) |
| static std::vector< MX > | transform (const std::vector< MX > &x, const Dict &opts=Dict()) |
| static std::vector< MX > | transform (const std::vector< MX > &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict()) |
| static MX | dot (const MX &x, const MX &y) |
| static MX | mrdivide (const MX &a, const MX &b) |
| static MX | mldivide (const MX &a, const MX &b) |
| static MX | norm_2 (const MX &x) |
| static MX | norm_fro (const MX &x) |
| static MX | norm_1 (const MX &x) |
| static MX | norm_inf (const MX &x) |
| static MX | unite (const MX &A, const MX &B) |
| static MX | trace (const MX &x) |
| static MX | diag (const MX &x) |
| static MX | sum2 (const MX &x) |
| static MX | sum1 (const MX &x) |
| static MX | polyval (const MX &p, const MX &x) |
| static MX | det (const MX &x) |
| static MX | det (const MX &x, const std::string &lsolver, const Dict &opts=Dict()) |
| static std::vector< MX > | symvar (const MX &x) |
| static MX | nullspace (const MX &A) |
| static MX | repsum (const MX &x, casadi_int n, casadi_int m=1) |
| static MX | densify (const MX &x, const MX &val=0) |
| static MX | _bilin (const MX &A, const MX &x, const MX &y) |
| static MX | _rank1 (const MX &A, const MX &alpha, const MX &x, const MX &y) |
| static MX | project (const MX &x, const Sparsity &sp, bool intersect=false) |
| static MX | cumsum (const MX &x, casadi_int axis=-1) |
| static MX | _logsumexp (const MX &x) |
| static std::vector< MX > | cse (const std::vector< MX > &e) |
| static void | extract_parametric (const MX &expr, const MX &par, MX &expr_ret, std::vector< MX > &symbols, std::vector< MX > ¶metric, const Dict &opts) |
| static void | separate_linear (const MX &expr, const MX &sym_lin, const MX &sym_const, MX &expr_const, MX &expr_lin, MX &expr_nonlin) |
| static MX | find (const MX &x) |
| static MX | low (const MX &v, const MX &p, const Dict &options=Dict()) |
| static MX | graph_substitute (const MX &x, const std::vector< MX > &v, const std::vector< MX > &vdef) |
| static MX | graph_substitute (const MX &x, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated) |
| static std::vector< MX > | graph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef) |
| static std::vector< MX > | graph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated) |
| static MX | matrix_expand (const MX &e, const std::vector< MX > &boundary, const Dict &options) |
| static std::vector< MX > | matrix_expand (const std::vector< MX > &e, const std::vector< MX > &boundary, const Dict &options) |
| static MX | lift (const MX &x, const MX &x_guess) |
| static DM | evalf (const MX &m) |
| static MX | bspline (const MX &x, const DM &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > °ree, casadi_int m, const Dict &opts=Dict()) |
| static MX | bspline (const MX &x, const MX &coeffs, const std::vector< std::vector< double > > &knots, const std::vector< casadi_int > °ree, casadi_int m, const Dict &opts=Dict()) |
| static MX | bspline (const MX &x, const MX &coeffs, const std::vector< MX > &knots, const std::vector< casadi_int > °ree, casadi_int m, const Dict &opts=Dict()) |
| static MX | convexify (const MX &H, const Dict &opts=Dict()) |
| static MX | stop_diff (const MX &expr, casadi_int order) |
| static MX | stop_diff (const MX &expr, const MX &var, casadi_int order) |
| static std::vector< MX > | difference (const std::vector< MX > &a, const std::vector< MX > &b) |
| static MX | interp1d (const std::vector< double > &x, const MX &v, const std::vector< double > &xq, const std::string &mode, bool equidistant) |
| Functions called by friend functions defined here. More... | |
| static casadi_int | sprank (const MX &x) |
| Functions called by friend functions defined here. More... | |
| static casadi_int | norm_0_mul (const MX &x, const MX &y) |
| Functions called by friend functions defined here. More... | |
| static MX | tril (const MX &x, bool includeDiagonal=true) |
| Functions called by friend functions defined here. More... | |
| static MX | triu (const MX &x, bool includeDiagonal=true) |
| Functions called by friend functions defined here. More... | |
| static MX | sumsqr (const MX &x) |
| Functions called by friend functions defined here. More... | |
| static MX | linspace (const MX &a, const MX &b, casadi_int nsteps) |
| Functions called by friend functions defined here. More... | |
| static MX | cross (const MX &a, const MX &b, casadi_int dim=-1) |
| Functions called by friend functions defined here. More... | |
| static MX | skew (const MX &a) |
| Functions called by friend functions defined here. More... | |
| static MX | inv_skew (const MX &a) |
| Functions called by friend functions defined here. More... | |
| static MX | tril2symm (const MX &x) |
| Functions called by friend functions defined here. More... | |
| static MX | triu2symm (const MX &x) |
| Functions called by friend functions defined here. More... | |
| static MX | repsum (const MX &x, casadi_int n, casadi_int m=1) |
| Functions called by friend functions defined here. More... | |
| static MX | diff (const MX &x, casadi_int n=1, casadi_int axis=-1) |
| Functions called by friend functions defined here. More... | |
| static bool | is_linear (const MX &expr, const MX &var) |
| Functions called by friend functions defined here. More... | |
| static bool | is_quadratic (const MX &expr, const MX &var) |
| Functions called by friend functions defined here. More... | |
| static void | quadratic_coeff (const MX &expr, const MX &var, MX &A, MX &b, MX &c, bool check) |
| Functions called by friend functions defined here. More... | |
| static void | linear_coeff (const MX &expr, const MX &var, MX &A, MX &b, bool check) |
| Functions called by friend functions defined here. More... | |
| static MX | mpower (const MX &x, const MX &y) |
| static MX | soc (const MX &x, const MX &y) |
| static MX | linearize (const MX &f, const MX &x, const MX &x0, const Dict &opts=Dict()) |
| static MX | gradient (const MX &ex, const MX &arg, const Dict &opts=Dict()) |
| static MX | tangent (const MX &ex, const MX &arg, const Dict &opts=Dict()) |
| static MX | jtimes (const MX &ex, const MX &arg, const MX &v, bool tr=false, const Dict &opts=Dict()) |
| static MX | bilin (const MX &A, const MX &x, const MX &y) |
| Calculate bilinear/quadratic form x^T A y. More... | |
| static MX | rank1 (const MX &A, const MX &alpha, const MX &x, const MX &y) |
| Make a rank-1 update to a matrix A. More... | |
Construct symbolic primitives | |
The "sym" function is intended to work in a similar way as "sym" used in the Symbolic Toolbox for Matlab but instead creating a CasADi symbolic primitive. | |
| static MX | sym (const std::string &name, casadi_int nrow=1, casadi_int ncol=1) |
| Create an nrow-by-ncol symbolic primitive. More... | |
| static MX | sym (const std::string &name, const std::pair< casadi_int, casadi_int > &rc) |
| Construct a symbolic primitive with given dimensions, 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... | |
Protected Member Functions | |
| void | count_up () |
| void | count_down () |
Static Private Member Functions | |
| static MX | printme (const MX &x, const MX &y) |
| Debug printing: (x,y) -> x, printing x when evaluated. 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... | |
| typedef GenericMatrix<MX> casadi::MX::B |
|
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 |
| typedef MX casadi::MX::ScalarType |
| 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
Definition at line 61 of file mx.cpp.
References casadi::ZeroByZero::getInstance(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
Referenced by binary(), blockcat(), create(), createMultipleOutput(), cse(), diagcat(), extract(), extract_parametric(), eye(), graph_substitute(), horzcat(), repmat(), separate_linear(), set(), set_nz(), simplify_const_folding(), simplify_ref_count(), solve(), and vertcat().
| 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
Definition at line 111 of file mx.cpp.
References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
|
explicit |
Extra doc: https://github.com/casadi/casadi/wiki/L_q2
Definition at line 115 of file mx.cpp.
References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
|
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
Definition at line 107 of file mx.cpp.
References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
| 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
Definition at line 85 of file mx.cpp.
References casadi::ConstantMX::create(), densify(), casadi::GenericMatrix< MatType >::dim(), casadi::MXNode::get_nzref(), casadi::GenericMatrix< MatType >::is_column(), is_constant(), casadi::GenericMatrix< MatType >::is_dense(), casadi::Sparsity::is_reshape(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::Sparsity::nnz(), casadi::GenericShared< SharedObject, SharedObjectInternal >::own(), casadi::range(), reshape(), casadi::Sparsity::size(), casadi::GenericMatrix< MatType >::size1(), sparsity(), and casadi::str().
| 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
Definition at line 123 of file mx.cpp.
References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
| 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
Definition at line 127 of file mx.cpp.
References casadi::ConstantMX::create(), name(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
| 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
Definition at line 73 of file mx.cpp.
References casadi::ConstantMX::create(), casadi::Sparsity::dense(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
| casadi::MX::MX | ( | const std::vector< double > & | x | ) |
Extra doc: https://github.com/casadi/casadi/wiki/L_q7
Definition at line 81 of file mx.cpp.
References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
| 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
Definition at line 77 of file mx.cpp.
References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
| casadi::MX::~MX | ( | ) |
Extra doc: https://github.com/casadi/casadi/wiki/L_q9
| casadi::MX::MX | ( | const Sparsity & | sp, |
| double | val, | ||
| bool | dummy | ||
| ) |
Definition at line 119 of file mx.cpp.
References casadi::ConstantMX::create(), and casadi::GenericShared< SharedObject, SharedObjectInternal >::own().
|
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
Functions called by friend functions defined for GenericMatrix
Definition at line 3203 of file mx.cpp.
References casadi::MXNode::get_bilin().
Functions called by friend functions defined for GenericMatrix
Definition at line 3211 of file mx.cpp.
References casadi::MXNode::get_logsumexp().
Functions called by friend functions defined for GenericMatrix
Definition at line 3207 of file mx.cpp.
References casadi::MXNode::get_rank1().
Definition at line 949 of file mx.cpp.
References create(), name(), casadi::Sparsity::nnz(), and casadi::GenericMatrix< MX >::zeros().
| void casadi::MX::ad_forward | ( | const std::vector< std::vector< MX > > & | fseed, |
| std::vector< std::vector< MX > > & | fsens | ||
| ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_ro
| void casadi::MX::ad_reverse | ( | const std::vector< std::vector< MX > > & | aseed, |
| std::vector< std::vector< MX > > & | asens | ||
| ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_ro
|
inherited |
improper use will cause memory leaks!
Extra doc: https://github.com/casadi/casadi/wiki/L_at
Definition at line 96 of file generic_shared_impl.hpp.
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
Definition at line 746 of file mx.cpp.
References casadi::GenericMatrix< MatType >::dim(), and casadi::GenericMatrix< MatType >::is_scalar().
|
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
Definition at line 534 of file mx.cpp.
References casadi::GenericMatrix< MatType >::dim(), casadi::MXNode::get_binary(), casadi::GenericMatrix< MatType >::is_empty(), casadi::GenericMatrix< MatType >::is_scalar(), MX(), op(), repmat(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), and casadi::str().
Referenced by casadi::BinaryMX< ScX, ScY >::eval_mx(), and printme().
Functions called by friend functions defined for SparsityInterface
Definition at line 1254 of file mx.cpp.
References horzcat(), MX(), casadi::GenericMatrix< MX >::rows(), and vertcat().
Referenced by casadi::Expm::get_forward(), casadi::Expm::get_reverse(), and casadi::Conic::sens_kkt().
|
static |
Functions called by friend functions defined for this class
Definition at line 2217 of file mx.cpp.
References casadi::BSpline::create(), and casadi::Matrix< Scalar >::nonzeros().
Referenced by casadi::Function::bspline(), casadi::BSplineInterpolant::construct_graph(), and casadi::BSplineCommon::jac().
|
static |
Functions called by friend functions defined for this class
Definition at line 2234 of file mx.cpp.
References casadi::BSplineParametric::create().
|
static |
Functions called by friend functions defined for this class
Definition at line 2226 of file mx.cpp.
References casadi::BSplineParametric::create().
|
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
Definition at line 2242 of file mx.cpp.
References casadi::BSpline::dual().
Referenced by casadi::BSplineInterpolant::construct_graph().
|
inherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_au
Definition at line 31 of file shared_object.cpp.
Referenced by casadi::FmuFunction::check_mem_count(), casadi::MXFunction::export_code_body(), and casadi::BlazingSplineFunction::merge().
|
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 606 of file generic_matrix.hpp.
|
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.
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1386 of file mx.cpp.
References casadi::Function::conditional(), if_else(), symvar(), and casadi::SparsityInterface< MatType >::veccat().
Functions called by friend functions defined for GenericMatrix
Functions called by friend functions defined for GenericMatrix
Definition at line 2191 of file mx.cpp.
Functions called by friend functions defined for this class
Definition at line 2249 of file mx.cpp.
References casadi::MXNode::get_convexify().
|
protectedinherited |
Definition at line 133 of file generic_shared_impl.hpp.
|
protectedinherited |
Definition at line 132 of file generic_shared_impl.hpp.
Extra doc: https://github.com/casadi/casadi/wiki/L_qa
Definition at line 69 of file mx.cpp.
References MX().
Referenced by casadi::MXNode::_get_binary(), _sym(), casadi::Kron::create(), casadi::KronContract::create(), casadi::GetNonzerosParam::create(), casadi::SetNonzerosParam< Add >::create(), casadi::SetNonzeros< Add >::create(), casadi::Multiplication::create(), casadi::GetNonzeros::create(), casadi::Call::create_call(), createMultipleOutput(), deserialize(), casadi::MXNode::get_assert(), casadi::MXNode::get_bilin(), casadi::MXNode::get_bspline(), casadi::MXNode::get_convexify(), casadi::MXNode::get_det(), casadi::MXNode::get_diagcat(), casadi::MXNode::get_dot(), casadi::MXNode::get_dump(), casadi::MXNode::get_einstein(), casadi::MXNode::get_find(), casadi::MXNode::get_horzcat(), casadi::MXNode::get_inv(), casadi::MXNode::get_logsumexp(), casadi::MXNode::get_low(), casadi::MXNode::get_mmax(), casadi::MXNode::get_mmin(), casadi::MXNode::get_monitor(), casadi::MXNode::get_norm_1(), casadi::MXNode::get_norm_2(), casadi::MXNode::get_norm_fro(), casadi::MXNode::get_norm_inf(), casadi::Constant< Value >::get_nzref(), casadi::Call::get_output(), casadi::MultipleOutput::get_output(), casadi::MXNode::get_project(), casadi::Constant< Value >::get_project(), casadi::MXNode::get_rank1(), casadi::MXNode::get_repmat(), casadi::MXNode::get_repsum(), casadi::MXNode::get_reshape(), casadi::Constant< Value >::get_reshape(), casadi::MXNode::get_solve(), casadi::MXNode::get_solve_tril(), casadi::MXNode::get_solve_tril_unity(), casadi::MXNode::get_solve_triu(), casadi::MXNode::get_solve_triu_unity(), casadi::MXNode::get_sparsity_cast(), casadi::MXNode::get_subassign(), casadi::MXNode::get_subref(), casadi::MXNode::get_transpose(), casadi::Constant< Value >::get_transpose(), casadi::MXNode::get_unary(), casadi::MXNode::get_vertcat(), inf(), casadi::MXFunction::init(), and nan().
Extra doc: https://github.com/casadi/casadi/wiki/L_qb
Definition at line 131 of file mx.cpp.
References create(), get_output(), casadi::GenericMatrix< MX >::is_empty(), MX(), casadi::GenericMatrix< MX >::nnz(), casadi::MXNode::nout(), and casadi::GenericMatrix< MX >::size().
Referenced by casadi::Call::create(), casadi::MXNode::get_diagsplit(), casadi::MXNode::get_horzsplit(), and casadi::MXNode::get_vertsplit().
|
staticinherited |
Definition at line 662 of file generic_matrix.hpp.
Functions called by friend functions defined for GenericMatrix
Definition at line 2635 of file mx.cpp.
References casadi::SimpleCache< K, T >::cache_map(), casadi::Call::create_call(), dep(), casadi::MXNode::dep_, casadi::Function::get(), get_output(), graph_substitute(), casadi::SimpleCache< K, T >::incache(), is_output(), join_primitives(), MX(), n_primitives(), op(), casadi::OP_CALL, casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, casadi::Function::serialize(), casadi::SimpleCache< K, T >::tocache(), which_function(), and which_output().
Functions called by friend functions defined for GenericMatrix
Definition at line 701 of file mx.cpp.
References casadi::GenericMatrix< MatType >::is_row(), casadi::Function::mapaccum(), casadi::GenericMatrix< MatType >::size2(), sparsity(), casadi::GenericMatrix< MX >::sym(), and T().
|
inherited |
Definition at line 112 of file generic_shared_impl.hpp.
Functions called by friend functions defined for GenericMatrix
Definition at line 926 of file mx.cpp.
References casadi::Sparsity::dense(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::MXNode::is_zero(), project(), repmat(), casadi::GenericMatrix< MatType >::size(), and sparsity().
| 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
Definition at line 786 of file mx.cpp.
References casadi::MXNode::dep().
Referenced by casadi::OptiNode::canon_expr(), casadi::Call::common_cond(), casadi::DaeBuilderInternal::create(), cse(), casadi::MXFunction::export_code_body(), casadi::MXNode::get_binary(), casadi::BinaryMX< ScX, ScY >::get_solve_tril(), casadi::BinaryMX< ScX, ScY >::get_solve_triu(), inv(), is_doubled(), casadi::DaeBuilderInternal::jac_vdef_v_from_calls(), casadi::Onnx::load(), casadi::DaeBuilderInternal::load_fmi_description(), and casadi::DaeBuilderInternal::when().
Functions called by friend functions defined for GenericMatrix
Definition at line 2158 of file mx.cpp.
References casadi::get_ptr(), and casadi::GenericMatrix< MatType >::nnz().
|
static |
Counterpart of serialize; use StringDeserializer.unpack from Python.
Extra doc: https://github.com/casadi/casadi/wiki/L_r0
Definition at line 866 of file mx.cpp.
References create(), and casadi::MXNode::deserialize().
Functions called by friend functions defined for GenericMatrix
Definition at line 2013 of file mx.cpp.
Functions called by friend functions defined for GenericMatrix
Definition at line 2017 of file mx.cpp.
References casadi::Linsol::det(), and sparsity().
Functions called by friend functions defined for GenericMatrix
Definition at line 1455 of file mx.cpp.
References casadi::Sparsity::get_diag(), casadi::MXNode::get_nzref(), mapping(), and sparsity().
Functions called by friend functions defined for SparsityInterface
Definition at line 1158 of file mx.cpp.
References casadi::has_empty(), MX(), and casadi::trim_empty().
|
static |
Functions called by friend functions defined for SparsityInterface
Definition at line 1223 of file mx.cpp.
References casadi::check_offset(), casadi::MXNode::get_diagsplit(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().
|
staticinherited |
Definition at line 668 of file generic_matrix.hpp.
|
static |
Functions called by friend functions defined for this class
Definition at line 3092 of file mx.cpp.
Referenced by stop_diff().
|
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
Definition at line 325 of file generic_matrix.hpp.
|
inherited |
Definition at line 35 of file shared_object.cpp.
References casadi::GenericShared< SharedObject, SharedObjectInternal >::is_null().
Referenced by casadi::WeakRefInternal::disp(), casadi::Nlpsol::disp_more(), and casadi::CsparseInterface::nfact().
Functions called by friend functions defined for GenericMatrix
Definition at line 738 of file mx.cpp.
References casadi::MXNode::get_dot().
Referenced by casadi::RuntimeIntegrator::jump_function().
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
Definition at line 757 of file mx.cpp.
References casadi::MXNode::get_dump().
|
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
Definition at line 685 of file mx.cpp.
References casadi::C.
Referenced by casadi::Einstein::ad_forward(), casadi::Einstein::ad_reverse(), and casadi::derivative_coeff_mx().
|
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
Definition at line 693 of file mx.cpp.
References casadi::MXNode::get_einstein(), casadi::product(), and casadi::GenericMatrix< MX >::zeros().
| 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
Definition at line 665 of file mx.cpp.
References casadi::Sparsity::enlarge(), casadi::MXNode::get_nzref(), casadi::GenericMatrix< MX >::nnz(), casadi::range(), and sparsity().
| 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
Definition at line 651 of file mx.cpp.
References casadi::Sparsity::erase(), casadi::MXNode::get_nzref(), mapping(), casadi::GenericMatrix< MX >::nnz(), casadi::GenericMatrix< MatType >::size(), and sparsity().
| 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
Definition at line 619 of file mx.cpp.
References casadi::Sparsity::erase(), casadi::MXNode::get_nzref(), mapping(), casadi::GenericMatrix< MX >::nnz(), casadi::GenericMatrix< MatType >::size(), and sparsity().
Referenced by set().
| 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
Definition at line 3216 of file mx.cpp.
References n_dep(), and casadi::str().
Functions called by friend functions defined for GenericMatrix
Definition at line 2147 of file mx.cpp.
References casadi::expmsol(), and sparsity().
Functions called by friend functions defined for GenericMatrix
Definition at line 2140 of file mx.cpp.
References casadi::expmsol(), and sparsity().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1733 of file mx.cpp.
References casadi::MXFunction::algorithm_, casadi::Function::get(), MX(), op(), casadi::OP_CALL, casadi::OP_CONST, casadi::OP_OUTPUT, casadi::OP_PARAMETER, casadi::replace(), casadi::sort(), and casadi::GenericMatrix< MX >::sym().
Referenced by shared().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 2803 of file mx.cpp.
References join_primitives(), MX(), n_primitives(), op(), casadi::OP_CONST, casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, casadi::register_symbol(), and split_primitives().
|
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
Definition at line 603 of file mx.cpp.
References casadi::Matrix< double >::eye(), and MX().
Referenced by casadi::OptiNode::canon_expr(), and inv().
Functions called by friend functions defined for this class
Definition at line 2209 of file mx.cpp.
References casadi::MXNode::get_find().
Referenced by casadi::DaeBuilderInternal::create(), graph_substitute(), casadi::DaeBuilderInternal::hess_v_v_from_calls(), casadi::DaeBuilderInternal::jac_vdef_v_from_calls(), and casadi::register_symbol().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1942 of file mx.cpp.
References casadi::FunctionInternal::call_forward(), casadi::extract_from_dict(), and op().
| MXNode * casadi::MX::get | ( | ) | const |
Definition at line 567 of file mx.cpp.
References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().
Referenced by casadi::MXNode::_get_binary(), casadi::Constant< Value >::_get_binary(), casadi::DaeBuilderInternal::create(), get(), is_equal(), is_norm(), casadi::DaeBuilderInternal::jac_vdef_v_from_calls(), casadi::register_symbol(), reset_dump_count(), casadi::OptiNode::set_meta(), and casadi::OptiNode::set_meta_con().
|
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
Definition at line 2962 of file mx.hpp.
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
Definition at line 189 of file mx.cpp.
References get_nz(), casadi::MXNode::get_nzref(), casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MX >::is_column(), casadi::GenericMatrix< MX >::is_dense(), casadi::GenericMatrix< MX >::is_row(), casadi::GenericMatrix< MatType >::is_row(), mapping(), casadi::Matrix< Scalar >::nonzeros(), casadi::Matrix< Scalar >::sparsity(), sparsity(), casadi::Sparsity::sub(), and casadi::Sparsity::T().
| 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
Definition at line 169 of file mx.cpp.
References casadi::MXNode::get_nzref(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_vector(), mapping(), casadi::Matrix< Scalar >::nonzeros(), sparsity(), and casadi::Sparsity::sub().
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
Definition at line 164 of file mx.cpp.
References casadi::Slice::all(), get(), and casadi::GenericMatrix< MX >::size2().
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
Definition at line 216 of file mx.cpp.
References casadi::GenericMatrix< MX >::dim(), get_nz(), and casadi::GenericMatrix< MX >::is_dense().
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
Definition at line 232 of file mx.cpp.
References casadi::GenericExpression< MX >::floor(), casadi::MXNode::get_nz_ref(), casadi::GenericMatrix< MX >::is_dense(), and casadi::GenericMatrix< MX >::size1().
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
Definition at line 227 of file mx.cpp.
References casadi::Slice::apply(), casadi::MXNode::get_nz_ref(), casadi::GenericMatrix< MX >::is_dense(), casadi::GenericMatrix< MX >::size1(), and casadi::GenericMatrix< MX >::size2().
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
Definition at line 184 of file mx.cpp.
References casadi::Slice::all(), get(), and casadi::GenericMatrix< MX >::numel().
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
Definition at line 159 of file mx.cpp.
References casadi::Slice::all(), get(), and casadi::GenericMatrix< MX >::size1().
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
Definition at line 222 of file mx.cpp.
References casadi::Slice::apply(), casadi::GenericExpression< MX >::floor(), casadi::MXNode::get_nz_ref(), casadi::GenericMatrix< MX >::is_dense(), and casadi::GenericMatrix< MX >::size1().
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
Definition at line 154 of file mx.cpp.
References casadi::Slice::all(), get(), casadi::GenericMatrix< MX >::size1(), and casadi::GenericMatrix< MX >::size2().
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
Definition at line 208 of file mx.cpp.
References project(), casadi::GenericMatrix< MX >::size(), casadi::Sparsity::size(), and casadi::str().
|
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
Definition at line 3199 of file mx.cpp.
References casadi::Function::free_mx().
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
Definition at line 3195 of file mx.cpp.
References casadi::Function::mx_in().
|
static |
Extra doc: https://github.com/casadi/casadi/wiki/L_rk
Definition at line 945 of file mx.cpp.
Referenced by is_doubled(), and casadi::MXNode::maxDepth().
| 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
Definition at line 633 of file mx.cpp.
References get_nz(), casadi::GenericMatrix< MatType >::nnz(), casadi::GenericMatrix< MX >::nz(), and primitives().
|
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
Definition at line 411 of file mx.cpp.
References get_nz(), casadi::MXNode::get_nzref(), casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MX >::is_column(), casadi::GenericMatrix< MX >::is_row(), casadi::GenericMatrix< MatType >::is_row(), casadi::GenericMatrix< MX >::nnz(), casadi::GenericMatrix< MatType >::nnz(), casadi::Matrix< Scalar >::nonzeros(), casadi::Matrix< Scalar >::sparsity(), casadi::str(), casadi::Sparsity::T(), and casadi::GenericMatrix< MX >::zeros().
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
Definition at line 449 of file mx.cpp.
References casadi::MXNode::get_nz_ref().
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
Definition at line 459 of file mx.cpp.
References casadi::MXNode::get_nz_ref().
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
Definition at line 444 of file mx.cpp.
References casadi::MXNode::get_nz_ref().
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
Definition at line 454 of file mx.cpp.
References casadi::MXNode::get_nz_ref().
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
Definition at line 406 of file mx.cpp.
References casadi::Slice::all(), and casadi::GenericMatrix< MX >::nnz().
Referenced by get(), casadi::get_boor(), get_nonzeros(), get_nz(), casadi::interpn_G(), and interpn_linear().
| 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
Definition at line 905 of file mx.cpp.
References casadi::MXNode::get_output().
Referenced by createMultipleOutput(), cse(), and graph_substitute().
|
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 |
|
inlineinherited |
Definition at line 91 of file shared_object.hpp.
| casadi_int casadi::MX::get_temp | ( | ) | const |
|
inherited |
Definition at line 102 of file generic_shared_impl.hpp.
|
staticinherited |
Functions called by friend functions defined here
|
static |
Functions called by friend functions defined for this class
Definition at line 1544 of file mx.cpp.
Referenced by cse(), graph_substitute(), and matrix_expand().
|
static |
Functions called by friend functions defined for this class
Definition at line 1549 of file mx.cpp.
References graph_substitute().
|
static |
Functions called by friend functions defined for this class
Definition at line 1554 of file mx.cpp.
References graph_substitute().
|
static |
Functions called by friend functions defined for this class
Definition at line 1560 of file mx.cpp.
References casadi::MXFunction::algorithm_, casadi::any(), casadi::GenericMatrix< MX >::dim(), find(), get_output(), casadi::MXNode::get_output(), casadi::MXNode::has_output(), is_equal(), MX(), n_primitives(), casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, casadi::GenericMatrix< MX >::size(), and casadi::str().
| bool casadi::MX::has_duplicates | ( | ) | const |
If a symbolic primitive appears more than once in this expression (a valid Function input), returns true and warns with the name of the duplicate. Only defined for valid inputs; other nodes raise an error. Note: marks the visited primitives using MX::set_temp; call reset_input() afterwards.
>>> x = MX.sym("x", 2)
>>> vertcat(x, x).has_duplicates()
True
>>> vertcat(x, x).reset_input()
>>> vertcat(x, MX.sym("y")).has_duplicates()
False
>> x = MX.sym('x', 2);
>> vertcat(x, x).has_duplicates()
...
1
>> vertcat(x, x).reset_input();
>> vertcat(x, MX.sym('y')).has_duplicates()
0
julia> x = ca.MX.sym("x", 2);
julia> ca.has_duplicates([x; x])
true
julia> ca.reset_input([x; x])
julia> ca.has_duplicates([x; ca.MX.sym("y")])
false
Extra doc: https://github.com/casadi/casadi/wiki/L_qs
| 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
Functions called by friend functions defined for GenericMatrix
Definition at line 1925 of file mx.cpp.
Functions called by friend functions defined for GenericMatrix
Definition at line 1930 of file mx.cpp.
References casadi::GenericMatrix< MX >::gradient, and jacobian().
Functions called by friend functions defined for SparsityInterface
Definition at line 1122 of file mx.cpp.
References casadi::GenericMatrix< MX >::dim(), casadi::has_empty(), MX(), casadi::GenericExpression< MX >::ne(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MX >::size1(), casadi::str(), casadi::trim_empty(), and casadi::GenericMatrix< MX >::zeros().
Referenced by blockcat(), and vertcat().
|
static |
Functions called by friend functions defined for SparsityInterface
Definition at line 1209 of file mx.cpp.
References casadi::check_offset(), casadi::MXNode::get_horzsplit(), casadi::SparsityInterface< MatType >::offset(), and casadi::GenericMatrix< MatType >::size2().
Referenced by vertsplit().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1364 of file mx.cpp.
References casadi::Function::if_else(), casadi::GenericExpression< MX >::if_else_zero(), symvar(), and casadi::SparsityInterface< MatType >::veccat().
Referenced by conditional().
|
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
Definition at line 579 of file mx.cpp.
References casadi::Sparsity::dense(), and inf().
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
Definition at line 587 of file mx.cpp.
References casadi::ConstantMX::create(), and create().
Referenced by inf(), and casadi::init_gen().
|
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
Definition at line 583 of file mx.cpp.
References inf().
| 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
Definition at line 858 of file mx.cpp.
Referenced by casadi::MXFunction::export_code_body(), and casadi::Onnx::load().
|
staticinherited |
Definition at line 648 of file generic_matrix.hpp.
|
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
Definition at line 3138 of file mx.cpp.
References casadi::GenericMatrix< MatType >::dim(), get_nz(), casadi::interpn_G(), casadi::GenericMatrix< MatType >::is_vector(), low(), n_out(), casadi::GenericMatrix< MatType >::numel(), op(), casadi::product(), casadi::GenericMatrix< MatType >::size(), and casadi::str().
Referenced by casadi::LinearInterpolant::do_inline().
| 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
Definition at line 1090 of file mx.cpp.
References dep(), is_op(), and casadi::OP_INV.
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 2030 of file mx.cpp.
References eye(), casadi::GenericMatrix< MatType >::size1(), and solve().
Functions called by friend functions defined for GenericMatrix
Functions called by friend functions defined for GenericMatrix
Definition at line 2022 of file mx.cpp.
References casadi::MXNode::get_inv().
|
staticinherited |
Definition at line 664 of file generic_matrix.hpp.
| 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
Definition at line 846 of file mx.cpp.
Referenced by casadi::MXFunction::export_code_body(), and is_commutative().
| 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
Definition at line 806 of file mx.cpp.
References casadi::OP_CALL.
Referenced by casadi::BlazingSplineFunction::merge().
|
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
Definition at line 882 of file mx.cpp.
References is_binary(), is_unary(), and op().
| 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
Definition at line 802 of file mx.cpp.
References casadi::OP_CONST.
Referenced by casadi::MXNode::_get_binary(), casadi::constant_ints(), casadi::DaeBuilderInternal::create(), casadi::ConstantMX::get_dot(), casadi::MXNode::get_einstein(), casadi::Constant< Value >::get_nzassign(), is_regular(), casadi::DaeBuilderInternal::load_fmi_description(), MX(), casadi::OptiNode::subject_to(), and casadi::MXNode::~MXNode().
|
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
Definition at line 1085 of file mx.cpp.
References dep(), get_max_depth(), is_equal(), op(), casadi::OP_ADD, and casadi::OP_TWICE.
|
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.
Functions called by friend functions defined for GenericExpression
Definition at line 870 of file mx.cpp.
References get(), and casadi::MXNode::is_equal().
Referenced by casadi::BinaryMX< ScX, ScY >::_get_binary(), casadi::UnaryMX::_get_binary(), casadi::Call::common_cond(), casadi::MXNode::get_binary(), graph_substitute(), is_doubled(), casadi::BinaryMX< ScX, ScY >::is_equal(), casadi::MXNode::sameOpAndDeps(), and substitute().
| 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
Definition at line 1029 of file mx.cpp.
Referenced by mac().
| 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
|
staticinherited |
Definition at line 670 of file generic_matrix.hpp.
| 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
Definition at line 830 of file mx.cpp.
References casadi::OP_MTIMES.
| 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
Definition at line 834 of file mx.cpp.
References get().
|
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
Definition at line 826 of file mx.cpp.
References op().
Referenced by casadi::OptiNode::canon_expr(), inv(), and casadi::DaeBuilderInternal::when().
| 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
Definition at line 814 of file mx.cpp.
Referenced by casadi::DaeBuilderInternal::create(), cse(), and casadi::DaeBuilderInternal::jac_vdef_v_from_calls().
|
staticinherited |
Definition at line 671 of file generic_matrix.hpp.
| 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
Definition at line 1065 of file mx.cpp.
References is_constant(), and casadi::Matrix< Scalar >::is_regular().
|
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
Definition at line 465 of file generic_matrix.hpp.
|
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
Definition at line 798 of file mx.cpp.
References casadi::OP_PARAMETER.
Referenced by casadi::DaeBuilder::add(), casadi::DaeBuilderInternal::der(), casadi::OptiNode::describe(), casadi::DaeBuilderInternal::find(), casadi::DaeBuilderInternal::load_fmi_description(), casadi::register_symbol(), and substitute_inplace().
| 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
Definition at line 1061 of file mx.cpp.
References op(), and casadi::OP_TRANSPOSE.
|
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
Definition at line 850 of file mx.cpp.
Referenced by casadi::MXFunction::export_code_body(), and is_commutative().
| 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
Definition at line 957 of file mx.cpp.
Referenced by casadi::DaeBuilderInternal::der(), casadi::OptiNode::set_domain(), and casadi::OptiNode::to_function().
| 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
Definition at line 1033 of file mx.cpp.
References casadi::GenericMatrix< MX >::nnz().
Referenced by casadi::MXNode::_get_binary(), casadi::MXNode::get_dot(), casadi::MXNode::get_einstein(), casadi::MXNode::get_mac(), and mac().
Functions called by friend functions defined for GenericMatrix
Definition at line 1913 of file mx.cpp.
References casadi::extract_from_dict(), and casadi::Function::get().
Referenced by hessian(), casadi::Scpgen::init(), and casadi::RuntimeIntegrator::jump_function().
Functions called by friend functions defined for GenericMatrix
Definition at line 2009 of file mx.cpp.
References casadi::_jacobian_sparsity().
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
Definition at line 1013 of file mx.cpp.
References n_primitives().
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
Definition at line 997 of file mx.cpp.
References casadi::MXNode::join_primitives(), and n_primitives().
Referenced by cse(), casadi::DaeBuilderInternal::der(), extract_parametric(), separate_linear(), simplify_const_folding(), and simplify_ref_count().
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
Definition at line 1005 of file mx.cpp.
References n_primitives().
|
staticinherited |
Functions called by friend functions defined here
Functions called by friend functions defined for SparsityInterface
Definition at line 2070 of file mx.cpp.
References casadi::MXNode::get_kron().
Functions called by friend functions defined for SparsityInterface
Definition at line 2074 of file mx.cpp.
References casadi::MXNode::get_kron_contract().
Referenced by casadi::kron_contract().
Functions called by friend functions defined for this class
Definition at line 766 of file mx.cpp.
References casadi::MXNode::_get_binary(), casadi::OP_LIFT, and sparsity().
|
staticinherited |
Definition at line 674 of file generic_matrix.hpp.
|
staticinherited |
Functions called by friend functions defined here
|
staticinherited |
Definition at line 661 of file generic_matrix.hpp.
Functions called by friend functions defined for GenericMatrix
Definition at line 2096 of file mx.cpp.
References vertcat().
|
staticinherited |
Functions called by friend functions defined for this class
Definition at line 2213 of file mx.cpp.
References casadi::MXNode::get_low().
Referenced by interpn_linear().
|
static |
Functions called by friend functions defined for SparsityInterface
Definition at line 715 of file mx.cpp.
References casadi::GenericMatrix< MatType >::dim(), casadi::MXNode::get_mac(), is_eye(), casadi::GenericMatrix< MatType >::is_scalar(), is_zero(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().
Referenced by mtimes().
| 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
|
static |
Functions called by friend functions defined for this class
Definition at line 2039 of file mx.cpp.
|
static |
Functions called by friend functions defined for this class
Definition at line 2043 of file mx.cpp.
References casadi::Function::call(), casadi::Function::expand(), graph_substitute(), sparsity(), casadi::GenericMatrix< MX >::sym(), symvar(), and casadi::SparsityInterface< MatType >::veccat().
Functions called by friend functions defined for GenericMatrix
Definition at line 781 of file mx.cpp.
References casadi::GenericMatrix< MatType >::is_scalar(), and solve().
Functions called by friend functions defined for GenericExpression
Definition at line 878 of file mx.cpp.
References casadi::MXNode::get_mmax().
Functions called by friend functions defined for GenericExpression
Definition at line 874 of file mx.cpp.
References casadi::MXNode::get_mmin().
| 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
Definition at line 753 of file mx.cpp.
References casadi::MXNode::get_monitor().
|
staticinherited |
Functions called by friend functions defined here
Functions called by friend functions defined for GenericMatrix
Definition at line 776 of file mx.cpp.
References casadi::GenericMatrix< MatType >::is_scalar(), solve(), and T().
Functions called by friend functions defined for SparsityInterface
Definition at line 675 of file mx.cpp.
References casadi::GenericMatrix< MatType >::is_scalar(), mac(), casadi::Sparsity::mtimes(), sparsity(), and casadi::GenericMatrix< MX >::zeros().
| 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
Definition at line 790 of file mx.cpp.
Referenced by casadi::DaeBuilderInternal::create(), eval_mx(), casadi::DaeBuilderInternal::load_fmi_description(), and print_operator().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1466 of file mx.cpp.
References casadi::Function::n_nodes().
| 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
Definition at line 901 of file mx.cpp.
Referenced by casadi::DaeBuilderInternal::create(), and interpn_linear().
| 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
Definition at line 961 of file mx.cpp.
Referenced by cse(), extract_parametric(), graph_substitute(), join_primitives(), primitives(), separate_linear(), simplify_const_folding(), simplify_ref_count(), and split_primitives().
| 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
Definition at line 794 of file mx.cpp.
Referenced by _sym(), casadi::DaeBuilder::add(), casadi::OptiNode::describe(), casadi::DaeBuilderInternal::find(), casadi::DaeBuilderInternal::import_binding_equations(), casadi::DaeBuilderInternal::import_dynamic_equations(), casadi::DaeBuilderInternal::import_model_variables(), casadi::DaeBuilderInternal::load_fmi_description(), and MX().
|
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
Definition at line 591 of file mx.cpp.
References casadi::Sparsity::dense(), and nan().
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
Definition at line 599 of file mx.cpp.
References casadi::ConstantMX::create(), and create().
Referenced by casadi::MXNode::_get_binary(), nan(), and casadi::qpsol_nlp().
|
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
Definition at line 595 of file mx.cpp.
References nan().
|
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
Definition at line 123 of file generic_matrix.hpp.
|
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
Definition at line 215 of file generic_matrix.hpp.
|
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
Definition at line 153 of file generic_matrix.hpp.
|
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
Definition at line 183 of file generic_matrix.hpp.
|
inlinestaticinherited |
Definition at line 651 of file generic_matrix.hpp.
Functions called by friend functions defined for GenericMatrix
Definition at line 1287 of file mx.cpp.
References casadi::MXNode::get_norm_1().
Functions called by friend functions defined for GenericMatrix
Definition at line 1275 of file mx.cpp.
References casadi::MXNode::get_norm_2(), casadi::GenericMatrix< MatType >::is_vector(), and norm_fro().
Functions called by friend functions defined for GenericMatrix
Definition at line 1283 of file mx.cpp.
References casadi::MXNode::get_norm_fro().
Referenced by norm_2().
Functions called by friend functions defined for GenericMatrix
Definition at line 1291 of file mx.cpp.
References casadi::MXNode::get_norm_inf().
Functions called by friend functions defined for GenericMatrix
Definition at line 2152 of file mx.cpp.
References casadi::Matrix< Scalar >::nullspace(), sparsity(), and casadi::GenericMatrix< Matrix< Scalar > >::sym().
|
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
Definition at line 247 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1bc
Definition at line 693 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1bb
Definition at line 683 of file generic_matrix.hpp.
Intended for writing unittests
Extra doc: https://github.com/casadi/casadi/wiki/L_2er
Definition at line 150 of file mx.cpp.
References casadi::MXNode::get_nzref(), and casadi::GenericMatrix< MX >::nz().
|
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
Definition at line 854 of file mx.cpp.
Referenced by casadi::UnaryMX::_get_binary(), binary(), cse(), extract(), extract_parametric(), forward(), casadi::MXNode::get_binary(), interpn_linear(), is_commutative(), is_doubled(), is_op(), is_transpose(), casadi::MXFunction::MXFunction(), reset_dump_count(), reverse(), and unary().
|
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
Definition at line 838 of file mx.cpp.
References casadi::MXNode::to_double().
|
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
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1bf
Definition at line 721 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1bd
Definition at line 701 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1bg
Definition at line 729 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1be
Definition at line 711 of file generic_matrix.hpp.
|
inline |
| 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
Definition at line 607 of file mx.cpp.
References casadi::MXNode::dep(), casadi::MXNode::get_unary(), and casadi::OP_NEG.
| MXNode * casadi::MX::operator-> | ( | ) |
Extra doc: https://github.com/casadi/casadi/wiki/L_qh
Definition at line 571 of file mx.cpp.
References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().
| const MXNode * casadi::MX::operator-> | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_qi
Definition at line 575 of file mx.cpp.
References casadi::GenericShared< SharedObject, SharedObjectInternal >::operator->().
|
inherited |
Assign the node to a node class pointer (or null)
Definition at line 89 of file generic_shared_impl.hpp.
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 2132 of file mx.cpp.
References mtimes(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), solve(), and T().
Functions called by friend functions defined for GenericMatrix
Definition at line 1480 of file mx.cpp.
References casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_vector(), casadi::GenericMatrix< MatType >::nnz(), and casadi::GenericMatrix< MatType >::nz().
| 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
Definition at line 965 of file mx.cpp.
References n_primitives().
Referenced by casadi::DaeBuilderInternal::der(), get_nonzeros(), casadi::DaeBuilderInternal::load_fmi_description(), casadi::OptiNode::set_domain(), and casadi::OptiNode::to_function().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1490 of file mx.cpp.
References casadi::MXNode::disp(), n_dep(), and casadi::str().
|
inherited |
Print the pointer to the internal class
Definition at line 43 of file shared_object.cpp.
References casadi::GenericShared< SharedObject, SharedObjectInternal >::get().
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
Definition at line 742 of file mx.cpp.
References binary(), and casadi::OP_PRINTME.
Functions called by friend functions defined for GenericMatrix
Definition at line 909 of file mx.cpp.
References casadi::GenericMatrix< MatType >::dim(), casadi::Sparsity::dim(), casadi::MXNode::get_project(), casadi::Sparsity::intersect(), casadi::GenericMatrix< MatType >::is_empty(), casadi::GenericMatrix< MatType >::size(), casadi::Sparsity::size(), and sparsity().
Referenced by densify(), get(), set(), set_nz(), simplify_const_folding(), and simplify_ref_count().
|
staticinherited |
Definition at line 672 of file generic_matrix.hpp.
|
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
Functions called by friend functions defined for SparsityInterface
Definition at line 2078 of file mx.cpp.
References casadi::MXNode::get_repmat(), MX(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().
|
staticinherited |
Definition at line 667 of file generic_matrix.hpp.
Functions called by friend functions defined for GenericMatrix
Definition at line 2092 of file mx.cpp.
References casadi::MXNode::get_repsum().
| void casadi::MX::reset_dump_count | ( | ) |
Definition at line 761 of file mx.cpp.
References get(), op(), and casadi::OP_DUMP.
| void casadi::MX::reset_input | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_qt
Functions called by friend functions defined for SparsityInterface
Definition at line 1334 of file mx.cpp.
References casadi::Sparsity::reshape(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), and sparsity().
Referenced by MX().
Functions called by friend functions defined for SparsityInterface
Definition at line 1342 of file mx.cpp.
References casadi::MXNode::get_reshape(), casadi::Sparsity::is_reshape(), and sparsity().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1973 of file mx.cpp.
References casadi::FunctionInternal::call_reverse(), casadi::extract_from_dict(), and op().
Referenced by substitute_inplace().
|
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 605 of file generic_matrix.hpp.
|
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.
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 2929 of file mx.cpp.
References join_primitives(), MX(), n_primitives(), casadi::OP_CONST, casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, split_primitives(), and casadi::GenericMatrix< MX >::zeros().
| 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
Definition at line 321 of file mx.cpp.
References erase(), casadi::Sparsity::get_col(), casadi::Sparsity::get_nz(), casadi::MXNode::get_nzassign(), casadi::Sparsity::get_row(), casadi::GenericMatrix< MX >::is_dense(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), MX(), casadi::GenericMatrix< MatType >::nnz(), casadi::GenericMatrix< MX >::nnz(), casadi::Matrix< Scalar >::nonzeros(), casadi::GenericMatrix< MX >::numel(), casadi::GenericMatrix< MX >::nz(), project(), set(), set_nz(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MX >::size1(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MX >::size2(), casadi::GenericMatrix< MatType >::size2(), casadi::Matrix< Scalar >::sparsity(), sparsity(), casadi::str(), T(), and casadi::Sparsity::triplet().
| 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
Definition at line 252 of file mx.cpp.
References casadi::GenericMatrix< MatType >::colind(), erase(), casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::Matrix< Scalar >::nonzeros(), repmat(), casadi::GenericMatrix< MatType >::row(), set(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MX >::size1(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MX >::size2(), casadi::GenericMatrix< MatType >::size2(), sparsity(), casadi::str(), casadi::Matrix< Scalar >::T(), T(), and casadi::GenericMatrix< MatType >::zeros().
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
Definition at line 247 of file mx.cpp.
References casadi::Slice::all(), set(), and casadi::GenericMatrix< MX >::size2().
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
Definition at line 316 of file mx.cpp.
References casadi::Slice::all(), and casadi::GenericMatrix< MX >::numel().
Referenced by set().
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
Definition at line 242 of file mx.cpp.
References casadi::Slice::all(), set(), and casadi::GenericMatrix< MX >::size1().
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
Definition at line 237 of file mx.cpp.
References casadi::Slice::all(), set(), casadi::GenericMatrix< MX >::size1(), and casadi::GenericMatrix< MX >::size2().
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
Definition at line 393 of file mx.cpp.
References densify(), casadi::Sparsity::find(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::GenericMatrix< MX >::size(), casadi::Sparsity::size(), and casadi::str().
|
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
Definition at line 3238 of file mx.hpp.
References set_nz().
Referenced by set_nz().
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
Definition at line 469 of file mx.cpp.
References casadi::MXNode::get_nzassign(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), MX(), casadi::GenericMatrix< MX >::nnz(), casadi::GenericMatrix< MatType >::nnz(), casadi::Matrix< Scalar >::nonzeros(), project(), set_nz(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), casadi::Matrix< Scalar >::sparsity(), sparsity(), casadi::str(), and T().
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
Definition at line 530 of file mx.cpp.
References casadi::MXNode::get_nzassign().
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
Definition at line 464 of file mx.cpp.
References casadi::Slice::all(), and casadi::GenericMatrix< MX >::nnz().
| void casadi::MX::set_temp | ( | casadi_int | t | ) | const |
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1906 of file mx.cpp.
References extract().
Functions called by friend functions defined for GenericMatrix
|
static |
Definition at line 2381 of file mx.cpp.
References casadi::MXFunction::algorithm_, casadi::MXNode::eval_mx(), casadi::Function::get(), casadi::get_const(), casadi::get_ptr(), join_primitives(), MX(), n_primitives(), casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, project(), casadi::simplify_const_folding_order(), split_primitives(), casadi::Function::sz_arg(), casadi::Function::sz_iw(), casadi::Function::sz_res(), casadi::Function::sz_w(), and casadi::MXFunction::workloc_.
|
static |
Definition at line 2511 of file mx.cpp.
References casadi::MXFunction::algorithm_, casadi::Function::get(), join_primitives(), MX(), n_primitives(), casadi::OP_INPUT, casadi::OP_OUTPUT, casadi::OP_PARAMETER, project(), split_primitives(), and casadi::MXFunction::workloc_.
|
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
Definition at line 358 of file generic_matrix.hpp.
|
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
Definition at line 366 of file generic_matrix.hpp.
|
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
Definition at line 278 of file generic_matrix.hpp.
|
inherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1au
Definition at line 290 of file generic_matrix.hpp.
|
staticinherited |
Definition at line 663 of file generic_matrix.hpp.
|
staticinherited |
Functions called by friend functions defined here
Functions called by friend functions defined for GenericMatrix
Definition at line 2108 of file mx.cpp.
References casadi::Sparsity::dense(), casadi::MXNode::get_solve_tril(), casadi::MXNode::get_solve_triu(), casadi::Sparsity::is_orthonormal(), casadi::GenericMatrix< MatType >::is_tril(), casadi::GenericMatrix< MatType >::is_triu(), mtimes(), MX(), casadi::GenericMatrix< MatType >::nnz(), casadi::GenericMatrix< MX >::nz(), casadi::Q, sparsity(), sparsity_cast(), and T().
Referenced by casadi::Conic::get_forward(), casadi::Nlpsol::get_forward(), casadi::Conic::get_reverse(), casadi::Nlpsol::get_reverse(), inv(), mldivide(), mrdivide(), pinv(), and solve().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 2126 of file mx.cpp.
References casadi::Sparsity::is_orthonormal(), casadi::Linsol::solve(), solve(), and sparsity().
| const Sparsity & casadi::MX::sparsity | ( | ) | const |
Every node has a fixed sparsity pattern, known at construction time.
>>> MX.sym("S", Sparsity.lower(2)).sparsity()
Sparsity(2x2,3nz)
>>> (MX.sym("S", Sparsity.lower(2)) + 1).sparsity()
Sparsity(2x2)
>> MX.sym('S', Sparsity.lower(2)).sparsity()
2x2,3nz
>> e = MX.sym('S', Sparsity.lower(2)) + 1;
>> e.sparsity()
2x2
julia> ca.sparsity(ca.MX.sym("S", ca.Sparsity.lower(2)))
Sparsity(2x2,3nz)
julia> ca.sparsity(ca.MX.sym("S", ca.Sparsity.lower(2)) + 1)
Sparsity(2x2)
Extra doc: https://github.com/casadi/casadi/wiki/L_qc
Definition at line 615 of file mx.cpp.
Referenced by casadi::MXNode::_get_binary(), casadi::Constant< Value >::_get_binary(), casadi::UnaryMX::_get_binary(), casadi::GetNonzeros::ad_forward(), casadi::SetNonzeros< Add >::ad_forward(), casadi::GetNonzeros::ad_reverse(), casadi::KronContract::ad_reverse(), casadi::Solve< Tr >::ad_reverse(), casadi::SparsityCast::ad_reverse(), casadi::DaeBuilderInternal::add(), casadi::Assertion::Assertion(), casadi::BinaryMX< ScX, ScY >::BinaryMX(), casadi::OptiNode::canon_expr(), casadi::Convexify::Convexify(), casadi::GetNonzerosParam::create(), casadi::SetNonzeros< Add >::create(), casadi::GetNonzeros::create(), cumsum(), densify(), det(), diag(), casadi::Diagsplit::Diagsplit(), casadi::Dot::Dot(), casadi::dplesol(), casadi::Dump::Dump(), enlarge(), erase(), casadi::GetNonzeros::eval_mx(), casadi::SetNonzeros< Add >::eval_mx(), expm(), expm_const(), casadi::MXFunction::export_code_body(), casadi::MXFunction::generate_lifted(), get(), casadi::MXNode::get_binary(), casadi::Variable::get_der(), casadi::MXNode::get_dot(), casadi::Nlpsol::get_forward(), casadi::MXNode::get_kron_contract(), casadi::MXNode::get_mac(), casadi::Project::get_nzref(), casadi::Nlpsol::get_reverse(), casadi::HorzRepmat::HorzRepmat(), casadi::HorzRepsum::HorzRepsum(), casadi::Horzsplit::Horzsplit(), casadi::Scpgen::init(), casadi::RuntimeIntegrator::jump_function(), casadi::Kron::Kron(), casadi::KronContract::KronContract(), lift(), casadi::Onnx::load(), casadi::Low::Low(), matrix_expand(), casadi::Monitor::Monitor(), mtimes(), casadi::Multiplication::Multiplication(), MX(), nullspace(), casadi::Horzcat::off(), casadi::Vertcat::off(), casadi::Diagcat::off(), casadi::DaeBuilderInternal::outputs(), casadi::MXFunction::print_arg(), project(), casadi::Rank1::Rank1(), casadi::register_symbol(), reshape(), set(), set_nz(), casadi::SetNonzeros< Add >::SetNonzeros(), casadi::SetNonzerosParam< Add >::SetNonzerosParam(), casadi::simpleIRK(), solve(), casadi::Solve< Tr >::Solve(), casadi::Bilin::sp_forward(), casadi::KronContract::sp_forward(), casadi::Bilin::sp_reverse(), casadi::KronContract::sp_reverse(), casadi::Project::sp_reverse(), sparsity_cast(), casadi::Transpose::Transpose(), casadi::PseudoDenseMultiplication::try_create(), unite(), and casadi::Vertsplit::Vertsplit().
Functions called by friend functions defined for SparsityInterface
Definition at line 1352 of file mx.cpp.
References casadi::MXNode::get_sparsity_cast(), casadi::GenericMatrix< MatType >::nnz(), casadi::Sparsity::nnz(), sparsity(), and casadi::str().
Referenced by solve().
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
Definition at line 989 of file mx.cpp.
References n_primitives().
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
Definition at line 973 of file mx.cpp.
References n_primitives().
Referenced by extract_parametric(), casadi::DaeBuilderInternal::load_fmi_description(), separate_linear(), simplify_const_folding(), and simplify_ref_count().
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
Definition at line 981 of file mx.cpp.
References n_primitives().
|
inlinestaticinherited |
Definition at line 650 of file generic_matrix.hpp.
Functions called by friend functions defined for this class
Definition at line 3020 of file mx.cpp.
References casadi::combine(), casadi::str(), symvar(), and casadi::SparsityInterface< MatType >::veccat().
Functions called by friend functions defined for this class
Definition at line 3052 of file mx.cpp.
References casadi::combine(), difference(), casadi::str(), symvar(), and casadi::SparsityInterface< MatType >::veccat().
Functions called by friend functions defined for GenericMatrix
Definition at line 1518 of file mx.cpp.
Referenced by casadi::RuntimeIntegrator::jump_function(), and casadi::DaeBuilderInternal::transition().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1522 of file mx.cpp.
References casadi::Function::call(), is_equal(), and casadi::GenericMatrix< MX >::size().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1496 of file mx.cpp.
References casadi::Function::get(), is_symbolic(), reverse(), casadi::GenericMatrix< MX >::size(), and casadi::str().
Functions called by friend functions defined for GenericMatrix
Definition at line 1476 of file mx.cpp.
References mtimes(), casadi::GenericMatrix< MX >::ones(), and casadi::GenericMatrix< MatType >::size1().
Functions called by friend functions defined for GenericMatrix
Definition at line 1472 of file mx.cpp.
References mtimes(), casadi::GenericMatrix< MX >::ones(), and casadi::GenericMatrix< MatType >::size2().
|
inlinestaticinherited |
Definition at line 660 of file generic_matrix.hpp.
|
inherited |
Definition at line 105 of file generic_shared_impl.hpp.
|
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.
Functions called by friend functions defined for GenericMatrix
Definition at line 2034 of file mx.cpp.
References casadi::Function::free_mx().
Referenced by conditional(), if_else(), matrix_expand(), casadi::OptiNode::set_initial(), casadi::OptiNode::set_linear_scale(), casadi::OptiNode::set_value(), stop_diff(), casadi::OptiNode::symvar(), transform(), and casadi::OptiNode::update_user_dict().
| 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
Definition at line 1098 of file mx.cpp.
References casadi::MXNode::get_transpose().
Referenced by casadi::Determinant::ad_forward(), casadi::Solve< Tr >::ad_forward(), casadi::BSplineCommon::ad_reverse(), casadi::Determinant::ad_reverse(), casadi::Inverse::ad_reverse(), casadi::conic_kkt_res(), casadi::BSplineInterpolant::construct_graph(), cumsum(), casadi::do_inline(), casadi::LinearInterpolant::do_inline(), casadi::get_boor(), casadi::MXNode::get_find(), casadi::Dple::get_forward(), casadi::Conic::get_reverse(), casadi::Expm::get_reverse(), casadi::Nlpsol::get_reverse(), casadi::SqicInterface::init(), mrdivide(), pinv(), casadi::Call::projectArg(), casadi::Conic::sens_kkt(), set(), set_nz(), solve(), vertcat(), and vertsplit().
|
staticinherited |
Functions called by friend functions defined here
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1446 of file mx.cpp.
References casadi::GenericMatrix< MatType >::is_square(), and casadi::GenericMatrix< MatType >::size2().
Functions called by friend functions defined for GenericMatrix
Definition at line 1306 of file mx.cpp.
Referenced by transform().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1310 of file mx.cpp.
References transform().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1315 of file mx.cpp.
References symvar(), casadi::Function::transform(), and casadi::SparsityInterface< MatType >::veccat().
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 1324 of file mx.cpp.
References symvar(), casadi::Function::transform(), and casadi::SparsityInterface< MatType >::veccat().
|
inlinestaticinherited |
Definition at line 654 of file generic_matrix.hpp.
|
staticinherited |
Definition at line 665 of file generic_matrix.hpp.
|
inlinestaticinherited |
Definition at line 657 of file generic_matrix.hpp.
|
staticinherited |
Definition at line 666 of file generic_matrix.hpp.
|
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
Definition at line 562 of file mx.cpp.
References casadi::MXNode::get_unary(), op(), and casadi::str().
Referenced by casadi::UnaryMX::eval_mx().
Functions called by friend functions defined for GenericMatrix
Definition at line 1420 of file mx.cpp.
References casadi::MXNode::get_nzassign(), mapping(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::sparsity(), sparsity(), casadi::Sparsity::unite(), and casadi::GenericMatrix< MX >::zeros().
Functions called by friend functions defined for SparsityInterface
Definition at line 1168 of file mx.cpp.
References casadi::GenericMatrix< MX >::dim(), casadi::MXNode::get_vertcat(), casadi::has_empty(), horzcat(), MX(), casadi::GenericExpression< MX >::ne(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MX >::size2(), casadi::str(), T(), casadi::trim_empty(), and casadi::GenericMatrix< MX >::zeros().
Referenced by blockcat(), casadi::Nlpsol::get_forward(), casadi::Nlpsol::get_reverse(), casadi::Blocksqp::init(), and linspace().
|
static |
Functions called by friend functions defined for SparsityInterface
Definition at line 1234 of file mx.cpp.
References casadi::check_offset(), casadi::MXNode::get_vertsplit(), horzsplit(), casadi::GenericMatrix< MatType >::is_column(), casadi::SparsityInterface< MatType >::offset(), casadi::GenericMatrix< MatType >::size1(), and T().
|
inherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_aw
Definition at line 130 of file generic_shared_impl.hpp.
|
static |
Functions called by friend functions defined for GenericMatrix
Definition at line 2005 of file mx.cpp.
References casadi::_which_depends().
| 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
Definition at line 810 of file mx.cpp.
Referenced by casadi::DaeBuilderInternal::create(), cse(), casadi::Onnx::load(), and casadi::BlazingSplineFunction::merge().
| 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
Definition at line 822 of file mx.cpp.
Referenced by casadi::DaeBuilderInternal::create(), cse(), and casadi::DaeBuilderInternal::jac_vdef_v_from_calls().
|
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.