Functions | |
| static ExType | casadi::GenericExpression< ExType >::plus (const ExType &x, const ExType &y) |
| Addition: (x,y) -> x + y. More... | |
| ExType & | casadi::GenericExpression< ExType >::operator+= (const ExType &y) |
| static MatType | casadi::GenericMatrix< MatType >::logsumexp (const MatType &x) |
Friends | |
| ExType | casadi::GenericExpression< ExType >::plus (const ExType &x, const ExType &y) |
| ExType | casadi::GenericExpression< ExType >::operator+ (const ExType &x, const ExType &y) |
| MatType | casadi::GenericMatrix< MatType >::interp1d (const std::vector< double > &x, const MatType &v, const std::vector< double > &xq, const std::string &mode, bool equidistant=false) |
| Performs 1d linear interpolation. More... | |
| MatType | casadi::GenericMatrix< MatType >::mpower (const MatType &x, const MatType &n) |
| Matrix power x^n. More... | |
| MatType | casadi::GenericMatrix< MatType >::soc (const MatType &x, const MatType &y) |
| Construct second-order-cone matrix. More... | |
| MatType | casadi::GenericMatrix< MatType >::mrdivide (const MatType &x, const MatType &n) |
| Matrix right divide, x/A (cf. slash '/' in MATLAB) More... | |
| MatType | casadi::GenericMatrix< MatType >::mldivide (const MatType &x, const MatType &n) |
| Matrix left divide, A\b (cf. backslash '\' in MATLAB) More... | |
| std::vector< MatType > | casadi::GenericMatrix< MatType >::symvar (const MatType &x) |
| Get all symbolic primitives present in an expression. More... | |
| MatType | casadi::GenericMatrix< MatType >::sumsqr (const MatType &x) |
| Calculate sum of squares: sum_ij X_ij^2. More... | |
| MatType | casadi::GenericMatrix< MatType >::logsumexp (const MatType &x) |
| x -> log(sum_i exp(x_i)) More... | |
| MatType | casadi::GenericMatrix< MatType >::logsumexp (const MatType &x, const MatType &margin) |
| Scaled version of logsumexp. More... | |
| MatType | casadi::GenericMatrix< MatType >::linspace (const MatType &a, const MatType &b, casadi_int nsteps) |
Matlab's linspace command. More... | |
| MatType | casadi::GenericMatrix< MatType >::cross (const MatType &a, const MatType &b, casadi_int dim=-1) |
Matlab's cross command. More... | |
| MatType | casadi::GenericMatrix< MatType >::skew (const MatType &a) |
| Generate a skew symmetric matrix from a 3-vector. More... | |
| MatType | casadi::GenericMatrix< MatType >::inv_skew (const MatType &a) |
| Generate the 3-vector progenitor of a skew symmetric matrix. More... | |
| MatType | casadi::GenericMatrix< MatType >::det (const MatType &A) |
| Matrix determinant (experimental) More... | |
| MatType | casadi::GenericMatrix< MatType >::det (const MatType &A, const std::string &lsolver, const Dict &dict=Dict()) |
| Matrix determinant through a linear solver factorization (experimental) More... | |
| MatType | casadi::GenericMatrix< MatType >::inv_minor (const MatType &A) |
| Matrix inverse by the adjugate (experimental) More... | |
| MatType | casadi::GenericMatrix< MatType >::inv (const MatType &A) |
| Matrix inverse. More... | |
| MatType | casadi::GenericMatrix< MatType >::inv (const MatType &A, const std::string &lsolver, const Dict &options=Dict()) |
| Matrix inverse using a linear solver plugin. More... | |
| MatType | casadi::GenericMatrix< MatType >::trace (const MatType &x) |
| Matrix trace. More... | |
| MatType | casadi::GenericMatrix< MatType >::tril2symm (const MatType &a) |
| Convert a lower triangular matrix to a symmetric one. More... | |
| MatType | casadi::GenericMatrix< MatType >::triu2symm (const MatType &a) |
| Convert a upper triangular matrix to a symmetric one. More... | |
| MatType | casadi::GenericMatrix< MatType >::norm_fro (const MatType &x) |
| Frobenius norm. More... | |
| MatType | casadi::GenericMatrix< MatType >::norm_2 (const MatType &x) |
| 2-norm More... | |
| MatType | casadi::GenericMatrix< MatType >::norm_1 (const MatType &x) |
| 1-norm More... | |
| MatType | casadi::GenericMatrix< MatType >::norm_inf (const MatType &x) |
| Infinity-norm. More... | |
| MatType | casadi::GenericMatrix< MatType >::diff (const MatType &x, casadi_int n=1, casadi_int axis=-1) |
| Returns difference (n-th order) along given axis (MATLAB convention) More... | |
| MatType | casadi::GenericMatrix< MatType >::cumsum (const MatType &x, casadi_int axis=-1) |
| Returns cumulative sum along given axis (MATLAB convention) More... | |
| MatType | casadi::GenericMatrix< MatType >::dot (const MatType &x, const MatType &y) |
| Inner product of two matrices. More... | |
| MatType | casadi::GenericMatrix< MatType >::nullspace (const MatType &A) |
| Computes the nullspace of a matrix A. More... | |
| MatType | casadi::GenericMatrix< MatType >::polyval (const MatType &p, const MatType &x) |
| Evaluate a polynomial with coefficients p in x. More... | |
| MatType | casadi::GenericMatrix< MatType >::diag (const MatType &A) |
| Get the diagonal of a matrix or construct a diagonal. More... | |
| MatType | casadi::GenericMatrix< MatType >::unite (const MatType &A, const MatType &B) |
| Unite two matrices with non-overlapping sparsity patterns. More... | |
| MatType | casadi::GenericMatrix< MatType >::densify (const MatType &x) |
| Make the matrix dense if not already. More... | |
| MatType | casadi::GenericMatrix< MatType >::densify (const MatType &x, const MatType &val) |
| Make the matrix dense and assign nonzeros to a value. More... | |
| MatType | casadi::GenericMatrix< MatType >::project (const MatType &A, const Sparsity &sp, bool intersect=false) |
| Create a new matrix with a given sparsity pattern but with the. More... | |
| MatType | casadi::GenericMatrix< MatType >::if_else (const MatType &cond, const MatType &if_true, const MatType &if_false, bool short_circuit=false) |
| Branching on MX nodes. More... | |
| MatType | casadi::GenericMatrix< MatType >::conditional (const MatType &ind, const std::vector< MatType > &x, const MatType &x_default, bool short_circuit=false) |
| Create a switch. More... | |
| bool | casadi::GenericMatrix< MatType >::depends_on (const MatType &f, const MatType &arg) |
| Check if expression depends on the argument. More... | |
| MatType | casadi::GenericMatrix< MatType >::substitute (const MatType &ex, const MatType &v, const MatType &vdef) |
| Substitute variable v with expression vdef in an expression ex. More... | |
| std::vector< MatType > | casadi::GenericMatrix< MatType >::substitute (const std::vector< MatType > &ex, const std::vector< MatType > &v, const std::vector< MatType > &vdef) |
| Substitute variables v with expressions vdef in multiple expressions ex. More... | |
| void | casadi::GenericMatrix< MatType >::substitute_inplace (const std::vector< MatType > &v, std::vector< MatType > &inout_vdef, std::vector< MatType > &inout_ex, bool reverse=false) |
| Inplace substitution with piggyback expressions. More... | |
| MatType | casadi::GenericMatrix< MatType >::cse (const MatType &e) |
| Common subexpression elimination. More... | |
| std::vector< MatType > | casadi::GenericMatrix< MatType >::cse (const std::vector< MatType > &e) |
| Common subexpression elimination over a list of expressions. More... | |
| MatType | casadi::GenericMatrix< MatType >::solve (const MatType &A, const MatType &b) |
| Solve a system of equations: A*x = b. More... | |
| MatType | casadi::GenericMatrix< MatType >::solve (const MatType &A, const MatType &b, const std::string &lsolver, const Dict &dict=Dict()) |
| Solve a system of equations: A*x = b, using a linear solver plugin. More... | |
| MatType | casadi::GenericMatrix< MatType >::linearize (const MatType &f, const MatType &x, const MatType &x0, const Dict &opts=Dict()) |
| Linearize an expression. More... | |
| MatType | casadi::GenericMatrix< MatType >::pinv (const MatType &A) |
| Computes the Moore-Penrose pseudo-inverse. More... | |
| MatType | casadi::GenericMatrix< MatType >::pinv (const MatType &A, const std::string &lsolver, const Dict &dict=Dict()) |
| Computes the Moore-Penrose pseudo-inverse using a linear solver plugin. More... | |
| MatType | casadi::GenericMatrix< MatType >::expm_const (const MatType &A, const MatType &t) |
| Calculate Matrix exponential. More... | |
| MatType | casadi::GenericMatrix< MatType >::expm (const MatType &A) |
| Calculate Matrix exponential. More... | |
| MatType | casadi::GenericMatrix< MatType >::jacobian (const MatType &ex, const MatType &arg, const Dict &opts=Dict()) |
| Calculate Jacobian. More... | |
| MatType | casadi::GenericMatrix< MatType >::gradient (const MatType &ex, const MatType &arg, const Dict &opts=Dict()) |
| Calculate the gradient of an expression. More... | |
| MatType | casadi::GenericMatrix< MatType >::tangent (const MatType &ex, const MatType &arg, const Dict &opts=Dict()) |
| Calculate the tangent of an expression. More... | |
| MatType | casadi::GenericMatrix< MatType >::jtimes (const MatType &ex, const MatType &arg, const MatType &v, bool tr=false, const Dict &opts=Dict()) |
| Calculate the Jacobian and multiply by a vector from the right. More... | |
| std::vector< std::vector< MatType > > | casadi::GenericMatrix< MatType >::forward (const std::vector< MatType > &ex, const std::vector< MatType > &arg, const std::vector< std::vector< MatType > > &v, const Dict &opts=Dict()) |
| Forward directional derivative. More... | |
| std::vector< std::vector< MatType > > | casadi::GenericMatrix< MatType >::reverse (const std::vector< MatType > &ex, const std::vector< MatType > &arg, const std::vector< std::vector< MatType > > &v, const Dict &opts=Dict()) |
| Reverse directional derivative. More... | |
| std::vector< bool > | casadi::GenericMatrix< MatType >::which_depends (const MatType &expr, const MatType &var, casadi_int order, bool tr) |
| Find out which variables enter with some order. More... | |
| Sparsity | casadi::GenericMatrix< MatType >::jacobian_sparsity (const MatType &f, const MatType &x) |
| Get the sparsity pattern of a jacobian. More... | |
| bool | casadi::GenericMatrix< MatType >::is_linear (const MatType &expr, const MatType &var) |
| Is expr linear in var? More... | |
| bool | casadi::GenericMatrix< MatType >::is_quadratic (const MatType &expr, const MatType &var) |
| Is expr quadratic in var? More... | |
| void | casadi::GenericMatrix< MatType >::quadratic_coeff (const MatType &expr, const MatType &var, MatType &A, MatType &b, MatType &c, bool check=true) |
| Recognizes quadratic form in scalar expression. More... | |
| void | casadi::GenericMatrix< MatType >::linear_coeff (const MatType &expr, const MatType &var, MatType &A, MatType &b, bool check=true) |
| Recognizes linear form in vector expression. More... | |
| void | casadi::GenericMatrix< MatType >::extract_parametric (const MatType &expr, const MatType &par, MatType &expr_ret, std::vector< MatType > &symbols, std::vector< MatType > ¶metric, const Dict &opts=Dict()) |
| Extract purely parametric parts from an expression graph. More... | |
| void | casadi::GenericMatrix< MatType >::extract_parametric (const std::vector< MatType > &expr, const MatType &par, std::vector< MatType > &expr_ret, std::vector< MatType > &symbols, std::vector< MatType > ¶metric, const Dict &opts=Dict()) |
| void | casadi::GenericMatrix< MatType >::extract_parametric (const std::vector< MatType > &expr, const std::vector< MatType > &par, std::vector< MatType > &expr_ret, std::vector< MatType > &symbols, std::vector< MatType > ¶metric, const Dict &opts=Dict()) |
| void | casadi::GenericMatrix< MatType >::extract_parametric (const MatType &expr, const std::vector< MatType > &par, MatType &expr_ret, std::vector< MatType > &symbols, std::vector< MatType > ¶metric, const Dict &opts=Dict()) |
| void | casadi::GenericMatrix< MatType >::separate_linear (const MatType &expr, const MatType &sym_lin, const MatType &sym_const, MatType &expr_const, MatType &expr_lin, MatType &expr_nonlin) |
| Separate an expression into subexpressions that are constant, linear and nonlinear. More... | |
| void | casadi::GenericMatrix< MatType >::separate_linear (const MatType &expr, const std::vector< MatType > &sym_lin, const std::vector< MatType > &sym_const, MatType &expr_const, MatType &expr_lin, MatType &expr_nonlin) |
| casadi_int | casadi::GenericMatrix< MatType >::n_nodes (const MatType &A) |
| Count the number of nodes in an expression graph. More... | |
| MatType | casadi::GenericMatrix< MatType >::simplify (const MatType &x) |
| Simplify an expression. More... | |
| std::string | casadi::GenericMatrix< MatType >::print_operator (const MatType &xb, const std::vector< std::string > &args) |
| Get a string representation for a binary MatType, using custom arguments. More... | |
| void | casadi::GenericMatrix< MatType >::extract (std::vector< MatType > &ex, std::vector< MatType > &v, std::vector< MatType > &vdef, const Dict &opts=Dict()) |
| Introduce intermediate variables for selected nodes in a graph. More... | |
| void | casadi::GenericMatrix< MatType >::shared (std::vector< MatType > &ex, std::vector< MatType > &v, std::vector< MatType > &vdef, const std::string &v_prefix="v_", const std::string &v_suffix="") |
| Extract shared subexpressions from an set of expressions. More... | |
| MatType | casadi::GenericMatrix< MatType >::repsum (const MatType &A, casadi_int n, casadi_int m=1) |
| Given a repeated matrix, computes the sum of repeated parts. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::adj (const Matrix< Scalar > &A) |
| Adjugate (classical adjoint) of a square matrix. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::minor (const Matrix< Scalar > &x, casadi_int i, casadi_int j) |
| Minor of a square matrix: determinant with one column and one row removed. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::cofactor (const Matrix< Scalar > &x, casadi_int i, casadi_int j) |
| Cofactor of a square matrix: (-1)^(i+j) times minor(x, i, j) More... | |
| void | casadi::Matrix< Scalar >::qr (const Matrix< Scalar > &A, Matrix< Scalar > &Q, Matrix< Scalar > &R) |
| Dense QR factorization using the modified Gram-Schmidt algorithm. More... | |
| void | casadi::Matrix< Scalar >::qr_sparse (const Matrix< Scalar > &A, Matrix< Scalar > &V, Matrix< Scalar > &R, Matrix< Scalar > &beta, std::vector< casadi_int > &prinv, std::vector< casadi_int > &pc, bool amd=true) |
| Sparse direct QR factorization with Householder reflections. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::qr_solve (const Matrix< Scalar > &b, const Matrix< Scalar > &v, const Matrix< Scalar > &r, const Matrix< Scalar > &beta, const std::vector< casadi_int > &prinv, const std::vector< casadi_int > &pc, bool tr=false) |
| Solve A*x = b (or A^T*x = b) with the factors returned by qr_sparse. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::chol (const Matrix< Scalar > &A) |
| Cholesky factorization of a symmetric positive definite matrix. More... | |
| void | casadi::Matrix< Scalar >::ldl (const Matrix< Scalar > &A, Matrix< Scalar > &D, Matrix< Scalar > <, std::vector< casadi_int > &p, bool amd=true) |
| Sparse LDL^T factorization of a symmetric matrix. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::ldl_solve (const Matrix< Scalar > &b, const Matrix< Scalar > &D, const Matrix< Scalar > <, const std::vector< casadi_int > &p) |
| Solve A*x = b with the factors returned by ldl. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::any (const Matrix< Scalar > &x) |
| True if any entry equals one. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::all (const Matrix< Scalar > &x) |
| True if every entry equals one. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::norm_inf_mul (const Matrix< Scalar > &x, const Matrix< Scalar > &y) |
| Infinity norm of a matrix product, without forming the product. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::sparsify (const Matrix< Scalar > &A, double tol=0) |
| Make a matrix sparse by turning numerical zeros into structural zeros. More... | |
| void | casadi::Matrix< Scalar >::expand (const Matrix< Scalar > &ex, Matrix< Scalar > &weights, Matrix< Scalar > &terms) |
| Expand a scalar SX expression as a weighted sum of terms with constant weights. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::pw_const (const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val) |
| Piecewise constant function of a scalar symbolic variable. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::pw_lin (const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val) |
| Piecewise linear function of a scalar symbolic variable. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::heaviside (const Matrix< Scalar > &x) |
| Heaviside step function, elementwise. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::rectangle (const Matrix< Scalar > &x) |
| Rectangle (gate, pulse, window) function, elementwise. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::triangle (const Matrix< Scalar > &x) |
| Triangle (hat) function, elementwise. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::ramp (const Matrix< Scalar > &x) |
| Ramp function, elementwise. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::mtaylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order=1) |
| Multivariate Taylor series expansion. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::mtaylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order, const std::vector< casadi_int > &order_contributions) |
| Multivariate Taylor series expansion with weighted degrees. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::poly_coeff (const Matrix< Scalar > &f, const Matrix< Scalar > &x) |
| Extract the polynomial coefficients of a scalar expression in one symbol. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::poly_roots (const Matrix< Scalar > &p) |
| Roots of a polynomial given by its coefficients, in closed form. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::eig_symbolic (const Matrix< Scalar > &m) |
| Eigenvalues of a square SX matrix in closed form. More... | |
| Matrix< double > | casadi::Matrix< Scalar >::evalf (const Matrix< Scalar > &expr) |
| Evaluate a constant expression numerically, returning a DM. More... | |
| MX | casadi::MX::find (const MX &x) |
| Find the index of the first nonzero entry of a vector. More... | |
| MX | casadi::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 | casadi::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 | casadi::MX::graph_substitute (const MX &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated) |
| std::vector< MX > | casadi::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 > | casadi::MX::graph_substitute (const std::vector< MX > &ex, const std::vector< MX > &v, const std::vector< MX > &vdef, bool &updated) |
| MX | casadi::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 > | casadi::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 | casadi::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 | casadi::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 | casadi::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 | casadi::MX::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 | casadi::MX::convexify (const MX &H, const Dict &opts=Dict()) |
| Make a symmetric matrix positive definite at evaluation time. More... | |
| MX | casadi::MX::lift (const MX &x, const MX &x_guess) |
| Lift the expression. More... | |
| MX | casadi::MX::inv_node (const MX &x) |
| Symbolic matrix inverse node. More... | |
| DM | casadi::MX::evalf (const MX &expr) |
| Evaluate an expression without free symbols numerically. More... | |
| MX | casadi::MX::stop_diff (const MX &expr, casadi_int order) |
| Stop derivatives of an expression with respect to all its symbolic variables. More... | |
| MX | casadi::MX::no_grad (const MX &expr) |
| Treat an expression as constant for differentiation (stop first derivatives) More... | |
| MX | casadi::MX::no_hess (const MX &expr) |
| Stop second derivatives of an expression wrt all its symbolic variables. More... | |
| MX | casadi::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 > | casadi::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... | |
| MatType | casadi::SparsityInterface< MatType >::horzcat (const std::vector< MatType > &v) |
| Concatenate a list of matrices horizontally. More... | |
| MatType | casadi::SparsityInterface< MatType >::vertcat (const std::vector< MatType > &v) |
| Concatenate a list of matrices vertically. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::horzsplit (const MatType &x, const std::vector< casadi_int > &offset) |
| Split a matrix horizontally into groups of columns. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::horzsplit (const MatType &x, casadi_int incr=1) |
| Split a matrix horizontally into fixed-size groups of columns. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::horzsplit_n (const MatType &x, casadi_int n) |
| Split a matrix horizontally into a given number of equal groups of columns. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::vertsplit (const MatType &x, const std::vector< casadi_int > &offset) |
| Split a matrix vertically into groups of rows. More... | |
| std::vector< casadi_int > | casadi::SparsityInterface< MatType >::offset (const std::vector< MatType > &v, bool vert=true) |
| Get the block offsets of a list of matrices. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::vertsplit (const MatType &x, casadi_int incr=1) |
| Split a matrix vertically into fixed-size groups of rows. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::vertsplit_n (const MatType &x, casadi_int n) |
| Split a matrix vertically into a given number of equal groups of rows. More... | |
| MatType | casadi::SparsityInterface< MatType >::blockcat (const std::vector< std::vector< MatType > > &v) |
| Construct a matrix from a list of lists of blocks. More... | |
| MatType | casadi::SparsityInterface< MatType >::blockcat (const MatType &A, const MatType &B, const MatType &C, const MatType &D) |
| Construct a matrix from 4 blocks. More... | |
| std::vector< std::vector< MatType > > | casadi::SparsityInterface< MatType >::blocksplit (const MatType &x, const std::vector< casadi_int > &vert_offset, const std::vector< casadi_int > &horz_offset) |
| Split a matrix into a grid of blocks. More... | |
| std::vector< std::vector< MatType > > | casadi::SparsityInterface< MatType >::blocksplit (const MatType &x, casadi_int vert_incr=1, casadi_int horz_incr=1) |
| Split a matrix into a grid of fixed-size blocks. More... | |
| MatType | casadi::SparsityInterface< MatType >::diagcat (const std::vector< MatType > &A) |
| Construct a block-diagonal matrix from a list of matrices. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::diagsplit (const MatType &x, const std::vector< casadi_int > &output_offset1, const std::vector< casadi_int > &output_offset2) |
| Split a matrix into diagonal blocks of given row and column boundaries. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::diagsplit (const MatType &x, const std::vector< casadi_int > &output_offset) |
| Split a square matrix into square diagonal blocks of given boundaries. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::diagsplit (const MatType &x, casadi_int incr=1) |
| Split a square matrix into square diagonal blocks of fixed size. More... | |
| std::vector< MatType > | casadi::SparsityInterface< MatType >::diagsplit (const MatType &x, casadi_int incr1, casadi_int incr2) |
| Split a matrix into diagonal blocks of fixed size. More... | |
| MatType | casadi::SparsityInterface< MatType >::veccat (const std::vector< MatType > &x) |
| Concatenate vertically after vectorizing every argument. More... | |
| MatType | casadi::SparsityInterface< MatType >::mtimes (const MatType &x, const MatType &y, const std::string &blas="reference") |
| Matrix product of two matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::mtimes (const std::vector< MatType > &args, const std::string &blas="reference") |
| Matrix product of n matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::mac (const MatType &x, const MatType &y, const MatType &z, const std::string &blas="reference") |
| Multiply-accumulate operation. More... | |
| MatType | casadi::SparsityInterface< MatType >::transpose (const MatType &X) |
| Transpose. More... | |
| MatType | casadi::SparsityInterface< MatType >::vec (const MatType &x) |
| Reshape a matrix into a column vector. More... | |
| MatType | casadi::SparsityInterface< MatType >::reshape (const MatType &x, casadi_int nrow, casadi_int ncol) |
| Returns a reshaped version of the matrix. More... | |
| MatType | casadi::SparsityInterface< MatType >::reshape (const MatType &x, std::pair< casadi_int, casadi_int > rc) |
| Returns a reshaped version of the matrix, dimensions as a vector. More... | |
| MatType | casadi::SparsityInterface< MatType >::reshape (const MatType &x, const Sparsity &sp) |
| Reshape the matrix to a given sparsity pattern. More... | |
| MatType | casadi::SparsityInterface< MatType >::sparsity_cast (const MatType &x, const Sparsity &sp) |
| Cast matrix nonzeros to different Sparsity. More... | |
| casadi_int | casadi::SparsityInterface< MatType >::sprank (const MatType &x) |
| Obtain the structural rank of a sparsity-pattern. More... | |
| casadi_int | casadi::SparsityInterface< MatType >::norm_0_mul (const MatType &x, const MatType &y) |
| 0-norm (nonzero count) of a Matrix-matrix product More... | |
| MatType | casadi::SparsityInterface< MatType >::triu (const MatType &x, bool includeDiagonal=true) |
| Get the upper triangular part of a matrix. More... | |
| MatType | casadi::SparsityInterface< MatType >::tril (const MatType &x, bool includeDiagonal=true) |
| Get the lower triangular part of a matrix. More... | |
| MatType | casadi::SparsityInterface< MatType >::kron (const MatType &a, const MatType &b) |
| Kronecker tensor product. More... | |
| MatType | casadi::SparsityInterface< MatType >::repmat (const MatType &A, casadi_int n, casadi_int m=1) |
| Repeat matrix A n times vertically and m times horizontally. More... | |
| MatType | casadi::SparsityInterface< MatType >::repmat (const MatType &A, const std::pair< casadi_int, casadi_int > &rc) |
| Repeat matrix A n times vertically and m times horizontally. More... | |
| MatType | casadi::SparsityInterface< MatType >::horzcat (const MatType &x, const MatType &y) |
| Concatenate horizontally, two matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::horzcat (const MatType &x, const MatType &y, const MatType &z) |
| Concatenate horizontally, three matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::horzcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w) |
| Concatenate horizontally, four matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::horzcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v) |
| Concatenate horizontally, five matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::horzcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v, const MatType &u) |
| Concatenate horizontally, six matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::vertcat (const MatType &x, const MatType &y) |
| Concatenate vertically, two matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::vertcat (const MatType &x, const MatType &y, const MatType &z) |
| Concatenate vertically, three matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::vertcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w) |
| Concatenate vertically, four matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::vertcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v) |
| Concatenate vertically, five matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::vertcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v, const MatType &u) |
| Concatenate vertically, six matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::diagcat (const MatType &x, const MatType &y) |
| Concatenate along diagonal, two matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::diagcat (const MatType &x, const MatType &y, const MatType &z) |
| Concatenate along diagonal, three matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::diagcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w) |
| Concatenate along diagonal, four matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::diagcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v) |
| Concatenate along diagonal, five matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::diagcat (const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v, const MatType &u) |
| Concatenate along diagonal, six matrices. More... | |
| MatType | casadi::SparsityInterface< MatType >::sum1 (const MatType &x) |
| Sum the elements of every column. More... | |
| MatType | casadi::SparsityInterface< MatType >::sum2 (const MatType &x) |
| Sum the elements of every row. More... | |
| MatType | casadi::SparsityInterface< MatType >::sum (const MatType &x) |
| Sum all elements. More... | |
| static ExType | casadi::GenericExpression< ExType >::minus (const ExType &x, const ExType &y) |
| Subtraction: (x,y) -> x - y. More... | |
| ExType & | casadi::GenericExpression< ExType >::operator-= (const ExType &y) |
| Subtraction: (x,y) -> x - y. More... | |
| ExType | casadi::GenericExpression< ExType >::minus (const ExType &x, const ExType &y) |
| Subtraction: (x,y) -> x - y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator- (const ExType &x, const ExType &y) |
| Subtraction: (x,y) -> x - y. More... | |
| static ExType | casadi::GenericExpression< ExType >::times (const ExType &x, const ExType &y) |
| Elementwise multiplication: (x,y) -> x .* y. More... | |
| ExType & | casadi::GenericExpression< ExType >::operator*= (const ExType &y) |
| Elementwise multiplication: (x,y) -> x .* y. More... | |
| ExType | casadi::GenericExpression< ExType >::times (const ExType &x, const ExType &y) |
| Elementwise multiplication: (x,y) -> x .* y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator* (const ExType &x, const ExType &y) |
| Elementwise multiplication: (x,y) -> x .* y. More... | |
| static ExType | casadi::GenericExpression< ExType >::rdivide (const ExType &x, const ExType &y) |
| Elementwise division: (x,y) -> x ./ y. More... | |
| ExType & | casadi::GenericExpression< ExType >::operator/= (const ExType &y) |
| Elementwise division: (x,y) -> x ./ y. More... | |
| ExType | casadi::GenericExpression< ExType >::rdivide (const ExType &x, const ExType &y) |
| Elementwise division: (x,y) -> x ./ y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator/ (const ExType &x, const ExType &y) |
| Elementwise division: (x,y) -> x ./ y. More... | |
| static ExType | casadi::GenericExpression< ExType >::lt (const ExType &x, const ExType &y) |
| Logical less than: (x,y) -> x < y. More... | |
| ExType | casadi::GenericExpression< ExType >::lt (const ExType &x, const ExType &y) |
| Logical less than: (x,y) -> x < y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator< (const ExType &x, const ExType &y) |
| Logical less than: (x,y) -> x < y. More... | |
| static ExType | casadi::GenericExpression< ExType >::le (const ExType &x, const ExType &y) |
| Logical less or equal to: (x,y) -> x <= y. More... | |
| ExType | casadi::GenericExpression< ExType >::le (const ExType &x, const ExType &y) |
| Logical less or equal to: (x,y) -> x <= y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator<= (const ExType &x, const ExType &y) |
| Logical less or equal to: (x,y) -> x <= y. More... | |
| static ExType | casadi::GenericExpression< ExType >::gt (const ExType &x, const ExType &y) |
| Logical greater than: (x,y) -> x > y. More... | |
| ExType | casadi::GenericExpression< ExType >::gt (const ExType &x, const ExType &y) |
| Logical greater than: (x,y) -> x > y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator> (const ExType &x, const ExType &y) |
| Logical greater than: (x,y) -> x > y. More... | |
| static ExType | casadi::GenericExpression< ExType >::ge (const ExType &x, const ExType &y) |
| Logical greater or equal to: (x,y) -> x >= y. More... | |
| ExType | casadi::GenericExpression< ExType >::ge (const ExType &x, const ExType &y) |
| Logical greater or equal to: (x,y) -> x >= y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator>= (const ExType &x, const ExType &y) |
| Logical greater or equal to: (x,y) -> x >= y. More... | |
| static ExType | casadi::GenericExpression< ExType >::eq (const ExType &x, const ExType &y) |
| Logical equal to: (x,y) -> x == y. More... | |
| ExType | casadi::GenericExpression< ExType >::eq (const ExType &x, const ExType &y) |
| Logical equal to: (x,y) -> x == y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator== (const ExType &x, const ExType &y) |
| Logical equal to: (x,y) -> x == y. More... | |
| static ExType | casadi::GenericExpression< ExType >::ne (const ExType &x, const ExType &y) |
| Logical not equal to: (x,y) -> x != y. More... | |
| ExType | casadi::GenericExpression< ExType >::ne (const ExType &x, const ExType &y) |
| Logical not equal to: (x,y) -> x != y. More... | |
| ExType | casadi::GenericExpression< ExType >::operator!= (const ExType &x, const ExType &y) |
| Logical not equal to: (x,y) -> x != y. More... | |
| static ExType | casadi::GenericExpression< ExType >::logic_and (const ExType &x, const ExType &y) |
Logical and More... | |
| ExType | casadi::GenericExpression< ExType >::logic_and (const ExType &x, const ExType &y) |
Logical and More... | |
| ExType | casadi::GenericExpression< ExType >::operator&& (const ExType &x, const ExType &y) |
Logical and More... | |
| static ExType | casadi::GenericExpression< ExType >::logic_or (const ExType &x, const ExType &y) |
Logical or More... | |
| ExType | casadi::GenericExpression< ExType >::logic_or (const ExType &x, const ExType &y) |
Logical or More... | |
| ExType | casadi::GenericExpression< ExType >::operator|| (const ExType &x, const ExType &y) |
Logical or More... | |
| static ExType | casadi::GenericExpression< ExType >::logic_not (const ExType &x) |
Logical not x -> !x. More... | |
| ExType | casadi::GenericExpression< ExType >::operator! () const |
Logical not x -> !x. More... | |
| ExType | casadi::GenericExpression< ExType >::logic_not (const ExType &x) |
Logical not x -> !x. More... | |
| static ExType | casadi::GenericExpression< ExType >::abs (const ExType &x) |
| Absolute value: x -> abs(x) More... | |
| ExType | casadi::GenericExpression< ExType >::abs (const ExType &x) |
| Absolute value: x -> abs(x) More... | |
| ExType | casadi::GenericExpression< ExType >::fabs (const ExType &x) |
| Absolute value: x -> abs(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::sqrt (const ExType &x) |
| Square root: x -> sqrt(x) More... | |
| ExType | casadi::GenericExpression< ExType >::sqrt (const ExType &x) |
| Square root: x -> sqrt(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::sq (const ExType &x) |
| Square: x -> x^2. More... | |
| ExType | casadi::GenericExpression< ExType >::sq (const ExType &x) |
| Square: x -> x^2. More... | |
| static ExType | casadi::GenericExpression< ExType >::sin (const ExType &x) |
| Sine: x -> sin(x) More... | |
| ExType | casadi::GenericExpression< ExType >::sin (const ExType &x) |
| Sine: x -> sin(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::cos (const ExType &x) |
| Cosine: x -> cos(x) More... | |
| ExType | casadi::GenericExpression< ExType >::cos (const ExType &x) |
| Cosine: x -> cos(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::tan (const ExType &x) |
| Tangent: x -> tan(x) More... | |
| ExType | casadi::GenericExpression< ExType >::tan (const ExType &x) |
| Tangent: x -> tan(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::atan (const ExType &x) |
| Arc tangent: x -> atan(x) More... | |
| ExType | casadi::GenericExpression< ExType >::atan (const ExType &x) |
| Arc tangent: x -> atan(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::asin (const ExType &x) |
| Arc sine: x -> asin(x) More... | |
| ExType | casadi::GenericExpression< ExType >::asin (const ExType &x) |
| Arc sine: x -> asin(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::acos (const ExType &x) |
| Arc cosine: x -> acos(x) More... | |
| ExType | casadi::GenericExpression< ExType >::acos (const ExType &x) |
| Arc cosine: x -> acos(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::tanh (const ExType &x) |
| Hyperbolic tangent: x -> tanh(x) More... | |
| ExType | casadi::GenericExpression< ExType >::tanh (const ExType &x) |
| Hyperbolic tangent: x -> tanh(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::sinh (const ExType &x) |
| Hyperbolic sin: x -> sinh(x) More... | |
| ExType | casadi::GenericExpression< ExType >::sinh (const ExType &x) |
| Hyperbolic sin: x -> sinh(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::cosh (const ExType &x) |
| Hyperbolic cosine: x -> cosh(x) More... | |
| ExType | casadi::GenericExpression< ExType >::cosh (const ExType &x) |
| Hyperbolic cosine: x -> cosh(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::atanh (const ExType &x) |
| Inverse hyperbolic tangent: x -> atanh(x) More... | |
| ExType | casadi::GenericExpression< ExType >::atanh (const ExType &x) |
| Inverse hyperbolic tangent: x -> atanh(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::asinh (const ExType &x) |
| Inverse hyperbolic sin: x -> asinh(x) More... | |
| ExType | casadi::GenericExpression< ExType >::asinh (const ExType &x) |
| Inverse hyperbolic sin: x -> asinh(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::acosh (const ExType &x) |
| Inverse hyperbolic cosine: x -> acosh(x) More... | |
| ExType | casadi::GenericExpression< ExType >::acosh (const ExType &x) |
| Inverse hyperbolic cosine: x -> acosh(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::exp (const ExType &x) |
| Elementwise exponential: x -> exp(x) More... | |
| ExType | casadi::GenericExpression< ExType >::exp (const ExType &x) |
| Elementwise exponential: x -> exp(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::log (const ExType &x) |
| Natural logarithm: x -> log(x) More... | |
| ExType | casadi::GenericExpression< ExType >::log (const ExType &x) |
| Natural logarithm: x -> log(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::log10 (const ExType &x) |
| Base-10 logarithm: x -> log10(x) More... | |
| ExType | casadi::GenericExpression< ExType >::log10 (const ExType &x) |
| Base-10 logarithm: x -> log10(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::log1p (const ExType &x) |
| Precision variant for natural logarithm: x -> log(x+1) More... | |
| ExType | casadi::GenericExpression< ExType >::log1p (const ExType &x) |
| Precision variant for natural logarithm: x -> log(x+1) More... | |
| static ExType | casadi::GenericExpression< ExType >::expm1 (const ExType &x) |
| Precision variant for elementwise exponential: x -> exp(x)-1. More... | |
| ExType | casadi::GenericExpression< ExType >::expm1 (const ExType &x) |
| Precision variant for elementwise exponential: x -> exp(x)-1. More... | |
| static ExType | casadi::GenericExpression< ExType >::floor (const ExType &x) |
| Round down to nearest integer: x -> floor(x) More... | |
| ExType | casadi::GenericExpression< ExType >::floor (const ExType &x) |
| Round down to nearest integer: x -> floor(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::ceil (const ExType &x) |
| Round up to nearest integer: x -> ceil(x) More... | |
| ExType | casadi::GenericExpression< ExType >::ceil (const ExType &x) |
| Round up to nearest integer: x -> ceil(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::erf (const ExType &x) |
| Error function: x -> erf(x) More... | |
| ExType | casadi::GenericExpression< ExType >::erf (const ExType &x) |
| Error function: x -> erf(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::erfinv (const ExType &x) |
| Inverse error function: x -> erfinv(x) More... | |
| ExType | casadi::GenericExpression< ExType >::erfinv (const ExType &x) |
| Inverse error function: x -> erfinv(x) More... | |
| static ExType | casadi::GenericExpression< ExType >::sign (const ExType &x) |
| Sign function: More... | |
| ExType | casadi::GenericExpression< ExType >::sign (const ExType &x) |
| Sign function: More... | |
| static ExType | casadi::GenericExpression< ExType >::pow (const ExType &x, const ExType &y) |
| Elementwise power: (x,y) -> x.^y. More... | |
| ExType | casadi::GenericExpression< ExType >::pow (const ExType &x, const ExType &y) |
| Elementwise power: (x,y) -> x.^y. More... | |
| static ExType | casadi::GenericExpression< ExType >::mod (const ExType &x, const ExType &y) |
| Remainder after division: (x,y) -> fmod(x,y) More... | |
| ExType | casadi::GenericExpression< ExType >::mod (const ExType &x, const ExType &y) |
| Remainder after division: (x,y) -> fmod(x,y) More... | |
| ExType | casadi::GenericExpression< ExType >::fmod (const ExType &x, const ExType &y) |
| Remainder after division: (x,y) -> fmod(x,y) More... | |
| static ExType | casadi::GenericExpression< ExType >::remainder (const ExType &x, const ExType &y) |
| Remainder after division: (x,y) -> remainder(x,y) More... | |
| ExType | casadi::GenericExpression< ExType >::remainder (const ExType &x, const ExType &y) |
| Remainder after division: (x,y) -> remainder(x,y) More... | |
| static ExType | casadi::GenericExpression< ExType >::atan2 (const ExType &y, const ExType &x) |
| Two argument arc tangent: (y,x) -> atan2(y,x) More... | |
| ExType | casadi::GenericExpression< ExType >::atan2 (const ExType &y, const ExType &x) |
| Two argument arc tangent: (y,x) -> atan2(y,x) More... | |
| static ExType | casadi::GenericExpression< ExType >::if_else_zero (const ExType &x, const ExType &y) |
| Conditional assignment: (x,y) -> x ? y : 0. More... | |
| ExType | casadi::GenericExpression< ExType >::if_else_zero (const ExType &x, const ExType &y) |
| Conditional assignment: (x,y) -> x ? y : 0. More... | |
| static ExType | casadi::GenericExpression< ExType >::fmin (const ExType &x, const ExType &y) |
| Smallest of two values: (x,y) -> min(x,y) More... | |
| ExType | casadi::GenericExpression< ExType >::fmin (const ExType &x, const ExType &y) |
| Smallest of two values: (x,y) -> min(x,y) More... | |
| static ExType | casadi::GenericExpression< ExType >::fmax (const ExType &x, const ExType &y) |
| Largest of two values: (x,y) -> max(x,y) More... | |
| ExType | casadi::GenericExpression< ExType >::fmax (const ExType &x, const ExType &y) |
| Largest of two values: (x,y) -> max(x,y) More... | |
| static ExType | casadi::GenericExpression< ExType >::copysign (const ExType &x, const ExType &y) |
| Copy sign: (x,y) -> copysign(x,y) More... | |
| ExType | casadi::GenericExpression< ExType >::copysign (const ExType &x, const ExType &y) |
| Copy sign: (x,y) -> copysign(x,y) More... | |
| static ExType | casadi::GenericExpression< ExType >::constpow (const ExType &x, const ExType &y) |
| Elementwise power with const power: (x,y) -> x^y with y constant. More... | |
| ExType | casadi::GenericExpression< ExType >::constpow (const ExType &x, const ExType &y) |
| Elementwise power with const power: (x,y) -> x^y with y constant. More... | |
| static ExType | casadi::GenericExpression< ExType >::printme (const ExType &x, const ExType &y) |
| Debug printing: (x,y) -> x, printing x when evaluated. More... | |
| ExType | casadi::GenericExpression< ExType >::printme (const ExType &x, const ExType &y) |
| Debug printing: (x,y) -> x, printing x when evaluated. More... | |
| static ExType | casadi::GenericExpression< ExType >::hypot (const ExType &x, const ExType &y) |
| Precision variant for 2 norm: (x,y) -> sqrt(x^2+y^2) More... | |
| ExType | casadi::GenericExpression< ExType >::hypot (const ExType &x, const ExType &y) |
| Precision variant for 2 norm: (x,y) -> sqrt(x^2+y^2) More... | |
| static MatType | casadi::GenericMatrix< MatType >::bilin (const MatType &A, const MatType &x, const MatType &y) |
| Calculate bilinear/quadratic form x^T A y. More... | |
| MatType | casadi::GenericMatrix< MatType >::bilin (const MatType &A, const MatType &x, const MatType &y) |
| Calculate bilinear/quadratic form x^T A y. More... | |
| MatType | casadi::GenericMatrix< MatType >::bilin (const MatType &A, const MatType &x) |
| Calculate bilinear/quadratic form x^T A y. More... | |
| static MatType | casadi::GenericMatrix< MatType >::rank1 (const MatType &A, const MatType &alpha, const MatType &x, const MatType &y) |
| Make a rank-1 update to a matrix A. More... | |
| MatType | casadi::GenericMatrix< MatType >::rank1 (const MatType &A, const MatType &alpha, const MatType &x, const MatType &y) |
| Make a rank-1 update to a matrix A. More... | |
| static MatType | casadi::GenericMatrix< MatType >::jtimes (const MatType &ex, const MatType &arg, const MatType &v, bool tr=false, const Dict &opts=Dict()) |
| static MatType | casadi::GenericMatrix< MatType >::gradient (const MatType &ex, const MatType &arg, const Dict &opts=Dict()) |
| static MatType | casadi::GenericMatrix< MatType >::tangent (const MatType &ex, const MatType &arg, const Dict &opts=Dict()) |
| static MatType | casadi::GenericMatrix< MatType >::linearize (const MatType &f, const MatType &x, const MatType &x0, const Dict &opts=Dict()) |
| static MatType | casadi::GenericMatrix< MatType >::mpower (const MatType &x, const MatType &y) |
| static MatType | casadi::GenericMatrix< MatType >::soc (const MatType &x, const MatType &y) |
| bool | casadi::GenericExpression< ExType >::is_equal (const ExType &x, const ExType &y, casadi_int depth=0) |
| Check if two nodes are equivalent up to a given depth. More... | |
| MatType | casadi::GenericMatrix< MatType >::einstein (const MatType &A, const MatType &B, const MatType &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 any contraction of two dense tensors, using index/einstein notation. More... | |
| MatType | casadi::GenericMatrix< MatType >::einstein (const MatType &A, const MatType &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 any contraction of two dense tensors, using index/einstein notation. More... | |
| bool | casadi::GenericMatrix< MatType >::contains (const std::vector< MatType > &v, const MatType &n) |
| Check if expression n is listed in v. More... | |
| bool | casadi::GenericMatrix< MatType >::contains_all (const std::vector< MatType > &v, const std::vector< MatType > &n) |
| Check if expression n is listed in v. More... | |
| bool | casadi::GenericMatrix< MatType >::contains_any (const std::vector< MatType > &v, const std::vector< MatType > &n) |
| Check if expression n is listed in v. More... | |
| MatType | casadi::GenericMatrix< MatType >::hessian (const MatType &ex, const MatType &arg, const Dict &opts=Dict()) |
| Hessian and (optionally) gradient. More... | |
| MatType | casadi::GenericMatrix< MatType >::hessian (const MatType &ex, const MatType &arg, MatType &output_g, const Dict &opts=Dict()) |
| Hessian and (optionally) gradient. More... | |
| MatType | casadi::GenericMatrix< MatType >::transform (const MatType &x, const Dict &opts=Dict()) |
| Apply transformation passes to an expression. More... | |
| MatType | casadi::GenericMatrix< MatType >::transform (const MatType &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict()) |
| Apply transformation passes to an expression. More... | |
| std::vector< MatType > | casadi::GenericMatrix< MatType >::transform (const std::vector< MatType > &x, const Dict &opts=Dict()) |
| Apply transformation passes to an expression. More... | |
| std::vector< MatType > | casadi::GenericMatrix< MatType >::transform (const std::vector< MatType > &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict()) |
| Apply transformation passes to an expression. More... | |
| MatType | casadi::GenericMatrix< MatType >::mmin (const MatType &x) |
| Smallest element in a matrix. More... | |
| MatType | casadi::GenericMatrix< MatType >::mmax (const MatType &x) |
| Largest element in a matrix. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::gauss_quadrature (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order=5) |
| Integrate a scalar SX expression over [a, b] with 5-point Gauss-Legendre quadrature. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::gauss_quadrature (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order, const Matrix< Scalar > &w) |
| Integrate a scalar SX expression over [a, b] with 5-point Gauss-Legendre quadrature. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::taylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order=1) |
| Univariate Taylor series expansion. More... | |
| Matrix< Scalar > | casadi::Matrix< Scalar >::taylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x) |
| Univariate Taylor series expansion. More... | |
Functions for manipulating DM, SX, MX or Sparsity
|
inlinestatic |
Elementwise; structural zeros are preserved. The unary functions of this group operate on every entry, keep the shape and build a symbolic expression for SX and MX. Those that map 0 to 0 (abs, sqrt, sin, tan, atan, asin, sinh, tanh, asinh, atanh, floor, ceil, sign, erf, erfinv, log1p, expm1) keep the sparsity pattern; the others (cos, cosh, exp, log, log10, acos, acosh, logic_not) return a dense result. Named fabs in Python, where the built-in abs also applies.
>>> fabs(DM([-1, 0, 2]))
DM([1, 0, 2])
>>> fabs(DM.eye(2) * -1)
DM(
[[1, 00],
[00, 1]])
>>> abs(SX.sym("x"))
SX(fabs(x))
>> abs(DM([-1; 0; 2]))
[1, 0, 2]
>> abs(-DM.eye(2))
[[1, 00],
[00, 1]]
>> abs(SX.sym('x'))
fabs(x)
julia> abs.(ca.DM([-1, 0, 2]))
DM([1, 0, 2])
julia> abs(-ca.DM.eye(2))
DM(
[[1, 00],
[00, 1]])
julia> abs(ca.SX.sym("x"))
SX(fabs(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p0
Definition at line 925 of file generic_expression.hpp.
References casadi::OP_FABS.
|
inlinestatic |
Elementwise; the result is dense (acos(0) == pi/2). Arguments outside [-1, 1] give NaN.
>>> acos(DM([0, 1])) DM([1.5708, 0])
>> acos(DM([0; 1])) [1.5708, 0]
julia> acos.(ca.DM([0, 1])) DM([1.5708, 0])
Extra doc: https://github.com/casadi/casadi/wiki/L_p8
Definition at line 1261 of file generic_expression.hpp.
References casadi::OP_ACOS.
|
inlinestatic |
Elementwise; the result is dense. Defined for x >= 1, NaN below.
>>> acosh(DM([1, 2])) DM([0, 1.31696])
>> acosh(DM([1; 2])) [0, 1.31696]
julia> acosh.(ca.DM([1, 2])) DM([0, 1.31696])
Extra doc: https://github.com/casadi/casadi/wiki/L_pe
Definition at line 1483 of file generic_expression.hpp.
References casadi::OP_ACOSH.
|
inlinestatic |
Elementwise; sparsity preserved. Arguments outside [-1, 1] give NaN.
>>> asin(DM([0, 1])) DM([0, 1.5708])
>> asin(DM([0; 1])) [0, 1.5708]
julia> asin.(ca.DM([0, 1])) DM([0, 1.5708])
Extra doc: https://github.com/casadi/casadi/wiki/L_p7
Definition at line 1224 of file generic_expression.hpp.
References casadi::OP_ASIN.
|
inlinestatic |
Elementwise; sparsity preserved.
>>> asinh(DM([-1, 1])) DM([-0.881374, 0.881374])
>> asinh(DM([-1; 1])) [-0.881374, 0.881374]
julia> asinh.(ca.DM([-1, 1])) DM([-0.881374, 0.881374])
Extra doc: https://github.com/casadi/casadi/wiki/L_pd
Definition at line 1446 of file generic_expression.hpp.
References casadi::OP_ASINH.
|
inlinestatic |
Elementwise; sparsity preserved. Result in (-pi/2, pi/2); use atan2 for a quadrant-aware angle.
>>> atan(DM([0, 1])) DM([0, 0.785398])
>> atan(DM([0; 1])) [0, 0.785398]
julia> atan.(ca.DM([0, 1])) DM([0, 0.785398])
Extra doc: https://github.com/casadi/casadi/wiki/L_p6
Definition at line 1187 of file generic_expression.hpp.
References casadi::OP_ATAN.
|
inlinestatic |
theta = atan2(y,x) corresponds to x = r cos(theta), y = r sin(theta)
Angle in (-pi, pi] of the point (x, y), taking the quadrant into account; the first argument is the y coordinate, as in C and numpy. Elementwise, shape rules as for plus. atan2(0, 0) is 0.
>>> atan2(DM([1, -1, 0]), DM([-1, -1, 1]))
DM([2.35619, -2.35619, 0])
>>> atan2(SX.sym("y"), SX.sym("x"))
SX(atan2(y,x))
>> atan2(DM([1; -1; 0]), DM([-1; -1; 1]))
[2.35619, -2.35619, 0]
>> atan2(SX.sym('y'), SX.sym('x'))
atan2(y,x)
julia> atan.(ca.DM([1, -1, 0]), ca.DM([-1, -1, 1]))
DM([2.35619, -2.35619, 0])
julia> atan(ca.SX.sym("y"), ca.SX.sym("x"))
SX(atan2(y,x))
Extra doc: https://github.com/casadi/casadi/wiki/L_pr
Definition at line 2146 of file generic_expression.hpp.
References casadi::OP_ATAN2.
|
inlinestatic |
Elementwise; sparsity preserved. Defined for |x| < 1, infinite at +-1.
>>> atanh(DM([0, 0.5])) DM([0, 0.549306])
>> atanh(DM([0; 0.5])) [0, 0.549306]
julia> atanh.(ca.DM([0, 0.5])) DM([0, 0.549306])
Extra doc: https://github.com/casadi/casadi/wiki/L_pc
Definition at line 1409 of file generic_expression.hpp.
References casadi::OP_ATANH.
|
static |
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
|
inlinestatic |
Elementwise, towards plus infinity; sparsity preserved. The derivative is zero everywhere.
>>> ceil(DM([-1.5, 1.5])) DM([-1, 2])
>> ceil(DM([-1.5; 1.5])) [-1, 2]
julia> ceil.(ca.DM([-1.5, 1.5])) DM([-1, 2])
Extra doc: https://github.com/casadi/casadi/wiki/L_pl
Definition at line 1789 of file generic_expression.hpp.
References casadi::OP_CEIL.
|
inlinestatic |
Same value as pow, but the exponent is assumed constant: the derivative with respect to y is taken as zero. pow itself produces this operation for a non-integer constant exponent, so it is rarely needed directly. Passing a symbolic exponent gives a wrong derivative for MX; SX falls back to pow.
>>> constpow(DM(2), 3)
DM(8)
>>> x = MX.sym("x")
>>> constpow(x, 2.5), jacobian(constpow(x, 2.5), x)
(MX(pow(x,2.5)), MX((2.5*pow(x,1.5))))
>> constpow(DM(2), 3)
8
>> x = MX.sym('x');
>> constpow(x, 2.5), jacobian(constpow(x, 2.5), x)
pow(x,2.5)
(2.5*pow(x,1.5))
julia> ca.constpow(ca.DM(2), 3)
DM(8)
julia> x = ca.MX.sym("x");
julia> ca.constpow(x, 2.5), ca.jacobian(ca.constpow(x, 2.5), x)
(pow(x,2.5), (2.5*pow(x,1.5)))
Extra doc: https://github.com/casadi/casadi/wiki/L_2om
Definition at line 2467 of file generic_expression.hpp.
References casadi::OP_CONSTPOW.
|
inlinestatic |
Elementwise value with the magnitude of x and the sign of y, as C copysign; a negative zero y counts as negative. Shape rules as for plus. The derivative with respect to y is zero.
>>> copysign(DM([1, -2]), DM([-1, 1]))
DM([-1, 2])
>>> copysign(DM(3), DM(-0.0))
DM(-3)
>>> copysign(SX.sym("x"), SX.sym("y"))
SX(copysign(x,y))
>> copysign(DM([1; -2]), DM([-1; 1]))
[-1, 2]
>> copysign(DM(3), DM(-0.0))
-3
>> copysign(SX.sym('x'), SX.sym('y'))
copysign(x,y)
julia> copysign.(ca.DM([1, -2]), ca.DM([-1, 1]))
DM([-1, 2])
julia> copysign.(ca.DM(3), ca.DM(-0.0))
DM(-3)
julia> ca.copysign(ca.SX.sym("x"), ca.SX.sym("y"))
SX(copysign(x,y))
Extra doc: https://github.com/casadi/casadi/wiki/L_2ol
Definition at line 2417 of file generic_expression.hpp.
References casadi::OP_COPYSIGN.
|
inlinestatic |
Elementwise; structural zeros become 1, so the result is dense.
>>> cos(DM.eye(2))
DM(
[[0.540302, 1],
[1, 0.540302]])
>>> cos(SX.sym("s", Sparsity.diag(2)))
SX(@1=1,
[[cos(s_0), @1],
[@1, cos(s_1)]])
>> cos(DM.eye(2))
[[0.540302, 1],
[1, 0.540302]]
>> cos(SX.sym('s', Sparsity.diag(2)))
@1=1,
[[cos(s_0), @1],
[@1, cos(s_1)]]
julia> cos.(ca.DM.eye(2))
DM(
[[0.540302, 1],
[1, 0.540302]])
julia> cos.(ca.SX.sym("s", ca.Sparsity.diag(2)))
SX(@1=1,
[[cos(s_0), @1],
[@1, cos(s_1)]])
Extra doc: https://github.com/casadi/casadi/wiki/L_p4
Definition at line 1112 of file generic_expression.hpp.
References casadi::OP_COS.
|
inlinestatic |
Elementwise; the result is dense (cosh(0) == 1).
>>> cosh(DM([0, 1])) DM([1, 1.54308])
>> cosh(DM([0; 1])) [1, 1.54308]
julia> cosh.(ca.DM([0, 1])) DM([1, 1.54308])
Extra doc: https://github.com/casadi/casadi/wiki/L_pb
Definition at line 1372 of file generic_expression.hpp.
References casadi::OP_COSH.
|
inlinestatic |
Elementwise comparison with 0/1 result, see lt: this is value equality of the entries, not identity of expressions; use is_equal to test whether two symbolic expressions are the same. For symbolic operands x == x with the same node simplifies to 1. NaN is not equal to anything, including itself.
>>> eq(DM([1, 2, 3]), 2)
DM([0, 1, 0])
>>> DM.eye(2) == DM([[1, 0], [0, 1]])
DM(
[[1, 1],
[1, 1]])
>>> x = SX.sym("x")
>>> x == x, x == SX.sym("x")
(SX(1), SX((x==x)))
>>> DM(float("nan")) == DM(float("nan"))
DM(0)
>> eq(DM([1; 2; 3]), 2)
[0, 1, 0]
>> DM.eye(2) == DM([1 0; 0 1])
[[1, 1],
[1, 1]]
>> x = SX.sym('x');
>> x == x, x == SX.sym('x')
1
(x==x)
>> DM(nan) == DM(nan)
0
julia> ca.eq(ca.DM([1, 2, 3]), 2)
DM([0, 1, 0])
julia> ca.DM.eye(2) == ca.DM([1 0; 0 1])
DM(
[[1, 1],
[1, 1]])
julia> x = ca.SX.sym("x");
julia> x == x, x == ca.SX.sym("x")
(1, (x==x))
julia> ca.DM(NaN) == ca.DM(NaN)
DM(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_ov
Definition at line 641 of file generic_expression.hpp.
References casadi::OP_EQ.
|
inlinestatic |
Elementwise; sparsity preserved (erf(0) == 0). Range (-1, 1).
>>> erf(DM([0, 1])) DM([0, 0.842701])
>> erf(DM([0; 1])) [0, 0.842701]
julia> ca.erf(ca.DM([0, 1])) DM([0, 0.842701])
Extra doc: https://github.com/casadi/casadi/wiki/L_pm
Definition at line 1826 of file generic_expression.hpp.
References casadi::OP_ERF.
|
inlinestatic |
Elementwise; sparsity preserved. Defined on [-1, 1] with erfinv(+-1) infinite; arguments outside give NaN.
>>> erfinv(DM([0, 0.5, 1])) DM([0, 0.476936, inf])
>> erfinv(DM([0; 0.5; 1])) [0, 0.476936, inf]
julia> ca.erfinv(ca.DM([0, 0.5, 1])) DM([0, 0.476936, inf])
Extra doc: https://github.com/casadi/casadi/wiki/L_pn
Definition at line 1864 of file generic_expression.hpp.
References casadi::OP_ERFINV.
|
inlinestatic |
Elementwise; the result is dense (exp(0) == 1).
>>> exp(DM.eye(2))
DM(
[[2.71828, 1],
[1, 2.71828]])
>>> exp(MX.sym("m", Sparsity.diag(2)))
MX(exp(dense(m)))
>> exp(DM.eye(2))
[[2.71828, 1],
[1, 2.71828]]
>> exp(MX.sym('m', Sparsity.diag(2)))
exp(dense(m))
julia> exp.(ca.DM.eye(2))
DM(
[[2.71828, 1],
[1, 2.71828]])
julia> exp.(ca.MX.sym("m", ca.Sparsity.diag(2)))
MX(exp(dense(m)))
Extra doc: https://github.com/casadi/casadi/wiki/L_pf
Definition at line 1531 of file generic_expression.hpp.
References casadi::OP_EXP.
|
inlinestatic |
Elementwise; accurate for small x where exp(x) - 1 would lose digits. Sparsity preserved (expm1(0) == 0).
>>> expm1(DM([0, 1e-10])) DM([0, 1e-10])
>> expm1(DM([0; 1e-10])) [0, 1e-10]
julia> expm1.(ca.DM([0, 1e-10])) DM([0, 1e-10])
Extra doc: https://github.com/casadi/casadi/wiki/L_pj
Definition at line 1701 of file generic_expression.hpp.
References casadi::OP_EXPM1.
|
inlinestatic |
Elementwise, towards minus infinity; sparsity preserved. The derivative is zero everywhere. Floor division x // y in Python is floor(x / y).
>>> floor(DM([-1.5, 1.5]))
DM([-2, 1])
>>> DM([7, -7]) // 2
DM([3, -4])
>>> SX.sym("x") // 2
SX(floor((x/2)))
>> floor(DM([-1.5; 1.5]))
[-2, 1]
>> floor(DM([7; -7]) ./ 2)
[3, -4]
>> floor(SX.sym('x') / 2)
floor((x/2))
julia> floor.(ca.DM([-1.5, 1.5]))
DM([-2, 1])
julia> fld.(ca.DM([7, -7]), 2)
DM([3, -4])
julia> floor(ca.SX.sym("x") / 2)
SX(floor((x/2)))
Extra doc: https://github.com/casadi/casadi/wiki/L_pk
Definition at line 1751 of file generic_expression.hpp.
References casadi::OP_FLOOR.
|
inlinestatic |
Elementwise maximum; shape rules as for plus. Follows C fmax: when one operand is NaN the other is returned. The derivative is 1 with respect to the larger operand (split evenly on ties). For the maximum over the entries of one matrix use mmax.
>>> fmax(DM([1, 5]), DM([3, 2]))
DM([3, 5])
>>> fmax(DM([1, 5]), 3)
DM([3, 5])
>>> fmax(DM([1, float("nan")]), DM([float("nan"), 2]))
DM([1, 2])
>>> fmax(MX.sym("x"), MX.sym("y"))
MX(fmax(x,y))
>> fmax(DM([1; 5]), DM([3; 2]))
[3, 5]
>> max(DM([1; 5]), 3)
[3, 5]
>> fmax(DM([1; nan]), DM([nan; 2]))
[1, 2]
>> max(MX.sym('x'), MX.sym('y'))
fmax(x,y)
julia> max.(ca.DM([1, 5]), ca.DM([3, 2]))
DM([3, 5])
julia> max.(ca.DM([1, 5]), 3)
DM([3, 5])
julia> max.(ca.DM([1, NaN]), ca.DM([NaN, 2]))
DM([1, 2])
julia> max(ca.MX.sym("x"), ca.MX.sym("y"))
MX(fmax(x,y))
Extra doc: https://github.com/casadi/casadi/wiki/L_pu
Definition at line 2289 of file generic_expression.hpp.
References casadi::OP_FMAX.
|
inlinestatic |
Elementwise minimum; shape rules as for plus. Follows C fmin: when one operand is NaN the other is returned, NaN results only when both are NaN. The derivative is 1 with respect to the smaller operand (split evenly on ties). The sparsity pattern is kept where both operands are structurally zero; fmin with a negative scalar densifies. For the minimum over the entries of one matrix use mmin.
>>> fmin(DM([1, 5]), DM([3, 2]))
DM([1, 2])
>>> fmin(DM([1, float("nan")]), DM([float("nan"), 2]))
DM([1, 2])
>>> fmin(DM.eye(2), 1)
DM(
[[1, 00],
[00, 1]])
>>> fmin(SX.sym("x"), SX.sym("y"))
SX(fmin(x,y))
>> fmin(DM([1; 5]), DM([3; 2]))
[1, 2]
>> min(DM([1; 5]), DM([3; 2]))
[1, 2]
>> fmin(DM([1; nan]), DM([nan; 2]))
[1, 2]
>> fmin(DM.eye(2), 1)
[[1, 00],
[00, 1]]
>> min(SX.sym('x'), SX.sym('y'))
fmin(x,y)
julia> min.(ca.DM([1, 5]), ca.DM([3, 2]))
DM([1, 2])
julia> min.(ca.DM([1, NaN]), ca.DM([NaN, 2]))
DM([1, 2])
julia> min.(ca.DM.eye(2), 1)
DM(
[[1, 00],
[00, 1]])
julia> min(ca.SX.sym("x"), ca.SX.sym("y"))
SX(fmin(x,y))
Extra doc: https://github.com/casadi/casadi/wiki/L_pt
Definition at line 2232 of file generic_expression.hpp.
References casadi::OP_FMIN.
|
inlinestatic |
Elementwise comparison with 0/1 result, see lt. Implemented as y <= x.
>>> ge(DM([1, 2, 3]), 2)
DM([0, 1, 1])
>>> ge(MX.sym("x"), MX.sym("y"))
MX((y<=x))
>> ge(DM([1; 2; 3]), 2)
[0, 1, 1]
>> MX.sym('x') >= MX.sym('y')
(y<=x)
julia> ca.ge(ca.DM([1, 2, 3]), 2)
DM([0, 1, 1])
julia> ca.ge(ca.MX.sym("x"), ca.MX.sym("y"))
MX((y<=x))
Extra doc: https://github.com/casadi/casadi/wiki/L_ou
Definition at line 571 of file generic_expression.hpp.
|
static |
Functions called by friend functions defined here
|
inlinestatic |
Elementwise comparison with 0/1 result, see lt. Implemented as y < x, which is how a symbolic expression prints.
>>> gt(DM([1, 2, 3]), 2)
DM([0, 0, 1])
>>> gt(SX.sym("x"), SX.sym("y"))
SX((y<x))
>> gt(DM([1; 2; 3]), 2)
[0, 0, 1]
>> SX.sym('x') > SX.sym('y')
(y<x)
julia> ca.gt(ca.DM([1, 2, 3]), 2)
DM([0, 0, 1])
julia> ca.gt(ca.SX.sym("x"), ca.SX.sym("y"))
SX((y<x))
Extra doc: https://github.com/casadi/casadi/wiki/L_ot
Definition at line 525 of file generic_expression.hpp.
|
inlinestatic |
Elementwise; avoids the overflow and underflow of forming the squares, as C hypot. Shape rules as for plus; the result is structurally zero where both operands are.
>>> hypot(DM(3), DM(4))
DM(5)
>>> hypot(DM(1e200), DM(1e200))
DM(1.41421e+200)
>>> hypot(SX.sym("x"), SX.sym("y"))
SX(hypot(x,y))
>> hypot(DM(3), DM(4))
5
>> hypot(DM(1e200), DM(1e200))
1.41421e+200
>> hypot(SX.sym('x'), SX.sym('y'))
hypot(x,y)
julia> hypot(ca.DM(3), ca.DM(4))
DM(5)
julia> hypot(ca.DM(1e200), ca.DM(1e200))
DM(1.41421e+200)
julia> hypot(ca.SX.sym("x"), ca.SX.sym("y"))
SX(hypot(x,y))
Extra doc: https://github.com/casadi/casadi/wiki/L_pw
Definition at line 2565 of file generic_expression.hpp.
References casadi::OP_HYPOT.
|
inlinestatic |
Elementwise: y where x is nonzero, 0 elsewhere; the result is structurally zero wherever either operand is. The value of y in the inactive branch does not propagate, so a NaN or inf there yields 0 rather than NaN, and the derivatives are treated accordingly. This is the building block of if_else; it is not exposed as a function in Python, use if_else(x, y, 0) there.
Extra doc: https://github.com/casadi/casadi/wiki/L_ps
Definition at line 2166 of file generic_expression.hpp.
References casadi::OP_IF_ELSE_ZERO.
|
static |
Functions called by friend functions defined here
|
inlinestatic |
Elementwise comparison with 0/1 result, see lt. Chained inequalities such as lb <= (x <= ub) are recognised by Opti as bound constraints.
>>> le(DM([1, 2, 3]), 2)
DM([1, 1, 0])
>>> x = SX.sym("x")
>>> x <= x
SX(1)
>> le(DM([1; 2; 3]), 2)
[1, 1, 0]
>> x = SX.sym('x');
>> x <= x
1
julia> ca.le(ca.DM([1, 2, 3]), 2)
DM([1, 1, 0])
julia> x = ca.SX.sym("x");
julia> x <= x
SX(1)
Extra doc: https://github.com/casadi/casadi/wiki/L_os
Definition at line 478 of file generic_expression.hpp.
References casadi::OP_LE.
|
static |
Functions called by friend functions defined here
|
inlinestatic |
Elementwise; the result is dense with -inf at structural zeros. Negative arguments give NaN; no error is raised.
>>> log(DM([1, 0]))
DM([0, -inf])
>>> log(SX.sym("x"))
SX(log(x))
>> log(DM([1; 0]))
[0, -inf]
>> log(SX.sym('x'))
log(x)
julia> log.(ca.DM([1, 0]))
DM([0, -inf])
julia> log(ca.SX.sym("x"))
SX(log(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_pg
Definition at line 1575 of file generic_expression.hpp.
References casadi::OP_LOG.
Referenced by casadi::GenericExpression< ExType >::log10().
|
inlinestatic |
Computed as log(x) * (1 / log(10)); there is no dedicated operation, which is visible in symbolic expressions. Dense result like log.
>>> log10(DM([1, 10, 1000]))
DM([0, 1, 3])
>>> log10(SX.sym("x"))
SX((0.434294*log(x)))
>> log10(DM([1; 10; 1000]))
[0, 1, 3]
>> log10(SX.sym('x'))
(0.434294*log(x))
julia> log10.(ca.DM([1, 10, 1000]))
DM([0, 1, 3])
julia> log10(ca.SX.sym("x"))
SX((0.434294*log(x)))
Extra doc: https://github.com/casadi/casadi/wiki/L_ph
Definition at line 1619 of file generic_expression.hpp.
References casadi::GenericExpression< ExType >::log().
|
inlinestatic |
Elementwise; accurate for small x where log(1 + x) would lose digits. Sparsity preserved (log1p(0) == 0).
>>> log1p(DM([0, 1e-10]))
DM([0, 1e-10])
>>> log1p(SX.sym("x"))
SX(log1p(x))
>> log1p(DM([0; 1e-10]))
[0, 1e-10]
>> log1p(SX.sym('x'))
log1p(x)
julia> log1p.(ca.DM([0, 1e-10]))
DM([0, 1e-10])
julia> log1p(ca.SX.sym("x"))
SX(log1p(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_pi
Definition at line 1663 of file generic_expression.hpp.
References casadi::OP_LOG1P.
|
inlinestatic |
Returns (an expression evaluating to) 1 where both entries are nonzero and 0 otherwise, elementwise
Any nonzero value, including NaN, counts as true. Shape rules as for plus; the result is structurally zero wherever either operand is. The Python keyword and does not work on matrices (it needs a single truth value); use this function.
>>> logic_and(DM([1, 2, 0]), DM([3, 0, 0]))
DM([1, 0, 0])
>>> logic_and(SX.sym("x"), SX.sym("y"))
SX((x&&y))
>>> logic_and(DM.eye(2), DM.ones(2, 2))
DM(
[[1, 00],
[00, 1]])
>> DM([1; 2; 0]) & DM([3; 0; 0])
[1, 0, 0]
>> SX.sym('x') & SX.sym('y')
(x&&y)
>> and(DM.eye(2), DM.ones(2, 2))
[[1, 00],
[00, 1]]
julia> ca.logic_and(ca.DM([1, 2, 0]), ca.DM([3, 0, 0]))
DM([1, 0, 0])
julia> ca.logic_and(ca.SX.sym("x"), ca.SX.sym("y"))
SX((x&&y))
julia> ca.logic_and(ca.DM.eye(2), ca.DM.ones(2, 2))
DM(
[[1, 00],
[00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_ox
Definition at line 753 of file generic_expression.hpp.
References casadi::OP_AND.
|
inlinestatic |
Returns (an expression evaluating to) 1 where the entry is zero and 0 otherwise, elementwise
Structural zeros map to 1, so a sparse input gives a dense result. The Python keyword not does not work on matrices; use this function.
>>> logic_not(DM([1, 0, -1]))
DM([0, 1, 0])
>>> logic_not(DM.eye(2))
DM(
[[0, 1],
[1, 0]])
>>> logic_not(SX.sym("x"))
SX((!x))
>> ~DM([1; 0; -1])
[0, 1, 0]
>> not(DM.eye(2))
[[0, 1],
[1, 0]]
>> ~SX.sym('x')
(!x)
julia> ca.logic_not(ca.DM([1, 0, -1]))
DM([0, 1, 0])
julia> ca.logic_not(ca.DM.eye(2))
DM(
[[0, 1],
[1, 0]])
julia> ca.logic_not(ca.SX.sym("x"))
SX((!x))
Extra doc: https://github.com/casadi/casadi/wiki/L_oz
Definition at line 863 of file generic_expression.hpp.
References casadi::OP_NOT.
Referenced by casadi::GenericExpression< ExType >::operator!().
|
inlinestatic |
returns (an expression evaluating to) 1 where at least one entry is nonzero and 0 otherwise, elementwise
Shape rules as for plus; the result is structurally zero where both operands are.
>>> logic_or(DM([1, 0, 0]), DM([0, 0, 2]))
DM([1, 0, 1])
>>> logic_or(MX.sym("x"), MX.sym("y"))
MX((x||y))
>> DM([1; 0; 0]) | DM([0; 0; 2])
[1, 0, 1]
>> or(MX.sym('x'), MX.sym('y'))
(x||y)
julia> ca.logic_or(ca.DM([1, 0, 0]), ca.DM([0, 0, 2]))
DM([1, 0, 1])
julia> ca.logic_or(ca.MX.sym("x"), ca.MX.sym("y"))
MX((x||y))
Extra doc: https://github.com/casadi/casadi/wiki/L_oy
Definition at line 802 of file generic_expression.hpp.
References casadi::OP_OR.
|
static |
|
inlinestatic |
Elementwise comparison; shape rules as for plus. Every comparison in this group returns a matrix of the same type as the operands with entries 1 (true) and 0 (false): for DM a numeric 0/1 matrix, not a boolean, and for SX and MX a symbolic expression that is only decided at evaluation time. Comparisons with NaN are false. The result is sparse where both operands are structurally zero (0 < 0 is false).
>>> lt(DM([1, 2, 3]), 2)
DM([1, 0, 0])
>>> DM([1, 2, 3]) < DM([3, 2, 1])
DM([1, 0, 0])
>>> SX.sym("x", 2) < SX.sym("y", 2)
SX([(x_0<y_0), (x_1<y_1)])
>>> DM.eye(2) < 1
DM(
[[0, 1],
[1, 0]])
>> lt(DM([1; 2; 3]), 2)
[1, 0, 0]
>> DM([1; 2; 3]) < DM([3; 2; 1])
[1, 0, 0]
>> SX.sym('x', 2) < SX.sym('y', 2)
[(x_0<y_0), (x_1<y_1)]
>> DM.eye(2) < 1
[[0, 1],
[1, 0]]
julia> ca.lt(ca.DM([1, 2, 3]), 2)
DM([1, 0, 0])
julia> ca.DM([1, 2, 3]) < ca.DM([3, 2, 1])
DM([1, 0, 0])
julia> ca.SX.sym("x", 2) < ca.SX.sym("y", 2)
SX([(x_0<y_0), (x_1<y_1)])
julia> ca.DM.eye(2) < 1
DM(
[[0, 1],
[1, 0]])
Extra doc: https://github.com/casadi/casadi/wiki/L_or
Definition at line 428 of file generic_expression.hpp.
References casadi::OP_LT.
|
inlinestatic |
Elementwise difference; shape and sparsity rules as for plus. For symbolic arguments, x - x with the same node simplifies to 0.
>>> minus(DM([5, 6]), DM([1, 2]))
DM([4, 4])
>>> DM.eye(2) - 1
DM(
[[0, -1],
[-1, 0]])
>>> x = SX.sym("x")
>>> x - x
SX(0)
>> minus(DM([5; 6]), DM([1; 2]))
[4, 4]
>> DM.eye(2) - 1
[[0, -1],
[-1, 0]]
>> x = SX.sym('x');
>> x - x
0
julia> ca.minus(ca.DM([5, 6]), ca.DM([1, 2]))
DM([4, 4])
julia> ca.DM.eye(2) - 1
DM(
[[0, -1],
[-1, 0]])
julia> x = ca.SX.sym("x");
julia> x - x
SX(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_oo
Definition at line 221 of file generic_expression.hpp.
References casadi::OP_SUB.
|
inlinestatic |
This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/fmod: the result has the sign of x and magnitude below |y|.
This is equivalent to Python's numpy.fmod and Matlab's rem. It differs from the Python operator x % y on these objects, which follows the Python convention x - y*floor(x/y) (result with the sign of y). Elementwise, shape rules as for plus; structural zeros of x stay zero. A zero divisor gives NaN.
>>> fmod(DM([5, 5, -5, -5]), DM([3, -3, 3, -3]))
DM([2, 2, -2, -2])
>>> DM([5, 5, -5, -5]) % DM([3, -3, 3, -3])
DM([2, -1, 1, -2])
>>> fmod(SX.sym("x"), 2), SX.sym("x") % 2
(SX(fmod(x,2)), SX((x-(2.*floor((x/2))))))
>> x = DM([5; 5; -5; -5]); y = DM([3; -3; 3; -3]);
>> fmod(x, y)
[2, 2, -2, -2]
>> rem(x, y)
[2, 2, -2, -2]
>> x - y .* floor(x ./ y)
[2, -1, 1, -2]
>> rem(SX.sym('x'), 2)
fmod(x,2)
julia> ca.fmod(ca.DM([5, 5, -5, -5]), ca.DM([3, -3, 3, -3]))
DM([2, 2, -2, -2])
julia> mod.(ca.DM([5, 5, -5, -5]), ca.DM([3, -3, 3, -3]))
DM([2, -1, 1, -2])
julia> ca.fmod(ca.SX.sym("x"), 2)
SX(fmod(x,2))
Definition at line 2036 of file generic_expression.hpp.
References casadi::OP_FMOD.
|
static |
Functions called by friend functions defined here
|
inlinestatic |
Elementwise comparison with 0/1 result, see lt and eq. For symbolic operands x != x with the same node simplifies to 0, so it cannot be used to detect NaN symbolically.
>>> ne(DM([1, 2, 3]), 2)
DM([1, 0, 1])
>>> x = MX.sym("x")
>>> x != x
MX(0)
>> ne(DM([1; 2; 3]), 2)
[1, 0, 1]
>> x = MX.sym('x');
>> x ~= x
0
julia> ca.ne(ca.DM([1, 2, 3]), 2)
DM([1, 0, 1])
julia> x = ca.MX.sym("x");
julia> x != x
MX(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_ow
Definition at line 691 of file generic_expression.hpp.
References casadi::OP_NE.
|
inline |
Returns (an expression evaluating to) 1 where the entry is zero and 0 otherwise, elementwise
Structural zeros map to 1, so a sparse input gives a dense result. The Python keyword not does not work on matrices; use this function.
>>> logic_not(DM([1, 0, -1]))
DM([0, 1, 0])
>>> logic_not(DM.eye(2))
DM(
[[0, 1],
[1, 0]])
>>> logic_not(SX.sym("x"))
SX((!x))
>> ~DM([1; 0; -1])
[0, 1, 0]
>> not(DM.eye(2))
[[0, 1],
[1, 0]]
>> ~SX.sym('x')
(!x)
julia> ca.logic_not(ca.DM([1, 0, -1]))
DM([0, 1, 0])
julia> ca.logic_not(ca.DM.eye(2))
DM(
[[0, 1],
[1, 0]])
julia> ca.logic_not(ca.SX.sym("x"))
SX((!x))
Extra doc: https://github.com/casadi/casadi/wiki/L_oz
Definition at line 869 of file generic_expression.hpp.
References casadi::GenericExpression< ExType >::logic_not().
|
inline |
Elementwise (Hadamard) product, not the matrix product; use mtimes for that. Shape rules as for plus. The result is structurally zero wherever either operand is, so the sparsity pattern is the intersection of the patterns.
>>> times(DM([1, 2]), DM([3, 4])) DM([3, 8]) >>> DM([[1, 2], [3, 4]]) * DM([[1, 2], [3, 4]]) DM( [[1, 4], [9, 16]]) >>> DM.eye(2) * DM.ones(2, 2) DM( [[1, 00], [00, 1]])
>> times(DM([1; 2]), DM([3; 4])) [3, 8] >> DM([1 2; 3 4]) .* DM([1 2; 3 4]) [[1, 4], [9, 16]] >> DM([1 2; 3 4]) * DM([1 2; 3 4]) [[7, 10], [15, 22]] >> DM.eye(2) .* DM.ones(2, 2) [[1, 00], [00, 1]]
julia> ca.times(ca.DM([1, 2]), ca.DM([3, 4])) DM([3, 8]) julia> ca.DM([1 2; 3 4]) .* ca.DM([1 2; 3 4]) DM( [[1, 4], [9, 16]]) julia> ca.DM.eye(2) .* ca.DM.ones(2, 2) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_op
Definition at line 298 of file generic_expression.hpp.
|
inline |
Definition at line 170 of file generic_expression.hpp.
|
inline |
Elementwise difference; shape and sparsity rules as for plus. For symbolic arguments, x - x with the same node simplifies to 0.
>>> minus(DM([5, 6]), DM([1, 2]))
DM([4, 4])
>>> DM.eye(2) - 1
DM(
[[0, -1],
[-1, 0]])
>>> x = SX.sym("x")
>>> x - x
SX(0)
>> minus(DM([5; 6]), DM([1; 2]))
[4, 4]
>> DM.eye(2) - 1
[[0, -1],
[-1, 0]]
>> x = SX.sym('x');
>> x - x
0
julia> ca.minus(ca.DM([5, 6]), ca.DM([1, 2]))
DM([4, 4])
julia> ca.DM.eye(2) - 1
DM(
[[0, -1],
[-1, 0]])
julia> x = ca.SX.sym("x");
julia> x - x
SX(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_oo
Definition at line 230 of file generic_expression.hpp.
|
inline |
Elementwise quotient, not a linear solve; use solve or mldivide for that. Shape rules as for plus. Division by zero follows IEEE arithmetic (inf or nan), no error is raised. Structural zeros of x stay structural zeros; dividing by a sparse y densifies.
>>> rdivide(DM([1, 2]), 4) DM([0.25, 0.5]) >>> DM([1, 2]) / DM([4, 8]) DM([0.25, 0.25]) >>> 1 / DM.eye(2) DM( [[1, inf], [inf, 1]]) >>> DM.eye(2) / 2 DM( [[0.5, 00], [00, 0.5]])
>> rdivide(DM([1; 2]), 4) [0.25, 0.5] >> DM([1; 2]) ./ DM([4; 8]) [0.25, 0.25] >> 1 ./ DM.eye(2) [[1, inf], [inf, 1]] >> DM.eye(2) ./ 2 [[0.5, 00], [00, 0.5]]
julia> ca.rdivide(ca.DM([1, 2]), 4) DM([0.25, 0.5]) julia> ca.DM([1, 2]) ./ ca.DM([4, 8]) DM([0.25, 0.25]) julia> 1 ./ ca.DM.eye(2) DM( [[1, inf], [inf, 1]]) julia> ca.DM.eye(2) / 2 DM( [[0.5, 00], [00, 0.5]])
Extra doc: https://github.com/casadi/casadi/wiki/L_oq
Definition at line 369 of file generic_expression.hpp.
|
inlinestatic |
Elementwise sum. The shape rules below hold for every binary operation in this group (minus, times, rdivide, the comparisons, logic_and, ...):
The result is sparse where both operands are structurally zero; an entry that is a structural zero in only one operand becomes an explicit value. Operations that map (0, y) or (x, 0) to a nonzero, such as x + 1 or cos, densify the result. Numeric (DM) operands are evaluated, symbolic ones (SX, MX) build an expression; DM and SX or MX can be mixed, SX and MX cannot.
>>> plus(DM([1, 2]), DM([10, 20]))
DM([11, 22])
>>> DM([1, 2]) + 1
DM([2, 3])
>>> DM.eye(2) + DM.eye(2)
DM(
[[2, 00],
[00, 2]])
>>> DM.eye(2) + 1
DM(
[[2, 1],
[1, 2]])
>>> SX.sym("x", 2, 2) + SX.sym("y", 2)
SX(
[[(x_0+y_0), (x_2+y_0)],
[(x_1+y_1), (x_3+y_1)]])
>>> (MX.sym("x", 2, 0) + 1).shape
(2, 0)
>>> DM.ones(2, 2) + DM.ones(1, 2)
Traceback (most recent call last):
...
RuntimeError: ...Dimension mismatch...
>> plus(DM([1; 2]), DM([10; 20]))
[11, 22]
>> DM([1; 2]) + 1
[2, 3]
>> DM.eye(2) + DM.eye(2)
[[2, 00],
[00, 2]]
>> DM.eye(2) + 1
[[2, 1],
[1, 2]]
>> SX.sym('x', 2, 2) + SX.sym('y', 2)
[[(x_0+y_0), (x_2+y_0)],
[(x_1+y_1), (x_3+y_1)]]
>> size(MX.sym('x', 2, 0) + 1)
2 0
>> try, DM.ones(2, 2) + DM.ones(1, 2); catch e, disp(e.message); end
...Dimension mismatch...
julia> ca.plus(ca.DM([1, 2]), ca.DM([10, 20]))
DM([11, 22])
julia> ca.DM([1, 2]) + 1
DM([2, 3])
julia> ca.DM.eye(2) + ca.DM.eye(2)
DM(
[[2, 00],
[00, 2]])
julia> ca.DM.eye(2) + 1
DM(
[[2, 1],
[1, 2]])
julia> ca.SX.sym("x", 2, 2) + ca.SX.sym("y", 2)
SX(
[[(x_0+y_0), (x_2+y_0)],
[(x_1+y_1), (x_3+y_1)]])
julia> size(ca.MX.sym("x", 2, 0) + 1)
(2, 0)
julia> try
ca.DM.ones(2, 2) + ca.DM.ones(1, 2)
catch e
println(occursin("Dimension mismatch", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_on
Definition at line 161 of file generic_expression.hpp.
References casadi::OP_ADD.
|
inlinestatic |
Elementwise; shape rules as for plus. Named power in Python, where the ** operator maps to it as well. A constant exponent is simplified symbolically: integer powers become repeated squaring and multiplication, 0.5 becomes sqrt, -1 a reciprocal, other constants a constpow operation. Structural zeros of x stay zero for a nonzero exponent; x**0 is dense (0**0 == 1).
>>> power(DM([1, 2, 3]), 2)
DM([1, 4, 9])
>>> DM([1, 2, 3])**DM([3, 2, 1]), 2**DM([1, 2, 3])
(DM([1, 4, 3]), DM([2, 4, 8]))
>>> x = SX.sym("x")
>>> x**2, x**3, x**-1, x**x
(SX(sq(x)), SX((x*sq(x))), SX((1./x)), SX(pow(x,x)))
>>> x**2.5
SX(pow(x,2.5))
>> power(DM([1; 2; 3]), 2)
[1, 4, 9]
>> DM([1; 2; 3]).^DM([3; 2; 1]), 2.^DM([1; 2; 3])
[1, 4, 3]
[2, 4, 8]
>> x = SX.sym('x');
>> x.^2, x.^3, x.^-1, x.^x
sq(x)
(x*sq(x))
(1./x)
pow(x,x)
>> x.^2.5
pow(x,2.5)
julia> ca.power(ca.DM([1, 2, 3]), 2)
DM([1, 4, 9])
julia> ca.DM([1, 2, 3]) .^ ca.DM([3, 2, 1]), 2 .^ ca.DM([1, 2, 3])
([1, 4, 3], [2, 4, 8])
julia> x = ca.SX.sym("x");
julia> x^2, x^3, x^-1, x^x
(sq(x), (x*sq(x)), (1./x), pow(x,x))
julia> x^2.5
SX(pow(x,2.5))
Extra doc: https://github.com/casadi/casadi/wiki/L_pp
Definition at line 1978 of file generic_expression.hpp.
References casadi::OP_POW.
|
inlinestatic |
Identity operation with a side effect: whenever the expression is evaluated inside a Function (and hence inside a solver), every nonzero of x is printed on its own line as "|> y : value" in storage (column-major) order, with y an identifier of choice to tell several printme nodes apart. Available as a method x.printme(y) in Python; the derivative is that of x. Use monitor to print a whole matrix at once.
>>> x = MX.sym("x")
>>> f = Function("f", [x], [x.printme(7) * 2])
>>> f(3)
|> 7 : 3.0000000000000000e+00
DM(6)
>> x = MX.sym('x');
>> f = Function('f', {x}, {x.printme(7) * 2});
>> f(3)
|> 7 : 3.0000000000000000e+00
6
julia> x = ca.MX.sym("x");
julia> f = ca.Function("f", [x], [ca.printme(x, 7) * 2]);
julia> f(3)
|> 7 : 3.0000000000000000e+00
DM(6)
Extra doc: https://github.com/casadi/casadi/wiki/L_2on
Definition at line 2515 of file generic_expression.hpp.
References casadi::OP_PRINTME.
|
static |
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
|
inlinestatic |
Elementwise quotient, not a linear solve; use solve or mldivide for that. Shape rules as for plus. Division by zero follows IEEE arithmetic (inf or nan), no error is raised. Structural zeros of x stay structural zeros; dividing by a sparse y densifies.
>>> rdivide(DM([1, 2]), 4) DM([0.25, 0.5]) >>> DM([1, 2]) / DM([4, 8]) DM([0.25, 0.25]) >>> 1 / DM.eye(2) DM( [[1, inf], [inf, 1]]) >>> DM.eye(2) / 2 DM( [[0.5, 00], [00, 0.5]])
>> rdivide(DM([1; 2]), 4) [0.25, 0.5] >> DM([1; 2]) ./ DM([4; 8]) [0.25, 0.25] >> 1 ./ DM.eye(2) [[1, inf], [inf, 1]] >> DM.eye(2) ./ 2 [[0.5, 00], [00, 0.5]]
julia> ca.rdivide(ca.DM([1, 2]), 4) DM([0.25, 0.5]) julia> ca.DM([1, 2]) ./ ca.DM([4, 8]) DM([0.25, 0.25]) julia> 1 ./ ca.DM.eye(2) DM( [[1, inf], [inf, 1]]) julia> ca.DM.eye(2) / 2 DM( [[0.5, 00], [00, 0.5]])
Extra doc: https://github.com/casadi/casadi/wiki/L_oq
Definition at line 360 of file generic_expression.hpp.
References casadi::OP_DIV.
|
inlinestatic |
This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/remainder: x - n*y with n the integer nearest to x/y (ties to even), so the result lies in [-|y|/2, |y|/2].
Notably:
This is equivalent to Python's math.remainder. There is no equivalence in Matlab. Elementwise, shape rules as for plus; structural zeros of x stay zero.
>>> remainder(DM([5, 5, -5, -5]), DM([3, -3, 3, -3]))
DM([-1, -1, 1, 1])
>>> remainder(DM([2.5, 3.5]), 2)
DM([0.5, -0.5])
>>> remainder(MX.sym("x"), 2)
MX(remainder(x,2))
>> remainder(DM([5; 5; -5; -5]), DM([3; -3; 3; -3]))
[-1, -1, 1, 1]
>> remainder(DM([2.5; 3.5]), 2)
[0.5, -0.5]
>> remainder(MX.sym('x'), 2)
remainder(x,2)
julia> ca.remainder(ca.DM([5, 5, -5, -5]), ca.DM([3, -3, 3, -3]))
DM([-1, -1, 1, 1])
julia> ca.remainder(ca.DM([2.5, 3.5]), 2)
DM([0.5, -0.5])
julia> ca.remainder(ca.MX.sym("x"), 2)
MX(remainder(x,2))
Extra doc: https://github.com/casadi/casadi/wiki/L_24x
Definition at line 2099 of file generic_expression.hpp.
References casadi::OP_REMAINDER.
|
inlinestatic |
sign(x) := -1 for x<0 sign(x) := 1 for x>0, sign(0) := 0 sign(NaN) := NaN
Elementwise; sparsity preserved. The derivative is zero everywhere.
>>> sign(DM([-2, 0, 3]))
DM([-1, 0, 1])
>>> sign(SX.sym("x"))
SX(sign(x))
>> sign(DM([-2; 0; 3]))
[-1, 0, 1]
>> sign(SX.sym('x'))
sign(x)
julia> sign.(ca.DM([-2, 0, 3]))
DM([-1, 0, 1])
julia> sign(ca.SX.sym("x"))
SX(sign(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_po
Definition at line 1912 of file generic_expression.hpp.
References casadi::OP_SIGN.
|
inlinestatic |
Elementwise; sparsity preserved (sin(0) == 0).
>>> sin(DM.eye(2))
DM(
[[0.841471, 00],
[00, 0.841471]])
>>> sin(MX.sym("x", 2))
MX(sin(x))
>> sin(DM.eye(2))
[[0.841471, 00],
[00, 0.841471]]
>> sin(MX.sym('x', 2))
sin(x)
julia> sin.(ca.DM.eye(2))
DM(
[[0.841471, 00],
[00, 0.841471]])
julia> sin.(ca.MX.sym("x", 2))
MX(sin(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p3
Definition at line 1058 of file generic_expression.hpp.
References casadi::OP_SIN.
|
inlinestatic |
Elementwise; sparsity preserved.
>>> sinh(DM([0, 1])) DM([0, 1.1752])
>> sinh(DM([0; 1])) [0, 1.1752]
julia> sinh.(ca.DM([0, 1])) DM([0, 1.1752])
Extra doc: https://github.com/casadi/casadi/wiki/L_pa
Definition at line 1335 of file generic_expression.hpp.
References casadi::OP_SINH.
|
static |
Functions called by friend functions defined here
|
inlinestatic |
Elementwise; sparsity preserved. Not exposed as a function in Python; a symbolic power with exponent 2 is turned into this operation.
>>> SX.sym("x")**2
SX(sq(x))
>> SX.sym('x').^2
sq(x)
julia> ca.SX.sym("x")^2
SX(sq(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p2
Definition at line 1010 of file generic_expression.hpp.
References casadi::OP_SQ.
|
inlinestatic |
Elementwise; sparsity preserved. A negative argument gives NaN, no error is raised. A symbolic power x**0.5 simplifies to sqrt(x).
>>> sqrt(DM([4, 9]))
DM([2, 3])
>>> SX.sym("x")**0.5
SX(sqrt(x))
>> sqrt(DM([4; 9]))
[2, 3]
>> SX.sym('x').^0.5
sqrt(x)
julia> sqrt.(ca.DM([4, 9]))
DM([2, 3])
julia> ca.SX.sym("x")^0.5
SX(sqrt(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p1
Definition at line 972 of file generic_expression.hpp.
References casadi::OP_SQRT.
|
inlinestatic |
Elementwise; sparsity preserved.
>>> tan(DM([0, 1])) DM([0, 1.55741])
>> tan(DM([0; 1])) [0, 1.55741]
julia> tan.(ca.DM([0, 1])) DM([0, 1.55741])
Extra doc: https://github.com/casadi/casadi/wiki/L_p5
Definition at line 1149 of file generic_expression.hpp.
References casadi::OP_TAN.
|
static |
Functions called by friend functions defined here
|
inlinestatic |
Elementwise; sparsity preserved.
>>> tanh(DM([0, 1])) DM([0, 0.761594])
>> tanh(DM([0; 1])) [0, 0.761594]
julia> tanh.(ca.DM([0, 1])) DM([0, 0.761594])
Extra doc: https://github.com/casadi/casadi/wiki/L_p9
Definition at line 1298 of file generic_expression.hpp.
References casadi::OP_TANH.
|
inlinestatic |
Elementwise (Hadamard) product, not the matrix product; use mtimes for that. Shape rules as for plus. The result is structurally zero wherever either operand is, so the sparsity pattern is the intersection of the patterns.
>>> times(DM([1, 2]), DM([3, 4])) DM([3, 8]) >>> DM([[1, 2], [3, 4]]) * DM([[1, 2], [3, 4]]) DM( [[1, 4], [9, 16]]) >>> DM.eye(2) * DM.ones(2, 2) DM( [[1, 00], [00, 1]])
>> times(DM([1; 2]), DM([3; 4])) [3, 8] >> DM([1 2; 3 4]) .* DM([1 2; 3 4]) [[1, 4], [9, 16]] >> DM([1 2; 3 4]) * DM([1 2; 3 4]) [[7, 10], [15, 22]] >> DM.eye(2) .* DM.ones(2, 2) [[1, 00], [00, 1]]
julia> ca.times(ca.DM([1, 2]), ca.DM([3, 4])) DM([3, 8]) julia> ca.DM([1 2; 3 4]) .* ca.DM([1 2; 3 4]) DM( [[1, 4], [9, 16]]) julia> ca.DM.eye(2) .* ca.DM.ones(2, 2) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_op
Definition at line 289 of file generic_expression.hpp.
References casadi::OP_MUL.
|
friend |
Elementwise; structural zeros are preserved. The unary functions of this group operate on every entry, keep the shape and build a symbolic expression for SX and MX. Those that map 0 to 0 (abs, sqrt, sin, tan, atan, asin, sinh, tanh, asinh, atanh, floor, ceil, sign, erf, erfinv, log1p, expm1) keep the sparsity pattern; the others (cos, cosh, exp, log, log10, acos, acosh, logic_not) return a dense result. Named fabs in Python, where the built-in abs also applies.
>>> fabs(DM([-1, 0, 2]))
DM([1, 0, 2])
>>> fabs(DM.eye(2) * -1)
DM(
[[1, 00],
[00, 1]])
>>> abs(SX.sym("x"))
SX(fabs(x))
>> abs(DM([-1; 0; 2]))
[1, 0, 2]
>> abs(-DM.eye(2))
[[1, 00],
[00, 1]]
>> abs(SX.sym('x'))
fabs(x)
julia> abs.(ca.DM([-1, 0, 2]))
DM([1, 0, 2])
julia> abs(-ca.DM.eye(2))
DM(
[[1, 00],
[00, 1]])
julia> abs(ca.SX.sym("x"))
SX(fabs(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p0
Definition at line 928 of file generic_expression.hpp.
|
friend |
Elementwise; the result is dense (acos(0) == pi/2). Arguments outside [-1, 1] give NaN.
>>> acos(DM([0, 1])) DM([1.5708, 0])
>> acos(DM([0; 1])) [1.5708, 0]
julia> acos.(ca.DM([0, 1])) DM([1.5708, 0])
Extra doc: https://github.com/casadi/casadi/wiki/L_p8
Definition at line 1264 of file generic_expression.hpp.
|
friend |
Elementwise; the result is dense. Defined for x >= 1, NaN below.
>>> acosh(DM([1, 2])) DM([0, 1.31696])
>> acosh(DM([1; 2])) [0, 1.31696]
julia> acosh.(ca.DM([1, 2])) DM([0, 1.31696])
Extra doc: https://github.com/casadi/casadi/wiki/L_pe
Definition at line 1486 of file generic_expression.hpp.
Transpose of the cofactor matrix, computed by Laplace expansion. For an invertible matrix inv(A) == adj(A)/det(A). Cost grows factorially with the size; intended for small (symbolic) matrices. A structural zero cofactor stays structurally zero. A non-square input raises an error.
>>> adj(DM([[1, 2], [3, 4]]))
DM(
[[4, -2],
[-3, 1]])
>>> X = SX.sym("X", 2, 2)
>>> adj(X)
SX(
[[X_3, (-X_2)],
[(-X_1), X_0]])
>>> adj(DM(5)), adj(DM(Sparsity.diag(3))).nnz()
(DM(1), 3)
>> adj(DM([1 2; 3 4]))
[[4, -2],
[-3, 1]]
>> X = SX.sym('X', 2, 2);
>> adj(X)
[[X_3, (-X_2)],
[(-X_1), X_0]]
>> adj(DM(5)), adj(DM(Sparsity.diag(3))).nnz()
1
3
julia> ca.adj(ca.DM([1 2; 3 4]))
DM(
[[4, -2],
[-3, 1]])
julia> X = ca.SX.sym("X", 2, 2);
julia> ca.adj(X)
SX(
[[X_3, (-X_2)],
[(-X_1), X_0]])
julia> ca.adj(ca.DM(5)), ca.nnz(ca.adj(ca.DM(ca.Sparsity.diag(3))))
(1, 3)
Extra doc: https://github.com/casadi/casadi/wiki/L_18p
Definition at line 1423 of file matrix_decl.hpp.
Returns a 1-by-1 matrix. A matrix with structural zeros gives false. Not available in Python (shadowed by the builtin); use logic_all.
>> all(DM([1; 1])), all(DM([0; 1])) 1 0 >> all(DM(Sparsity.diag(2))) 0
Extra doc: https://github.com/casadi/casadi/wiki/L_18z
Definition at line 1916 of file matrix_decl.hpp.
Returns a 1-by-1 matrix. A matrix with structural zeros gives false. Not available in Python (shadowed by the builtin); use logic_any or sum1/sum2.
>> any(DM([0; 1])), any(DM([0; 0])) 1 0 >> any(DM(Sparsity.diag(2))) 0
Extra doc: https://github.com/casadi/casadi/wiki/L_18y
Definition at line 1894 of file matrix_decl.hpp.
|
friend |
Elementwise; sparsity preserved. Arguments outside [-1, 1] give NaN.
>>> asin(DM([0, 1])) DM([0, 1.5708])
>> asin(DM([0; 1])) [0, 1.5708]
julia> asin.(ca.DM([0, 1])) DM([0, 1.5708])
Extra doc: https://github.com/casadi/casadi/wiki/L_p7
Definition at line 1227 of file generic_expression.hpp.
|
friend |
Elementwise; sparsity preserved.
>>> asinh(DM([-1, 1])) DM([-0.881374, 0.881374])
>> asinh(DM([-1; 1])) [-0.881374, 0.881374]
julia> asinh.(ca.DM([-1, 1])) DM([-0.881374, 0.881374])
Extra doc: https://github.com/casadi/casadi/wiki/L_pd
Definition at line 1449 of file generic_expression.hpp.
|
friend |
Elementwise; sparsity preserved. Result in (-pi/2, pi/2); use atan2 for a quadrant-aware angle.
>>> atan(DM([0, 1])) DM([0, 0.785398])
>> atan(DM([0; 1])) [0, 0.785398]
julia> atan.(ca.DM([0, 1])) DM([0, 0.785398])
Extra doc: https://github.com/casadi/casadi/wiki/L_p6
Definition at line 1190 of file generic_expression.hpp.
|
friend |
theta = atan2(y,x) corresponds to x = r cos(theta), y = r sin(theta)
Angle in (-pi, pi] of the point (x, y), taking the quadrant into account; the first argument is the y coordinate, as in C and numpy. Elementwise, shape rules as for plus. atan2(0, 0) is 0.
>>> atan2(DM([1, -1, 0]), DM([-1, -1, 1]))
DM([2.35619, -2.35619, 0])
>>> atan2(SX.sym("y"), SX.sym("x"))
SX(atan2(y,x))
>> atan2(DM([1; -1; 0]), DM([-1; -1; 1]))
[2.35619, -2.35619, 0]
>> atan2(SX.sym('y'), SX.sym('x'))
atan2(y,x)
julia> atan.(ca.DM([1, -1, 0]), ca.DM([-1, -1, 1]))
DM([2.35619, -2.35619, 0])
julia> atan(ca.SX.sym("y"), ca.SX.sym("x"))
SX(atan2(y,x))
Extra doc: https://github.com/casadi/casadi/wiki/L_pr
Definition at line 2149 of file generic_expression.hpp.
|
friend |
Elementwise; sparsity preserved. Defined for |x| < 1, infinite at +-1.
>>> atanh(DM([0, 0.5])) DM([0, 0.549306])
>> atanh(DM([0; 0.5])) [0, 0.549306]
julia> atanh.(ca.DM([0, 0.5])) DM([0, 0.549306])
Extra doc: https://github.com/casadi/casadi/wiki/L_pc
Definition at line 1412 of file generic_expression.hpp.
|
friend |
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
Definition at line 1210 of file generic_matrix.hpp.
|
friend |
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
Definition at line 1207 of file generic_matrix.hpp.
|
friend |
Shorthand for the two-by-two block layout [[A, B], [C, D]].
>>> blockcat(1, 2, 3, 4) DM( [[1, 2], [3, 4]])
>> [DM(1), 2; 3, 4] [[1, 2], [3, 4]]
julia> ca.blockcat(ca.DM(1), ca.DM(2), ca.DM(3), ca.DM(4)) DM( [[1, 2], [3, 4]])
Extra doc: https://github.com/casadi/casadi/wiki/L_3m
Definition at line 814 of file sparsity_interface.hpp.
|
friend |
Each inner list is a block row: its entries are concatenated horizontally, and the resulting block rows are concatenated vertically. The usual concatenation rules apply: blocks in one block row need the same number of rows, block rows need the same total number of columns, otherwise an error is raised. Inverse of blocksplit: blockcat(blocksplit(x, ...)) == x.
| v | List of block rows, each a list of matrices |
>>> blockcat([[DM(1), DM([[2, 3]])], [DM([4, 5]), DM.eye(2)]])
DM(
[[1, 2, 3],
[4, 1, 00],
[5, 00, 1]])
>>> a, b, c, d = MX.sym("a", 2, 2), MX.sym("b", 2, 1), MX.sym("c", 1, 2), MX.sym("d")
>>> blockcat([[a, b], [c, d]])
MX(horzcat(horzcat(a, b)', horzcat(c, d)')')
>> blockcat({{DM(1), DM([2 3])}, {DM([4; 5]), DM.eye(2)}})
[[1, 2, 3],
[4, 1, 00],
[5, 00, 1]]
>> a = MX.sym('a', 2, 2); b = MX.sym('b', 2, 1); c = MX.sym('c', 1, 2); d = MX.sym('d');
>> blockcat({{a, b}, {c, d}})
horzcat(horzcat(a, b)', horzcat(c, d)')'
>> [a, b; c, d]
horzcat(horzcat(a, b)', horzcat(c, d)')'
julia> ca.blockcat([[ca.DM(1), ca.DM([2 3])], [ca.DM([4, 5]), ca.DM.eye(2)]])
DM(
[[1, 2, 3],
[4, 1, 00],
[5, 00, 1]])
julia> a, b = ca.MX.sym("a", 2, 2), ca.MX.sym("b", 2, 1);
julia> c, d = ca.MX.sym("c", 1, 2), ca.MX.sym("d");
julia> ca.blockcat([[a, b], [c, d]])
MX(horzcat(horzcat(a, b)', horzcat(c, d)')')
julia> print([a b; c d])
horzcat(horzcat(a, b)', horzcat(c, d)')'
Extra doc: https://github.com/casadi/casadi/wiki/L_3l
Definition at line 778 of file sparsity_interface.hpp.
|
friend |
Every block has vert_incr rows and horz_incr columns; the blocks in the last block row or column are smaller when the dimensions are not multiples of the increments. Inverse of blockcat: blockcat(blocksplit(x, vert_incr, horz_incr)) == x.
| x | Matrix (or Sparsity) to split; any shape |
| vert_incr | Rows per block, must be positive |
| horz_incr | Columns per block, must be positive |
x
>>> x = DM([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> blocksplit(x, 2, 2) [[DM( [[1, 2], [4, 5]]), DM([3, 6])], [DM([[7, 8]]), DM(9)]] >>> blockcat(blocksplit(x, 2, 2)) DM( [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>> x = DM([1 2 3; 4 5 6; 7 8 9]);
>> b = blocksplit(x, 2, 2); disp(b{1}{1}), disp(b{1}{2}), disp(b{2}{1}), disp(b{2}{2})
[[1, 2],
[4, 5]]
[3, 6]
[[7, 8]]
9
>> blockcat(blocksplit(x, 2, 2))
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
julia> x = ca.DM([1 2 3; 4 5 6; 7 8 9]);
julia> ca.blocksplit(x, 2, 2)
2-element Vector{Vector{DM}}:
DM[
[[1, 2],
[4, 5]], [3, 6]]
DM[[[7, 8]], 9]
julia> ca.blockcat(ca.blocksplit(x, 2, 2))
DM(
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
Extra doc: https://github.com/casadi/casadi/wiki/L_3o
Definition at line 939 of file sparsity_interface.hpp.
|
friend |
The rows are split at vert_offset and every row block is then split at horz_offset. Both offset lists follow the rules of vertsplit and horzsplit: start at 0, non-decreasing, end at the row (column) count. Inverse of blockcat: blockcat(blocksplit(x, vert_offset, horz_offset)) == x.
| x | Matrix (or Sparsity) to split; any shape |
| vert_offset | Row boundaries of the block rows |
| horz_offset | Column boundaries of the block columns |
x
>>> x = DM([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> blocksplit(x, [0, 1, 3], [0, 2, 3]) [[DM([[1, 2]]), DM(3)], [DM( [[4, 5], [7, 8]]), DM([6, 9])]]
>> x = DM([1 2 3; 4 5 6; 7 8 9]);
>> b = blocksplit(x, [0, 1, 3], [0, 2, 3]); disp(size(b)), disp(b{1}{1}), disp(b{2}{1})
1 2
[[1, 2]]
[[4, 5],
[7, 8]]
>> b{1}{2}, b{2}{2}
3
[6, 9]
julia> x = ca.DM([1 2 3; 4 5 6; 7 8 9]);
julia> ca.blocksplit(x, [0, 1, 3], [0, 2, 3])
2-element Vector{Vector{DM}}:
DM[[[1, 2]], 3]
DM[
[[4, 5],
[7, 8]], [6, 9]]
Extra doc: https://github.com/casadi/casadi/wiki/L_3n
Definition at line 870 of file sparsity_interface.hpp.
|
friend |
Returns an m-by-1 expression with the spline values at x. The spline is defined by one knot vector and one degree per dimension; the number of basis functions per dimension is len(knots[i]) - degree[i] - 1 and the coefficient vector must hold m times the product of these counts, in column-major order. Outside the knot range the spline is zero. Derivatives are available.
| x | Column vector with one entry per dimension |
| coeffs | Coefficient vector; its length is not validated |
| knots | One knot vector per dimension, numeric |
| degree | Degree per dimension; must have as many entries as knots |
| m | Number of outputs per evaluation |
| opts | "lookup_mode" (see low) and "inline" (bool, default false: build an explicit expression instead of a BSpline node). Unknown keys are ignored. |
>>> x = MX.sym("x")
>>> knots = [[0, 0, 0, 0, 1, 2, 3, 3, 3, 3]]
>>> c = DM(range(6))
>>> y = bspline(x, c, knots, [3], 1)
>>> f = Function("f", [x], [y])
>>> y, f(1.5), f(4)
(MX(BSpline(x)), DM(2.5), DM(0))
>>> Function("df", [x], [jacobian(y, x)])(1.5)
DM(1.125)
>>> try:
... bspline(MX.sym("v", 2), c, knots, [3], 1)
... except Exception as e:
... print("must match" in str(e))
True
>> x = MX.sym('x');
>> knots = {[0 0 0 0 1 2 3 3 3 3]};
>> c = DM((0:5)');
>> y = bspline(x, c, knots, 3, 1);
>> f = Function('f', {x}, {y});
>> y, f(1.5), f(4)
BSpline(x)
2.5
0
>> df = Function('df', {x}, {jacobian(y, x)});
>> df(1.5)
1.125
>> try, bspline(MX.sym('v', 2), c, knots, 3, 1); catch e, disp('must match'); end
must match
julia> x = ca.MX.sym("x");
julia> knots = [[0, 0, 0, 0, 1, 2, 3, 3, 3, 3]];
julia> c = ca.DM(0:5);
julia> y = ca.bspline(x, c, knots, [3], 1);
julia> f = ca.Function("f", [x], [y]);
julia> y, f(1.5), f(4)
(BSpline(x), 2.5, 0)
julia> ca.Function("df", [x], [ca.jacobian(y, x)])(1.5)
DM(1.125)
julia> try
ca.bspline(ca.MX.sym("v", 2), c, knots, [3], 1)
catch e
println(occursin("must match", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2qi
Definition at line 4115 of file mx.hpp.
|
friend |
With symbolic knots the evaluation is always inlined into explicit MX operations.
>>> x = MX.sym("x")
>>> C = MX.sym("C", 6)
>>> K = MX.sym("K", 10)
>>> y = bspline(x, C, [K], [3], 1)
>>> f = Function("f", [x, C, K], [y])
>>> f(1.5, DM(range(6)), DM([0, 0, 0, 0, 1, 2, 3, 3, 3, 3]))
DM(2.5)
>> x = MX.sym('x');
>> C = MX.sym('C', 6);
>> K = MX.sym('K', 10);
>> y = bspline(x, C, {K}, 3, 1);
>> f = Function('f', {x, C, K}, {y});
>> f(1.5, DM((0:5)'), DM([0; 0; 0; 0; 1; 2; 3; 3; 3; 3]))
2.5
julia> x = ca.MX.sym("x"); C = ca.MX.sym("C", 6); K = ca.MX.sym("K", 10);
julia> y = ca.bspline(x, C, [K], [3], 1);
julia> f = ca.Function("f", [x, C, K], [y]);
julia> f(1.5, 0:5, [0, 0, 0, 0, 1, 2, 3, 3, 3, 3])
DM(2.5)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qk
|
friend |
Same as the fixed-coefficient overload, but coeffs may be symbolic, so the spline is differentiable with respect to its coefficients as well.
>>> x = MX.sym("x")
>>> C = MX.sym("C", 6)
>>> knots = [[0, 0, 0, 0, 1, 2, 3, 3, 3, 3]]
>>> y = bspline(x, C, knots, [3], 1)
>>> y
MX(BSplineParametric(x, C))
>>> Function("f", [x, C], [y])(1.5, DM(range(6)))
DM(2.5)
>> x = MX.sym('x');
>> C = MX.sym('C', 6);
>> knots = {[0 0 0 0 1 2 3 3 3 3]};
>> y = bspline(x, C, knots, 3, 1);
>> y
BSplineParametric(x, C)
>> f = Function('f', {x, C}, {y});
>> f(1.5, DM((0:5)'))
2.5
julia> x = ca.MX.sym("x"); C = ca.MX.sym("C", 6);
julia> knots = [[0, 0, 0, 0, 1, 2, 3, 3, 3, 3]];
julia> y = ca.bspline(x, C, knots, [3], 1);
julia> y
MX(BSplineParametric(x, C))
julia> ca.Function("f", [x, C], [y])(1.5, 0:5)
DM(2.5)
Extra doc: https://github.com/casadi/casadi/wiki/L_2qj
|
friend |
Definition at line 4225 of file mx.hpp.
|
friend |
Elementwise, towards plus infinity; sparsity preserved. The derivative is zero everywhere.
>>> ceil(DM([-1.5, 1.5])) DM([-1, 2])
>> ceil(DM([-1.5; 1.5])) [-1, 2]
julia> ceil.(ca.DM([-1.5, 1.5])) DM([-1, 2])
Extra doc: https://github.com/casadi/casadi/wiki/L_pl
Definition at line 1792 of file generic_expression.hpp.
Returns the upper triangular factor R with R^T*R == A, obtained from the sparse LDL^T factorization (without fill-reducing permutation) as diag(sqrt(D))*L^T. The sparsity pattern of A must be symmetric; otherwise an error is raised. An indefinite A gives nan entries without an error. Works symbolically on SX.
>>> R = chol(DM([[4, 2], [2, 3]])) >>> R DM( [[2, 1], [00, 1.41421]]) >>> mtimes(R.T, R) DM( [[4, 2], [2, 3]]) >>> chol(DM(Sparsity.diag(3)) * 4).nnz() 3
>> R = chol(DM([4 2; 2 3])); >> R [[2, 1], [00, 1.41421]] >> R'*R [[4, 2], [2, 3]] >> chol(DM(Sparsity.diag(3)) * 4).nnz() 3
julia> R = ca.chol(ca.DM([4 2; 2 3])) DM( [[2, 1], [00, 1.41421]]) julia> R' * R DM( [[4, 2], [2, 3]]) julia> ca.nnz(ca.chol(ca.DM(ca.Sparsity.diag(3)) * 4)) 3
Extra doc: https://github.com/casadi/casadi/wiki/L_18v
Definition at line 1750 of file matrix_decl.hpp.
|
friend |
Same argument convention as minor: i is a column index, j a row index.
>>> A = DM([[1, 2, 3], [0, 1, 4], [5, 6, 0]]) >>> cofactor(A, 0, 1), cofactor(A, 0, 0) (DM(18), DM(-24))
>> A = DM([1 2 3; 0 1 4; 5 6 0]); >> cofactor(A, 0, 1), cofactor(A, 0, 0) 18 -24
julia> A = ca.DM([1 2 3; 0 1 4; 5 6 0]); julia> ca.cofactor(A, 0, 1), ca.cofactor(A, 0, 0) (18, -24)
Extra doc: https://github.com/casadi/casadi/wiki/L_18r
Definition at line 1508 of file matrix_decl.hpp.
|
friend |
If the scalar condition ind evaluates to the integer k, where 0<=k<x.size(), then x[k] is returned, otherwise x_default is returned (also for negative or non-integer values). By default this is a chain of if_else expressions, so all cases are evaluated. With short_circuit true (MX only; SX raises an error) a Switch function evaluates only the selected case.
>>> conditional(DM(1), [DM(10), DM(20)], DM(-1))
DM(20)
>>> conditional(DM(5), [DM(10), DM(20)], DM(-1))
DM(-1)
>>> x = SX.sym("x"); y = SX.sym("y"); z = SX.sym("z")
>>> conditional(x, [y, z], 0)
SX(@1=(x==1), ((@1?z:0)+((!@1)?((x==0)?y:0):0)))
>>> X = MX.sym("X"); Y = MX.sym("Y")
>>> conditional(X, [Y, 2*Y], 0, True)
MX(switch(X, Y){0})
>> conditional(DM(1), {DM(10), DM(20)}, DM(-1))
20
>> conditional(DM(5), {DM(10), DM(20)}, DM(-1))
-1
>> x = SX.sym('x'); y = SX.sym('y'); z = SX.sym('z');
>> conditional(x, {y, z}, 0)
@1=(x==1), ((@1?z:0)+((!@1)?((x==0)?y:0):0))
>> X = MX.sym('X'); Y = MX.sym('Y');
>> conditional(X, {Y, 2*Y}, 0, true)
switch(X, Y){0}
julia> ca.conditional(ca.DM(1), [ca.DM(10), ca.DM(20)], ca.DM(-1))
DM(20)
julia> ca.conditional(ca.DM(5), [ca.DM(10), ca.DM(20)], ca.DM(-1))
DM(-1)
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); z = ca.SX.sym("z");
julia> ca.conditional(x, [y, z], 0)
SX(@1=(x==1), ((@1?z:0)+((!@1)?((x==0)?y:0):0)))
julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
julia> ca.conditional(X, [Y, 2 * Y], 0, true)
MX(switch(X, Y){0})
Extra doc: https://github.com/casadi/casadi/wiki/L_1cj
Definition at line 2711 of file generic_matrix.hpp.
|
friend |
Same value as pow, but the exponent is assumed constant: the derivative with respect to y is taken as zero. pow itself produces this operation for a non-integer constant exponent, so it is rarely needed directly. Passing a symbolic exponent gives a wrong derivative for MX; SX falls back to pow.
>>> constpow(DM(2), 3)
DM(8)
>>> x = MX.sym("x")
>>> constpow(x, 2.5), jacobian(constpow(x, 2.5), x)
(MX(pow(x,2.5)), MX((2.5*pow(x,1.5))))
>> constpow(DM(2), 3)
8
>> x = MX.sym('x');
>> constpow(x, 2.5), jacobian(constpow(x, 2.5), x)
pow(x,2.5)
(2.5*pow(x,1.5))
julia> ca.constpow(ca.DM(2), 3)
DM(8)
julia> x = ca.MX.sym("x");
julia> ca.constpow(x, 2.5), ca.jacobian(ca.constpow(x, 2.5), x)
(pow(x,2.5), (2.5*pow(x,1.5)))
Extra doc: https://github.com/casadi/casadi/wiki/L_2om
Definition at line 2470 of file generic_expression.hpp.
|
friend |
This function checks for correspondence between nodes. The detection does not descend into the expression graph.
contains_all checks that every entry of n is listed in v, contains_any that at least one is. For SX the entries must be scalar. Not defined for DM.
For mathematical dependency, see depends_on
* >>> x = SX.sym("x"); y = SX.sym("y"); z = SX.sym("z")
* >>> e = x + y
* >>> contains([x, y], y), contains([e], y), contains([e], e)
* (True, False, True)
* >>> contains([SX.sym("x")], x)
* False
* >>> contains_all([x, y, z], [x, y]), contains_all([x, y], [x, z])
* (True, False)
* >>> contains_any([x, y], [x, z]), contains_any([x, y], [z])
* (True, False)
* >>> X = MX.sym("X"); Y = MX.sym("Y")
* >>> contains([X, Y], Y), contains([X + Y], Y)
* (True, False)
*
* >> x = SX.sym('x'); y = SX.sym('y');
* >> e = x + y;
* >> fprintf('%d %d %d\n', contains({x, y}, y), contains({e}, y), contains({e}, e))
* 1 0 1
* >> contains({SX.sym('x')}, x)
* 0
* >> X = MX.sym('X'); Y = MX.sym('Y');
* >> fprintf('%d %d\n', contains({X, Y}, Y), contains({X + Y}, Y))
* 1 0
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); z = ca.SX.sym("z");
* julia> e = x + y;
* julia> ca.contains([x, y], y), ca.contains([e], y), ca.contains([e], e)
* (true, false, true)
* julia> ca.contains([ca.SX.sym("x")], x)
* false
* julia> ca.contains_all([x, y, z], [x, y]), ca.contains_all([x, y], [x, z])
* (true, false)
* julia> ca.contains_any([x, y], [x, z]), ca.contains_any([x, y], [z])
* (true, false)
* julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
* julia> ca.contains([X, Y], Y), ca.contains([X + Y], Y)
* (true, false)
*
Extra doc: https://github.com/casadi/casadi/wiki/L_2c8
Definition at line 2846 of file generic_matrix.hpp.
|
friend |
This function checks for correspondence between nodes. The detection does not descend into the expression graph.
contains_all checks that every entry of n is listed in v, contains_any that at least one is. For SX the entries must be scalar. Not defined for DM.
For mathematical dependency, see depends_on
* >>> x = SX.sym("x"); y = SX.sym("y"); z = SX.sym("z")
* >>> e = x + y
* >>> contains([x, y], y), contains([e], y), contains([e], e)
* (True, False, True)
* >>> contains([SX.sym("x")], x)
* False
* >>> contains_all([x, y, z], [x, y]), contains_all([x, y], [x, z])
* (True, False)
* >>> contains_any([x, y], [x, z]), contains_any([x, y], [z])
* (True, False)
* >>> X = MX.sym("X"); Y = MX.sym("Y")
* >>> contains([X, Y], Y), contains([X + Y], Y)
* (True, False)
*
* >> x = SX.sym('x'); y = SX.sym('y');
* >> e = x + y;
* >> fprintf('%d %d %d\n', contains({x, y}, y), contains({e}, y), contains({e}, e))
* 1 0 1
* >> contains({SX.sym('x')}, x)
* 0
* >> X = MX.sym('X'); Y = MX.sym('Y');
* >> fprintf('%d %d\n', contains({X, Y}, Y), contains({X + Y}, Y))
* 1 0
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); z = ca.SX.sym("z");
* julia> e = x + y;
* julia> ca.contains([x, y], y), ca.contains([e], y), ca.contains([e], e)
* (true, false, true)
* julia> ca.contains([ca.SX.sym("x")], x)
* false
* julia> ca.contains_all([x, y, z], [x, y]), ca.contains_all([x, y], [x, z])
* (true, false)
* julia> ca.contains_any([x, y], [x, z]), ca.contains_any([x, y], [z])
* (true, false)
* julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
* julia> ca.contains([X, Y], Y), ca.contains([X + Y], Y)
* (true, false)
*
Extra doc: https://github.com/casadi/casadi/wiki/L_2c8
Definition at line 2850 of file generic_matrix.hpp.
|
friend |
This function checks for correspondence between nodes. The detection does not descend into the expression graph.
contains_all checks that every entry of n is listed in v, contains_any that at least one is. For SX the entries must be scalar. Not defined for DM.
For mathematical dependency, see depends_on
* >>> x = SX.sym("x"); y = SX.sym("y"); z = SX.sym("z")
* >>> e = x + y
* >>> contains([x, y], y), contains([e], y), contains([e], e)
* (True, False, True)
* >>> contains([SX.sym("x")], x)
* False
* >>> contains_all([x, y, z], [x, y]), contains_all([x, y], [x, z])
* (True, False)
* >>> contains_any([x, y], [x, z]), contains_any([x, y], [z])
* (True, False)
* >>> X = MX.sym("X"); Y = MX.sym("Y")
* >>> contains([X, Y], Y), contains([X + Y], Y)
* (True, False)
*
* >> x = SX.sym('x'); y = SX.sym('y');
* >> e = x + y;
* >> fprintf('%d %d %d\n', contains({x, y}, y), contains({e}, y), contains({e}, e))
* 1 0 1
* >> contains({SX.sym('x')}, x)
* 0
* >> X = MX.sym('X'); Y = MX.sym('Y');
* >> fprintf('%d %d\n', contains({X, Y}, Y), contains({X + Y}, Y))
* 1 0
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); z = ca.SX.sym("z");
* julia> e = x + y;
* julia> ca.contains([x, y], y), ca.contains([e], y), ca.contains([e], e)
* (true, false, true)
* julia> ca.contains([ca.SX.sym("x")], x)
* false
* julia> ca.contains_all([x, y, z], [x, y]), ca.contains_all([x, y], [x, z])
* (true, false)
* julia> ca.contains_any([x, y], [x, z]), ca.contains_any([x, y], [z])
* (true, false)
* julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
* julia> ca.contains([X, Y], Y), ca.contains([X + Y], Y)
* (true, false)
*
Extra doc: https://github.com/casadi/casadi/wiki/L_2c8
Definition at line 2854 of file generic_matrix.hpp.
Returns an expression with the sparsity pattern of H that, when evaluated, modifies the value of H so that it is positive definite. Intended for Hessians in SQP-type methods. H must be square and symmetric or triangular (a triangular pattern is interpreted as one half of a symmetric matrix); other patterns raise an error. The node has no derivatives.
| H | Square expression with a symmetric or triangular sparsity pattern |
| opts | Options: "strategy": "eigen-clip" (default, eigenvalues below the margin are set to the margin), "eigen-reflect" (their absolute value is taken) or "regularize" (a multiple of the identity is added; symmetric patterns only); "margin": smallest allowed eigenvalue, default 1e-7, must be nonnegative; "max_iter_eig": iteration limit of the eigenvalue computation, default 200; "verbose": print the block structure found. Unknown keys raise an error. |
>>> H = MX.sym("H", 2, 2)
>>> f = Function("f", [H], [convexify(H)])
>>> f(DM([[1, 0], [0, -2]]))
DM(
[[1, 0],
[0, 1e-07]])
>>> f = Function("f", [H], [convexify(H, {"strategy": "eigen-reflect"})])
>>> f(DM([[1, 0], [0, -2]]))
DM(
[[1, 0],
[0, 2]])
>>> f = Function("f", [H], [convexify(H, {"strategy": "regularize", "margin": 0.5})])
>>> f(DM([[1, 0], [0, -2]]))
DM(
[[3.5, 0],
[0, 0.5]])
>>> try:
... convexify(H, {"strategy": "foo"})
... except Exception as e:
... print("Invalid convexify strategy" in str(e))
True
>> H = MX.sym('H', 2, 2);
>> f = Function('f', {H}, {convexify(H)});
>> f(DM([1 0; 0 -2]))
[[1, 0],
[0, 1e-07]]
>> f = Function('f', {H}, {convexify(H, struct('strategy', 'eigen-reflect'))});
>> f(DM([1 0; 0 -2]))
[[1, 0],
[0, 2]]
>> f = Function('f', {H}, {convexify(H, struct('strategy', 'regularize', 'margin', 0.5))});
>> f(DM([1 0; 0 -2]))
[[3.5, 0],
[0, 0.5]]
>> try, convexify(H, struct('strategy', 'foo')); catch e, disp('invalid strategy'); end
invalid strategy
julia> H = ca.MX.sym("H", 2, 2);
julia> f = ca.Function("f", [H], [ca.convexify(H)]);
julia> print(f([1 0; 0 -2]))
[[1, 0],
[0, 1e-07]]
julia> f = ca.Function("f", [H], [ca.convexify(H, Dict("strategy" => "eigen-reflect"))]);
julia> f([1 0; 0 -2])
DM(
[[1, 0],
[0, 2]])
julia> opts = Dict("strategy" => "regularize", "margin" => 0.5);
julia> f = ca.Function("f", [H], [ca.convexify(H, opts)]);
julia> f([1 0; 0 -2])
DM(
[[3.5, 0],
[0, 0.5]])
julia> try
ca.convexify(H, Dict("strategy" => "foo"))
catch e
println(occursin("Invalid convexify strategy", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_2ql
Definition at line 4326 of file mx.hpp.
|
friend |
Elementwise value with the magnitude of x and the sign of y, as C copysign; a negative zero y counts as negative. Shape rules as for plus. The derivative with respect to y is zero.
>>> copysign(DM([1, -2]), DM([-1, 1]))
DM([-1, 2])
>>> copysign(DM(3), DM(-0.0))
DM(-3)
>>> copysign(SX.sym("x"), SX.sym("y"))
SX(copysign(x,y))
>> copysign(DM([1; -2]), DM([-1; 1]))
[-1, 2]
>> copysign(DM(3), DM(-0.0))
-3
>> copysign(SX.sym('x'), SX.sym('y'))
copysign(x,y)
julia> copysign.(ca.DM([1, -2]), ca.DM([-1, 1]))
DM([-1, 2])
julia> copysign.(ca.DM(3), ca.DM(-0.0))
DM(-3)
julia> ca.copysign(ca.SX.sym("x"), ca.SX.sym("y"))
SX(copysign(x,y))
Extra doc: https://github.com/casadi/casadi/wiki/L_2ol
Definition at line 2420 of file generic_expression.hpp.
|
friend |
Elementwise; structural zeros become 1, so the result is dense.
>>> cos(DM.eye(2))
DM(
[[0.540302, 1],
[1, 0.540302]])
>>> cos(SX.sym("s", Sparsity.diag(2)))
SX(@1=1,
[[cos(s_0), @1],
[@1, cos(s_1)]])
>> cos(DM.eye(2))
[[0.540302, 1],
[1, 0.540302]]
>> cos(SX.sym('s', Sparsity.diag(2)))
@1=1,
[[cos(s_0), @1],
[@1, cos(s_1)]]
julia> cos.(ca.DM.eye(2))
DM(
[[0.540302, 1],
[1, 0.540302]])
julia> cos.(ca.SX.sym("s", ca.Sparsity.diag(2)))
SX(@1=1,
[[cos(s_0), @1],
[@1, cos(s_1)]])
Extra doc: https://github.com/casadi/casadi/wiki/L_p4
Definition at line 1115 of file generic_expression.hpp.
|
friend |
Elementwise; the result is dense (cosh(0) == 1).
>>> cosh(DM([0, 1])) DM([1, 1.54308])
>> cosh(DM([0; 1])) [1, 1.54308]
julia> cosh.(ca.DM([0, 1])) DM([1, 1.54308])
Extra doc: https://github.com/casadi/casadi/wiki/L_pb
Definition at line 1375 of file generic_expression.hpp.
|
friend |
Cross product of 3-vectors. a and b must have the same shape and one of the dimensions must be 3; for 3-by-n or n-by-3 matrices the products are taken per column or per row respectively.
| dim | 1 to take the products along the rows (3-by-n input), 2 along the columns, -1 (default) to pick the dimension of length 3 (rows first) |
>>> cross(DM([1, 0, 0]), DM([0, 1, 0]))
DM([0, 0, 1])
>>> cross(DM([[1, 0, 0], [0, 1, 0]]), DM([[0, 1, 0], [0, 0, 1]]))
DM(
[[0, 0, 1],
[1, 0, 0]])
>>> cross(SX.sym("a", 3), SX.sym("b", 3))
SX([((a_1*b_2)-(a_2*b_1)), ((a_2*b_0)-(a_0*b_2)), ((a_0*b_1)-(a_1*b_0))])
>> cross(DM([1; 0; 0]), DM([0; 1; 0]))
[0, 0, 1]
>> cross(DM([1 0 0; 0 1 0]), DM([0 1 0; 0 0 1]))
[[0, 0, 1],
[1, 0, 0]]
>> cross(SX.sym('a', 3), SX.sym('b', 3))
[((a_1*b_2)-(a_2*b_1)), ((a_2*b_0)-(a_0*b_2)), ((a_0*b_1)-(a_1*b_0))]
julia> ca.cross(ca.DM([1, 0, 0]), ca.DM([0, 1, 0]))
DM([0, 0, 1])
julia> ca.cross(ca.DM([1 0 0; 0 1 0]), ca.DM([0 1 0; 0 0 1]))
DM(
[[0, 0, 1],
[1, 0, 0]])
julia> ca.cross(ca.SX.sym("a", 3), ca.SX.sym("b", 3))
SX([((a_1*b_2)-(a_2*b_1)), ((a_2*b_0)-(a_0*b_2)), ((a_0*b_1)-(a_1*b_0))])
Extra doc: https://github.com/casadi/casadi/wiki/L_1bu
Definition at line 1501 of file generic_matrix.hpp.
|
friend |
Returns an equivalent expression in which identical subexpressions that were built separately share a single node, reducing the number of nodes and the evaluation cost. The shape is preserved. DM is returned unchanged.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> e = sin(x + y)*cos(x + y)
>>> cse(e)
SX(@1=(x+y), (sin(@1)*cos(@1)))
>>> n_nodes(e), n_nodes(cse(e))
(7, 6)
>> x = SX.sym('x'); y = SX.sym('y');
>> e = sin(x + y)*cos(x + y);
>> cse(e)
@1=(x+y), (sin(@1)*cos(@1))
>> fprintf('%d %d\n', n_nodes(e), n_nodes(cse(e)))
7 6
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> e = sin(x + y) * cos(x + y);
julia> ca.cse(e)
SX(@1=(x+y), (sin(@1)*cos(@1)))
julia> ca.n_nodes(e), ca.n_nodes(ca.cse(e))
(7, 6)
Extra doc: https://github.com/casadi/casadi/wiki/L_1co
Definition at line 3072 of file generic_matrix.hpp.
|
friend |
Subexpressions are shared across all entries of the list.
>>> X = MX.sym("X"); Y = MX.sym("Y")
>>> vertcat(sin(X + Y), cos(X + Y))
MX(vertcat(sin((X+Y)), cos((X+Y))))
>>> vertcat(*cse([sin(X + Y), cos(X + Y)]))
MX(@1=(X+Y), vertcat(sin(@1), cos(@1)))
>> X = MX.sym('X'); Y = MX.sym('Y');
>> [sin(X + Y); cos(X + Y)]
vertcat(sin((X+Y)), cos((X+Y)))
>> r = cse({sin(X + Y), cos(X + Y)});
>> vertcat(r{:})
@1=(X+Y), vertcat(sin(@1), cos(@1))
julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
julia> [sin(X + Y); cos(X + Y)]
MX(vertcat(sin((X+Y)), cos((X+Y))))
julia> vcat(ca.cse([sin(X + Y), cos(X + Y)])...)
MX(@1=(X+Y), vertcat(sin(@1), cos(@1)))
Extra doc: https://github.com/casadi/casadi/wiki/L_1cp
Definition at line 3113 of file generic_matrix.hpp.
|
friend |
Running sum down the rows (axis 0) or along the columns (axis 1); the shape is preserved. With axis -1, the columns are summed for a row vector and the rows otherwise. MATLAB numbers the axes 1 (rows) and 2 (columns).
>>> cumsum(DM([1, 2, 3]))
DM([1, 3, 6])
>>> cumsum(DM([[1, 2], [3, 4]]))
DM(
[[1, 2],
[4, 6]])
>>> cumsum(DM([[1, 2], [3, 4]]), 1)
DM(
[[1, 3],
[3, 7]])
>>> cumsum(SX.sym("x", 3))
SX(@1=(x_1+x_0), [x_0, @1, (x_2+@1)])
>> cumsum(DM([1; 2; 3]))
[1, 3, 6]
>> cumsum(DM([1 2; 3 4]))
[[1, 2],
[4, 6]]
>> cumsum(DM([1 2; 3 4]), 2)
[[1, 3],
[3, 7]]
>> cumsum(SX.sym('x', 3))
@1=(x_1+x_0), [x_0, @1, (x_2+@1)]
julia> cumsum(ca.DM([1, 2, 3]))
DM([1, 3, 6])
julia> cumsum(ca.DM([1 2; 3 4]); dims=1)
DM(
[[1, 2],
[4, 6]])
julia> cumsum(ca.DM([1 2; 3 4]); dims=2)
DM(
[[1, 3],
[3, 7]])
julia> cumsum(ca.SX.sym("x", 3))
SX(@1=(x_1+x_0), [x_0, @1, (x_2+@1)])
Extra doc: https://github.com/casadi/casadi/wiki/L_1c9
Definition at line 2190 of file generic_matrix.hpp.
|
friend |
Structural zeros become stored numerical zeros; the shape and the values of the existing nonzeros are unchanged. A dense input is returned as is.
>>> densify(DM.eye(2))
DM(
[[1, 0],
[0, 1]])
>>> densify(SX.sym("x", Sparsity.diag(2)))
SX(@1=0,
[[x_0, @1],
[@1, x_1]])
>>> densify(MX.sym("x", Sparsity.diag(2)))
MX(dense(x))
>> densify(DM.eye(2))
[[1, 0],
[0, 1]]
>> densify(SX.sym('x', Sparsity.diag(2)))
@1=0,
[[x_0, @1],
[@1, x_1]]
>> densify(MX.sym('x', Sparsity.diag(2)))
dense(x)
julia> ca.densify(ca.DM.eye(2))
DM(
[[1, 0],
[0, 1]])
julia> ca.densify(ca.SX.sym("x", ca.Sparsity.diag(2)))
SX(@1=0,
[[x_0, @1],
[@1, x_1]])
julia> ca.densify(ca.MX.sym("x", ca.Sparsity.diag(2)))
MX(dense(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_1cf
Definition at line 2501 of file generic_matrix.hpp.
|
friend |
Like densify(x) but the structural zeros get the scalar val instead of zero.
Extra doc: https://github.com/casadi/casadi/wiki/L_1cg
Definition at line 2510 of file generic_matrix.hpp.
|
friend |
The argument must be symbolic (for MX: symbolic primitives as created by MX.sym, not elements of them).
The dependency is in a mathematical way: Does the value of the argument affect the value of the expression? Equivalently, will the corresponding entry of the Jacobian by a non-zero? This is decided by sparsity propagation through the graph, so 0*x and x-x do not depend on x.
The symbol could still be present in the expression graph.
To check that kind of dependency, use contains(symvar(f),arg)
>>> x = SX.sym("x"); y = SX.sym("y")
>>> depends_on(x*y, x), depends_on(x*y, SX.sym("z"))
(True, False)
>>> depends_on(0*x, x), depends_on(x - x, x), depends_on(SX(3), x)
(False, False, False)
>>> depends_on(vertcat(x, 3), vertcat(x, y))
True
>>> v = MX.sym("v", 2)
>>> depends_on(v[0], v)
True
>> x = SX.sym('x'); y = SX.sym('y');
>> fprintf('%d %d\n', depends_on(x*y, x), depends_on(x*y, SX.sym('z')))
1 0
>> fprintf('%d %d %d\n', depends_on(0*x, x), depends_on(x - x, x), depends_on(SX(3), x))
0 0 0
>> depends_on(vertcat(x, 3), vertcat(x, y))
1
>> v = MX.sym('v', 2);
>> depends_on(v(1), v)
1
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.depends_on(x * y, x), ca.depends_on(x * y, ca.SX.sym("z"))
(true, false)
julia> ca.depends_on(0 * x, x), ca.depends_on(x - x, x), ca.depends_on(ca.SX(3), x)
(false, false, false)
julia> ca.depends_on([x; 3], [x; y])
true
julia> v = ca.MX.sym("v", 2);
julia> ca.depends_on(v[1], v)
true
Extra doc: https://github.com/casadi/casadi/wiki/L_1ck
Definition at line 2779 of file generic_matrix.hpp.
|
friend |
For DM and SX the determinant is formed by minor expansion along the sparsest row or column (a 2-by-2 directly, a scalar is returned as is); the cost grows quickly with the matrix size. For MX a determinant node is created that is evaluated through the 'qr' linear solver. A non-square argument raises an error.
>>> det(DM([[1, 2], [3, 4]]))
DM(-2)
>>> det(SX.sym("A", 2, 2))
SX(((A_0*A_3)-(A_2*A_1)))
>>> det(MX.sym("A", 2, 2))
MX(det(A))
>> det(DM([1 2; 3 4]))
-2
>> det(SX.sym('A', 2, 2))
((A_0*A_3)-(A_2*A_1))
>> det(MX.sym('A', 2, 2))
det(A)
julia> ca.det(ca.DM([1 2; 3 4]))
DM(-2)
julia> ca.det(ca.SX.sym("A", 2, 2))
SX(((A_0*A_3)-(A_2*A_1)))
julia> ca.det(ca.MX.sym("A", 2, 2))
MX(det(A))
Extra doc: https://github.com/casadi/casadi/wiki/L_1bx
Definition at line 1607 of file generic_matrix.hpp.
|
friend |
| lsolver | Name of a Linsol plugin, e.g. "qr" or "symbolicqr" (for SX only plugins with a symbolic determinant, such as "symbolicqr", are accepted) |
| dict | Options passed to the linear solver |
>>> det(DM([[1, 2], [3, 4]]), "qr") DM(-2)
>> det(DM([1 2; 3 4]), 'qr') -2
julia> ca.det(ca.DM([1 2; 3 4]), "qr") DM(-2)
Extra doc: https://github.com/casadi/casadi/wiki/L_2hx
Definition at line 1639 of file generic_matrix.hpp.
|
friend |
If the input is a vector (row or column), a square matrix with the vector on its diagonal and structural zeros elsewhere is constructed. Otherwise the diagonal entries are returned as a column vector of length min(size1(), size2()); only structurally nonzero entries are kept.
>>> diag(DM([1, 2])) DM( [[1, 00], [00, 2]]) >>> diag(DM([[1, 2], [3, 4]])) DM([1, 4]) >>> diag(DM(Sparsity.upper(2), [1, 2, 3])) DM([1, 3]) >>> diag(DM.ones(2, 3)) DM([1, 1])
>> diag(DM([1; 2])) [[1, 00], [00, 2]] >> diag(DM([1 2; 3 4])) [1, 4] >> diag(DM(Sparsity.upper(2), [1; 2; 3])) [1, 3] >> diag(DM.ones(2, 3)) [1, 1]
julia> ca.diag(ca.DM([1, 2])) DM( [[1, 00], [00, 2]]) julia> ca.diag(ca.DM([1 2; 3 4])) DM([1, 4]) julia> ca.diag(ca.DM(ca.Sparsity.upper(2), [1, 2, 3])) DM([1, 3]) julia> ca.diag(ca.DM.ones(2, 3)) DM([1, 1])
Extra doc: https://github.com/casadi/casadi/wiki/L_1cd
Definition at line 2393 of file generic_matrix.hpp.
|
friend |
Same as the list form of diagcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4k
Definition at line 2301 of file sparsity_interface.hpp.
|
friend |
Same as the list form of diagcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4l
Definition at line 2310 of file sparsity_interface.hpp.
|
friend |
Same as the list form of diagcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4m
Definition at line 2319 of file sparsity_interface.hpp.
|
friend |
Same as the list form of diagcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4n
Definition at line 2329 of file sparsity_interface.hpp.
|
friend |
Same as the list form of diagcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4o
Definition at line 2339 of file sparsity_interface.hpp.
|
friend |
Places the matrices along the diagonal, in order; all other entries are structural zeros. The blocks need not be square: the result has the sum of the row counts by the sum of the column counts. Type rules are those of horzcat. With no arguments the result is a 0-by-0 matrix. Inverse of diagsplit: diagcat(diagsplit(x, ...)) == x.
| A | List of matrices of any shape |
>>> diagcat(DM.ones(1, 2), 3)
DM(
[[1, 1, 00],
[00, 00, 3]])
>>> diagcat(SX.sym("x"), SX.sym("y", 2))
SX(
[[x, 00],
[00, y_0],
[00, y_1]])
>>> diagcat(MX.sym("x"), MX.sym("y", 2, 2))
MX(diagcat(x, y))
>>> diagcat().shape
(0, 0)
>> diagcat(DM.ones(1, 2), 3)
[[1, 1, 00],
[00, 00, 3]]
>> diagcat(SX.sym('x'), SX.sym('y', 2))
[[x, 00],
[00, y_0],
[00, y_1]]
>> diagcat(MX.sym('x'), MX.sym('y', 2, 2))
diagcat(x, y)
julia> ca.diagcat(ca.DM.ones(1, 2), 3)
DM(
[[1, 1, 00],
[00, 00, 3]])
julia> ca.diagcat(ca.SX.sym("x"), ca.SX.sym("y", 2))
SX(
[[x, 00],
[00, y_0],
[00, y_1]])
julia> ca.diagcat(ca.MX.sym("x"), ca.MX.sym("y", 2, 2))
MX(diagcat(x, y))
Extra doc: https://github.com/casadi/casadi/wiki/L_3p
Definition at line 1005 of file sparsity_interface.hpp.
|
friend |
Block i covers rows i*incr1 onwards and columns i*incr2 onwards. The number of row blocks must equal the number of column blocks.
| x | Matrix (or Sparsity) to split |
| incr1 | Rows per block, must be positive |
| incr2 | Columns per block, must be positive |
>>> diagsplit(DM([[1, 2, 0, 0], [0, 0, 7, 8]]), 1, 2) [DM([[1, 2]]), DM([[7, 8]])]
>> v = diagsplit(DM([1 2 0 0; 0 0 7 8]), 1, 2); disp(v{1}), disp(v{2})
[[1, 2]]
[[7, 8]]
julia> ca.diagsplit(ca.DM([1 2 0 0; 0 0 7 8]), 1, 2)
2-element Vector{DM}:
DM([[1, 2]])
DM([[7, 8]])
Extra doc: https://github.com/casadi/casadi/wiki/L_3t
Definition at line 1242 of file sparsity_interface.hpp.
|
friend |
Returns the consecutive incr-by- blocks of incr diagonalx; the last block is smaller when the dimension is not a multiple of incr. An error is raised when x is not square. Entries outside the blocks must be zero (structurally zero for MX and Sparsity). Inverse of diagcat: diagcat(diagsplit(x, incr)) == x for block-diagonal x.
| x | Square matrix (or Sparsity) to split |
| incr | Size of each block, must be positive |
>>> diagsplit(DM([[1, 0], [0, 4]]))
[DM(1), DM(4)]
>>> diagsplit(diagcat(SX.sym("a", 2, 2), SX.sym("b", 2, 2)), 2)
[SX(
[[a_0, a_2],
[a_1, a_3]]), SX(
[[b_0, b_2],
[b_1, b_3]])]
>>> diagsplit(MX.sym("x", Sparsity.diag(4)), 2)
[MX(diagsplit(x){0}), MX(diagsplit(x){1})]
>>> diagsplit(MX.sym("x", 4, 4), 2)
Traceback (most recent call last):
...
RuntimeError: ...nonzeros outside the diagonal blocks...
>> v = diagsplit(DM([1 0; 0 4])); disp(v{1}), disp(v{2})
1
4
>> v = diagsplit(diagcat(SX.sym('a', 2, 2), SX.sym('b', 2, 2)), 2); disp(v{1}), disp(v{2})
[[a_0, a_2],
[a_1, a_3]]
[[b_0, b_2],
[b_1, b_3]]
>> v = diagsplit(MX.sym('x', Sparsity.diag(4)), 2); disp(v{1}), disp(v{2})
diagsplit(x){0}
diagsplit(x){1}
>> try, diagsplit(MX.sym('x', 4, 4), 2); catch e, disp(e.message); end
...nonzeros outside the diagonal blocks...
julia> ca.diagsplit(ca.DM([1 0; 0 4]))
2-element Vector{DM}:
DM(1)
DM(4)
julia> v = ca.diagsplit(ca.diagcat(ca.SX.sym("a", 2, 2), ca.SX.sym("b", 2, 2)), 2);
julia> v[1]
SX(
[[a_0, a_2],
[a_1, a_3]])
julia> v[2]
SX(
[[b_0, b_2],
[b_1, b_3]])
julia> ca.diagsplit(ca.MX.sym("x", ca.Sparsity.diag(4)), 2)
2-element Vector{MX}:
MX(diagsplit(x){0})
MX(diagsplit(x){1})
julia> try
ca.diagsplit(ca.MX.sym("x", 4, 4), 2)
catch err
println(occursin("nonzeros outside the diagonal blocks", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_3s
Definition at line 1201 of file sparsity_interface.hpp.
|
friend |
Same as the two-offset variant with output_offset used for both rows and columns. An error is raised when x is not square.
| x | Square matrix (or Sparsity) to split |
| output_offset | Boundaries of the blocks |
>>> x = DM([[1, 2, 0], [3, 4, 0], [0, 0, 5]]) >>> diagsplit(x, [0, 2, 3]) [DM( [[1, 2], [3, 4]]), DM(5)] >>> diagsplit(DM.ones(2, 3), [0, 2]) Traceback (most recent call last): ... RuntimeError: ...must be square...
>> x = DM([1 2 0; 3 4 0; 0 0 5]);
>> v = diagsplit(x, [0, 2, 3]); disp(v{1}), disp(v{2})
[[1, 2],
[3, 4]]
5
>> try, diagsplit(DM.ones(2, 3), [0, 2]); catch e, disp(e.message); end
...must be square...
julia> x = ca.DM([1 2 0; 3 4 0; 0 0 5]);
julia> v = ca.diagsplit(x, [0, 2, 3]);
julia> v[1]
DM(
[[1, 2],
[3, 4]])
julia> v[2]
DM(5)
julia> try
ca.diagsplit(ca.DM.ones(2, 3), [0, 2])
catch err
println(occursin("must be square", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_3r
Definition at line 1117 of file sparsity_interface.hpp.
|
friend |
Block i is x[output_offset1[i]:output_offset1[i+1], output_offset2[i]:output_offset2[i+1]]. Both lists must have the same length, start at 0, be non-decreasing and end at the row (column) count of x. Entries of x outside the diagonal blocks must be zero (structurally zero for MX and Sparsity), otherwise an error is raised. Inverse of diagcat: diagcat(diagsplit(x, ...)) == x for block-diagonal x.
| x | Matrix (or Sparsity) to split; any shape |
| output_offset1 | Row boundaries of the blocks |
| output_offset2 | Column boundaries of the blocks |
x, one per block
>>> x = DM([[1, 2, 0], [0, 0, 6]]) >>> diagsplit(x, [0, 1, 2], [0, 2, 3]) [DM([[1, 2]]), DM(6)]
>> x = DM([1 2 0; 0 0 6]);
>> v = diagsplit(x, [0, 1, 2], [0, 2, 3]); disp(v{1}), disp(v{2})
[[1, 2]]
6
julia> x = ca.DM([1 2 0; 0 0 6]);
julia> ca.diagsplit(x, [0, 1, 2], [0, 2, 3])
2-element Vector{DM}:
DM([[1, 2]])
DM(6)
Extra doc: https://github.com/casadi/casadi/wiki/L_3q
Definition at line 1054 of file sparsity_interface.hpp.
|
friend |
Each pass subtracts neighbouring rows (axis 0) or columns (axis 1), shrinking that dimension by one; n passes are applied. With axis -1 the first non-singleton dimension is used (columns for a row vector, rows otherwise) and, as in MATLAB, a scalar gives an empty 0-by-0 result.
| n | Order, at least 1 |
| axis | 0 (rows), 1 (columns) or -1 (automatic); 1 and 2 in MATLAB |
>>> diff(DM([1, 4, 9, 16]))
DM([3, 5, 7])
>>> diff(DM([1, 4, 9, 16]), 2)
DM([2, 2])
>>> diff(DM([[1, 2], [4, 8], [9, 10]]), 1, 1)
DM([1, 4, 1])
>>> diff(SX.sym("x", 3))
SX([(x_1-x_0), (x_2-x_1)])
>>> diff(DM(3)).dim()
'0x0'
>> diff(DM([1; 4; 9; 16]))
[3, 5, 7]
>> diff(DM([1; 4; 9; 16]), 2)
[2, 2]
>> diff(DM([1 2; 4 8; 9 10]), 1, 2)
[1, 4, 1]
>> diff(SX.sym('x', 3))
[(x_1-x_0), (x_2-x_1)]
>> d = diff(DM(3)); disp(d.dim())
0x0
julia> diff(ca.DM([1, 4, 9, 16]))
DM([3, 5, 7])
julia> ca.diff(ca.DM([1, 4, 9, 16]), 2)
DM([2, 2])
julia> diff(ca.DM([1 2; 4 8; 9 10]); dims=2)
DM([1, 4, 1])
julia> diff(ca.SX.sym("x", 3))
SX([(x_1-x_0), (x_2-x_1)])
julia> ca.dim(diff(ca.DM(3)))
"0x1"
Extra doc: https://github.com/casadi/casadi/wiki/L_1c8
Definition at line 2128 of file generic_matrix.hpp.
Comparison is by node identity, not by value: two separately built expressions with the same formula are different nodes. Duplicates in a are kept.
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> difference([x, y, x], [y]), difference([x + 1], [x + 1])
([MX(x), MX(x)], [MX((1+x))])
>> x = MX.sym('x'); y = MX.sym('y');
>> d = difference({x, y, x}, {y});
>> numel(d), d{1}, d{2}
2
x
x
>> d = difference({x + 1}, {x + 1});
>> numel(d), d{1}
1
(1+x)
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> ca.difference([x, y, x], [y]), ca.difference([x + 1], [x + 1])
(MX[x, x], MX[(1+x)])
Extra doc: https://github.com/casadi/casadi/wiki/L_2qm
Definition at line 4674 of file mx.hpp.
|
friend |
Sum of the elementwise products over all entries, with x and y of the same shape (a matrix is treated as the vector of its entries). Only entries that are structurally nonzero in both arguments contribute. A shape mismatch raises an error.
>>> dot(DM([1, 2]), DM([3, 4]))
DM(11)
>>> dot(DM([[1, 2], [3, 4]]), DM([[1, 1], [1, 1]]))
DM(10)
>>> dot(DM(Sparsity.diag(2), [1, 2]), DM([[1, 1], [1, 1]]))
DM(3)
>>> dot(SX.sym("x", 2), SX.sym("y", 2))
SX(((x_0*y_0)+(x_1*y_1)))
>> dot(DM([1; 2]), DM([3; 4]))
11
>> dot(DM([1 2; 3 4]), DM([1 1; 1 1]))
10
>> dot(DM(Sparsity.diag(2), [1; 2]), DM([1 1; 1 1]))
3
>> dot(SX.sym('x', 2), SX.sym('y', 2))
((x_0*y_0)+(x_1*y_1))
julia> ca.dot(ca.DM([1, 2]), ca.DM([3, 4]))
DM(11)
julia> ca.dot(ca.DM([1 2; 3 4]), ca.DM([1 1; 1 1]))
DM(10)
julia> ca.dot(ca.DM(ca.Sparsity.diag(2), [1, 2]), ca.DM([1 1; 1 1]))
DM(3)
julia> ca.dot(ca.SX.sym("x", 2), ca.SX.sym("y", 2))
SX(((x_0*y_0)+(x_1*y_1)))
Extra doc: https://github.com/casadi/casadi/wiki/L_1ca
Definition at line 2242 of file generic_matrix.hpp.
Referenced by casadi::GenericMatrix< MatType >::sumsqr().
Splits the matrix into its strongly connected (block diagonal) components and solves the characteristic polynomial of each block with poly_roots, so every block may be at most 4-by-4. Larger blocks raise an error. Eigenvalues are assumed real. Returns a column vector; the order follows the block structure, not the magnitude. Only defined for SX; pass SX(m) for a numeric matrix.
>>> evalf(eig_symbolic(SX([[2, 1], [1, 2]])))
DM([1, 3])
>>> M = SX.sym("M", 2, 2)
>>> eig_symbolic(M)
SX(@1=(M_3+M_0), @2=sqrt((sq(@1)-(4*((M_0*M_3)-(M_2*M_1))))), @3=2, [((@1-@2)/@3),
((@1+@2)/@3)])
>>> evalf(eig_symbolic(SX.eye(5) * 3)).T
DM([[3, 3, 3, 3, 3]])
>> evalf(eig_symbolic(SX([2 1; 1 2])))
[1, 3]
>> a = SX.sym('a'); b = SX.sym('b'); c = SX.sym('c'); d = SX.sym('d');
>> eig_symbolic([a b; c d])
@1=(d+a), @2=sqrt((sq(@1)-(4*((a*d)-(b*c))))), @3=2, [((@1-@2)/@3), ((@1+@2)/@3)]
>> evalf(eig_symbolic(SX.eye(5) * 3))'
[[3, 3, 3, 3, 3]]
julia> ca.evalf(ca.eig_symbolic(ca.SX([2 1; 1 2])))
DM([1, 3])
julia> M = ca.SX.sym("M", 2, 2);
julia> l = ca.eig_symbolic(M); size(l)
(2, 1)
julia> l[1]
SX(@1=(M_3+M_0), ((@1-sqrt((sq(@1)-(4*((M_0*M_3)-(M_2*M_1))))))/2))
julia> l[2]
SX(@1=(M_3+M_0), ((@1+sqrt((sq(@1)-(4*((M_0*M_3)-(M_2*M_1))))))/2))
julia> ca.evalf(ca.eig_symbolic(ca.SX.eye(5) * 3))'
DM([[3, 3, 3, 3, 3]])
Extra doc: https://github.com/casadi/casadi/wiki/L_199
Definition at line 2720 of file matrix_decl.hpp.
|
friend |
Given two tensors, A and B, computes a third tensor C such that:
C_c = A_a * B_b
With a, b, c representing einstein indices. Instead of the classical index labels i,j,k,... we employ -1,-2,-3,... An index that appears in a or b but not in c is summed over.
A, B, C are represented as CasADi column vectors (column-major flattening), with dim_a, dim_b, dim_c indicating their tensorial dimensions. The product of dim_a must equal the number of elements of A, and likewise for B and C.
In the overload with an explicit C argument, the contraction is added to C.
>>> A = DM([1, 2, 3, 4]) >>> einstein(A, A, [2, 2], [2, 2], [2, 2], [-1, -2], [-2, -3], [-1, -3]) DM([7, 10, 15, 22]) >>> mtimes(DM([[1, 3], [2, 4]]), DM([[1, 3], [2, 4]])) DM( [[7, 15], [10, 22]]) >>> einstein(DM([1, 2, 3]), DM([4, 5, 6]), [3], [3], [], [-1], [-1], []) DM(32)
>> A = DM([1; 2; 3; 4]); >> einstein(A, A, [2, 2], [2, 2], [2, 2], [-1, -2], [-2, -3], [-1, -3]) [7, 10, 15, 22] >> DM([1 3; 2 4])*DM([1 3; 2 4]) [[7, 15], [10, 22]] >> einstein(DM([1; 2; 3]), DM([4; 5; 6]), 3, 3, [], -1, -1, []) 32
julia> A = ca.DM([1, 2, 3, 4]); julia> ca.einstein(A, A, [2, 2], [2, 2], [2, 2], [-1, -2], [-2, -3], [-1, -3]) DM([7, 10, 15, 22]) julia> ca.DM([1 3; 2 4]) * ca.DM([1 3; 2 4]) DM( [[7, 15], [10, 22]]) julia> ca.einstein(ca.DM([1, 2, 3]), ca.DM([4, 5, 6]), [3], [3], Int[], [-1], [-1], Int[]) DM(32)
Extra doc: https://github.com/casadi/casadi/wiki/L_1bk
Definition at line 1002 of file generic_matrix.hpp.
|
friend |
Given two tensors, A and B, computes a third tensor C such that:
C_c = A_a * B_b
With a, b, c representing einstein indices. Instead of the classical index labels i,j,k,... we employ -1,-2,-3,... An index that appears in a or b but not in c is summed over.
A, B, C are represented as CasADi column vectors (column-major flattening), with dim_a, dim_b, dim_c indicating their tensorial dimensions. The product of dim_a must equal the number of elements of A, and likewise for B and C.
In the overload with an explicit C argument, the contraction is added to C.
>>> A = DM([1, 2, 3, 4]) >>> einstein(A, A, [2, 2], [2, 2], [2, 2], [-1, -2], [-2, -3], [-1, -3]) DM([7, 10, 15, 22]) >>> mtimes(DM([[1, 3], [2, 4]]), DM([[1, 3], [2, 4]])) DM( [[7, 15], [10, 22]]) >>> einstein(DM([1, 2, 3]), DM([4, 5, 6]), [3], [3], [], [-1], [-1], []) DM(32)
>> A = DM([1; 2; 3; 4]); >> einstein(A, A, [2, 2], [2, 2], [2, 2], [-1, -2], [-2, -3], [-1, -3]) [7, 10, 15, 22] >> DM([1 3; 2 4])*DM([1 3; 2 4]) [[7, 15], [10, 22]] >> einstein(DM([1; 2; 3]), DM([4; 5; 6]), 3, 3, [], -1, -1, []) 32
julia> A = ca.DM([1, 2, 3, 4]); julia> ca.einstein(A, A, [2, 2], [2, 2], [2, 2], [-1, -2], [-2, -3], [-1, -3]) DM([7, 10, 15, 22]) julia> ca.DM([1 3; 2 4]) * ca.DM([1 3; 2 4]) DM( [[7, 15], [10, 22]]) julia> ca.einstein(ca.DM([1, 2, 3]), ca.DM([4, 5, 6]), [3], [3], Int[], [-1], [-1], Int[]) DM(32)
Extra doc: https://github.com/casadi/casadi/wiki/L_1bk
Definition at line 1011 of file generic_matrix.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt: this is value equality of the entries, not identity of expressions; use is_equal to test whether two symbolic expressions are the same. For symbolic operands x == x with the same node simplifies to 1. NaN is not equal to anything, including itself.
>>> eq(DM([1, 2, 3]), 2)
DM([0, 1, 0])
>>> DM.eye(2) == DM([[1, 0], [0, 1]])
DM(
[[1, 1],
[1, 1]])
>>> x = SX.sym("x")
>>> x == x, x == SX.sym("x")
(SX(1), SX((x==x)))
>>> DM(float("nan")) == DM(float("nan"))
DM(0)
>> eq(DM([1; 2; 3]), 2)
[0, 1, 0]
>> DM.eye(2) == DM([1 0; 0 1])
[[1, 1],
[1, 1]]
>> x = SX.sym('x');
>> x == x, x == SX.sym('x')
1
(x==x)
>> DM(nan) == DM(nan)
0
julia> ca.eq(ca.DM([1, 2, 3]), 2)
DM([0, 1, 0])
julia> ca.DM.eye(2) == ca.DM([1 0; 0 1])
DM(
[[1, 1],
[1, 1]])
julia> x = ca.SX.sym("x");
julia> x == x, x == ca.SX.sym("x")
(1, (x==x))
julia> ca.DM(NaN) == ca.DM(NaN)
DM(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_ov
Definition at line 644 of file generic_expression.hpp.
|
friend |
Elementwise; sparsity preserved (erf(0) == 0). Range (-1, 1).
>>> erf(DM([0, 1])) DM([0, 0.842701])
>> erf(DM([0; 1])) [0, 0.842701]
julia> ca.erf(ca.DM([0, 1])) DM([0, 0.842701])
Extra doc: https://github.com/casadi/casadi/wiki/L_pm
Definition at line 1829 of file generic_expression.hpp.
|
friend |
Elementwise; sparsity preserved. Defined on [-1, 1] with erfinv(+-1) infinite; arguments outside give NaN.
>>> erfinv(DM([0, 0.5, 1])) DM([0, 0.476936, inf])
>> erfinv(DM([0; 0.5; 1])) [0, 0.476936, inf]
julia> ca.erfinv(ca.DM([0, 0.5, 1])) DM([0, 0.476936, inf])
Extra doc: https://github.com/casadi/casadi/wiki/L_pn
Definition at line 1867 of file generic_expression.hpp.
Works on SX and MX expressions without free symbols (including constant results of function calls). The sparsity pattern is preserved. An expression that still depends on a symbol raises an error, unlike the DM(SX) constructor which yields nan.
>>> evalf(SX([[1, 2], [3, 4]]) * 2)
DM(
[[2, 4],
[6, 8]])
>>> evalf(MX(DM([1, 2])) + 1)
DM([2, 3])
>>> try: evalf(SX.sym("x"))
... except Exception as e: print("error")
error
>> evalf(SX([1 2; 3 4]) * 2)
[[2, 4],
[6, 8]]
>> evalf(MX(DM([1; 2])) + 1)
[2, 3]
>> try, evalf(SX.sym('x')); catch e, disp('error'); end
error
julia> ca.evalf(ca.SX([1 2; 3 4]) * 2)
DM(
[[2, 4],
[6, 8]])
julia> ca.evalf(ca.MX(ca.DM([1, 2])) + 1)
DM([2, 3])
julia> try ca.evalf(ca.SX.sym("x")); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_19a
Definition at line 2773 of file matrix_decl.hpp.
Builds a Function without inputs around expr and evaluates it. Function calls, solver calls and sparse constants are handled. An error is raised when the expression depends on a symbolic primitive.
>>> evalf(MX(DM([[1, 2], [3, 4]])) @ MX([1, 1]))
DM([3, 7])
>>> evalf(MX(Sparsity.lower(2)) * 2)
DM(
[[2, 00],
[2, 2]])
>>> try:
... evalf(MX.sym("x") + 1)
... except Exception as e:
... print("are free" in str(e))
True
>> evalf(MX(DM([1 2; 3 4])) * MX([1; 1]))
[3, 7]
>> evalf(MX(Sparsity.lower(2)) * 2)
[[2, 00],
[2, 2]]
>> try, evalf(MX.sym('x') + 1); catch e, disp('free variables'); end
free variables
julia> ca.evalf(ca.MX([1 2; 3 4]) * ca.MX([1, 1]))
DM([3, 7])
julia> ca.evalf(ca.MX(ca.Sparsity.lower(2)) * 2)
DM(
[[2, 00],
[2, 2]])
julia> try
ca.evalf(ca.MX.sym("x") + 1)
catch e
println(occursin("are free", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_rf
Definition at line 4451 of file mx.hpp.
|
friend |
Elementwise; the result is dense (exp(0) == 1).
>>> exp(DM.eye(2))
DM(
[[2.71828, 1],
[1, 2.71828]])
>>> exp(MX.sym("m", Sparsity.diag(2)))
MX(exp(dense(m)))
>> exp(DM.eye(2))
[[2.71828, 1],
[1, 2.71828]]
>> exp(MX.sym('m', Sparsity.diag(2)))
exp(dense(m))
julia> exp.(ca.DM.eye(2))
DM(
[[2.71828, 1],
[1, 2.71828]])
julia> exp.(ca.MX.sym("m", ca.Sparsity.diag(2)))
MX(exp(dense(m)))
Extra doc: https://github.com/casadi/casadi/wiki/L_pf
Definition at line 1534 of file generic_expression.hpp.
|
friend |
Collects additions, subtractions and multiplications by constants so that ex == dot(weights, terms), merging repeated terms. Any other operation (a product of two non-constant factors, a function call, ...) is kept as a single term with weight 1. The input must be a scalar SX; DM is not supported.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> w, t = expand(3*x - x + 5*y)
>>> w, t
(SX([2, 5]), SX([x, y]))
>>> w, t = expand(3*(x + y) + 1)
>>> t
SX([x, y, 1])
>> x = SX.sym('x'); y = SX.sym('y');
>> [w, t] = expand(3*x - x + 5*y);
>> w, t
[2, 5]
[x, y]
>> [w, t] = expand(3*(x + y) + 1);
>> t
[x, y, 1]
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> w, t = ca.expand(3*x - x + 5*y);
julia> w
SX([2, 5])
julia> t
SX([x, y])
julia> w, t = ca.expand(3*(x + y) + 1);
julia> t
SX([x, y, 1])
Extra doc: https://github.com/casadi/casadi/wiki/L_192
Definition at line 2071 of file matrix_decl.hpp.
|
friend |
Computes expm(A) for a square matrix through the 'slicot' expm plugin, which must be available in the build. Only defined for DM and MX (SX raises an error).
Extra doc: https://github.com/casadi/casadi/wiki/L_23w
Definition at line 3434 of file generic_matrix.hpp.
|
friend |
Elementwise; accurate for small x where exp(x) - 1 would lose digits. Sparsity preserved (expm1(0) == 0).
>>> expm1(DM([0, 1e-10])) DM([0, 1e-10])
>> expm1(DM([0; 1e-10])) [0, 1e-10]
julia> expm1.(ca.DM([0, 1e-10])) DM([0, 1e-10])
Extra doc: https://github.com/casadi/casadi/wiki/L_pj
Definition at line 1704 of file generic_expression.hpp.
|
friend |
Computes expm(A*t) with A constant, through the 'slicot' expm plugin, which must be available in the build. Only defined for DM and MX (SX raises an error).
| A | Square matrix |
| t | Scalar |
Extra doc: https://github.com/casadi/casadi/wiki/L_23v
Definition at line 3422 of file generic_matrix.hpp.
|
friend |
Rewrites the expressions ex so that selected intermediate results are replaced by new symbols v with definitions vdef (ex, v and vdef are outputs; in Python the call is extract(ex, opts) -> (ex, v, vdef)). Substituting vdef for v in the result gives back the original expressions. Only nodes that are physically shared in the graph are detected: two separately constructed copies of x+y are distinct nodes (apply cse first to merge them). Not defined for DM.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> e = x + y
>>> extract([sin(e), cos(e)])
([SX(sin(v_0)), SX(cos(v_0))], [SX(v_0)], [SX((x+y))])
>>> extract([sin(e), cos(e)], {"prefix": "w_", "offset": 3})
([SX(sin(w_3)), SX(cos(w_3))], [SX(w_3)], [SX((x+y))])
>>> extract([sin(x + y), cos(x + y)])
([SX(sin((x+y))), SX(cos((x+y)))], [], [])
>>> X = MX.sym("X"); Y = MX.sym("Y")
>>> f = Function("f", [X], [sin(X)]); E = X + Y
>>> extract([f(E)*f(E)], {"lift_shared": False, "lift_calls": True})
([MX((v_1*v_2))], [MX(v_0), MX(v_1), MX(v_2)], [MX((X+Y)), MX(f(v_0){0}), MX(f(v_0){0})])
>> x = SX.sym('x'); y = SX.sym('y');
>> e = x + y;
>> [ex, v, vdef] = extract({sin(e), cos(e)});
>> ex{1}, ex{2}, v{1}, vdef{1}
sin(v_0)
cos(v_0)
v_0
(x+y)
>> [ex, v, vdef] = extract({sin(e), cos(e)}, struct('prefix', 'w_', 'offset', 3));
>> ex{1}, v{1}
sin(w_3)
w_3
>> [ex, v, vdef] = extract({sin(x + y), cos(x + y)});
>> ex{1}, numel(v)
sin((x+y))
0
>> X = MX.sym('X'); Y = MX.sym('Y');
>> f = Function('f', {X}, {sin(X)}); E = X + Y;
>> opts = struct('lift_shared', false, 'lift_calls', true);
>> [ex, v, vdef] = extract({f(E)*f(E)}, opts);
>> ex{1}, numel(v), vdef{2}
(v_1*v_2)
3
f(v_0){0}
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> e = x + y;
julia> ca.extract([sin(e), cos(e)])
(SX[sin(v_0), cos(v_0)], SX[v_0], SX[(x+y)])
julia> ca.extract([sin(e), cos(e)], Dict("prefix" => "w_", "offset" => 3))
(SX[sin(w_3), cos(w_3)], SX[w_3], SX[(x+y)])
julia> ca.extract([sin(x + y), cos(x + y)])
(SX[sin((x+y)), cos((x+y))], SX[], SX[])
julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
julia> f = ca.Function("f", [X], [sin(X)]); E = X + Y;
julia> ca.extract([f(E) * f(E)], Dict("lift_shared" => false, "lift_calls" => true))
(MX[(v_1*v_2)], MX[v_0, v_1, v_2], MX[(X+Y), f(v_0){0}, f(v_0){0}])
Extra doc: https://github.com/casadi/casadi/wiki/L_1d5
Definition at line 4666 of file generic_matrix.hpp.
|
friend |
The purpose of extract_parametric is ultimately to save on evaluation time of an expression, by extracting out the parts that are only solely dependent on parameters.
For any: [expr_ret, symbols, parametric] = extract_parametric(expr, par) It holds that: substitute(expr_ret,symbols,parametric) == expr
parametric is only dependant on par expr_ret is not dependant on par, but is dependant on symbols
Example: [expr_ret, symbols, parametric] = extract_parametric((x-sqrt(p))*y+cos(p)**2, p)
expr_ret: (((x-extracted1)*y)+extracted2) symbols: [extracted1, extracted2] parametric: [sqrt(p),cos(p)**2]
Options to control the name of new symbols:
Option 'extract_trivial' controls the behaviour for extracted parts that consist of pure symbols. If false (default), these parts are not extracted.
expr may also be a list of expressions and par a list of parameter symbols (concatenated internally). An unknown option raises an error. Not defined for DM.
* >>> x = SX.sym("x"); y = SX.sym("y"); p = SX.sym("p")
* >>> expr_ret, symbols, parametric = extract_parametric((x - sqrt(p))*y + cos(p)**2, p)
* >>> expr_ret
* SX((((x-e_0)*y)+e_1))
* >>> symbols, parametric
* ([SX(e_0), SX(e_1)], [SX(sqrt(p)), SX(sq(cos(p)))])
* >>> extract_parametric(x*p, p)
* (SX((x*p)), [], [])
* >>> extract_parametric(x*p, p, {"extract_trivial": True})
* (SX((x*e_0)), [SX(e_0)], [SX(p)])
*
* >> x = SX.sym('x'); y = SX.sym('y'); p = SX.sym('p');
* >> [expr_ret, symbols, parametric] = extract_parametric((x - sqrt(p))*y + cos(p)^2, p);
* >> expr_ret
* (((x-e_0)*y)+e_1)
* >> vertcat(symbols{:}), vertcat(parametric{:})
* [e_0, e_1]
* [sqrt(p), sq(cos(p))]
* >> [expr_ret, symbols, parametric] = extract_parametric(x*p, p);
* >> expr_ret, numel(symbols)
* (x*p)
* 0
* >> opts = struct('extract_trivial', true);
* >> [expr_ret, symbols, parametric] = extract_parametric(x*p, p, opts);
* >> expr_ret, symbols{1}, parametric{1}
* (x*e_0)
* e_0
* p
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); p = ca.SX.sym("p");
* julia> e = (x - sqrt(p)) * y + cos(p)^2;
* julia> expr_ret, symbols, parametric = ca.extract_parametric(e, p);
* julia> expr_ret
* SX((((x-e_0)*y)+e_1))
* julia> symbols, parametric
* (SX[e_0, e_1], SX[sqrt(p), sq(cos(p))])
* julia> ca.extract_parametric(x * p, p)
* ((x*p), SX[], SX[])
* julia> ca.extract_parametric(x * p, p, Dict("extract_trivial" => true))
* ((x*e_0), SX[e_0], SX[p])
*
Extra doc: https://github.com/casadi/casadi/wiki/L_288
Definition at line 4272 of file generic_matrix.hpp.
|
friend |
Definition at line 4316 of file generic_matrix.hpp.
|
friend |
Definition at line 4280 of file generic_matrix.hpp.
|
friend |
Definition at line 4307 of file generic_matrix.hpp.
|
friend |
Elementwise; structural zeros are preserved. The unary functions of this group operate on every entry, keep the shape and build a symbolic expression for SX and MX. Those that map 0 to 0 (abs, sqrt, sin, tan, atan, asin, sinh, tanh, asinh, atanh, floor, ceil, sign, erf, erfinv, log1p, expm1) keep the sparsity pattern; the others (cos, cosh, exp, log, log10, acos, acosh, logic_not) return a dense result. Named fabs in Python, where the built-in abs also applies.
>>> fabs(DM([-1, 0, 2]))
DM([1, 0, 2])
>>> fabs(DM.eye(2) * -1)
DM(
[[1, 00],
[00, 1]])
>>> abs(SX.sym("x"))
SX(fabs(x))
>> abs(DM([-1; 0; 2]))
[1, 0, 2]
>> abs(-DM.eye(2))
[[1, 00],
[00, 1]]
>> abs(SX.sym('x'))
fabs(x)
julia> abs.(ca.DM([-1, 0, 2]))
DM([1, 0, 2])
julia> abs(-ca.DM.eye(2))
DM(
[[1, 00],
[00, 1]])
julia> abs(ca.SX.sym("x"))
SX(fabs(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p0
Definition at line 931 of file generic_expression.hpp.
Returns a 1-by-1 expression that evaluates to the index of the first entry of x whose value is not zero, or to the length of x when all entries are zero. Structural zeros are skipped. The result is piecewise constant, so its derivative is zero. x must be a column or row vector; matrices raise an error.
>>> v = MX.sym("v", 3)
>>> f = Function("f", [v], [find(v)])
>>> find(v).shape, f(DM([0, 3, 1])), f(DM([0, 0, 0]))
((1, 1), DM(1), DM(3))
>>> evalf(find(MX(DM(Sparsity.unit(3, 2), [1]))))
DM(2)
>>> try:
... find(MX.sym("A", 2, 2))
... except Exception as e:
... print("Argument must be vector" in str(e))
True
>> v = MX.sym('v', 3);
>> f = Function('f', {v}, {find(v)});
>> size(find(v)), f(DM([0; 3; 1])), f(DM([0; 0; 0]))
1 1
1
3
>> evalf(find(MX(DM(Sparsity.unit(3, 2), 1))))
2
>> try, find(MX.sym('A', 2, 2)); catch e, disp('argument must be vector'); end
argument must be vector
julia> v = ca.MX.sym("v", 3);
julia> f = ca.Function("f", [v], [ca.find(v)]);
julia> size(ca.find(v)), f([0, 3, 1]), f([0, 0, 0])
((1, 1), 1, 3)
julia> ca.evalf(ca.find(ca.MX(ca.DM(ca.Sparsity.unit(3, 2), [1]))))
DM(2)
julia> try
ca.find(ca.MX.sym("A", 2, 2))
catch e
println(occursin("Argument must be vector", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_r7
Definition at line 3732 of file mx.hpp.
|
friend |
Elementwise, towards minus infinity; sparsity preserved. The derivative is zero everywhere. Floor division x // y in Python is floor(x / y).
>>> floor(DM([-1.5, 1.5]))
DM([-2, 1])
>>> DM([7, -7]) // 2
DM([3, -4])
>>> SX.sym("x") // 2
SX(floor((x/2)))
>> floor(DM([-1.5; 1.5]))
[-2, 1]
>> floor(DM([7; -7]) ./ 2)
[3, -4]
>> floor(SX.sym('x') / 2)
floor((x/2))
julia> floor.(ca.DM([-1.5, 1.5]))
DM([-2, 1])
julia> fld.(ca.DM([7, -7]), 2)
DM([3, -4])
julia> floor(ca.SX.sym("x") / 2)
SX(floor((x/2)))
Extra doc: https://github.com/casadi/casadi/wiki/L_pk
Definition at line 1754 of file generic_expression.hpp.
|
friend |
Elementwise maximum; shape rules as for plus. Follows C fmax: when one operand is NaN the other is returned. The derivative is 1 with respect to the larger operand (split evenly on ties). For the maximum over the entries of one matrix use mmax.
>>> fmax(DM([1, 5]), DM([3, 2]))
DM([3, 5])
>>> fmax(DM([1, 5]), 3)
DM([3, 5])
>>> fmax(DM([1, float("nan")]), DM([float("nan"), 2]))
DM([1, 2])
>>> fmax(MX.sym("x"), MX.sym("y"))
MX(fmax(x,y))
>> fmax(DM([1; 5]), DM([3; 2]))
[3, 5]
>> max(DM([1; 5]), 3)
[3, 5]
>> fmax(DM([1; nan]), DM([nan; 2]))
[1, 2]
>> max(MX.sym('x'), MX.sym('y'))
fmax(x,y)
julia> max.(ca.DM([1, 5]), ca.DM([3, 2]))
DM([3, 5])
julia> max.(ca.DM([1, 5]), 3)
DM([3, 5])
julia> max.(ca.DM([1, NaN]), ca.DM([NaN, 2]))
DM([1, 2])
julia> max(ca.MX.sym("x"), ca.MX.sym("y"))
MX(fmax(x,y))
Extra doc: https://github.com/casadi/casadi/wiki/L_pu
Definition at line 2292 of file generic_expression.hpp.
|
friend |
Elementwise minimum; shape rules as for plus. Follows C fmin: when one operand is NaN the other is returned, NaN results only when both are NaN. The derivative is 1 with respect to the smaller operand (split evenly on ties). The sparsity pattern is kept where both operands are structurally zero; fmin with a negative scalar densifies. For the minimum over the entries of one matrix use mmin.
>>> fmin(DM([1, 5]), DM([3, 2]))
DM([1, 2])
>>> fmin(DM([1, float("nan")]), DM([float("nan"), 2]))
DM([1, 2])
>>> fmin(DM.eye(2), 1)
DM(
[[1, 00],
[00, 1]])
>>> fmin(SX.sym("x"), SX.sym("y"))
SX(fmin(x,y))
>> fmin(DM([1; 5]), DM([3; 2]))
[1, 2]
>> min(DM([1; 5]), DM([3; 2]))
[1, 2]
>> fmin(DM([1; nan]), DM([nan; 2]))
[1, 2]
>> fmin(DM.eye(2), 1)
[[1, 00],
[00, 1]]
>> min(SX.sym('x'), SX.sym('y'))
fmin(x,y)
julia> min.(ca.DM([1, 5]), ca.DM([3, 2]))
DM([1, 2])
julia> min.(ca.DM([1, NaN]), ca.DM([NaN, 2]))
DM([1, 2])
julia> min.(ca.DM.eye(2), 1)
DM(
[[1, 00],
[00, 1]])
julia> min(ca.SX.sym("x"), ca.SX.sym("y"))
SX(fmin(x,y))
Extra doc: https://github.com/casadi/casadi/wiki/L_pt
Definition at line 2235 of file generic_expression.hpp.
|
friend |
This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/fmod: the result has the sign of x and magnitude below |y|.
This is equivalent to Python's numpy.fmod and Matlab's rem. It differs from the Python operator x % y on these objects, which follows the Python convention x - y*floor(x/y) (result with the sign of y). Elementwise, shape rules as for plus; structural zeros of x stay zero. A zero divisor gives NaN.
>>> fmod(DM([5, 5, -5, -5]), DM([3, -3, 3, -3]))
DM([2, 2, -2, -2])
>>> DM([5, 5, -5, -5]) % DM([3, -3, 3, -3])
DM([2, -1, 1, -2])
>>> fmod(SX.sym("x"), 2), SX.sym("x") % 2
(SX(fmod(x,2)), SX((x-(2.*floor((x/2))))))
>> x = DM([5; 5; -5; -5]); y = DM([3; -3; 3; -3]);
>> fmod(x, y)
[2, 2, -2, -2]
>> rem(x, y)
[2, 2, -2, -2]
>> x - y .* floor(x ./ y)
[2, -1, 1, -2]
>> rem(SX.sym('x'), 2)
fmod(x,2)
julia> ca.fmod(ca.DM([5, 5, -5, -5]), ca.DM([3, -3, 3, -3]))
DM([2, 2, -2, -2])
julia> mod.(ca.DM([5, 5, -5, -5]), ca.DM([3, -3, 3, -3]))
DM([2, -1, 1, -2])
julia> ca.fmod(ca.SX.sym("x"), 2)
SX(fmod(x,2))
Definition at line 2042 of file generic_expression.hpp.
|
friend |
For each seed direction v[d] (a list with one seed per entry of arg, with matching shapes), computes the forward sensitivities of every entry of ex: the result is a list over directions of lists over ex, containing jtimes(ex[i], arg, v[d]) summed over all arguments. Not defined for DM.
| ex | List of expressions |
| arg | List of symbolic expressions |
| v | List of directions, each a list of seeds matching arg |
| opts | Options, see jacobian |
>>> x = SX.sym("x"); y = SX.sym("y")
>>> forward([x*y, x**2], [x, y], [[1, 0]])
[[SX(y), SX((2.*x))]]
>>> forward([x*y, x**2], [x, y], [[1, 0], [0, 1]])
[[SX(y), SX((2.*x))], [SX(x), SX(0)]]
>> x = SX.sym('x'); y = SX.sym('y');
>> r = forward({x*y, x^2}, {x, y}, {{1, 0}});
>> r{1}{1}, r{1}{2}
y
(2.*x)
>> r = forward({x*y, x^2}, {x, y}, {{1, 0}, {0, 1}});
>> r{2}{1}, r{2}{2}
x
0
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.forward([x*y, x^2], [x, y], [[ca.SX(1), ca.SX(0)]])
1-element Vector{Vector{SX}}:
SX[y, (2.*x)]
julia> ca.forward([x*y, x^2], [x, y], [[ca.SX(1), ca.SX(0)], [ca.SX(0), ca.SX(1)]])
2-element Vector{Vector{SX}}:
SX[y, (2.*x)]
SX[x, 0]
Extra doc: https://github.com/casadi/casadi/wiki/L_1cx
Definition at line 3735 of file generic_matrix.hpp.
|
friend |
Evaluates f at the five Gauss points of [a, b] and returns the weighted sum, which is exact for polynomials in x up to degree 9. Only defined for SX.
| f | Scalar expression to integrate; it may depend only on x |
| x | Scalar symbolic integration variable |
| a | Lower bound, a numeric constant |
| b | Upper bound, a numeric constant |
| order | Must be 5; any other value raises an error |
| w | Reserved; must be empty |
>>> x = SX.sym("x")
>>> try: gauss_quadrature(x**2, x, 0, 1, 3)
... except Exception as e: print("error")
error
>> x = SX.sym('x');
>> try, gauss_quadrature(x^2, x, 0, 1, 3); catch e, disp('error'); end
error
julia> x = ca.SX.sym("x");
julia> try ca.gauss_quadrature(x^2, x, 0, 1, 3); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_196
Definition at line 2390 of file matrix_decl.hpp.
|
friend |
Evaluates f at the five Gauss points of [a, b] and returns the weighted sum, which is exact for polynomials in x up to degree 9. Only defined for SX.
| f | Scalar expression to integrate; it may depend only on x |
| x | Scalar symbolic integration variable |
| a | Lower bound, a numeric constant |
| b | Upper bound, a numeric constant |
| order | Must be 5; any other value raises an error |
| w | Reserved; must be empty |
>>> x = SX.sym("x")
>>> try: gauss_quadrature(x**2, x, 0, 1, 3)
... except Exception as e: print("error")
error
>> x = SX.sym('x');
>> try, gauss_quadrature(x^2, x, 0, 1, 3); catch e, disp('error'); end
error
julia> x = ca.SX.sym("x");
julia> try ca.gauss_quadrature(x^2, x, 0, 1, 3); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_196
Definition at line 2384 of file matrix_decl.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt. Implemented as y <= x.
>>> ge(DM([1, 2, 3]), 2)
DM([0, 1, 1])
>>> ge(MX.sym("x"), MX.sym("y"))
MX((y<=x))
>> ge(DM([1; 2; 3]), 2)
[0, 1, 1]
>> MX.sym('x') >= MX.sym('y')
(y<=x)
julia> ca.ge(ca.DM([1, 2, 3]), 2)
DM([0, 1, 1])
julia> ca.ge(ca.MX.sym("x"), ca.MX.sym("y"))
MX((y<=x))
Extra doc: https://github.com/casadi/casadi/wiki/L_ou
Definition at line 574 of file generic_expression.hpp.
|
friend |
Computed with one reverse-mode sweep (jtimes with tr true) and projected onto the sparsity of arg: the result has the shape and pattern of arg, also for a matrix arg. A non-scalar ex raises an error (use jacobian).
| ex | Scalar expression to take the gradient of |
| arg | Symbolic expression (any shape) |
| opts | Options, see jacobian |
arg
>>> x = SX.sym("x"); y = SX.sym("y")
>>> gradient(x*y + x**2, vertcat(x, y))
SX([((2.*x)+y), x])
>>> gradient(x**2, vertcat(x, y))
SX([(2.*x), 0])
>>> A = SX.sym("A", 2, 2)
>>> gradient(sumsqr(A), A)
SX(
[[(2.*A_0), (2.*A_2)],
[(2.*A_1), (2.*A_3)]])
>> x = SX.sym('x'); y = SX.sym('y');
>> gradient(x*y + x^2, vertcat(x, y))
[((2.*x)+y), x]
>> gradient(x^2, vertcat(x, y))
[(2.*x), 0]
>> A = SX.sym('A', 2, 2);
>> gradient(sumsqr(A), A)
[[(2.*A_0), (2.*A_2)],
[(2.*A_1), (2.*A_3)]]
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.gradient(x * y + x^2, [x; y])
SX([((2.*x)+y), x])
julia> ca.gradient(x^2, [x; y])
SX([(2.*x), 0])
julia> A = ca.SX.sym("A", 2, 2);
julia> ca.gradient(ca.sumsqr(A), A)
SX(
[[(2.*A_0), (2.*A_2)],
[(2.*A_1), (2.*A_3)]])
Extra doc: https://github.com/casadi/casadi/wiki/L_23x
Definition at line 3570 of file generic_matrix.hpp.
|
friend |
Replaces every occurrence of the node v[i] in ex by vdef[i]. Unlike substitute, which only accepts symbolic primitives for v, graph_substitute matches any node, so intermediate results and Function call results can be replaced. Matching is by identity: an expression that was rebuilt (x + y created twice) is a different node and is not matched. Nodes that do not depend on any substituted node are reused, not copied. Shapes of v[i] and vdef[i] must agree.
| ex | Expression to substitute in |
| v | Nodes to replace |
| vdef | Replacements, same length as v |
| updated | Set to true if any substitution took place (C++ only) |
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> s = x + y
>>> e = sin(s) + s
>>> graph_substitute(e, [s], [MX(3)])
MX(3.14112)
>>> graph_substitute(e, [x + y], [MX(3)])
MX(@1=(x+y), (sin(@1)+@1))
>>> try:
... substitute(e, s, MX(3))
... except Exception as err:
... print("not symbolic" in str(err))
True
>>> try:
... graph_substitute(e, [s], [MX.sym("z", 2)])
... except Exception as err:
... print("Inconsistent shapes" in str(err))
True
>> x = MX.sym('x'); y = MX.sym('y');
>> s = x + y;
>> e = sin(s) + s;
>> graph_substitute(e, {s}, {MX(3)})
3.14112
>> graph_substitute(e, {x + y}, {MX(3)})
@1=(x+y), (sin(@1)+@1)
>> try, substitute(e, s, MX(3)); catch err, disp('not symbolic'); end
not symbolic
>> z = MX.sym('z', 2);
>> try, graph_substitute(e, {s}, {z}); catch err, disp('inconsistent shapes'); end
inconsistent shapes
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> s = x + y;
julia> e = sin(s) + s;
julia> ca.graph_substitute(e, [s], [ca.MX(3)])
MX(3.14112)
julia> ca.graph_substitute(e, [x + y], [ca.MX(3)])
MX(@1=(x+y), (sin(@1)+@1))
julia> try
ca.substitute(e, s, ca.MX(3))
catch err
println(occursin("not symbolic", sprint(showerror, err)))
end
true
julia> try
ca.graph_substitute(e, [s], [ca.MX.sym("z", 2)])
catch err
println(occursin("Inconsistent shapes", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_r9
Definition at line 3887 of file mx.hpp.
|
friend |
|
friend |
Same as the single-expression overload, applied to a list of expressions sharing one traversal.
>>> x = MX.sym("x")
>>> s = x + 1
>>> graph_substitute([sin(s), 2*s], [s], [MX(3)])
[MX(0.14112), MX(6)]
>> x = MX.sym('x');
>> s = x + 1;
>> r = graph_substitute({sin(s), 2*s}, {s}, {MX(3)});
>> r{1}, r{2}
0.14112
6
julia> x = ca.MX.sym("x");
julia> s = x + 1;
julia> ca.graph_substitute([sin(s), 2 * s], [s], [ca.MX(3)])
2-element Vector{MX}:
MX(0.14112)
MX(6)
Extra doc: https://github.com/casadi/casadi/wiki/L_ra
|
friend |
|
friend |
Elementwise comparison with 0/1 result, see lt. Implemented as y < x, which is how a symbolic expression prints.
>>> gt(DM([1, 2, 3]), 2)
DM([0, 0, 1])
>>> gt(SX.sym("x"), SX.sym("y"))
SX((y<x))
>> gt(DM([1; 2; 3]), 2)
[0, 0, 1]
>> SX.sym('x') > SX.sym('y')
(y<x)
julia> ca.gt(ca.DM([1, 2, 3]), 2)
DM([0, 0, 1])
julia> ca.gt(ca.SX.sym("x"), ca.SX.sym("y"))
SX((y<x))
Extra doc: https://github.com/casadi/casadi/wiki/L_ot
Definition at line 528 of file generic_expression.hpp.
H(x) = 0 for x < 0, 1/2 for x == 0 and 1 for x > 0, computed as (1 + sign(x))/2. Structural zeros of a sparse input become 1/2. Not defined for MX.
>>> heaviside(DM([-1, 0, 1]))
DM([0, 0.5, 1])
>>> heaviside(SX.sym("x"))
SX(((1+sign(x))/2))
>> heaviside(DM([-1; 0; 1]))
[0, 0.5, 1]
>> heaviside(SX.sym('x'))
((1+sign(x))/2)
julia> ca.heaviside(ca.DM([-1, 0, 1]))
DM([0, 0.5, 1])
julia> ca.heaviside(ca.SX.sym("x"))
SX(((1+sign(x))/2))
Extra doc: https://github.com/casadi/casadi/wiki/L_195
Definition at line 2234 of file matrix_decl.hpp.
|
friend |
Computes the gradient g = gradient(ex, arg) and the Hessian jacobian(g, arg), an arg.numel()-by-arg.numel() symmetric matrix; the "symmetric" option is set unless given in opts. ex must be scalar. The overload with output_g also returns the gradient; in Python, MATLAB and Julia this is the variant that is exposed, so the result is always the pair (H, g). Not defined for DM.
| opts | Options, see jacobian |
>>> x = SX.sym("x"); y = SX.sym("y")
>>> H, g = hessian(x**2*y, vertcat(x, y))
>>> H
SX(@1=(2.*x),
[[(2.*y), @1],
[@1, 00]])
>>> g
SX([((2.*x)*y), sq(x)])
>> x = SX.sym('x'); y = SX.sym('y');
>> [H, g] = hessian(x^2*y, vertcat(x, y));
>> H
@1=(2.*x),
[[(2.*y), @1],
[@1, 00]]
>> g
[((2.*x)*y), sq(x)]
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> H, g = ca.hessian(x^2 * y, [x; y]);
julia> H
SX(@1=(2.*x),
[[(2.*y), @1],
[@1, 00]])
julia> g
SX([((2.*x)*y), sq(x)])
Extra doc: https://github.com/casadi/casadi/wiki/L_23z
Definition at line 3851 of file generic_matrix.hpp.
|
friend |
Computes the gradient g = gradient(ex, arg) and the Hessian jacobian(g, arg), an arg.numel()-by-arg.numel() symmetric matrix; the "symmetric" option is set unless given in opts. ex must be scalar. The overload with output_g also returns the gradient; in Python, MATLAB and Julia this is the variant that is exposed, so the result is always the pair (H, g). Not defined for DM.
| opts | Options, see jacobian |
>>> x = SX.sym("x"); y = SX.sym("y")
>>> H, g = hessian(x**2*y, vertcat(x, y))
>>> H
SX(@1=(2.*x),
[[(2.*y), @1],
[@1, 00]])
>>> g
SX([((2.*x)*y), sq(x)])
>> x = SX.sym('x'); y = SX.sym('y');
>> [H, g] = hessian(x^2*y, vertcat(x, y));
>> H
@1=(2.*x),
[[(2.*y), @1],
[@1, 00]]
>> g
[((2.*x)*y), sq(x)]
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> H, g = ca.hessian(x^2 * y, [x; y]);
julia> H
SX(@1=(2.*x),
[[(2.*y), @1],
[@1, 00]])
julia> g
SX([((2.*x)*y), sq(x)])
Extra doc: https://github.com/casadi/casadi/wiki/L_23z
Definition at line 3855 of file generic_matrix.hpp.
|
friend |
Same as the list form of horzcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4a
Definition at line 2205 of file sparsity_interface.hpp.
|
friend |
Same as the list form of horzcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4b
Definition at line 2214 of file sparsity_interface.hpp.
|
friend |
Same as the list form of horzcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4c
Definition at line 2223 of file sparsity_interface.hpp.
|
friend |
Same as the list form of horzcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4d
Definition at line 2233 of file sparsity_interface.hpp.
|
friend |
Same as the list form of horzcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4e
Definition at line 2243 of file sparsity_interface.hpp.
|
friend |
Places the matrices side by side, in order: the result has the row count of the inputs and a column count equal to the sum of the column counts. All inputs must have the same number of rows; a 0-by-0 matrix is ignored. The result is of the type of the arguments, numeric arguments are converted to the symbolic type (DM mixes with SX or MX, but SX and MX cannot be mixed). The sparsity pattern of each block is preserved. With no arguments the result is a 1-by-0 matrix.
Alternative terminology: horizontal stack, hstack, horizontal append, [a b]. Inverse of horzsplit: horzcat(horzsplit(x, ...)) == x.
| v | List of matrices with matching row count |
v side by side
>>> horzcat(DM([1, 2]), DM([3, 4]), DM([5, 6]))
DM(
[[1, 3, 5],
[2, 4, 6]])
>>> horzcat(SX.sym("x", 2), DM.ones(2, 1))
SX(@1=1,
[[x_0, @1],
[x_1, @1]])
>>> horzcat(MX.sym("x", 2, 2), MX.sym("y", 2, 0))
MX(x)
>>> horzcat().shape, horzcat(DM(2, 3), DM(0, 0)).shape
((1, 0), (2, 3))
>>> horzcat(DM.ones(2, 2), DM.ones(3, 1))
Traceback (most recent call last):
...
RuntimeError: ...Mismatching number of rows...
>> [DM([1; 2]), DM([3; 4]), DM([5; 6])]
[[1, 3, 5],
[2, 4, 6]]
>> horzcat(SX.sym('x', 2), DM.ones(2, 1))
@1=1,
[[x_0, @1],
[x_1, @1]]
>> [MX.sym('x', 2, 2), MX.sym('y', 2, 0)]
x
>> size([DM(2, 3), DM(0, 0)])
2 3
>> try, [DM.ones(2, 2), DM.ones(3, 1)]; catch e, disp(e.message); end
...Mismatching number of rows
julia> [ca.DM([1, 2]) ca.DM([3, 4]) ca.DM([5, 6])]
DM(
[[1, 3, 5],
[2, 4, 6]])
julia> [ca.SX.sym("x", 2) ca.DM.ones(2, 1)]
SX(@1=1,
[[x_0, @1],
[x_1, @1]])
julia> [ca.MX.sym("x", 2, 2) ca.MX.sym("y", 2, 0)]
MX(x)
julia> size([ca.DM(2, 3) ca.DM(0, 0)])
(2, 3)
julia> try
[ca.DM.ones(2, 2) ca.DM.ones(3, 1)]
catch err
println(occursin("dimension mismatch", sprint(showerror, err)))
end
false
Extra doc: https://github.com/casadi/casadi/wiki/L_3e
Definition at line 171 of file sparsity_interface.hpp.
|
friend |
Returns the consecutive column blocks of x, each with incr columns, in order. The last block is smaller when the column count is not a multiple of incr. A matrix without columns gives an empty list. Each block carries the corresponding part of the sparsity pattern. Inverse of horzcat: horzcat(horzsplit(x, incr)) == x.
| x | Matrix (or Sparsity) to split; any shape |
| incr | Number of columns per block, must be positive |
x
>>> horzsplit(SX.sym("x", 1, 3))
[SX(x_0), SX(x_1), SX(x_2)]
>>> horzsplit(DM([[1, 2, 3, 4, 5]]), 2)
[DM([[1, 2]]), DM([[3, 4]]), DM(5)]
>>> horzsplit(MX.sym("x", 2, 4), 2)
[MX(horzsplit(x){0}), MX(horzsplit(x){1})]
>>> horzsplit(Sparsity.diag(3), 2)
[Sparsity(3x2,2nz), Sparsity(3x1,1nz)]
>>> horzsplit(MX.sym("x", 2, 0))
[]
>> v = horzsplit(SX.sym('x', 1, 3)); disp(numel(v)), disp(v{1}), disp(v{3})
3
x_0
x_2
>> v = horzsplit(DM([1 2 3 4 5]), 2); disp(numel(v)), disp(v{1}), disp(v{3})
3
[[1, 2]]
5
>> v = horzsplit(MX.sym('x', 2, 4), 2); disp(v{1}), disp(v{2})
horzsplit(x){0}
horzsplit(x){1}
>> v = horzsplit(Sparsity.diag(3), 2); disp(v{1}), disp(v{2})
3x2,2nz
3x1,1nz
>> v = horzsplit(MX.sym('x', 2, 0)); disp(numel(v))
0
julia> ca.horzsplit(ca.SX.sym("x", 1, 3))
3-element Vector{SX}:
SX(x_0)
SX(x_1)
SX(x_2)
julia> ca.horzsplit(ca.DM([1 2 3 4 5]), 2)
3-element Vector{DM}:
DM([[1, 2]])
DM([[3, 4]])
DM(5)
julia> ca.horzsplit(ca.MX.sym("x", 2, 4), 2)
2-element Vector{MX}:
MX(horzsplit(x){0})
MX(horzsplit(x){1})
julia> ca.horzsplit(ca.Sparsity.diag(3), 2)
2-element Vector{Sparsity}:
Sparsity(3x2,2nz)
Sparsity(3x1,1nz)
julia> ca.horzsplit(ca.MX.sym("x", 2, 0))
MX[]
Extra doc: https://github.com/casadi/casadi/wiki/L_3h
Definition at line 408 of file sparsity_interface.hpp.
|
friend |
Returns the column blocks x[:, offset[i]:offset[i+1]], in order. The offsets must start at 0, be non-decreasing and end at the number of columns of x, otherwise an error is raised. Two equal consecutive offsets give an empty block. Each block carries the corresponding part of the sparsity pattern. Inverse of horzcat: horzcat(horzsplit(x, offset)) == x.
| x | Matrix (or Sparsity) to split; any shape |
| offset | Start column of every block followed by the column count of x |
x, one per block
>>> x = DM([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) >>> horzsplit(x, [0, 2, 5]) [DM( [[1, 2], [6, 7]]), DM( [[3, 4, 5], [8, 9, 10]])] >>> horzsplit(x, [0, 0, 5])[0].shape (2, 0) >>> horzsplit(x, [0, 2]) Traceback (most recent call last): ... RuntimeError: ...must start at 0, be nondecreasing and end at 5...
>> x = DM([1 2 3 4 5; 6 7 8 9 10]);
>> v = horzsplit(x, [0, 2, 5]); disp(numel(v)), disp(v{1}), disp(v{2})
2
[[1, 2],
[6, 7]]
[[3, 4, 5],
[8, 9, 10]]
>> v = horzsplit(x, [0, 0, 5]); disp(size(v{1}))
2 0
>> try, horzsplit(x, [0, 2]); catch e, disp(e.message); end
...must start at 0, be nondecreasing and end at 5...
julia> x = ca.DM([1 2 3 4 5; 6 7 8 9 10]);
julia> v = ca.horzsplit(x, [0, 2, 5]);
julia> length(v)
2
julia> v[1]
DM(
[[1, 2],
[6, 7]])
julia> v[2]
DM(
[[3, 4, 5],
[8, 9, 10]])
julia> size(ca.horzsplit(x, [0, 0, 5])[1])
(2, 0)
julia> try
ca.horzsplit(x, [0, 2])
catch err
println(occursin("end at 5", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_3g
Definition at line 328 of file sparsity_interface.hpp.
|
friend |
Returns n column blocks of equal width, in order. An error is raised when the column count of x is not a multiple of n or n is negative. A matrix without columns gives n copies of itself. Inverse of horzcat: horzcat(horzsplit_n(x, n)) == x.
n matrices of the same type as x
>>> horzsplit_n(DM([[1, 2, 3, 4]]), 2) [DM([[1, 2]]), DM([[3, 4]])] >>> horzsplit_n(DM(2, 0), 3) [DM(2x0), DM(2x0), DM(2x0)] >>> horzsplit_n(DM([[1, 2, 3]]), 2) Traceback (most recent call last): ... RuntimeError: ...must be a multiple of n...
>> v = horzsplit_n(DM([1 2 3 4]), 2); disp(v{1}), disp(v{2})
[[1, 2]]
[[3, 4]]
>> v = horzsplit_n(DM(2, 0), 3); disp(numel(v)), disp(size(v{1}))
3
2 0
>> try, horzsplit_n(DM([1 2 3]), 2); catch e, disp(e.message); end
...must be a multiple of n...
julia> ca.horzsplit_n(ca.DM([1 2 3 4]), 2)
2-element Vector{DM}:
DM([[1, 2]])
DM([[3, 4]])
julia> ca.horzsplit_n(ca.DM(2, 0), 3)
3-element Vector{DM}:
DM(2x0)
DM(2x0)
DM(2x0)
julia> try
ca.horzsplit_n(ca.DM([1 2 3]), 2)
catch err
println(occursin("must be a multiple of n", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_277
Definition at line 472 of file sparsity_interface.hpp.
|
friend |
Elementwise; avoids the overflow and underflow of forming the squares, as C hypot. Shape rules as for plus; the result is structurally zero where both operands are.
>>> hypot(DM(3), DM(4))
DM(5)
>>> hypot(DM(1e200), DM(1e200))
DM(1.41421e+200)
>>> hypot(SX.sym("x"), SX.sym("y"))
SX(hypot(x,y))
>> hypot(DM(3), DM(4))
5
>> hypot(DM(1e200), DM(1e200))
1.41421e+200
>> hypot(SX.sym('x'), SX.sym('y'))
hypot(x,y)
julia> hypot(ca.DM(3), ca.DM(4))
DM(5)
julia> hypot(ca.DM(1e200), ca.DM(1e200))
DM(1.41421e+200)
julia> hypot(ca.SX.sym("x"), ca.SX.sym("y"))
SX(hypot(x,y))
Extra doc: https://github.com/casadi/casadi/wiki/L_pw
Definition at line 2568 of file generic_expression.hpp.
|
friend |
Ternary operator, "cond ? if_true : if_false"
Selects if_true where cond is nonzero and if_false elsewhere. cond may be a scalar or have the shape of the branches (elementwise selection); a scalar branch is broadcast. By default the result is if_else_zero(cond, if_true) + if_else_zero(!cond, if_false): both branches are part of the expression and are evaluated, but the value of the unselected branch is discarded, so a nan or inf there does not propagate. With short_circuit true (MX only; ignored for SX and DM) the branches are wrapped in functions and only the selected one is evaluated.
>>> if_else(DM(1), DM(10), DM(20)), if_else(DM(0), DM(10), DM(20))
(DM(10), DM(20))
>>> if_else(DM([1, 0]), DM([1, 2]), DM([3, 4]))
DM([1, 4])
>>> x = SX.sym("x")
>>> if_else(x > 0, x, -x)
SX(@1=(0<x), ((@1?x:0)+((!@1)?(-x):0)))
>>> f = Function("f", [x], [if_else(x >= 0, sqrt(x), 0)])
>>> f(-1)
DM(0)
>>> X = MX.sym("X")
>>> if_else(X > 0, X, -X, True)
MX(switch((0<X), X){0})
>> if_else(DM(1), DM(10), DM(20)), if_else(DM(0), DM(10), DM(20))
10
20
>> if_else(DM([1; 0]), DM([1; 2]), DM([3; 4]))
[1, 4]
>> x = SX.sym('x');
>> if_else(x > 0, x, -x)
@1=(0<x), ((@1?x:0)+((!@1)?(-x):0))
>> f = Function('f', {x}, {if_else(x >= 0, sqrt(x), 0)});
>> f(-1)
0
>> X = MX.sym('X');
>> if_else(X > 0, X, -X, true)
switch((0<X), X){0}
julia> a = ca.DM(10); b = ca.DM(20);
julia> ca.if_else(ca.DM(1), a, b), ca.if_else(ca.DM(0), a, b)
(10, 20)
julia> ca.if_else(ca.DM([1, 0]), ca.DM([1, 2]), ca.DM([3, 4]))
DM([1, 4])
julia> x = ca.SX.sym("x");
julia> ca.if_else(x > 0, x, -x)
SX(@1=(0<x), ((@1?x:0)+((!@1)?(-x):0)))
julia> f = ca.Function("f", [x], [ca.if_else(x >= 0, sqrt(x), 0)]);
julia> f(-1)
DM(0)
julia> X = ca.MX.sym("X");
julia> ca.if_else(X > 0, X, -X, true)
MX(switch((0<X), X){0})
Extra doc: https://github.com/casadi/casadi/wiki/L_1ci
Definition at line 2650 of file generic_matrix.hpp.
|
friend |
Elementwise: y where x is nonzero, 0 elsewhere; the result is structurally zero wherever either operand is. The value of y in the inactive branch does not propagate, so a NaN or inf there yields 0 rather than NaN, and the derivatives are treated accordingly. This is the building block of if_else; it is not exposed as a function in Python, use if_else(x, y, 0) there.
Extra doc: https://github.com/casadi/casadi/wiki/L_ps
Definition at line 2169 of file generic_expression.hpp.
|
friend |
The data points are (x[i], v[i, :]): row i of v holds the values at abscissa x[i], so v has as many rows as x has entries and every column is interpolated independently. The result has one row per query point xq[j].
Queries outside the range of x are clamped to the first or last data point (no extrapolation). The result is a constant sparse matrix times v, so for symbolic v the expression is linear in v.
| x | Abscissae, strictly increasing, at least two entries |
| v | Data values, x.size()-by-m |
| xq | Query abscissae, any order |
| mode | "linear" (interpolate), "floor" (value at the data point at or below the query) or "ceil" (at or above); any other string raises an error |
| equidistant | When true, x is assumed uniformly spaced and the interval is located arithmetically from x[0] and x[1] instead of by search |
>>> interp1d([0, 1, 2], DM([0, 10, 20]), [0.5, 1.5])
DM([5, 15])
>>> interp1d([0, 1, 2], DM([0, 10, 20]), [0.5, 1.5], "floor")
DM([0, 10])
>>> interp1d([0, 1, 2], DM([[0, 1], [10, 11], [20, 21]]), [0.5, 2])
DM(
[[5, 6],
[20, 21]])
>>> interp1d([0, 1, 2], DM([0, 10, 20]), [-1, 3])
DM([0, 20])
>>> interp1d([0, 1, 2], SX.sym("v", 3), [0.5])
SX(@1=0.5, ((@1*v_0)+(@1*v_1)))
>> interp1d([0, 1, 2], DM([0; 10; 20]), [0.5, 1.5])
[5, 15]
>> interp1d([0, 1, 2], DM([0; 10; 20]), [0.5, 1.5], 'floor')
[0, 10]
>> interp1d([0, 1, 2], DM([0 1; 10 11; 20 21]), [0.5, 2])
[[5, 6],
[20, 21]]
>> interp1d([0, 1, 2], DM([0; 10; 20]), [-1, 3])
[0, 20]
>> interp1d([0, 1, 2], SX.sym('v', 3), 0.5)
@1=0.5, ((@1*v_0)+(@1*v_1))
julia> ca.interp1d([0, 1, 2], ca.DM([0, 10, 20]), [0.5, 1.5])
DM([5, 15])
julia> ca.interp1d([0, 1, 2], ca.DM([0, 10, 20]), [0.5, 1.5], "floor")
DM([0, 10])
julia> ca.interp1d([0, 1, 2], ca.DM([0 1; 10 11; 20 21]), [0.5, 2])
DM(
[[5, 6],
[20, 21]])
julia> ca.interp1d([0, 1, 2], ca.DM([0, 10, 20]), [-1, 3])
DM([0, 20])
julia> ca.interp1d([0, 1, 2], ca.SX.sym("v", 3), [0.5])
SX(@1=0.5, ((@1*v_0)+(@1*v_1)))
Extra doc: https://github.com/casadi/casadi/wiki/L_1bh
Definition at line 812 of file generic_matrix.hpp.
|
friend |
Computed as solve(A, eye(n)), see solve for the algorithm. A non-square argument raises an error. A numerically singular DM does not raise; the result contains inf or nan. For MX the result is a solve node.
>>> inv(DM([[1, 2], [3, 4]]))
DM(
[[-2, 1],
[1.5, -0.5]])
>>> inv(SX.sym("A", 2, 2))
SX(@1=((A_0*A_3)-(A_2*A_1)),
[[(A_3/@1), (-(A_2/@1))],
[(-(A_1/@1)), (A_0/@1)]])
>>> inv(DM(Sparsity.diag(2), [2, 4]))
DM(
[[0.5, 00],
[00, 0.25]])
>> inv(DM([1 2; 3 4]))
[[-2, 1],
[1.5, -0.5]]
>> inv(SX.sym('A', 2, 2))
@1=((A_0*A_3)-(A_2*A_1)),
[[(A_3/@1), (-(A_2/@1))],
[(-(A_1/@1)), (A_0/@1)]]
>> inv(DM(Sparsity.diag(2), [2; 4]))
[[0.5, 00],
[00, 0.25]]
julia> print(inv(ca.DM([1 2; 3 4])))
[[-2, 1],
[1.5, -0.5]]
julia> inv(ca.SX.sym("A", 2, 2))
SX(@1=((A_0*A_3)-(A_2*A_1)),
[[(A_3/@1), (-(A_2/@1))],
[(-(A_1/@1)), (A_0/@1)]])
julia> inv(ca.DM(ca.Sparsity.diag(2), [2, 4]))
DM(
[[0.5, 00],
[00, 0.25]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1bz
Definition at line 1737 of file generic_matrix.hpp.
|
friend |
Computes solve(A, eye(n), lsolver, options). Available for DM and MX; SX raises.
| lsolver | Name of a Linsol plugin, e.g. "qr", "csparse", "lapacklu" |
| options | Options passed to the linear solver |
>>> inv(DM([[1, 2], [3, 4]]), "qr") DM( [[-2, 1], [1.5, -0.5]])
>> inv(DM([1 2; 3 4]), 'qr') [[-2, 1], [1.5, -0.5]]
julia> print(ca.inv(ca.DM([1 2; 3 4]), "qr")) [[-2, 1], [1.5, -0.5]]
Extra doc: https://github.com/casadi/casadi/wiki/L_1c0
Definition at line 1776 of file generic_matrix.hpp.
|
friend |
Computes adj(A)/det(A) by minor expansion. Available for DM and SX; MX raises "Not implemented". Use inv for the general case.
>>> inv_minor(DM([[1, 2], [3, 4]])) DM( [[-2, 1], [1.5, -0.5]])
>> inv_minor(DM([1 2; 3 4])) [[-2, 1], [1.5, -0.5]]
julia> ca.inv_minor(ca.DM([1 2; 3 4])) DM( [[-2, 1], [1.5, -0.5]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1by
Definition at line 1678 of file generic_matrix.hpp.
Creates a single node representing the inverse of the square matrix x. The node defines its derivatives (via -inv(x) dx inv(x)) but cannot be evaluated numerically or expanded to SX; it is meant as a placeholder in symbolic manipulations. For an inverse that can be evaluated use inv or solve.
>>> A = MX.sym("A", 2, 2)
>>> inv_node(A), inv_node(A).is_op(OP_INVERSE), jacobian(inv_node(A), A).shape
(MX(inv(A)), True, (4, 4))
>>> try:
... inv_node(MX.sym("B", 2, 3))
... except Exception as e:
... print("must be square" in str(e))
True
>> A = MX.sym('A', 2, 2);
>> e = inv_node(A); J = jacobian(e, A);
>> e, e.is_op(OP_INVERSE), size(J)
inv(A)
1
4 4
>> try, inv_node(MX.sym('B', 2, 3)); catch e, disp('must be square'); end
must be square
julia> A = ca.MX.sym("A", 2, 2);
julia> B = ca.inv_node(A);
julia> B, ca.is_op(B, ca.OP_INVERSE), size(ca.jacobian(B, A))
(inv(A), true, (4, 4))
julia> try
ca.inv_node(ca.MX.sym("B", 2, 3))
catch e
println(occursin("must be square", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_re
Definition at line 4393 of file mx.hpp.
|
friend |
Inverse of skew: for a 3-by-3 matrix S, returns 0.5*[S(2,1)-S(1,2); S(0,2)-S(2,0); S(1,0)-S(0,1)], which recovers a from skew(a). A non-3-by-3 argument raises an error.
Extra doc: https://github.com/casadi/casadi/wiki/L_1bw
Definition at line 1560 of file generic_matrix.hpp.
|
friend |
Depth=0 checks if the expressions are identical, i.e. points to the same node.
a = x*x b = x*x
is_equal(a,b,0) will return false, but is_equal(a,b,1) will return true
Returns a plain boolean, unlike the elementwise comparison eq. With depth > 0 two different nodes are equivalent when they have the same operation and their dependencies are equivalent up to depth-1. For SX and DM matrices the test is applied entry by entry; matrices of different shape raise an error, and for DM it is value equality. Both arguments must be of the same type.
| x | First expression |
| y | Second expression |
| depth | Number of levels of the expression graph to compare, 0 for identity |
>>> x = SX.sym("x")
>>> is_equal(x, x), is_equal(x, SX.sym("x"))
(True, False)
>>> is_equal(x*x, x*x), is_equal(x*x, x*x, 1)
(False, True)
>>> is_equal(DM([1, 2]), DM([1, 2])), is_equal(DM([1, 2]), DM([1, 3]))
(True, False)
>>> y = MX.sym("y")
>>> is_equal(y * y, y * y), is_equal(y * y, y * y, 1)
(False, True)
>> x = SX.sym('x');
>> is_equal(x, x), is_equal(x, SX.sym('x'))
1
0
>> is_equal(x*x, x*x), is_equal(x*x, x*x, 1)
0
1
>> is_equal(DM([1; 2]), DM([1; 2])), is_equal(DM([1; 2]), DM([1; 3]))
1
0
>> y = MX.sym('y');
>> is_equal(y * y, y * y), is_equal(y * y, y * y, 1)
0
1
julia> x = ca.SX.sym("x");
julia> ca.is_equal(x, x), ca.is_equal(x, ca.SX.sym("x"))
(true, false)
julia> ca.is_equal(x*x, x*x), ca.is_equal(x*x, x*x, 1)
(false, true)
julia> ca.is_equal(ca.DM([1, 2]), ca.DM([1, 2])), ca.is_equal(ca.DM([1, 2]), ca.DM([1, 3]))
(true, false)
julia> y = ca.MX.sym("y");
julia> ca.is_equal(y * y, y * y), ca.is_equal(y * y, y * y, 1)
(false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_pv
Definition at line 2369 of file generic_expression.hpp.
|
friend |
Defined as: no entry of expr depends on var with order 2 (see which_depends). Only the structure of the graph is inspected, not the values: false negatives are possible (an expression may not be recognised as linear while it really is, e.g. x*x/x). Operations whose derivative is structurally zero, such as floor, sign or comparisons, are treated as linear. A constant expression counts as linear.
* >>> x = SX.sym("x"); y = SX.sym("y")
* >>> is_linear(2*x + y, vertcat(x, y)), is_linear(x*y, vertcat(x, y))
* (True, False)
* >>> is_linear(sin(y)*x, x), is_linear(x*x/x, x)
* (True, False)
*
* >> x = SX.sym('x'); y = SX.sym('y');
* >> fprintf('%d %d\n', is_linear(2*x + y, vertcat(x, y)), is_linear(x*y, vertcat(x, y)))
* 1 0
* >> fprintf('%d %d\n', is_linear(sin(y)*x, x), is_linear(x*x/x, x))
* 1 0
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
* julia> ca.is_linear(2 * x + y, [x; y]), ca.is_linear(x * y, [x; y])
* (true, false)
* julia> ca.is_linear(sin(y) * x, x), ca.is_linear(x * x / x, x)
* (true, false)
*
Extra doc: https://github.com/casadi/casadi/wiki/L_1d0
Definition at line 4010 of file generic_matrix.hpp.
|
friend |
Defined as: gradient(expr, var) is linear in var; hence expr must be scalar. False negatives are possible (an expression may not be recognised as quadratic while it really is), see is_linear for the structural nature of the check. Linear and constant expressions count as quadratic.
* >>> x = SX.sym("x"); y = SX.sym("y")
* >>> is_quadratic(x*y + x**2, vertcat(x, y)), is_quadratic(x**3, x)
* (True, False)
* >>> is_quadratic(x, x)
* True
*
* >> x = SX.sym('x'); y = SX.sym('y');
* >> fprintf('%d %d\n', is_quadratic(x*y + x^2, vertcat(x, y)), is_quadratic(x^3, x))
* 1 0
* >> is_quadratic(x, x)
* 1
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
* julia> ca.is_quadratic(x * y + x^2, [x; y]), ca.is_quadratic(x^3, x)
* (true, false)
* julia> ca.is_quadratic(x, x)
* true
*
Extra doc: https://github.com/casadi/casadi/wiki/L_1d1
Definition at line 4055 of file generic_matrix.hpp.
|
friend |
The derivative of ex with respect to arg, with both treated as column-major vectors of their elements: the result is ex.numel()-by-arg.numel(), one row per element of ex and one column per element of arg. Entries that are structurally zero are left out of the sparsity pattern.
arg must be symbolic (for MX: symbolic primitives as created by MX.sym, or a concatenation of them; elements of a primitive are rejected). Not defined for DM.
| opts | Options: "allow_forward" and "allow_reverse" (bool, default true) restrict the AD mode; "symmetric" (bool, default false) hints that the Jacobian is symmetric; "verbose" |
>>> x = SX.sym("x"); y = SX.sym("y")
>>> J = jacobian(vertcat(x*y, x**2), vertcat(x, y))
>>> J
SX(
[[y, x],
[(2.*x), 00]])
>>> J.dim(True)
'2x2,3nz'
>>> A = SX.sym("A", 2, 2)
>>> jacobian(2*A, A).dim()
'4x4'
>>> jacobian(SX(0, 1), vertcat(x, y)).dim()
'0x2'
>> x = SX.sym('x'); y = SX.sym('y');
>> J = jacobian(vertcat(x*y, x^2), vertcat(x, y));
>> J
[[y, x],
[(2.*x), 00]]
>> J.dim(true)
2x2,3nz
>> A = SX.sym('A', 2, 2);
>> J = jacobian(2*A, A); disp(J.dim())
4x4
>> J = jacobian(SX(0, 1), vertcat(x, y)); disp(J.dim())
0x2
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> J = ca.jacobian([x * y; x^2], [x; y])
SX(
[[y, x],
[(2.*x), 00]])
julia> ca.dim(J, true)
"2x2,3nz"
julia> A = ca.SX.sym("A", 2, 2);
julia> ca.dim(ca.jacobian(2 * A, A))
"4x4"
julia> ca.dim(ca.jacobian(ca.SX(0, 1), [x; y]))
"0x2"
Extra doc: https://github.com/casadi/casadi/wiki/L_1cv
Definition at line 3508 of file generic_matrix.hpp.
|
friend |
Equivalent to, but cheaper to compute than, jacobian(f,x).sparsity()
>>> x = SX.sym("x"); y = SX.sym("y")
>>> jacobian_sparsity(vertcat(x*y, x**2, 3), vertcat(x, y))
Sparsity(3x2,3nz)
>> x = SX.sym('x'); y = SX.sym('y');
>> jacobian_sparsity(vertcat(x*y, x^2, 3), vertcat(x, y))
3x2,3nz
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.jacobian_sparsity([x * y; x^2; 3], [x; y])
Sparsity(3x2,3nz)
Extra doc: https://github.com/casadi/casadi/wiki/L_259
Definition at line 3963 of file generic_matrix.hpp.
|
friend |
This is equivalent to mul(jacobian(ex, arg), v) or mul(jacobian(ex, arg).T, v) for tr set to false and true respectively. If contrast to these expressions, it will use directional derivatives which is typically (but not necessarily) more efficient if the complete Jacobian is not needed and v has few rows.
The matrix shapes of ex and arg are kept: v must have the shape of arg (or of ex when tr is true), and several directions can be passed at once by concatenating them horizontally, i.e. v.size2() a multiple of arg.size2(). The result is ex.size1()-by-ex.size2()*n_dir (arg.size1()-by-arg.size2()*n_dir when tr is true). An inconsistent shape of v raises an error.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> ex = vertcat(x*y, x**2); arg = vertcat(x, y)
>>> jtimes(ex, arg, DM([1, 0]))
SX([y, (2.*x)])
>>> jtimes(ex, arg, DM([1, 0]), True)
SX([y, x])
>>> jtimes(ex, arg, DM.eye(2))
SX(
[[y, x],
[(2.*x), 0]])
>>> jtimes(ex, arg, SX.sym("v", 2))
SX([((y*v_0)+(x*v_1)), ((2.*x)*v_0)])
>> x = SX.sym('x'); y = SX.sym('y');
>> ex = vertcat(x*y, x^2); arg = vertcat(x, y);
>> jtimes(ex, arg, DM([1; 0]))
[y, (2.*x)]
>> jtimes(ex, arg, DM([1; 0]), true)
[y, x]
>> jtimes(ex, arg, DM.eye(2))
[[y, x],
[(2.*x), 0]]
>> jtimes(ex, arg, SX.sym('v', 2))
[((y*v_0)+(x*v_1)), ((2.*x)*v_0)]
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ex = [x * y; x^2]; arg = [x; y];
julia> ca.jtimes(ex, arg, ca.DM([1, 0]))
SX([y, (2.*x)])
julia> ca.jtimes(ex, arg, ca.DM([1, 0]), true)
SX([y, x])
julia> ca.jtimes(ex, arg, ca.DM.eye(2))
SX(
[[y, x],
[(2.*x), 0]])
julia> ca.jtimes(ex, arg, ca.SX.sym("v", 2))
SX([((y*v_0)+(x*v_1)), ((2.*x)*v_0)])
Extra doc: https://github.com/casadi/casadi/wiki/L_1cw
Definition at line 3677 of file generic_matrix.hpp.
|
friend |
Creates a block matrix in which block (i, j) is a_ij*b, for any shapes of a and b. The result is a.size1()*b.size1() by a.size2()*b.size2() with the Kronecker product of the sparsity patterns.
>>> kron(DM([[1, 2]]), DM([[1], [10]]))
DM(
[[1, 2],
[10, 20]])
>>> kron(DM.eye(2), DM([[1, 2], [3, 4]]))
DM(
[[1, 2, 00, 00],
[3, 4, 00, 00],
[00, 00, 1, 2],
[00, 00, 3, 4]])
>>> kron(MX.sym("a", 2, 2), MX.sym("b", 1, 2)).shape
(2, 4)
>> kron(DM([1 2]), DM([1; 10]))
[[1, 2],
[10, 20]]
>> kron(DM.eye(2), DM([1 2; 3 4]))
[[1, 2, 00, 00],
[3, 4, 00, 00],
[00, 00, 1, 2],
[00, 00, 3, 4]]
>> size(kron(MX.sym('a', 2, 2), MX.sym('b', 1, 2)))
2 4
julia> kron(ca.DM([1 2]), ca.DM([1; 10]))
DM(
[[1, 2],
[10, 20]])
julia> kron(ca.DM.eye(2), ca.DM([1 2; 3 4]))
DM(
[[1, 2, 00, 00],
[3, 4, 00, 00],
[00, 00, 1, 2],
[00, 00, 3, 4]])
julia> size(kron(ca.MX.sym("a", 2, 2), ca.MX.sym("b", 1, 2)))
(2, 4)
Extra doc: https://github.com/casadi/casadi/wiki/L_47
Definition at line 2096 of file sparsity_interface.hpp.
|
friend |
Computes A(p, p) = L*diag(D)*L^T with L unit lower triangular. Returns D as a vector, LT holding the strictly upper triangular entries of L^T (the unit diagonal is omitted), and the permutation p. Only the upper triangle of A is referenced. The sparsity pattern of A must be symmetric. Only guaranteed to work for positive definite matrices (no pivoting). Works symbolically on SX.
| A | Square matrix with symmetric sparsity pattern |
| amd | Use an approximate minimum degree ordering to reduce fill-in |
>>> D, LT, p = ldl(DM([[4, 2], [2, 3]])) >>> D, p (DM([4, 2]), [0, 1]) >>> LT DM( [[00, 0.5], [00, 00]]) >>> L = DM.eye(2) + LT.T >>> mtimes(mtimes(L, diag(D)), L.T) DM( [[4, 2], [2, 3]])
>> [D, LT, p] = ldl(DM([4 2; 2 3])); >> D, p [4, 2] 0 1 >> LT [[00, 0.5], [00, 00]] >> L = DM.eye(2) + LT'; >> L*diag(D)*L' [[4, 2], [2, 3]]
julia> D, LT, p = ca.ldl(ca.DM([4 2; 2 3]));
julia> D
DM([4, 2])
julia> p
2-element Vector{Int64}:
0
1
julia> LT
DM(
[[00, 0.5],
[00, 00]])
julia> L = ca.DM.eye(2) + LT';
julia> L * ca.diag(D) * L'
DM(
[[4, 2],
[2, 3]])
Extra doc: https://github.com/casadi/casadi/wiki/L_18w
Definition at line 1823 of file matrix_decl.hpp.
|
friend |
| b | Right-hand side, one column per system; a sparse b is densified |
| D,LT,p | Output of ldl(A) |
b
>>> A = DM([[4, 2], [2, 3]]) >>> D, LT, p = ldl(A) >>> ldl_solve(DM([1, 2]), D, LT, p) DM([-0.125, 0.75]) >>> solve(A, DM([1, 2])) DM([-0.125, 0.75])
>> A = DM([4 2; 2 3]); >> [D, LT, p] = ldl(A); >> ldl_solve(DM([1; 2]), D, LT, p) [-0.125, 0.75] >> solve(A, DM([1; 2])) [-0.125, 0.75]
julia> A = ca.DM([4 2; 2 3]); julia> D, LT, p = ca.ldl(A); julia> ca.ldl_solve(ca.DM([1, 2]), D, LT, p) DM([-0.125, 0.75]) julia> A \ [1, 2] DM([-0.125, 0.75])
Extra doc: https://github.com/casadi/casadi/wiki/L_18x
Definition at line 1871 of file matrix_decl.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt. Chained inequalities such as lb <= (x <= ub) are recognised by Opti as bound constraints.
>>> le(DM([1, 2, 3]), 2)
DM([1, 1, 0])
>>> x = SX.sym("x")
>>> x <= x
SX(1)
>> le(DM([1; 2; 3]), 2)
[1, 1, 0]
>> x = SX.sym('x');
>> x <= x
1
julia> ca.le(ca.DM([1, 2, 3]), 2)
DM([1, 1, 0])
julia> x = ca.SX.sym("x");
julia> x <= x
SX(1)
Extra doc: https://github.com/casadi/casadi/wiki/L_os
Definition at line 481 of file generic_expression.hpp.
Experimental feature. Marks x as a lifted intermediate variable with initial guess x_guess, for use by lifted Newton-type methods. Evaluates to x. Both arguments must have the same sparsity pattern.
Extra doc: https://github.com/casadi/casadi/wiki/L_rd
Definition at line 4338 of file mx.hpp.
|
friend |
A x + b
Returns A = jacobian(expr, var) at var = 0 and b = vec(expr) at var = 0. expr must be a vector (a matrix raises an error).
| check[in] | When true (default), expr is checked to be linear in var (is_linear) and an error is raised otherwise. Provided to deal with false positive dependency checks. |
* >>> x = SX.sym("x"); y = SX.sym("y")
* >>> A, b = linear_coeff(vertcat(2*x + y + 1, 3*y), vertcat(x, y))
* >>> A
* SX(
* [[2, 1],
* [00, 3]])
* >>> b
* SX([1, 0])
*
* >> x = SX.sym('x'); y = SX.sym('y');
* >> [A, b] = linear_coeff(vertcat(2*x + y + 1, 3*y), vertcat(x, y));
* >> A
* [[2, 1],
* [00, 3]]
* >> b
* [1, 0]
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
* julia> A, b = ca.linear_coeff([2 * x + y + 1; 3 * y], [x; y]);
* julia> A
* SX(
* [[2, 1],
* [00, 3]])
* julia> b
* SX([1, 0])
*
Extra doc: https://github.com/casadi/casadi/wiki/L_1d3
Definition at line 4179 of file generic_matrix.hpp.
|
friend |
[DEPRECATED] confusing behaviour
This function linearizes an expression around a point x0, using x as delta around that point:
linearize(sin(x),x,x0) -> sin(x0)+cos(x0)*x
x0 must have the shape of x or be a scalar (broadcast). For a variant that returns sin(x0)+cos(x0)*(x-x0), see taylor.
* >>> x = SX.sym("x"); y = SX.sym("y")
* >>> linearize(sin(x), x, y)
* SX((sin(y)+(cos(y)*x)))
*
* >> x = SX.sym('x'); y = SX.sym('y');
* >> linearize(sin(x), x, y)
* (sin(y)+(cos(y)*x))
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
* julia> ca.linearize(sin(x), x, y)
* SX((sin(y)+(cos(y)*x)))
*
Extra doc: https://github.com/casadi/casadi/wiki/L_1cs
Definition at line 3293 of file generic_matrix.hpp.
|
friend |
Returns the column vector [a, a + (b-a)/(nsteps-1), ..., b] with nsteps entries, the endpoints included. For nsteps == 1 the result is b. When a and b are matrices, the nsteps intermediate matrices are stacked vertically (vertcat). nsteps must be at least 1.
>>> linspace(0, 1, 5)
DM([0, 0.25, 0.5, 0.75, 1])
>>> linspace(SX.sym("a"), SX.sym("b"), 3)
SX([a, (a+((b-a)/2)), b])
>>> linspace(DM([0, 0]), DM([1, 2]), 3)
DM([0, 0, 0.5, 1, 1, 2])
>> linspace(DM(0), DM(1), 5)
[0, 0.25, 0.5, 0.75, 1]
>> linspace(SX.sym('a'), SX.sym('b'), 3)
[a, (a+((b-a)/2)), b]
>> linspace(DM([0; 0]), DM([1; 2]), 3)
[0, 0, 0.5, 1, 1, 2]
julia> ca.linspace(0, 1, 5)
DM([0, 0.25, 0.5, 0.75, 1])
julia> ca.linspace(ca.SX.sym("a"), ca.SX.sym("b"), 3)
SX([a, (a+((b-a)/2)), b])
julia> ca.linspace(ca.DM([0, 0]), ca.DM([1, 2]), 3)
DM([0, 0, 0.5, 1, 1, 2])
Extra doc: https://github.com/casadi/casadi/wiki/L_1bt
Definition at line 1447 of file generic_matrix.hpp.
|
friend |
Elementwise; the result is dense with -inf at structural zeros. Negative arguments give NaN; no error is raised.
>>> log(DM([1, 0]))
DM([0, -inf])
>>> log(SX.sym("x"))
SX(log(x))
>> log(DM([1; 0]))
[0, -inf]
>> log(SX.sym('x'))
log(x)
julia> log.(ca.DM([1, 0]))
DM([0, -inf])
julia> log(ca.SX.sym("x"))
SX(log(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_pg
Definition at line 1578 of file generic_expression.hpp.
|
friend |
Computed as log(x) * (1 / log(10)); there is no dedicated operation, which is visible in symbolic expressions. Dense result like log.
>>> log10(DM([1, 10, 1000]))
DM([0, 1, 3])
>>> log10(SX.sym("x"))
SX((0.434294*log(x)))
>> log10(DM([1; 10; 1000]))
[0, 1, 3]
>> log10(SX.sym('x'))
(0.434294*log(x))
julia> log10.(ca.DM([1, 10, 1000]))
DM([0, 1, 3])
julia> log10(ca.SX.sym("x"))
SX((0.434294*log(x)))
Extra doc: https://github.com/casadi/casadi/wiki/L_ph
Definition at line 1622 of file generic_expression.hpp.
|
friend |
Elementwise; accurate for small x where log(1 + x) would lose digits. Sparsity preserved (log1p(0) == 0).
>>> log1p(DM([0, 1e-10]))
DM([0, 1e-10])
>>> log1p(SX.sym("x"))
SX(log1p(x))
>> log1p(DM([0; 1e-10]))
[0, 1e-10]
>> log1p(SX.sym('x'))
log1p(x)
julia> log1p.(ca.DM([0, 1e-10]))
DM([0, 1e-10])
julia> log1p(ca.SX.sym("x"))
SX(log1p(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_pi
Definition at line 1666 of file generic_expression.hpp.
|
friend |
Returns (an expression evaluating to) 1 where both entries are nonzero and 0 otherwise, elementwise
Any nonzero value, including NaN, counts as true. Shape rules as for plus; the result is structurally zero wherever either operand is. The Python keyword and does not work on matrices (it needs a single truth value); use this function.
>>> logic_and(DM([1, 2, 0]), DM([3, 0, 0]))
DM([1, 0, 0])
>>> logic_and(SX.sym("x"), SX.sym("y"))
SX((x&&y))
>>> logic_and(DM.eye(2), DM.ones(2, 2))
DM(
[[1, 00],
[00, 1]])
>> DM([1; 2; 0]) & DM([3; 0; 0])
[1, 0, 0]
>> SX.sym('x') & SX.sym('y')
(x&&y)
>> and(DM.eye(2), DM.ones(2, 2))
[[1, 00],
[00, 1]]
julia> ca.logic_and(ca.DM([1, 2, 0]), ca.DM([3, 0, 0]))
DM([1, 0, 0])
julia> ca.logic_and(ca.SX.sym("x"), ca.SX.sym("y"))
SX((x&&y))
julia> ca.logic_and(ca.DM.eye(2), ca.DM.ones(2, 2))
DM(
[[1, 00],
[00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_ox
Definition at line 756 of file generic_expression.hpp.
|
friend |
Returns (an expression evaluating to) 1 where the entry is zero and 0 otherwise, elementwise
Structural zeros map to 1, so a sparse input gives a dense result. The Python keyword not does not work on matrices; use this function.
>>> logic_not(DM([1, 0, -1]))
DM([0, 1, 0])
>>> logic_not(DM.eye(2))
DM(
[[0, 1],
[1, 0]])
>>> logic_not(SX.sym("x"))
SX((!x))
>> ~DM([1; 0; -1])
[0, 1, 0]
>> not(DM.eye(2))
[[0, 1],
[1, 0]]
>> ~SX.sym('x')
(!x)
julia> ca.logic_not(ca.DM([1, 0, -1]))
DM([0, 1, 0])
julia> ca.logic_not(ca.DM.eye(2))
DM(
[[0, 1],
[1, 0]])
julia> ca.logic_not(ca.SX.sym("x"))
SX((!x))
Extra doc: https://github.com/casadi/casadi/wiki/L_oz
Definition at line 866 of file generic_expression.hpp.
|
friend |
returns (an expression evaluating to) 1 where at least one entry is nonzero and 0 otherwise, elementwise
Shape rules as for plus; the result is structurally zero where both operands are.
>>> logic_or(DM([1, 0, 0]), DM([0, 0, 2]))
DM([1, 0, 1])
>>> logic_or(MX.sym("x"), MX.sym("y"))
MX((x||y))
>> DM([1; 0; 0]) | DM([0; 0; 2])
[1, 0, 1]
>> or(MX.sym('x'), MX.sym('y'))
(x||y)
julia> ca.logic_or(ca.DM([1, 0, 0]), ca.DM([0, 0, 2]))
DM([1, 0, 1])
julia> ca.logic_or(ca.MX.sym("x"), ca.MX.sym("y"))
MX((x||y))
Extra doc: https://github.com/casadi/casadi/wiki/L_oy
Definition at line 805 of file generic_expression.hpp.
|
friend |
Can be used to achieve a smooth max.
The argument must be a dense column vector; a scalar is returned unchanged. Implementations for DM/SX/MX are hardened against overflow by shifting with the largest entry. Implementations for DM/MX are more accurate with log1p (*).
(*) https://nhigham.com/2021/01/05/what-is-the-log-sum-exp-function/
>>> logsumexp(DM([1, 2, 3]))
DM(3.40761)
>>> logsumexp(DM([1000, 1000]))
DM(1000.69)
>>> logsumexp(MX.sym("x", 3))
MX(logsumexp(x))
>>> try: logsumexp(DM([1, 2, 3]).T)
... except Exception as e: print("error")
error
>> logsumexp(DM([1; 2; 3]))
3.40761
>> logsumexp(DM([1000; 1000]))
1000.69
>> logsumexp(MX.sym('x', 3))
logsumexp(x)
>> try, logsumexp(DM([1; 2; 3])'); catch e, disp('error'); end
error
julia> ca.logsumexp(ca.DM([1, 2, 3]))
DM(3.40761)
julia> ca.logsumexp(ca.DM([1000, 1000]))
DM(1000.69)
julia> ca.logsumexp(ca.MX.sym("x", 3))
MX(logsumexp(x))
julia> try ca.logsumexp(ca.DM([1, 2, 3])') catch e; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_1br
Definition at line 1369 of file generic_matrix.hpp.
|
friend |
Scaled such that max(x) <= logsumexp(x, margin) <= max(x)+margin, computed as logsumexp(alpha*x)/alpha with alpha = log(n)/margin for n = x.size1(). margin must be of the same type as x (MX for MX).
>>> logsumexp(DM([1, 2, 3]), 0.1) DM(3)
>> logsumexp(DM([1; 2; 3]), 0.1) 3
julia> ca.logsumexp(ca.DM([1, 2, 3]), 0.1) DM(3)
Extra doc: https://github.com/casadi/casadi/wiki/L_1bs
Definition at line 1400 of file generic_matrix.hpp.
For each entry p_i of p, returns the index k such that v[k] <= p_i < v[k+1] for the ascending grid v, clipped to [0, len(v)-2] so that values outside the grid map to the first or last interval. This is the lookup step of linear interpolation. The result has the shape of p and is piecewise constant, so its derivative is zero.
| v | Dense ascending grid, vector |
| p | Query values, dense vector |
| options | "lookup_mode": "linear" (scan), "binary" (bisection), "exact" (assumes an equidistant grid and computes the index arithmetically) or "auto" (default: "binary" for grids longer than 100 entries, else "linear"). Any other key or mode raises an error. |
>>> g = MX.sym("g", 4)
>>> p = MX.sym("p", 5)
>>> f = Function("f", [g, p], [low(g, p)])
>>> f(DM([0, 1, 2, 3]), DM([-1, 0, 1.5, 3, 4]))
DM([0, 0, 1, 2, 2])
>>> jacobian(low(g, p), p).nnz()
0
>>> try:
... low(g, p, {"lookup_mode": "foo"})
... except Exception as e:
... print("Invalid lookup mode" in str(e))
True
>> g = MX.sym('g', 4); p = MX.sym('p', 5);
>> f = Function('f', {g, p}, {low(g, p)});
>> f(DM([0; 1; 2; 3]), DM([-1; 0; 1.5; 3; 4]))
[0, 0, 1, 2, 2]
>> J = jacobian(low(g, p), p);
>> J.nnz()
0
>> try, low(g, p, struct('lookup_mode', 'foo')); catch e, disp('invalid lookup mode'); end
invalid lookup mode
julia> g = ca.MX.sym("g", 4); p = ca.MX.sym("p", 5);
julia> f = ca.Function("f", [g, p], [ca.low(g, p)]);
julia> f([0, 1, 2, 3], [-1, 0, 1.5, 3, 4])
DM([0, 0, 1, 2, 2])
julia> ca.nnz(ca.jacobian(ca.low(g, p), p))
0
julia> try
ca.low(g, p, Dict("lookup_mode" => "foo"))
catch e
println(occursin("Invalid lookup mode", sprint(showerror, e)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_r8
Definition at line 3802 of file mx.hpp.
|
friend |
Elementwise comparison; shape rules as for plus. Every comparison in this group returns a matrix of the same type as the operands with entries 1 (true) and 0 (false): for DM a numeric 0/1 matrix, not a boolean, and for SX and MX a symbolic expression that is only decided at evaluation time. Comparisons with NaN are false. The result is sparse where both operands are structurally zero (0 < 0 is false).
>>> lt(DM([1, 2, 3]), 2)
DM([1, 0, 0])
>>> DM([1, 2, 3]) < DM([3, 2, 1])
DM([1, 0, 0])
>>> SX.sym("x", 2) < SX.sym("y", 2)
SX([(x_0<y_0), (x_1<y_1)])
>>> DM.eye(2) < 1
DM(
[[0, 1],
[1, 0]])
>> lt(DM([1; 2; 3]), 2)
[1, 0, 0]
>> DM([1; 2; 3]) < DM([3; 2; 1])
[1, 0, 0]
>> SX.sym('x', 2) < SX.sym('y', 2)
[(x_0<y_0), (x_1<y_1)]
>> DM.eye(2) < 1
[[0, 1],
[1, 0]]
julia> ca.lt(ca.DM([1, 2, 3]), 2)
DM([1, 0, 0])
julia> ca.DM([1, 2, 3]) < ca.DM([3, 2, 1])
DM([1, 0, 0])
julia> ca.SX.sym("x", 2) < ca.SX.sym("y", 2)
SX([(x_0<y_0), (x_1<y_1)])
julia> ca.DM.eye(2) < 1
DM(
[[0, 1],
[1, 0]])
Extra doc: https://github.com/casadi/casadi/wiki/L_or
Definition at line 431 of file generic_expression.hpp.
|
friend |
Matrix product of two matrices (x and y), adding the result to a third matrix z. The result has the same sparsity pattern as z, meaning that other entries of the product are ignored. The operation is equivalent to z + project(mtimes(x, y), z.sparsity()). The dimensions of z must match the product, otherwise an error is raised. When x or y is a scalar the result is z + x*y. See mtimes for the meaning of the blas argument.
mtimes is implemented as mac with a structurally zero z of the product pattern.
| x | Left factor |
| y | Right factor |
| z | Matrix to add to; its sparsity pattern selects the computed entries |
z
>>> A = DM([[1, 2], [3, 4]])
>>> mac(A, A, DM.eye(2))
DM(
[[8, 00],
[00, 23]])
>>> mac(A, A, DM.ones(2, 2))
DM(
[[8, 11],
[16, 23]])
>>> mac(MX.sym("x", 2, 3), MX.sym("y", 3, 2), MX.sym("z", Sparsity.diag(2)))
MX(mac(x,y,z))
>> A = DM([1 2; 3 4]);
>> mac(A, A, DM.eye(2))
[[8, 00],
[00, 23]]
>> mac(A, A, DM.ones(2, 2))
[[8, 11],
[16, 23]]
>> mac(MX.sym('x', 2, 3), MX.sym('y', 3, 2), MX.sym('z', Sparsity.diag(2)))
mac(x,y,z)
julia> A = ca.DM([1 2; 3 4]);
julia> ca.mac(A, A, ca.DM.eye(2))
DM(
[[8, 00],
[00, 23]])
julia> ca.mac(A, A, ca.DM.ones(2, 2))
DM(
[[8, 11],
[16, 23]])
julia> x, y = ca.MX.sym("x", 2, 3), ca.MX.sym("y", 3, 2);
julia> ca.mac(x, y, ca.MX.sym("z", ca.Sparsity.diag(2)))
MX(mac(x,y,z))
Extra doc: https://github.com/casadi/casadi/wiki/L_3x
Definition at line 1489 of file sparsity_interface.hpp.
|
friend |
Converts the whole matrix graph of e to scalar SX operations (including inlined Function calls, as Function.expand does) and returns a call to the resulting SXFunction, with the free symbols of e as arguments. Expressions listed in boundary are not expanded: they stay as MX inputs of the call.
| e | Expression to expand |
| boundary | Sub-expressions at which the expansion stops |
| options | Options for the SXFunction, forwarded to Function.expand |
>>> x = MX.sym("x")
>>> g = Function("g", [x], [x**2 + 1])
>>> sx = sin(x)
>>> e = g(x) + sx
>>> r = matrix_expand(e)
>>> r, r.is_output(), r.dep(0).which_function()
(MX(expand_tmp_matrix_expand(x){0}), True, Function(expand_tmp_matrix_expand:(i0)->(o0)
SXFunction))
>>> Function("f", [x], [r])(2)
DM(5.9093)
>>> matrix_expand(e, [sx]).dep(0).which_function()
Function(expand_tmp_matrix_expand:(i0,i1)->(o0) SXFunction)
>> x = MX.sym('x');
>> g = Function('g', {x}, {x^2 + 1});
>> sx = sin(x);
>> e = g(x) + sx;
>> r = matrix_expand(e);
>> r, r.is_output(), r.dep(0).which_function()
expand_tmp_matrix_expand(x){0}
1
expand_tmp_matrix_expand:(i0)->(o0) SXFunction
>> f = Function('f', {x}, {r});
>> f(2)
5.9093
>> r = matrix_expand(e, {sx});
>> r.dep(0).which_function()
expand_tmp_matrix_expand:(i0,i1)->(o0) SXFunction
julia> x = ca.MX.sym("x");
julia> g = ca.Function("g", [x], [x^2 + 1]);
julia> sx = sin(x);
julia> e = g(x) + sx;
julia> r = ca.matrix_expand(e);
julia> r, ca.is_output(r)
(expand_tmp_matrix_expand(x){0}, true)
julia> ca.which_function(ca.dep(r, 0))
Function(expand_tmp_matrix_expand:(i0)->(o0) SXFunction)
julia> ca.Function("f", [x], [r])(2)
DM(5.9093)
julia> ca.which_function(ca.dep(ca.matrix_expand(e, [sx]), 0))
Function(expand_tmp_matrix_expand:(i0,i1)->(o0) SXFunction)
Extra doc: https://github.com/casadi/casadi/wiki/L_rb
Definition at line 4020 of file mx.hpp.
|
friend |
Same as the single-expression overload; the result is one output per expression.
Extra doc: https://github.com/casadi/casadi/wiki/L_rc
|
friend |
Note the argument order: i is the column that is removed, j the row. The input must be square; a 1-by-1 input gives 1.
| x | Square matrix |
| i | Column index to remove (zero-based) |
| j | Row index to remove (zero-based) |
>>> A = DM([[1, 2, 3], [0, 1, 4], [5, 6, 0]])
>>> minor(A, 0, 1)
DM(-18)
>>> X = SX.sym("X", 2, 2)
>>> minor(X, 0, 1)
SX(X_2)
>> A = DM([1 2 3; 0 1 4; 5 6 0]);
>> minor(A, 0, 1)
-18
>> X = SX.sym('X', 2, 2);
>> minor(X, 0, 1)
X_2
julia> A = ca.DM([1 2 3; 0 1 4; 5 6 0]);
julia> ca.minor(A, 0, 1)
DM(-18)
julia> X = ca.SX.sym("X", 2, 2);
julia> ca.minor(X, 0, 1)
SX(X_2)
Extra doc: https://github.com/casadi/casadi/wiki/L_18q
Definition at line 1472 of file matrix_decl.hpp.
|
friend |
Elementwise difference; shape and sparsity rules as for plus. For symbolic arguments, x - x with the same node simplifies to 0.
>>> minus(DM([5, 6]), DM([1, 2]))
DM([4, 4])
>>> DM.eye(2) - 1
DM(
[[0, -1],
[-1, 0]])
>>> x = SX.sym("x")
>>> x - x
SX(0)
>> minus(DM([5; 6]), DM([1; 2]))
[4, 4]
>> DM.eye(2) - 1
[[0, -1],
[-1, 0]]
>> x = SX.sym('x');
>> x - x
0
julia> ca.minus(ca.DM([5, 6]), ca.DM([1, 2]))
DM([4, 4])
julia> ca.DM.eye(2) - 1
DM(
[[0, -1],
[-1, 0]])
julia> x = ca.SX.sym("x");
julia> x - x
SX(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_oo
Definition at line 224 of file generic_expression.hpp.
|
friend |
Computes inv(A)*b as solve(A, b). If either argument is scalar, the elementwise division b/A is returned instead.
>>> A = DM([[1, 2], [3, 4]]) >>> mldivide(A, DM([1, 2])) DM([0, 0.5])
>> A = DM([1 2; 3 4]); >> A\DM([1; 2]) [0, 0.5]
julia> A = ca.DM([1 2; 3 4]); julia> A \ ca.DM([1, 2]) DM([0, 0.5])
Extra doc: https://github.com/casadi/casadi/wiki/L_1bm
Definition at line 1088 of file generic_matrix.hpp.
|
friend |
Over all entries, structural zeros included. See mmin.
>>> mmax(DM(Sparsity.diag(2), [-3, -4]))
DM(0)
>>> mmax(MX.sym("x", 3))
MX(max(x))
>> mmax(DM(Sparsity.diag(2), [-3; -4]))
0
>> mmax(MX.sym('x', 3))
max(x)
julia> ca.mmax(ca.DM(ca.Sparsity.diag(2), [-3, -4]))
DM(0)
julia> ca.mmax(ca.MX.sym("x", 3))
MX(max(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_1d9
Definition at line 4861 of file generic_matrix.hpp.
|
friend |
Over all entries, structural zeros included (so a sparse matrix with only positive nonzeros has minimum 0). An empty matrix gives an empty 0-by-0 result. For SX a chain of fmin operations is built; for MX a single node.
>>> mmin(DM([[3, -1], [2, 5]])), mmax(DM([[3, -1], [2, 5]]))
(DM(-1), DM(5))
>>> mmin(DM(Sparsity.diag(2), [3, 4]))
DM(0)
>>> mmin(SX.sym("x", 3))
SX(fmin(fmin(x_0,x_1),x_2))
>> mmin(DM([3 -1; 2 5])), mmax(DM([3 -1; 2 5]))
-1
5
>> mmin(DM(Sparsity.diag(2), [3; 4]))
0
>> mmin(SX.sym('x', 3))
fmin(fmin(x_0,x_1),x_2)
julia> ca.mmin(ca.DM([3 -1; 2 5])), ca.mmax(ca.DM([3 -1; 2 5]))
(-1, 5)
julia> minimum(ca.DM([3 -1; 2 5])), maximum(ca.DM([3 -1; 2 5]))
(-1, 5)
julia> ca.mmin(ca.DM(ca.Sparsity.diag(2), [3, 4]))
DM(0)
julia> ca.mmin(ca.SX.sym("x", 3))
SX(fmin(fmin(x_0,x_1),x_2))
Extra doc: https://github.com/casadi/casadi/wiki/L_1d8
Definition at line 4821 of file generic_matrix.hpp.
|
friend |
This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/fmod: the result has the sign of x and magnitude below |y|.
This is equivalent to Python's numpy.fmod and Matlab's rem. It differs from the Python operator x % y on these objects, which follows the Python convention x - y*floor(x/y) (result with the sign of y). Elementwise, shape rules as for plus; structural zeros of x stay zero. A zero divisor gives NaN.
>>> fmod(DM([5, 5, -5, -5]), DM([3, -3, 3, -3]))
DM([2, 2, -2, -2])
>>> DM([5, 5, -5, -5]) % DM([3, -3, 3, -3])
DM([2, -1, 1, -2])
>>> fmod(SX.sym("x"), 2), SX.sym("x") % 2
(SX(fmod(x,2)), SX((x-(2.*floor((x/2))))))
>> x = DM([5; 5; -5; -5]); y = DM([3; -3; 3; -3]);
>> fmod(x, y)
[2, 2, -2, -2]
>> rem(x, y)
[2, 2, -2, -2]
>> x - y .* floor(x ./ y)
[2, -1, 1, -2]
>> rem(SX.sym('x'), 2)
fmod(x,2)
julia> ca.fmod(ca.DM([5, 5, -5, -5]), ca.DM([3, -3, 3, -3]))
DM([2, 2, -2, -2])
julia> mod.(ca.DM([5, 5, -5, -5]), ca.DM([3, -3, 3, -3]))
DM([2, -1, 1, -2])
julia> ca.fmod(ca.SX.sym("x"), 2)
SX(fmod(x,2))
Definition at line 2039 of file generic_expression.hpp.
|
friend |
For a square matrix x and a constant integer scalar n, computes the repeated matrix product by squaring. n == 0 gives the (sparse) identity, negative n gives the inverse of the positive power (via inv). If both arguments are scalar, this is the elementwise pow. A non-integer or symbolic n for a matrix raises an error.
>>> A = DM([[1, 2], [3, 4]])
>>> mpower(A, 2)
DM(
[[7, 10],
[15, 22]])
>>> mpower(A, 0)
DM(
[[1, 00],
[00, 1]])
>>> mpower(A, -1)
DM(
[[-2, 1],
[1.5, -0.5]])
>>> mpower(DM(2), 0.5)
DM(1.41421)
>>> try: mpower(A, 0.5)
... except Exception as e: print("error")
error
>> A = DM([1 2; 3 4]);
>> A^2
[[7, 10],
[15, 22]]
>> A^0
[[1, 00],
[00, 1]]
>> mpower(A, -1)
[[-2, 1],
[1.5, -0.5]]
>> DM(2)^0.5
1.41421
>> try, A^0.5; catch e, disp('error'); end
error
julia> A = ca.DM([1 2; 3 4]);
julia> A^2
DM(
[[7, 10],
[15, 22]])
julia> A^0
DM(
[[1, 00],
[00, 1]])
julia> A^-1
DM(
[[-2, 1],
[1.5, -0.5]])
julia> ca.DM(2)^0.5
DM(1.41421)
julia> try A^0.5 catch e; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_1bi
Definition at line 891 of file generic_matrix.hpp.
|
friend |
Computes x*inv(A) as solve(A', x')'. If either argument is scalar, the elementwise division x/A is returned instead.
>>> A = DM([[1, 2], [3, 4]]) >>> mrdivide(DM([[1, 2]]), A) DM([[1, 0]])
>> A = DM([1 2; 3 4]); >> DM([1 2])/A [[1, 0]]
julia> A = ca.DM([1 2; 3 4]); julia> ca.DM([1 2]) / A DM([[1, 0]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1bl
Definition at line 1052 of file generic_matrix.hpp.
|
friend |
Same as mtaylor, but each variable contributes a given weight to the total degree: with x = [x, y] and order_contributions = [1, 2] the degree of x^n*y^m is n + 2*m. The length of order_contributions must equal the number of entries of x.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> mtaylor(sin(x + y), vertcat(x, y), vertcat(0, 0), 3, [1, 2])
SX(((x-((sq(x)*x)/6))+y))
>> x = SX.sym('x'); y = SX.sym('y');
>> mtaylor(sin(x + y), [x; y], [0; 0], 3, [1 2])
((x-((sq(x)*x)/6))+y)
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.mtaylor(sin(x + y), [x; y], [0; 0], 3, [1, 2])
SX(((x-((sq(x)*x)/6))+y))
Extra doc: https://github.com/casadi/casadi/wiki/L_23s
Definition at line 2549 of file matrix_decl.hpp.
|
friend |
Expands ex around the point a with respect to the symbols in x, keeping all terms whose total degree is at most order. The total degree of x^n*y^m is n+m. ex and x must be dense; a must have the same number of entries as x. Only defined for SX.
| ex | Dense SX expression to expand |
| x | Vector of SX symbols |
| a | Expansion point, a vector of the same length as x |
| order | Maximum total degree, default 1 (linearization) |
>>> x = SX.sym("x"); y = SX.sym("y"); a = SX.sym("a"); b = SX.sym("b")
>>> mtaylor(sin(x + y), vertcat(x, y), vertcat(a, b), 1)
SX(((sin((a+b))+(cos((a+b))*(x-a)))+(cos((a+b))*(y-b))))
>>> mtaylor(exp(x * y), vertcat(x, y), DM([0, 0]), 2)
SX(@1=2, ((1+((x*y)/@1))+((y*x)/@1)))
>> x = SX.sym('x'); y = SX.sym('y'); a = SX.sym('a'); b = SX.sym('b');
>> mtaylor(sin(x + y), [x; y], [a; b], 1)
((sin((a+b))+(cos((a+b))*(x-a)))+(cos((a+b))*(y-b)))
>> mtaylor(exp(x * y), [x; y], DM([0; 0]), 2)
@1=2, ((1+((x*y)/@1))+((y*x)/@1))
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); a = ca.SX.sym("a"); b = ca.SX.sym("b");
julia> ca.mtaylor(sin(x + y), [x; y], [a; b], 1)
SX(((sin((a+b))+(cos((a+b))*(x-a)))+(cos((a+b))*(y-b))))
julia> ca.mtaylor(exp(x * y), [x; y], ca.DM([0, 0]), 2)
SX(@1=2, ((1+((x*y)/@1))+((y*x)/@1)))
Extra doc: https://github.com/casadi/casadi/wiki/L_23r
Definition at line 2511 of file matrix_decl.hpp.
|
friend |
Computes x*y in the linear-algebra sense; the column count of x must equal the row count of y, otherwise an error is raised. When either argument is a scalar the result is the elementwise product instead. The sparsity pattern of the result is the structural product of the patterns (entries that are structurally zero in every term stay structural zeros). For Sparsity arguments only the pattern of the product is computed.
Optional blas selects the BLAS plugin used for dense numeric kernels. The choice only takes effect on numeric DM / MX dense * dense; symbolic types (Sparsity, SX) and the sparse fallback path ignore it.
Values of blas:
reference (default): built-in reference kernel (triple loop)classic: whatever BLAS was built into casadi via WITH_LAPACK (typically OpenBLAS)blasfeo: BLASFEOPlugins (classic, blasfeo) are loaded lazily on first use; if the corresponding plugin DLL isn't present in the build, calling them raises an error.
| x | Left factor |
| y | Right factor |
| blas | Name of the BLAS plugin for dense numeric products |
>>> A = DM([[1, 2], [3, 4]])
>>> mtimes(A, A)
DM(
[[7, 10],
[15, 22]])
>>> mtimes(A, 2)
DM(
[[2, 4],
[6, 8]])
>>> mtimes(Sparsity.diag(2), Sparsity.dense(2, 1))
Sparsity(2x1)
>>> mtimes(MX.sym("x", 2, 3), MX.sym("y", 3, 1))
MX(mac(x,y,zeros(2x1)))
>>> mtimes(A, DM.ones(3, 1))
Traceback (most recent call last):
...
RuntimeError: ...incompatible dimensions...
>> A = DM([1 2; 3 4]);
>> A * A
[[7, 10],
[15, 22]]
>> mtimes(A, 2)
[[2, 4],
[6, 8]]
>> MX.sym('x', 2, 3) * MX.sym('y', 3, 1)
mac(x,y,zeros(2x1))
>> try, A * DM.ones(3, 1); catch e, disp(e.message); end
...incompatible dimensions...
julia> A = ca.DM([1 2; 3 4]);
julia> A * A
DM(
[[7, 10],
[15, 22]])
julia> A * 2
DM(
[[2, 4],
[6, 8]])
julia> ca.mtimes(ca.Sparsity.diag(2), ca.Sparsity.dense(2, 1))
Sparsity(2x1)
julia> ca.MX.sym("x", 2, 3) * ca.MX.sym("y", 3, 1)
MX(mac(x,y,zeros(2x1)))
julia> try
A * ca.DM.ones(3, 1)
catch err
println(occursin("incompatible dimensions", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_3v
Definition at line 1381 of file sparsity_interface.hpp.
|
friend |
Multiplies the matrices left to right: mtimes([a, b, c]) == mtimes(mtimes(a, b), c). An empty list raises an error; a single matrix is returned as is. See the 2-arg mtimes for the meaning of blas.
>>> mtimes([DM([[1, 2]]), DM([[1, 0], [0, 2]]), DM([1, 1])]) DM(5) >>> mtimes([]) Traceback (most recent call last): ... RuntimeError: ...must not be empty...
julia> ca.DM([1 2]) * ca.DM([1 0; 0 2]) * ca.DM([1, 1])
DM(5)
julia> try
ca.mtimes(ca.DM[])
catch err
println(occursin("must not be empty", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_3w
Definition at line 1417 of file sparsity_interface.hpp.
|
friend |
The number of nodes of the Function that evaluates the expression, which for SX includes symbols and constants and for MX also output nodes. Shared subexpressions are counted once; identical subexpressions built separately are counted separately (use cse to merge them). Not defined for DM.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> n_nodes(x), n_nodes(x + y), n_nodes(vertcat(x + y, x + y))
(1, 3, 4)
>>> n_nodes(SX(0, 1))
0
>> x = SX.sym('x'); y = SX.sym('y');
>> fprintf('%d %d %d\n', n_nodes(x), n_nodes(x + y), n_nodes(vertcat(x + y, x + y)))
1 3 4
>> n_nodes(SX(0, 1))
0
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.n_nodes(x), ca.n_nodes(x + y), ca.n_nodes([x + y; x + y])
(1, 3, 4)
julia> ca.n_nodes(ca.SX(0, 1))
0
Extra doc: https://github.com/casadi/casadi/wiki/L_2mp
Definition at line 4445 of file generic_matrix.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt and eq. For symbolic operands x != x with the same node simplifies to 0, so it cannot be used to detect NaN symbolically.
>>> ne(DM([1, 2, 3]), 2)
DM([1, 0, 1])
>>> x = MX.sym("x")
>>> x != x
MX(0)
>> ne(DM([1; 2; 3]), 2)
[1, 0, 1]
>> x = MX.sym('x');
>> x ~= x
0
julia> ca.ne(ca.DM([1, 2, 3]), 2)
DM([1, 0, 1])
julia> x = ca.MX.sym("x");
julia> x != x
MX(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_ow
Definition at line 694 of file generic_expression.hpp.
Same as stop_diff(expr, 1): the value is unchanged but all derivatives with respect to the symbols in expr are zero.
>>> x = MX.sym("x")
>>> y = no_grad(x**2)
>>> Function("f", [x], [y])(3), jacobian(y, x).nnz()
(DM(9), 0)
>>> Function("f", [x], [jacobian(x * y, x)])(3)
DM(9)
>> x = MX.sym('x');
>> y = no_grad(x^2); J = jacobian(y, x);
>> f = Function('f', {x}, {y});
>> f(3), J.nnz()
9
0
>> f = Function('f', {x}, {jacobian(x * y, x)});
>> f(3)
9
julia> x = ca.MX.sym("x");
julia> y = ca.no_grad(x^2);
julia> ca.Function("f", [x], [y])(3), ca.nnz(ca.jacobian(y, x))
(9, 0)
julia> ca.Function("f", [x], [ca.jacobian(x * y, x)])(3)
DM(9)
Extra doc: https://github.com/casadi/casadi/wiki/L_25m
Definition at line 4544 of file mx.hpp.
Same as stop_diff(expr, 2): first derivatives are exact, the Hessian contribution is zero. Useful for Gauss-Newton-type Hessians.
>>> x = MX.sym("x")
>>> y = no_hess(x**3)
>>> Function("f", [x], [jacobian(y, x)])(2), hessian(y, x)[0].nnz()
(DM(12), 0)
>> x = MX.sym('x');
>> y = no_hess(x^3);
>> f = Function('f', {x}, {jacobian(y, x)});
>> [H, g] = hessian(y, x);
>> f(2), H.nnz()
12
0
julia> x = ca.MX.sym("x");
julia> y = ca.no_hess(x^3);
julia> ca.Function("f", [x], [ca.jacobian(y, x)])(2), ca.nnz(first(ca.hessian(y, x)))
(12, 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_25n
|
friend |
Number of structural nonzeros that mtimes(x, y) would have, computed from the sparsity patterns without forming the product. The inner dimensions must match, otherwise an error is raised.
>>> norm_0_mul(DM.eye(3), DM.ones(3, 2)) 6 >>> norm_0_mul(Sparsity.diag(3), Sparsity.diag(3)) 3 >>> norm_0_mul(DM.ones(2, 3), DM.ones(2, 3)) Traceback (most recent call last): ... RuntimeError: ...Dimension error...
>> norm_0_mul(DM.eye(3), DM.ones(3, 2)) 6 >> norm_0_mul(Sparsity.diag(3), Sparsity.diag(3)) 3 >> try, norm_0_mul(DM.ones(2, 3), DM.ones(2, 3)); catch e, disp(e.message); end ...Dimension error...
julia> ca.norm_0_mul(ca.DM.eye(3), ca.DM.ones(3, 2))
6
julia> ca.norm_0_mul(ca.Sparsity.diag(3), ca.Sparsity.diag(3))
3
julia> try
ca.norm_0_mul(ca.DM.ones(2, 3), ca.DM.ones(2, 3))
catch err
println(occursin("Dimension error", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_44
Definition at line 1921 of file sparsity_interface.hpp.
|
friend |
Sum of the absolute values of all entries. For a matrix this is the entrywise norm, not the induced (maximum column sum) matrix norm. Nonsmooth at zero entries.
>>> norm_1(DM([[1, -2], [3, 4]]))
DM(10)
>>> norm_1(SX.sym("x", 2))
SX((fabs(x_0)+fabs(x_1)))
>> norm_1(DM([1 -2; 3 4]))
10
>> norm_1(SX.sym('x', 2))
(fabs(x_0)+fabs(x_1))
julia> ca.norm_1(ca.DM([1 -2; 3 4]))
DM(10)
julia> ca.norm_1(ca.SX.sym("x", 2))
SX((fabs(x_0)+fabs(x_1)))
Extra doc: https://github.com/casadi/casadi/wiki/L_1c6
Definition at line 2031 of file generic_matrix.hpp.
|
friend |
For a vector (row or column) this is the Euclidean norm, identical to norm_fro. For a matrix argument DM and SX raise an error (use norm_fro if that is what you meant); MX creates a spectral-norm node that cannot be evaluated. Not differentiable at x == 0; use sumsqr in objectives where possible.
>>> norm_2(DM([3, 4]))
DM(5)
>>> norm_2(MX.sym("x", 2))
MX(||x||_F)
>>> try: norm_2(DM([[1, 2], [3, 4]]))
... except Exception as e: print("error")
error
>> norm_2(DM([3; 4]))
5
>> norm_2(MX.sym('x', 2))
||x||_F
>> try, norm_2(DM([1 2; 3 4])); catch e, disp('error'); end
error
julia> ca.norm_2(ca.DM([3, 4]))
DM(5)
julia> ca.norm_2(ca.MX.sym("x", 2))
MX(||x||_F)
julia> try ca.norm_2(ca.DM([1 2; 3 4])) catch e; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_1c5
Definition at line 1994 of file generic_matrix.hpp.
|
friend |
sqrt(sum_ij x_ij^2) over all entries, for a matrix of any shape. Not differentiable at x == 0 (the derivative evaluates to nan there); use sumsqr in objectives where possible.
>>> norm_fro(DM([[1, -2], [3, 4]]))
DM(5.47723)
>>> norm_fro(SX.sym("x", 2))
SX(sqrt((sq(x_0)+sq(x_1))))
>> norm_fro(DM([1 -2; 3 4]))
5.47723
>> norm_fro(SX.sym('x', 2))
sqrt((sq(x_0)+sq(x_1)))
julia> ca.norm_fro(ca.DM([1 -2; 3 4]))
DM(5.47723)
julia> ca.norm_fro(ca.SX.sym("x", 2))
SX(sqrt((sq(x_0)+sq(x_1))))
Extra doc: https://github.com/casadi/casadi/wiki/L_1c4
Definition at line 1948 of file generic_matrix.hpp.
|
friend |
Largest absolute value among all entries. For a matrix this is the entrywise norm, not the induced (maximum row sum) matrix norm. Nonsmooth.
>>> norm_inf(DM([[1, -2], [3, 4]]))
DM(4)
>>> norm_inf(SX.sym("x", 2))
SX(fmax(fmax(0,fabs(x_0)),fabs(x_1)))
>> norm_inf(DM([1 -2; 3 4]))
4
>> norm_inf(SX.sym('x', 2))
fmax(fmax(0,fabs(x_0)),fabs(x_1))
julia> ca.norm_inf(ca.DM([1 -2; 3 4]))
DM(4)
julia> ca.norm_inf(ca.SX.sym("x", 2))
SX(fmax(fmax(0,fabs(x_0)),fabs(x_1)))
Extra doc: https://github.com/casadi/casadi/wiki/L_1c7
Definition at line 2068 of file generic_matrix.hpp.
|
friend |
Equals norm_inf(mtimes(x, y)): the largest absolute entry of x*y. Exploits sparsity; a shape mismatch raises an error. Works symbolically on SX.
>>> A = DM([[1, 2], [3, 4]]) >>> norm_inf_mul(A, A), norm_inf(mtimes(A, A)) (DM(22), DM(22))
>> A = DM([1 2; 3 4]); >> norm_inf_mul(A, A), norm_inf(A*A) 22 22
julia> A = ca.DM([1 2; 3 4]); julia> ca.norm_inf_mul(A, A), ca.norm_inf(A * A) (22, 22)
Extra doc: https://github.com/casadi/casadi/wiki/L_190
Definition at line 1954 of file matrix_decl.hpp.
|
friend |
Finds Z m-by-(m-n) such that AZ = 0 with A n-by-m with m >= n (a matrix with more rows than columns raises an error).
Assumes A is full rank. Computed with Householder reflections, dense; for MX the SX algorithm is embedded as a function call node.
Inspired by Numerical Methods in Scientific Computing by Ake Bjorck
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> Z = nullspace(A)
>>> Z.dim(), norm_1(mtimes(A, Z))
('3x1', DM(0))
>> A = DM([1 2 3; 4 5 6]); >> Z = nullspace(A); >> Z.dim(), norm_1(A*Z) 3x1 0
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> Z = ca.nullspace(A);
julia> ca.dim(Z), ca.norm_1(A * Z)
("3x1", 0)
Extra doc: https://github.com/casadi/casadi/wiki/L_1cb
Definition at line 2287 of file generic_matrix.hpp.
|
friend |
Returns the cumulative row counts (or column counts when vert is false) of the matrices in v, starting with 0. The result has one entry more than v and is the offset list that vertsplit (or horzsplit) needs to undo a vertcat (or horzcat) of v.
| v | List of matrices (or Sparsity patterns) |
| vert | True for row offsets, false for column offsets |
>>> offset([DM(2, 3), DM(4, 3)]) [0, 2, 6] >>> offset([DM(2, 3), DM(2, 4)], False) [0, 3, 7] >>> offset([]) [0]
julia> ca.offset([ca.DM(2, 3), ca.DM(4, 3)])
3-element Vector{Int64}:
0
2
6
julia> ca.offset([ca.DM(2, 3), ca.DM(2, 4)], false)
3-element Vector{Int64}:
0
3
7
julia> ca.offset(ca.DM[])
1-element Vector{Int64}:
0
Extra doc: https://github.com/casadi/casadi/wiki/L_3j
Definition at line 583 of file sparsity_interface.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt and eq. For symbolic operands x != x with the same node simplifies to 0, so it cannot be used to detect NaN symbolically.
>>> ne(DM([1, 2, 3]), 2)
DM([1, 0, 1])
>>> x = MX.sym("x")
>>> x != x
MX(0)
>> ne(DM([1; 2; 3]), 2)
[1, 0, 1]
>> x = MX.sym('x');
>> x ~= x
0
julia> ca.ne(ca.DM([1, 2, 3]), 2)
DM([1, 0, 1])
julia> x = ca.MX.sym("x");
julia> x != x
MX(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_ow
Definition at line 697 of file generic_expression.hpp.
|
friend |
Returns (an expression evaluating to) 1 where both entries are nonzero and 0 otherwise, elementwise
Any nonzero value, including NaN, counts as true. Shape rules as for plus; the result is structurally zero wherever either operand is. The Python keyword and does not work on matrices (it needs a single truth value); use this function.
>>> logic_and(DM([1, 2, 0]), DM([3, 0, 0]))
DM([1, 0, 0])
>>> logic_and(SX.sym("x"), SX.sym("y"))
SX((x&&y))
>>> logic_and(DM.eye(2), DM.ones(2, 2))
DM(
[[1, 00],
[00, 1]])
>> DM([1; 2; 0]) & DM([3; 0; 0])
[1, 0, 0]
>> SX.sym('x') & SX.sym('y')
(x&&y)
>> and(DM.eye(2), DM.ones(2, 2))
[[1, 00],
[00, 1]]
julia> ca.logic_and(ca.DM([1, 2, 0]), ca.DM([3, 0, 0]))
DM([1, 0, 0])
julia> ca.logic_and(ca.SX.sym("x"), ca.SX.sym("y"))
SX((x&&y))
julia> ca.logic_and(ca.DM.eye(2), ca.DM.ones(2, 2))
DM(
[[1, 00],
[00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_ox
Definition at line 759 of file generic_expression.hpp.
|
friend |
Elementwise (Hadamard) product, not the matrix product; use mtimes for that. Shape rules as for plus. The result is structurally zero wherever either operand is, so the sparsity pattern is the intersection of the patterns.
>>> times(DM([1, 2]), DM([3, 4])) DM([3, 8]) >>> DM([[1, 2], [3, 4]]) * DM([[1, 2], [3, 4]]) DM( [[1, 4], [9, 16]]) >>> DM.eye(2) * DM.ones(2, 2) DM( [[1, 00], [00, 1]])
>> times(DM([1; 2]), DM([3; 4])) [3, 8] >> DM([1 2; 3 4]) .* DM([1 2; 3 4]) [[1, 4], [9, 16]] >> DM([1 2; 3 4]) * DM([1 2; 3 4]) [[7, 10], [15, 22]] >> DM.eye(2) .* DM.ones(2, 2) [[1, 00], [00, 1]]
julia> ca.times(ca.DM([1, 2]), ca.DM([3, 4])) DM([3, 8]) julia> ca.DM([1 2; 3 4]) .* ca.DM([1 2; 3 4]) DM( [[1, 4], [9, 16]]) julia> ca.DM.eye(2) .* ca.DM.ones(2, 2) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_op
Definition at line 295 of file generic_expression.hpp.
|
friend |
Definition at line 167 of file generic_expression.hpp.
|
friend |
Elementwise difference; shape and sparsity rules as for plus. For symbolic arguments, x - x with the same node simplifies to 0.
>>> minus(DM([5, 6]), DM([1, 2]))
DM([4, 4])
>>> DM.eye(2) - 1
DM(
[[0, -1],
[-1, 0]])
>>> x = SX.sym("x")
>>> x - x
SX(0)
>> minus(DM([5; 6]), DM([1; 2]))
[4, 4]
>> DM.eye(2) - 1
[[0, -1],
[-1, 0]]
>> x = SX.sym('x');
>> x - x
0
julia> ca.minus(ca.DM([5, 6]), ca.DM([1, 2]))
DM([4, 4])
julia> ca.DM.eye(2) - 1
DM(
[[0, -1],
[-1, 0]])
julia> x = ca.SX.sym("x");
julia> x - x
SX(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_oo
Definition at line 227 of file generic_expression.hpp.
|
friend |
Elementwise quotient, not a linear solve; use solve or mldivide for that. Shape rules as for plus. Division by zero follows IEEE arithmetic (inf or nan), no error is raised. Structural zeros of x stay structural zeros; dividing by a sparse y densifies.
>>> rdivide(DM([1, 2]), 4) DM([0.25, 0.5]) >>> DM([1, 2]) / DM([4, 8]) DM([0.25, 0.25]) >>> 1 / DM.eye(2) DM( [[1, inf], [inf, 1]]) >>> DM.eye(2) / 2 DM( [[0.5, 00], [00, 0.5]])
>> rdivide(DM([1; 2]), 4) [0.25, 0.5] >> DM([1; 2]) ./ DM([4; 8]) [0.25, 0.25] >> 1 ./ DM.eye(2) [[1, inf], [inf, 1]] >> DM.eye(2) ./ 2 [[0.5, 00], [00, 0.5]]
julia> ca.rdivide(ca.DM([1, 2]), 4) DM([0.25, 0.5]) julia> ca.DM([1, 2]) ./ ca.DM([4, 8]) DM([0.25, 0.25]) julia> 1 ./ ca.DM.eye(2) DM( [[1, inf], [inf, 1]]) julia> ca.DM.eye(2) / 2 DM( [[0.5, 00], [00, 0.5]])
Extra doc: https://github.com/casadi/casadi/wiki/L_oq
Definition at line 366 of file generic_expression.hpp.
|
friend |
Elementwise comparison; shape rules as for plus. Every comparison in this group returns a matrix of the same type as the operands with entries 1 (true) and 0 (false): for DM a numeric 0/1 matrix, not a boolean, and for SX and MX a symbolic expression that is only decided at evaluation time. Comparisons with NaN are false. The result is sparse where both operands are structurally zero (0 < 0 is false).
>>> lt(DM([1, 2, 3]), 2)
DM([1, 0, 0])
>>> DM([1, 2, 3]) < DM([3, 2, 1])
DM([1, 0, 0])
>>> SX.sym("x", 2) < SX.sym("y", 2)
SX([(x_0<y_0), (x_1<y_1)])
>>> DM.eye(2) < 1
DM(
[[0, 1],
[1, 0]])
>> lt(DM([1; 2; 3]), 2)
[1, 0, 0]
>> DM([1; 2; 3]) < DM([3; 2; 1])
[1, 0, 0]
>> SX.sym('x', 2) < SX.sym('y', 2)
[(x_0<y_0), (x_1<y_1)]
>> DM.eye(2) < 1
[[0, 1],
[1, 0]]
julia> ca.lt(ca.DM([1, 2, 3]), 2)
DM([1, 0, 0])
julia> ca.DM([1, 2, 3]) < ca.DM([3, 2, 1])
DM([1, 0, 0])
julia> ca.SX.sym("x", 2) < ca.SX.sym("y", 2)
SX([(x_0<y_0), (x_1<y_1)])
julia> ca.DM.eye(2) < 1
DM(
[[0, 1],
[1, 0]])
Extra doc: https://github.com/casadi/casadi/wiki/L_or
Definition at line 434 of file generic_expression.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt. Chained inequalities such as lb <= (x <= ub) are recognised by Opti as bound constraints.
>>> le(DM([1, 2, 3]), 2)
DM([1, 1, 0])
>>> x = SX.sym("x")
>>> x <= x
SX(1)
>> le(DM([1; 2; 3]), 2)
[1, 1, 0]
>> x = SX.sym('x');
>> x <= x
1
julia> ca.le(ca.DM([1, 2, 3]), 2)
DM([1, 1, 0])
julia> x = ca.SX.sym("x");
julia> x <= x
SX(1)
Extra doc: https://github.com/casadi/casadi/wiki/L_os
Definition at line 484 of file generic_expression.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt: this is value equality of the entries, not identity of expressions; use is_equal to test whether two symbolic expressions are the same. For symbolic operands x == x with the same node simplifies to 1. NaN is not equal to anything, including itself.
>>> eq(DM([1, 2, 3]), 2)
DM([0, 1, 0])
>>> DM.eye(2) == DM([[1, 0], [0, 1]])
DM(
[[1, 1],
[1, 1]])
>>> x = SX.sym("x")
>>> x == x, x == SX.sym("x")
(SX(1), SX((x==x)))
>>> DM(float("nan")) == DM(float("nan"))
DM(0)
>> eq(DM([1; 2; 3]), 2)
[0, 1, 0]
>> DM.eye(2) == DM([1 0; 0 1])
[[1, 1],
[1, 1]]
>> x = SX.sym('x');
>> x == x, x == SX.sym('x')
1
(x==x)
>> DM(nan) == DM(nan)
0
julia> ca.eq(ca.DM([1, 2, 3]), 2)
DM([0, 1, 0])
julia> ca.DM.eye(2) == ca.DM([1 0; 0 1])
DM(
[[1, 1],
[1, 1]])
julia> x = ca.SX.sym("x");
julia> x == x, x == ca.SX.sym("x")
(1, (x==x))
julia> ca.DM(NaN) == ca.DM(NaN)
DM(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_ov
Definition at line 647 of file generic_expression.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt. Implemented as y < x, which is how a symbolic expression prints.
>>> gt(DM([1, 2, 3]), 2)
DM([0, 0, 1])
>>> gt(SX.sym("x"), SX.sym("y"))
SX((y<x))
>> gt(DM([1; 2; 3]), 2)
[0, 0, 1]
>> SX.sym('x') > SX.sym('y')
(y<x)
julia> ca.gt(ca.DM([1, 2, 3]), 2)
DM([0, 0, 1])
julia> ca.gt(ca.SX.sym("x"), ca.SX.sym("y"))
SX((y<x))
Extra doc: https://github.com/casadi/casadi/wiki/L_ot
Definition at line 531 of file generic_expression.hpp.
|
friend |
Elementwise comparison with 0/1 result, see lt. Implemented as y <= x.
>>> ge(DM([1, 2, 3]), 2)
DM([0, 1, 1])
>>> ge(MX.sym("x"), MX.sym("y"))
MX((y<=x))
>> ge(DM([1; 2; 3]), 2)
[0, 1, 1]
>> MX.sym('x') >= MX.sym('y')
(y<=x)
julia> ca.ge(ca.DM([1, 2, 3]), 2)
DM([0, 1, 1])
julia> ca.ge(ca.MX.sym("x"), ca.MX.sym("y"))
MX((y<=x))
Extra doc: https://github.com/casadi/casadi/wiki/L_ou
Definition at line 577 of file generic_expression.hpp.
|
friend |
returns (an expression evaluating to) 1 where at least one entry is nonzero and 0 otherwise, elementwise
Shape rules as for plus; the result is structurally zero where both operands are.
>>> logic_or(DM([1, 0, 0]), DM([0, 0, 2]))
DM([1, 0, 1])
>>> logic_or(MX.sym("x"), MX.sym("y"))
MX((x||y))
>> DM([1; 0; 0]) | DM([0; 0; 2])
[1, 0, 1]
>> or(MX.sym('x'), MX.sym('y'))
(x||y)
julia> ca.logic_or(ca.DM([1, 0, 0]), ca.DM([0, 0, 2]))
DM([1, 0, 1])
julia> ca.logic_or(ca.MX.sym("x"), ca.MX.sym("y"))
MX((x||y))
Extra doc: https://github.com/casadi/casadi/wiki/L_oy
Definition at line 808 of file generic_expression.hpp.
|
friend |
If the matrix A is fat (size1<size2), mul(A, pinv(A)) is unity.
pinv(A)' = (AA')^(-1) A
If the matrix A is slender (size1>size2), mul(pinv(A), A) is unity.
pinv(A) = (A'A)^(-1) A'
The normal equations are solved with solve, so A is assumed to have full rank. For a square matrix this is the inverse.
>>> A = DM([[1, 0, 0], [0, 2, 0]])
>>> pinv(A)
DM(
[[1, 0],
[0, 0.5],
[0, 0]])
>>> mtimes(A, pinv(A))
DM(
[[1, 0],
[0, 1]])
>>> pinv(SX.sym("A", 1, 2))
SX(@1=(sq(A_0)+sq(A_1)), [(A_0/@1), (A_1/@1)])
>> A = DM([1 0 0; 0 2 0]);
>> pinv(A)
[[1, 0],
[0, 0.5],
[0, 0]]
>> A*pinv(A)
[[1, 0],
[0, 1]]
>> pinv(SX.sym('A', 1, 2))
@1=(sq(A_0)+sq(A_1)), [(A_0/@1), (A_1/@1)]
julia> A = ca.DM([1 0 0; 0 2 0]);
julia> ca.pinv(A)
DM(
[[1, 0],
[0, 0.5],
[0, 0]])
julia> A * ca.pinv(A)
DM(
[[1, 0],
[0, 1]])
julia> ca.pinv(ca.SX.sym("A", 1, 2))
SX(@1=(sq(A_0)+sq(A_1)), [(A_0/@1), (A_1/@1)])
Extra doc: https://github.com/casadi/casadi/wiki/L_1ct
Definition at line 3364 of file generic_matrix.hpp.
|
friend |
Same as pinv(A) but the normal equations are solved with the given Linsol plugin. Available for DM and MX; SX raises an error.
>>> pinv(DM([[1, 0, 0], [0, 2, 0]]), "qr") DM( [[1, 0], [0, 0.5], [0, 0]])
>> pinv(DM([1 0 0; 0 2 0]), 'qr') [[1, 0], [0, 0.5], [0, 0]]
julia> print(ca.pinv(ca.DM([1 0 0; 0 2 0]), "qr")) [[1, 0], [0, 0.5], [0, 0]]
Extra doc: https://github.com/casadi/casadi/wiki/L_1cu
Definition at line 3405 of file generic_matrix.hpp.
|
friend |
Definition at line 164 of file generic_expression.hpp.
|
friend |
Returns the coefficients in decreasing power order (highest degree first), as a column vector; the constant term is last. Coefficients may be symbolic in other variables. Found by repeated differentiation, so an expression that is not polynomial in x raises an error. Only defined for SX.
| ex | Scalar SX expression that is a polynomial in x |
| x | Scalar SX symbol |
>>> x = SX.sym("x"); a = SX.sym("a")
>>> poly_coeff(3*x**2 + 2*x + 1, x)
SX([3, 2, 1])
>>> poly_coeff((x - a)*(x + a), x)
SX([1, 0, (-sq(a))])
>>> try: poly_coeff(sin(x), x)
... except Exception as e: print("error")
error
>> x = SX.sym('x'); a = SX.sym('a');
>> poly_coeff(3*x^2 + 2*x + 1, x)
[3, 2, 1]
>> poly_coeff((x - a)*(x + a), x)
[1, 0, (-sq(a))]
>> try, poly_coeff(sin(x), x); catch e, disp('error'); end
error
julia> x = ca.SX.sym("x"); a = ca.SX.sym("a");
julia> ca.poly_coeff(3*x^2 + 2*x + 1, x)
SX([3, 2, 1])
julia> ca.poly_coeff((x - a)*(x + a), x)
SX([1, 0, (-sq(a))])
julia> try ca.poly_coeff(sin(x), x); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_197
Definition at line 2605 of file matrix_decl.hpp.
p is a dense column vector of coefficients in decreasing power order, as returned by poly_coeff. Closed-form formulas are used for degrees 1 to 4; a zero constant term is split off as a root 0 first. Higher degrees raise an error. All roots are assumed real: complex roots give nan. The result stays symbolic for symbolic coefficients. Only defined for SX; pass SX(p) for numeric coefficients.
>>> poly_roots(SX([1, -3, 2]))
SX([1, 2])
>>> evalf(poly_roots(SX([1, -6, 11, -6])))
DM([3, 1, 2])
>>> a = SX.sym("a")
>>> poly_roots(vertcat(a, 2))
SX((-2/a))
>>> try: poly_roots(SX([1, 1, 1, 1, 1, 1]))
... except Exception as e: print("error")
error
>> poly_roots(SX([1; -3; 2]))
[1, 2]
>> evalf(poly_roots(SX([1; -6; 11; -6])))
[3, 1, 2]
>> a = SX.sym('a');
>> poly_roots([a; 2])
(-2/a)
>> try, poly_roots(SX([1; 1; 1; 1; 1; 1])); catch e, disp('error'); end
error
julia> ca.poly_roots(ca.SX([1, -3, 2]))
SX([1, 2])
julia> ca.evalf(ca.poly_roots(ca.SX([1, -6, 11, -6])))
DM([3, 1, 2])
julia> a = ca.SX.sym("a");
julia> ca.poly_roots([a; 2])
SX((-2/a))
julia> try ca.poly_roots(ca.SX([1, 1, 1, 1, 1, 1])); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_198
Definition at line 2664 of file matrix_decl.hpp.
|
friend |
Horner evaluation of p[0]*x^(n-1) + ... + p[n-2]*x + p[n-1]: the first coefficient belongs to the highest power, as in MATLAB's polyval. The polynomial is applied to every structurally nonzero entry of x; the result keeps the shape and sparsity of x (structural zeros stay zero even when p[n-1] != 0).
| p | Dense column vector of coefficients, at least one entry |
| x | Point(s) of evaluation, any shape |
>>> polyval(DM([1, 2, 3]), 2)
DM(11)
>>> polyval(DM([1, 0, -1]), DM([0, 1, 2]))
DM([-1, 0, 3])
>>> polyval(SX.sym("p", 3), SX.sym("x"))
SX(((((p_0*x)+p_1)*x)+p_2))
>> polyval(DM([1; 2; 3]), 2)
11
>> polyval(DM([1; 0; -1]), DM([0; 1; 2]))
[-1, 0, 3]
>> polyval(SX.sym('p', 3), SX.sym('x'))
((((p_0*x)+p_1)*x)+p_2)
julia> ca.polyval(ca.DM([1, 2, 3]), 2)
DM(11)
julia> ca.polyval(ca.DM([1, 0, -1]), ca.DM([0, 1, 2]))
DM([-1, 0, 3])
julia> ca.polyval(ca.SX.sym("p", 3), ca.SX.sym("x"))
SX(((((p_0*x)+p_1)*x)+p_2))
Extra doc: https://github.com/casadi/casadi/wiki/L_1cc
Definition at line 2335 of file generic_matrix.hpp.
|
friend |
Elementwise; shape rules as for plus. Named power in Python, where the ** operator maps to it as well. A constant exponent is simplified symbolically: integer powers become repeated squaring and multiplication, 0.5 becomes sqrt, -1 a reciprocal, other constants a constpow operation. Structural zeros of x stay zero for a nonzero exponent; x**0 is dense (0**0 == 1).
>>> power(DM([1, 2, 3]), 2)
DM([1, 4, 9])
>>> DM([1, 2, 3])**DM([3, 2, 1]), 2**DM([1, 2, 3])
(DM([1, 4, 3]), DM([2, 4, 8]))
>>> x = SX.sym("x")
>>> x**2, x**3, x**-1, x**x
(SX(sq(x)), SX((x*sq(x))), SX((1./x)), SX(pow(x,x)))
>>> x**2.5
SX(pow(x,2.5))
>> power(DM([1; 2; 3]), 2)
[1, 4, 9]
>> DM([1; 2; 3]).^DM([3; 2; 1]), 2.^DM([1; 2; 3])
[1, 4, 3]
[2, 4, 8]
>> x = SX.sym('x');
>> x.^2, x.^3, x.^-1, x.^x
sq(x)
(x*sq(x))
(1./x)
pow(x,x)
>> x.^2.5
pow(x,2.5)
julia> ca.power(ca.DM([1, 2, 3]), 2)
DM([1, 4, 9])
julia> ca.DM([1, 2, 3]) .^ ca.DM([3, 2, 1]), 2 .^ ca.DM([1, 2, 3])
([1, 4, 3], [2, 4, 8])
julia> x = ca.SX.sym("x");
julia> x^2, x^3, x^-1, x^x
(sq(x), (x*sq(x)), (1./x), pow(x,x))
julia> x^2.5
SX(pow(x,2.5))
Extra doc: https://github.com/casadi/casadi/wiki/L_pp
Definition at line 1981 of file generic_expression.hpp.
|
friend |
Prints the operation at the root of a scalar expression with the given strings in place of its operands. xb must be a unary or binary operation (a symbol or constant raises an error for SX) and args must have one entry per operand.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> print_operator(x + y, ["a", "b"]), print_operator(sin(x), ["a"])
('(a+b)', 'sin(a)')
>>> X = MX.sym("X"); Y = MX.sym("Y")
>>> print_operator(vertcat(X, Y), ["a", "b"])
'vertcat(a, b)'
>> x = SX.sym('x'); y = SX.sym('y');
>> print_operator(x + y, {'a', 'b'}), print_operator(sin(x), {'a'})
(a+b)
sin(a)
>> X = MX.sym('X'); Y = MX.sym('Y');
>> print_operator(vertcat(X, Y), {'a', 'b'})
vertcat(a, b)
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.print_operator(x + y, ["a", "b"]), ca.print_operator(sin(x), ["a"])
("(a+b)", "sin(a)")
julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
julia> ca.print_operator([X; Y], ["a", "b"])
"vertcat(a, b)"
Extra doc: https://github.com/casadi/casadi/wiki/L_1d4
Definition at line 4580 of file generic_matrix.hpp.
|
friend |
Identity operation with a side effect: whenever the expression is evaluated inside a Function (and hence inside a solver), every nonzero of x is printed on its own line as "|> y : value" in storage (column-major) order, with y an identifier of choice to tell several printme nodes apart. Available as a method x.printme(y) in Python; the derivative is that of x. Use monitor to print a whole matrix at once.
>>> x = MX.sym("x")
>>> f = Function("f", [x], [x.printme(7) * 2])
>>> f(3)
|> 7 : 3.0000000000000000e+00
DM(6)
>> x = MX.sym('x');
>> f = Function('f', {x}, {x.printme(7) * 2});
>> f(3)
|> 7 : 3.0000000000000000e+00
6
julia> x = ca.MX.sym("x");
julia> f = ca.Function("f", [x], [ca.printme(x, 7) * 2]);
julia> f(3)
|> 7 : 3.0000000000000000e+00
DM(6)
Extra doc: https://github.com/casadi/casadi/wiki/L_2on
Definition at line 2518 of file generic_expression.hpp.
|
friend |
nonzeros taken from an existing matrix
Entries of A outside sp are dropped; entries of sp not present in A become numerical zeros. The shape of sp must equal that of A. With intersect true, the target pattern is the intersection of sp and the pattern of A, so the result only ever loses entries.
>>> project(DM([[1, 2], [3, 4]]), Sparsity.diag(2)) DM( [[1, 00], [00, 4]]) >>> project(DM.eye(2), Sparsity.dense(2, 2)) DM( [[1, 0], [0, 1]]) >>> project(DM(Sparsity.diag(2), [1, 2]), Sparsity.upper(2), True) DM( [[1, 00], [00, 2]])
>> project(DM([1 2; 3 4]), Sparsity.diag(2)) [[1, 00], [00, 4]] >> project(DM.eye(2), Sparsity.dense(2, 2)) [[1, 0], [0, 1]] >> project(DM(Sparsity.diag(2), [1; 2]), Sparsity.upper(2), true) [[1, 00], [00, 2]]
julia> ca.project(ca.DM([1 2; 3 4]), ca.Sparsity.diag(2)) DM( [[1, 00], [00, 4]]) julia> ca.project(ca.DM.eye(2), ca.Sparsity.dense(2, 2)) DM( [[1, 0], [0, 1]]) julia> ca.project(ca.DM(ca.Sparsity.diag(2), [1, 2]), ca.Sparsity.upper(2), true) DM( [[1, 00], [00, 2]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1ch
Definition at line 2574 of file generic_matrix.hpp.
Referenced by casadi::GenericMatrix< MatType >::tril(), and casadi::GenericMatrix< MatType >::triu().
|
friend |
Builds an SX expression that equals val[0] for t < tval[0], val[k] for tval[k-1] <= t < tval[k] and val[n-1] for t >= tval[n-2], with n = val.numel(). tval must be increasing. The result is a sum of step functions, so it is not smooth; its derivative with respect to t is zero almost everywhere. Only defined for SX.
| t | Scalar SX variable (e.g. time) |
| tval | Breakpoints, length n-1; a length mismatch raises an error |
| val | Function value on each interval, length n |
>>> t = SX.sym("t")
>>> e = pw_const(t, [0, 2], [7, 1, 3])
>>> f = Function("f", [t], [e])
>>> [float(f(v)) for v in [-1, 0, 1, 2, 5]]
[7.0, 1.0, 1.0, 3.0, 3.0]
>>> try: pw_const(t, [0], [7, 1, 3])
... except Exception as e: print("error")
error
>> t = SX.sym('t');
>> e = pw_const(t, [0 2], [7 1 3]);
>> f = Function('f', {t}, {e});
>> f([-1; 0; 1; 2; 5])
[7, 1, 1, 3, 3]
>> try, pw_const(t, 0, [7 1 3]); catch e, disp('error'); end
error
julia> t = ca.SX.sym("t");
julia> e = ca.pw_const(t, [0, 2], [7, 1, 3]);
julia> f = ca.Function("f", [t], [e]);
julia> [Float64(f(v)) for v in [-1, 0, 1, 2, 5]]
5-element Vector{Float64}:
7.0
1.0
1.0
3.0
3.0
julia> try ca.pw_const(t, [0], [7, 1, 3]); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_193
Definition at line 2133 of file matrix_decl.hpp.
|
friend |
Builds an SX expression that interpolates linearly between the points (tval[k], val[k]). Outside [tval[0], tval[N-1]] the first and last segments are extrapolated. Only defined for SX.
| t | Scalar SX variable (e.g. time) |
| tval | Breakpoints, increasing, at least two |
| val | Function values at the breakpoints, same length as tval |
>>> t = SX.sym("t")
>>> f = Function("f", [t], [pw_lin(t, [0, 1, 3], [0, 2, 1])])
>>> [float(f(v)) for v in [-1, 0, 0.5, 1, 2, 3, 4]]
[-2.0, 0.0, 1.0, 2.0, 1.5, 1.0, 0.5]
>>> try: pw_lin(t, [0], [7])
... except Exception as e: print("error")
error
>> t = SX.sym('t');
>> f = Function('f', {t}, {pw_lin(t, [0 1 3], [0 2 1])});
>> f([-1; 0; 0.5; 1; 2; 3; 4])
[-2, 0, 1, 2, 1.5, 1, 0.5]
>> try, pw_lin(t, 0, 7); catch e, disp('error'); end
error
julia> t = ca.SX.sym("t");
julia> f = ca.Function("f", [t], [ca.pw_lin(t, [0, 1, 3], [0, 2, 1])]);
julia> [Float64(f(v)) for v in [-1, 0, 0.5, 1, 2, 3, 4]]
7-element Vector{Float64}:
-2.0
0.0
1.0
2.0
1.5
1.0
0.5
julia> try ca.pw_lin(t, [0], [7]); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_194
Definition at line 2194 of file matrix_decl.hpp.
|
friend |
Factorizes A = Q*R with Q of the same shape as A (orthonormal columns) and R square upper triangular. More stable than classical Gram-Schmidt, but breaks down (nan entries, no error) when the columns of A are (nearly) linearly dependent. A must have at least as many rows as columns. Works symbolically on SX. See J. Demmel: Applied Numerical Linear Algebra (algorithm 3.1). In Python and MATLAB, Q and R are returned as a tuple.
>>> Q, R = qr(DM([[3, 1], [4, 2]]))
>>> Q
DM(
[[0.6, -0.8],
[0.8, 0.6]])
>>> R
DM(
[[5, 2.2],
[00, 0.4]])
>>> mtimes(Q, R)
DM(
[[3, 1],
[4, 2]])
>>> try: qr(DM([[1, 2, 3]]))
... except Exception as e: print("error")
error
>> [Q, R] = qr(DM([3 1; 4 2]));
>> Q
[[0.6, -0.8],
[0.8, 0.6]]
>> R
[[5, 2.2],
[00, 0.4]]
>> Q*R
[[3, 1],
[4, 2]]
>> try, [Q, R] = qr(DM([1 2 3])); catch e, disp('error'); end
error
julia> Q, R = ca.qr(ca.DM([3 1; 4 2]));
julia> Q
DM(
[[0.6, -0.8],
[0.8, 0.6]])
julia> R
DM(
[[5, 2.2],
[00, 0.4]])
julia> Q * R
DM(
[[3, 1],
[4, 2]])
julia> try ca.qr(ca.DM([1 2 3])); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_18s
Definition at line 1582 of file matrix_decl.hpp.
|
friend |
| b | Right-hand side, one column per system; a sparse b is densified |
| v,r,beta,prinv,pc | Output of qr_sparse(A) |
| tr | Solve with the transpose of A instead |
b
>>> A = DM([[3, 1], [4, 2]]) >>> V, R, beta, prinv, pc = qr_sparse(A) >>> qr_solve(DM([1, 2]), V, R, beta, prinv, pc, True) DM([-3, 2.5]) >>> solve(A.T, DM([1, 2])) DM([-3, 2.5])
>> A = DM([3 1; 4 2]); >> [V, R, beta, prinv, pc] = qr_sparse(A); >> qr_solve(DM([1; 2]), V, R, beta, prinv, pc, true) [-3, 2.5] >> solve(A', DM([1; 2])) [-3, 2.5]
julia> A = ca.DM([3 1; 4 2]); julia> V, R, beta, prinv, pc = ca.qr_sparse(A); julia> ca.qr_solve(ca.DM([1, 2]), V, R, beta, prinv, pc, true) DM([-3, 2.5]) julia> A' \ [1, 2] DM([-3, 2.5])
Extra doc: https://github.com/casadi/casadi/wiki/L_18u
Definition at line 1688 of file matrix_decl.hpp.
|
friend |
Computes a compact representation of Q (Householder vectors V and scaling factors beta), the upper triangular factor R and the row and column permutations prinv and pc that were applied, so that the factors can be reused by qr_solve. See T. Davis: Direct Methods for Sparse Linear Systems. Works symbolically on SX.
| A | Matrix to factorize |
| amd | Use an approximate minimum degree column ordering to reduce fill-in |
>>> A = DM([[3, 1], [4, 2]]) >>> V, R, beta, prinv, pc = qr_sparse(A) >>> R DM( [[5, 2.2], [00, 0.4]]) >>> qr_solve(DM([1, 2]), V, R, beta, prinv, pc) DM([0, 1])
>> A = DM([3 1; 4 2]); >> [V, R, beta, prinv, pc] = qr_sparse(A); >> R [[5, 2.2], [00, 0.4]] >> qr_solve(DM([1; 2]), V, R, beta, prinv, pc) [0, 1]
julia> A = ca.DM([3 1; 4 2]); julia> V, R, beta, prinv, pc = ca.qr_sparse(A); julia> R DM( [[5, 2.2], [00, 0.4]]) julia> ca.qr_solve(ca.DM([1, 2]), V, R, beta, prinv, pc) DM([0, 1])
Extra doc: https://github.com/casadi/casadi/wiki/L_18t
Definition at line 1638 of file matrix_decl.hpp.
|
friend |
1/2*x' A x + b' x + c
e = 0.5*bilin(A,x,x)+dot(b,x)+c
Returns A = hessian(expr, var), b = jacobian(expr, var) at var = 0 as a column, and c = expr at var = 0. A non-scalar expr raises an error.
| check[in] | When true (default), A is checked to be independent of x and an error is raised otherwise ("called on non-quadratic expression"). Provided to deal with false positive dependency checks. |
* >>> x = SX.sym("x"); y = SX.sym("y")
* >>> A, b, c = quadratic_coeff(x**2 + 2*x*y + 3*x + 4, vertcat(x, y))
* >>> A
* SX(@1=2,
* [[@1, @1],
* [@1, 00]])
* >>> b, c
* (SX([3, 0]), SX(4))
* >>> try: quadratic_coeff(x**3, x)
* ... except Exception as e: print("error")
* error
*
* >> x = SX.sym('x'); y = SX.sym('y');
* >> [A, b, c] = quadratic_coeff(x^2 + 2*x*y + 3*x + 4, vertcat(x, y));
* >> A
* @1=2,
* [[@1, @1],
* [@1, 00]]
* >> b, c
* [3, 0]
* 4
* >> try, [A, b, c] = quadratic_coeff(x^3, x); catch e, disp('error'); end
* error
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
* julia> A, b, c = ca.quadratic_coeff(x^2 + 2 * x * y + 3 * x + 4, [x; y]);
* julia> A
* SX(@1=2,
* [[@1, @1],
* [@1, 00]])
* julia> b, c
* ([3, 0], 4)
* julia> try ca.quadratic_coeff(x^3, x) catch e; println("error") end
* error
*
Extra doc: https://github.com/casadi/casadi/wiki/L_1d2
Definition at line 4122 of file generic_matrix.hpp.
x for x > 0 and 0 for x <= 0, computed as x*heaviside(x). Also called the slope function or relu. Not defined for MX; use fmax(x, 0) for an MX-compatible alternative.
>>> ramp(DM([0, 0.5, 3]))
DM([0, 0.5, 3])
>>> ramp(SX.sym("x"))
SX((x*((1+sign(x))/2)))
>> ramp(DM([0; 0.5; 3]))
[0, 0.5, 3]
>> ramp(SX.sym('x'))
(x*((1+sign(x))/2))
julia> ca.ramp(ca.DM([0, 0.5, 3]))
DM([0, 0.5, 3])
julia> ca.ramp(ca.SX.sym("x"))
SX((x*((1+sign(x))/2)))
Extra doc: https://github.com/casadi/casadi/wiki/L_23p
Definition at line 2338 of file matrix_decl.hpp.
|
friend |
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
Definition at line 1263 of file generic_matrix.hpp.
|
friend |
Elementwise quotient, not a linear solve; use solve or mldivide for that. Shape rules as for plus. Division by zero follows IEEE arithmetic (inf or nan), no error is raised. Structural zeros of x stay structural zeros; dividing by a sparse y densifies.
>>> rdivide(DM([1, 2]), 4) DM([0.25, 0.5]) >>> DM([1, 2]) / DM([4, 8]) DM([0.25, 0.25]) >>> 1 / DM.eye(2) DM( [[1, inf], [inf, 1]]) >>> DM.eye(2) / 2 DM( [[0.5, 00], [00, 0.5]])
>> rdivide(DM([1; 2]), 4) [0.25, 0.5] >> DM([1; 2]) ./ DM([4; 8]) [0.25, 0.25] >> 1 ./ DM.eye(2) [[1, inf], [inf, 1]] >> DM.eye(2) ./ 2 [[0.5, 00], [00, 0.5]]
julia> ca.rdivide(ca.DM([1, 2]), 4) DM([0.25, 0.5]) julia> ca.DM([1, 2]) ./ ca.DM([4, 8]) DM([0.25, 0.25]) julia> 1 ./ ca.DM.eye(2) DM( [[1, inf], [inf, 1]]) julia> ca.DM.eye(2) / 2 DM( [[0.5, 00], [00, 0.5]])
Extra doc: https://github.com/casadi/casadi/wiki/L_oq
Definition at line 363 of file generic_expression.hpp.
1 for |x| < 1/2, 1/2 for |x| == 1/2 and 0 for |x| > 1/2, built from sign. Not defined for MX.
>>> rectangle(DM([-1, -0.5, 0, 0.5, 1])) DM([0, 0.5, 1, 0.5, 0])
>> rectangle(DM([-1; -0.5; 0; 0.5; 1])) [0, 0.5, 1, 0.5, 0]
julia> ca.rectangle(ca.DM([-1, -0.5, 0, 0.5, 1])) DM([0, 0.5, 1, 0.5, 0])
Extra doc: https://github.com/casadi/casadi/wiki/L_23n
Definition at line 2267 of file matrix_decl.hpp.
|
friend |
This Function follows the convention of https://en.cppreference.com/w/c/numeric/math/remainder: x - n*y with n the integer nearest to x/y (ties to even), so the result lies in [-|y|/2, |y|/2].
Notably:
This is equivalent to Python's math.remainder. There is no equivalence in Matlab. Elementwise, shape rules as for plus; structural zeros of x stay zero.
>>> remainder(DM([5, 5, -5, -5]), DM([3, -3, 3, -3]))
DM([-1, -1, 1, 1])
>>> remainder(DM([2.5, 3.5]), 2)
DM([0.5, -0.5])
>>> remainder(MX.sym("x"), 2)
MX(remainder(x,2))
>> remainder(DM([5; 5; -5; -5]), DM([3; -3; 3; -3]))
[-1, -1, 1, 1]
>> remainder(DM([2.5; 3.5]), 2)
[0.5, -0.5]
>> remainder(MX.sym('x'), 2)
remainder(x,2)
julia> ca.remainder(ca.DM([5, 5, -5, -5]), ca.DM([3, -3, 3, -3]))
DM([-1, -1, 1, 1])
julia> ca.remainder(ca.DM([2.5, 3.5]), 2)
DM([0.5, -0.5])
julia> ca.remainder(ca.MX.sym("x"), 2)
MX(remainder(x,2))
Extra doc: https://github.com/casadi/casadi/wiki/L_24x
Definition at line 2102 of file generic_expression.hpp.
|
friend |
Tiles A into an n-by-m grid of copies; the sparsity pattern is tiled along. A zero count gives an empty matrix with the remaining dimension kept. For MX the horizontal repetition is a single node, the vertical one a vertcat of n references.
| A | Matrix (or Sparsity) to tile; any shape |
| n | Number of vertical repetitions, non-negative |
| m | Number of horizontal repetitions, non-negative |
>>> repmat(DM([[1, 2]]), 2, 2)
DM(
[[1, 2, 1, 2],
[1, 2, 1, 2]])
>>> repmat(DM.eye(2), 1, 2)
DM(
[[1, 00, 1, 00],
[00, 1, 00, 1]])
>>> repmat(MX.sym("x", 2), 1, 3)
MX(repmat(x, 3))
>>> repmat(MX.sym("x", 2), 3, 1)
MX(vertcat(x, x, x))
>>> repmat(DM.ones(2, 3), 0, 2).shape
(0, 6)
>> repmat(DM([1 2]), 2, 2)
[[1, 2, 1, 2],
[1, 2, 1, 2]]
>> repmat(DM.eye(2), 1, 2)
[[1, 00, 1, 00],
[00, 1, 00, 1]]
>> repmat(MX.sym('x', 2), 1, 3)
repmat(x, 3)
>> repmat(MX.sym('x', 2), 3, 1)
vertcat(x, x, x)
>> size(repmat(DM.ones(2, 3), 0, 2))
0 6
julia> repeat(ca.DM([1 2]), 2, 2)
DM(
[[1, 2, 1, 2],
[1, 2, 1, 2]])
julia> repeat(ca.DM.eye(2), 1, 2)
DM(
[[1, 00, 1, 00],
[00, 1, 00, 1]])
julia> repeat(ca.MX.sym("x", 2), 1, 3)
MX(repmat(x, 3))
julia> repeat(ca.MX.sym("x", 2), 3, 1)
MX(vertcat(x, x, x))
julia> size(repeat(ca.DM.ones(2, 3), 0, 2))
(0, 6)
Extra doc: https://github.com/casadi/casadi/wiki/L_48
Definition at line 2166 of file sparsity_interface.hpp.
|
friend |
Same as repmat(A, rc[0], rc[1]).
>>> repmat(DM(7), (1, 3)) DM([[7, 7, 7]])
>> repmat(DM(7), [1, 3]) [[7, 7, 7]]
julia> ca.repmat(ca.DM(7), 1, 3) DM([[7, 7, 7]])
Extra doc: https://github.com/casadi/casadi/wiki/L_49
Definition at line 2196 of file sparsity_interface.hpp.
|
friend |
Splits A into an n-by-m grid of equally sized blocks and returns their sum, a matrix of size A.size1()/n by A.size2()/m. The inverse of repmat(x, n, m) in the sense that repsum(repmat(x, n, m), n, m) == n*m*x. The dimensions of A must be multiples of n and m.
>>> repsum(DM([[1, 2, 3, 4], [5, 6, 7, 8]]), 1, 2)
DM(
[[4, 6],
[12, 14]])
>>> repsum(SX.sym("x", 4), 2)
SX([(x_0+x_2), (x_1+x_3)])
>> repsum(DM([1 2 3 4; 5 6 7 8]), 1, 2)
[[4, 6],
[12, 14]]
>> repsum(SX.sym('x', 4), 2)
[(x_0+x_2), (x_1+x_3)]
julia> ca.repsum(ca.DM([1 2 3 4; 5 6 7 8]), 1, 2)
DM(
[[4, 6],
[12, 14]])
julia> ca.repsum(ca.SX.sym("x", 4), 2)
SX([(x_0+x_2), (x_1+x_3)])
Extra doc: https://github.com/casadi/casadi/wiki/L_1d7
Definition at line 4771 of file generic_matrix.hpp.
|
friend |
Reinterprets the entries of x in column-major order as a matrix of nrow by ncol, as reshape does in MATLAB and numpy with order='F'. The number of elements must not change, otherwise an error is raised. One of the dimensions can be -1, it is then inferred from the other. The sparsity pattern is reshaped along; no entries are densified. For MX this is a cheap reordering node.
| x | Matrix (or Sparsity) to reshape; any shape |
| nrow | Number of rows of the result, or -1 |
| ncol | Number of columns of the result, or -1 |
>>> x = DM([[1, 2, 3], [4, 5, 6]])
>>> reshape(x, 3, 2)
DM(
[[1, 5],
[4, 3],
[2, 6]])
>>> reshape(x, -1, 1)
DM([1, 4, 2, 5, 3, 6])
>>> reshape(DM.eye(2), 1, 4)
DM([[1, 00, 00, 1]])
>>> reshape(MX.sym("x", 2, 3), 3, 2)
MX(reshape(x))
>>> reshape(x, 4, 2)
Traceback (most recent call last):
...
RuntimeError: ...number of elements must remain the same...
>> x = DM([1 2 3; 4 5 6]);
>> reshape(x, 3, 2)
[[1, 5],
[4, 3],
[2, 6]]
>> reshape(x, -1, 1)
[1, 4, 2, 5, 3, 6]
>> reshape(DM.eye(2), 1, 4)
[[1, 00, 00, 1]]
>> reshape(MX.sym('x', 2, 3), 3, 2)
reshape(x)
>> try, reshape(x, 4, 2); catch e, disp(e.message); end
...number of elements must remain the same...
julia> x = ca.DM([1 2 3; 4 5 6]);
julia> reshape(x, 3, 2)
DM(
[[1, 5],
[4, 3],
[2, 6]])
julia> reshape(x, :, 1)
DM([1, 4, 2, 5, 3, 6])
julia> reshape(ca.DM.eye(2), 1, 4)
DM([[1, 00, 00, 1]])
julia> reshape(ca.MX.sym("x", 2, 3), 3, 2)
MX(reshape(x))
julia> try
reshape(x, 4, 2)
catch err
println(occursin("number of elements must remain", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_40
Definition at line 1669 of file sparsity_interface.hpp.
|
friend |
sp must be the reshaped pattern of x.sparsity() (same number of elements and the same nonzeros in column-major order), otherwise an error is raised. Useful when the target pattern is already available, e.g. to undo a vec.
>>> reshape(SX.sym("x", 2, 2), Sparsity.dense(4, 1))
SX([x_0, x_1, x_2, x_3])
>>> reshape(MX.sym("x", Sparsity.diag(2)), Sparsity.dense(4, 1))
Traceback (most recent call last):
...
RuntimeError: ...Reshape mismatch...
>> reshape(SX.sym('x', 2, 2), Sparsity.dense(4, 1))
[x_0, x_1, x_2, x_3]
>> x = MX.sym('x', Sparsity.diag(2));
>> try, reshape(x, Sparsity.dense(4, 1)); catch e, disp(e.message); end
...Reshape mismatch...
julia> ca.reshape(ca.SX.sym("x", 2, 2), ca.Sparsity.dense(4, 1))
SX([x_0, x_1, x_2, x_3])
julia> try
ca.reshape(ca.MX.sym("x", ca.Sparsity.diag(2)), ca.Sparsity.dense(4, 1))
catch err
println(occursin("Reshape mismatch", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_42
Definition at line 1751 of file sparsity_interface.hpp.
|
friend |
Same as reshape(x, rc[0], rc[1]).
>>> reshape(DM([1, 2, 3, 4]), (2, 2)) DM( [[1, 3], [2, 4]])
>> reshape(DM([1; 2; 3; 4]), [2, 2]) [[1, 3], [2, 4]]
julia> reshape(ca.DM([1, 2, 3, 4]), (2, 2)) DM( [[1, 3], [2, 4]])
Extra doc: https://github.com/casadi/casadi/wiki/L_41
Definition at line 1704 of file sparsity_interface.hpp.
|
friend |
For each adjoint seed v[d] (a list with one seed per entry of ex, with matching shapes), computes the adjoint sensitivities with respect to every entry of arg: the result is a list over directions of lists over arg. Not defined for DM.
| ex | List of expressions |
| arg | List of symbolic expressions |
| v | List of directions, each a list of seeds matching ex |
| opts | Options, see jacobian |
>>> x = SX.sym("x"); y = SX.sym("y")
>>> reverse([x*y, x**2], [x, y], [[1, 0]])
[[SX(y), SX(x)]]
>>> reverse([x*y, x**2], [x, y], [[1, 1]])
[[SX(((2.*x)+y)), SX(x)]]
>> x = SX.sym('x'); y = SX.sym('y');
>> r = reverse({x*y, x^2}, {x, y}, {{1, 0}});
>> r{1}{1}, r{1}{2}
y
x
>> r = reverse({x*y, x^2}, {x, y}, {{1, 1}});
>> r{1}{1}, r{1}{2}
((2.*x)+y)
x
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.reverse([x*y, x^2], [x, y], [[ca.SX(1), ca.SX(0)]])
1-element Vector{Vector{SX}}:
SX[y, x]
julia> ca.reverse([x*y, x^2], [x, y], [[ca.SX(1), ca.SX(1)]])
1-element Vector{Vector{SX}}:
SX[((2.*x)+y), x]
Extra doc: https://github.com/casadi/casadi/wiki/L_1cy
Definition at line 3792 of file generic_matrix.hpp.
|
friend |
| expr[in] | The expression to be separated |
| sym_lin[in] | The symbolic variables w.r.t. which linearity should be checked |
| sym_const[in] | The symbolic variables that are deemed constant |
| expr_const[out] | The constant part of the expression |
| expr_lin[out] | The linear part of the expression |
| expr_nonlin[out] | The nonlinear part of the expression |
Every symbol in expr must be listed in sym_lin or sym_const; otherwise an error about free variables is raised.
A post condition is that the following holds: expr = expr_const + expr_lin + expr_nonlin
Here, expr_const is only dependant on sym_const, expr_lin is linear in sym_lin (with coefficients that may depend on sym_const)
Example:
[expr_const,expr_lin,expr_nonlin] = separate_linear(cos(p)+7*x+x*y, vertcat(x,y), p)
expr_const: cos(p) expr_lin: 7*x expr_nonlin: x*y
sym_lin and sym_const may also be lists of symbols. Not defined for DM.
* >>> x = SX.sym("x"); y = SX.sym("y"); p = SX.sym("p")
* >>> separate_linear(cos(p) + 7*x + x*y, vertcat(x, y), p)
* (SX(cos(p)), SX((7*x)), SX((x*y)))
* >>> separate_linear(p*x, x, p)
* (SX(0), SX((p*x)), SX(0))
*
* >> x = SX.sym('x'); y = SX.sym('y'); p = SX.sym('p');
* >> [c, l, n] = separate_linear(cos(p) + 7*x + x*y, vertcat(x, y), p);
* >> c, l, n
* cos(p)
* (7*x)
* (x*y)
* >> [c, l, n] = separate_linear(p*x, x, p);
* >> c, l, n
* 0
* (p*x)
* 0
*
* julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); p = ca.SX.sym("p");
* julia> ca.separate_linear(cos(p) + 7 * x + x * y, [x; y], p)
* (cos(p), (7*x), (x*y))
* julia> ca.separate_linear(p * x, x, p)
* (0, (p*x), 0)
*
Extra doc: https://github.com/casadi/casadi/wiki/L_2mo
Definition at line 4392 of file generic_matrix.hpp.
|
friend |
Definition at line 4398 of file generic_matrix.hpp.
|
friend |
Same as extract with the options lift_shared true and lift_calls false: every node that is used more than once is replaced by a new symbol named v_prefix + counter
v_suffix. In Python the call is shared(ex, v_prefix, v_suffix) -> (ex, v, vdef).
>>> x = SX.sym("x"); y = SX.sym("y")
>>> e = x + y
>>> shared([sin(e)*cos(e) + e])
([SX(((sin(v_0)*cos(v_0))+v_0))], [SX(v_0)], [SX((x+y))])
>>> shared([sin(e), cos(e)], "w_", "_s")
([SX(sin(w_0_s)), SX(cos(w_0_s))], [SX(w_0_s)], [SX((x+y))])
>> x = SX.sym('x'); y = SX.sym('y');
>> e = x + y;
>> [ex, v, vdef] = shared({sin(e)*cos(e) + e});
>> ex{1}, v{1}, vdef{1}
((sin(v_0)*cos(v_0))+v_0)
v_0
(x+y)
>> [ex, v, vdef] = shared({sin(e), cos(e)}, 'w_', '_s');
>> ex{1}, ex{2}, v{1}
sin(w_0_s)
cos(w_0_s)
w_0_s
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> e = x + y;
julia> ca.shared([sin(e) * cos(e) + e])
(SX[((sin(v_0)*cos(v_0))+v_0)], SX[v_0], SX[(x+y)])
julia> ca.shared([sin(e), cos(e)], "w_", "_s")
(SX[sin(w_0_s), cos(w_0_s)], SX[w_0_s], SX[(x+y)])
Extra doc: https://github.com/casadi/casadi/wiki/L_1d6
Definition at line 4721 of file generic_matrix.hpp.
|
friend |
sign(x) := -1 for x<0 sign(x) := 1 for x>0, sign(0) := 0 sign(NaN) := NaN
Elementwise; sparsity preserved. The derivative is zero everywhere.
>>> sign(DM([-2, 0, 3]))
DM([-1, 0, 1])
>>> sign(SX.sym("x"))
SX(sign(x))
>> sign(DM([-2; 0; 3]))
[-1, 0, 1]
>> sign(SX.sym('x'))
sign(x)
julia> sign.(ca.DM([-2, 0, 3]))
DM([-1, 0, 1])
julia> sign(ca.SX.sym("x"))
SX(sign(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_po
Definition at line 1915 of file generic_expression.hpp.
|
friend |
For SX, applies simplification passes such as constant folding and removal of trivial operations. For MX and DM the expression is returned unchanged.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> simplify(x*2*3), simplify(x*0 + y*1)
(SX((6*x)), SX(y))
>> x = SX.sym('x'); y = SX.sym('y');
>> simplify(x*2*3), simplify(x*0 + y*1)
(6*x)
y
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.simplify(x * 2 * 3), ca.simplify(x * 0 + y * 1)
((6*x), y)
Extra doc: https://github.com/casadi/casadi/wiki/L_2mq
Definition at line 4482 of file generic_matrix.hpp.
|
friend |
Elementwise; sparsity preserved (sin(0) == 0).
>>> sin(DM.eye(2))
DM(
[[0.841471, 00],
[00, 0.841471]])
>>> sin(MX.sym("x", 2))
MX(sin(x))
>> sin(DM.eye(2))
[[0.841471, 00],
[00, 0.841471]]
>> sin(MX.sym('x', 2))
sin(x)
julia> sin.(ca.DM.eye(2))
DM(
[[0.841471, 00],
[00, 0.841471]])
julia> sin.(ca.MX.sym("x", 2))
MX(sin(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p3
Definition at line 1061 of file generic_expression.hpp.
|
friend |
Elementwise; sparsity preserved.
>>> sinh(DM([0, 1])) DM([0, 1.1752])
>> sinh(DM([0; 1])) [0, 1.1752]
julia> sinh.(ca.DM([0, 1])) DM([0, 1.1752])
Extra doc: https://github.com/casadi/casadi/wiki/L_pa
Definition at line 1338 of file generic_expression.hpp.
|
friend |
skew(a) is the 3-by-3 matrix S with S*b == cross(a, b).
>>> skew(DM([1, 2, 3])) DM( [[0, -3, 2], [3, 0, -1], [-2, 1, 0]]) >>> inv_skew(skew(DM([1, 2, 3]))) DM([1, 2, 3])
>> skew(DM([1; 2; 3])) [[0, -3, 2], [3, 0, -1], [-2, 1, 0]] >> inv_skew(skew(DM([1; 2; 3]))) [1, 2, 3]
julia> ca.skew(ca.DM([1, 2, 3])) DM( [[0, -3, 2], [3, 0, -1], [-2, 1, 0]]) julia> ca.inv_skew(ca.skew(ca.DM([1, 2, 3]))) DM([1, 2, 3])
Extra doc: https://github.com/casadi/casadi/wiki/L_1bv
Definition at line 1547 of file generic_matrix.hpp.
|
friend |
soc(x, y) computes the (n+1)-by-(n+1) matrix [y*eye(n) x; x' y]. This matrix is positive semidefinite if and only if norm_2(x) <= y, which makes it a way to express a second-order cone constraint as a semidefinite constraint.
| x | Vector expression of size n (row or column; sparse entries are densified) |
| y | Scalar expression |
>>> soc(DM([1, 2]), 3) DM( [[3, 00, 1], [00, 3, 2], [1, 2, 3]])
>> soc(DM([1; 2]), 3) [[3, 00, 1], [00, 3, 2], [1, 2, 3]]
julia> ca.soc(ca.DM([1, 2]), 3) DM( [[3, 00, 1], [00, 3, 2], [1, 2, 3]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1bj
Definition at line 936 of file generic_matrix.hpp.
|
friend |
The solve routine works similar to Matlab's backslash when A is square and nonsingular. The algorithm used is the following:
Note 1: If there are entries of the linear system known to be zero, these will be removed. Elements that are very small, or will evaluate to be zero, can still cause numerical errors, due to the lack of pivoting (which is not possible since cannot compare the size of entries)
Note 2: When permuting the linear system, a BLT (block lower triangular) transformation is formed. Only the permutation part of this is however used. An improvement would be to solve block-by-block if there are multiple BLT blocks.
The description above applies to DM and SX. For MX, triangular systems give dedicated solve nodes, an orthonormal pattern is inverted by transposition, and everything else falls back to solve(A, b, "qr"). A scalar A gives the elementwise division b/A. b may have several columns (one right-hand side each). A non-square A or a row count mismatch raises an error; a numerically singular DM returns nan or inf.
>>> A = DM([[1, 2], [3, 4]])
>>> solve(A, DM([1, 2]))
DM([0, 0.5])
>>> solve(A, DM.eye(2))
DM(
[[-2, 1],
[1.5, -0.5]])
>>> solve(SX.sym("A", 2, 2), SX.sym("b", 2))
SX(@1=((A_0*A_3)-(A_2*A_1)), [(((A_3/@1)*b_0)-((A_2/@1)*b_1)),
(((A_0/@1)*b_1)-((A_1/@1)*b_0))])
>>> solve(MX.sym("A", 2, 2), MX.sym("b", 2))
MX((A\b))
>>> solve(DM(2), DM([1, 2]))
DM([0.5, 1])
>> A = DM([1 2; 3 4]);
>> solve(A, DM([1; 2]))
[0, 0.5]
>> solve(A, DM.eye(2))
[[-2, 1],
[1.5, -0.5]]
>> solve(SX.sym('A', 2, 2), SX.sym('b', 2))
@1=((A_0*A_3)-(A_2*A_1)), [(((A_3/@1)*b_0)-((A_2/@1)*b_1)), (((A_0/@1)*b_1)-((A_1/@1)*b_0))]
>> solve(MX.sym('A', 2, 2), MX.sym('b', 2))
(A\b)
>> solve(DM(2), DM([1; 2]))
[0.5, 1]
julia> A = ca.DM([1 2; 3 4]);
julia> ca.solve(A, ca.DM([1, 2]))
DM([0, 0.5])
julia> ca.solve(A, ca.DM.eye(2))
DM(
[[-2, 1],
[1.5, -0.5]])
julia> ca.solve(ca.SX.sym("A", 2, 2), ca.SX.sym("b", 2))
SX(@1=((A_0*A_3)-(A_2*A_1)), [(((A_3/@1)*b_0)-((A_2/@1)*b_1)), (((A_0/@1)*b_1)-((A_1/@1)*b_0))])
julia> ca.solve(ca.MX.sym("A", 2, 2), ca.MX.sym("b", 2))
MX((A\b))
julia> ca.solve(ca.DM(2), ca.DM([1, 2]))
DM([0.5, 1])
Extra doc: https://github.com/casadi/casadi/wiki/L_1cq
Definition at line 3197 of file generic_matrix.hpp.
|
friend |
Available for DM and MX (for MX the solve becomes a call to the solver, evaluated numerically); SX raises an error. A scalar A gives the elementwise division b/A.
| lsolver | Name of a Linsol plugin, e.g. "qr", "csparse", "lapacklu", "lapackqr", "symbolicqr", "ldl", "ma27"; which ones are available depends on the build |
| dict | Options passed to the linear solver |
>>> A = DM([[1, 2], [3, 4]])
>>> solve(A, DM([1, 2]), "qr")
DM([0, 0.5])
>>> solve(MX.sym("A", 2, 2), MX.sym("b", 2), "qr")
MX((A\b))
>> A = DM([1 2; 3 4]);
>> solve(A, DM([1; 2]), 'qr')
[0, 0.5]
>> solve(MX.sym('A', 2, 2), MX.sym('b', 2), 'qr')
(A\b)
julia> A = ca.DM([1 2; 3 4]);
julia> ca.solve(A, ca.DM([1, 2]), "qr")
DM([0, 0.5])
julia> ca.solve(ca.MX.sym("A", 2, 2), ca.MX.sym("b", 2), "qr")
MX((A\b))
Extra doc: https://github.com/casadi/casadi/wiki/L_1cr
Definition at line 3245 of file generic_matrix.hpp.
|
friend |
Every stored entry with absolute value at most tol is dropped from the sparsity pattern. With the default tol=0 only exact zeros are removed; SX entries that the symbolic simplifications already reduced to the constant 0 count as zeros. Returns a new matrix; the input is unchanged.
| A | Matrix to compact |
| tol | Absolute threshold below which an entry counts as zero |
>>> sparsify(DM([[1, 0], [0, 2]]))
DM(
[[1, 00],
[00, 2]])
>>> A = DM([[1, 0], [1e-9, 2]])
>>> sparsify(A).nnz(), sparsify(A, 1e-6).nnz()
(3, 2)
>>> x = SX.sym("x")
>>> sparsify(vertcat(x, 0, x * 0))
SX([x, 00, 00])
>> sparsify(DM([1 0; 0 2]))
[[1, 00],
[00, 2]]
>> A = DM([1 0; 1e-9 2]);
>> fprintf('%d %d\n', sparsify(A).nnz(), sparsify(A, 1e-6).nnz())
3 2
>> x = SX.sym('x');
>> sparsify([x; 0; x * 0])
[x, 00, 00]
julia> ca.sparsify(ca.DM([1 0; 0 2]))
DM(
[[1, 00],
[00, 2]])
julia> A = ca.DM([1 0; 1e-9 2]);
julia> ca.nnz(ca.sparsify(A)), ca.nnz(ca.sparsify(A, 1e-6))
(3, 2)
julia> x = ca.SX.sym("x");
julia> ca.sparsify([x; 0; x * 0])
SX([x, 00, 00])
Extra doc: https://github.com/casadi/casadi/wiki/L_191
Definition at line 2016 of file matrix_decl.hpp.
|
friend |
Keeps the nonzero values of x in storage order and gives them the pattern sp, which must have the same number of nonzeros (an error is raised otherwise). Unlike reshape, the dimensions and the positions of the nonzeros can change freely; only the nonzero count is preserved. This is how the nonzeros of a sparse matrix are extracted as a dense vector.
x with pattern sp
>>> sparsity_cast(DM([[1, 2], [3, 4]]), Sparsity.dense(1, 4))
DM([[1, 3, 2, 4]])
>>> sparsity_cast(DM.eye(3), Sparsity.dense(3, 1))
DM([1, 1, 1])
>>> sparsity_cast(MX.sym("x", Sparsity.diag(3)), Sparsity.dense(3, 1))
MX(nonzeros(x))
>>> sparsity_cast(MX.sym("x", 2, 2), Sparsity.dense(3, 1))
Traceback (most recent call last):
...
RuntimeError: ...Mismatching nonzero count...
>> sparsity_cast(DM([1 2; 3 4]), Sparsity.dense(1, 4))
[[1, 3, 2, 4]]
>> sparsity_cast(DM.eye(3), Sparsity.dense(3, 1))
[1, 1, 1]
>> sparsity_cast(MX.sym('x', Sparsity.diag(3)), Sparsity.dense(3, 1))
nonzeros(x)
>> x = MX.sym('x', 2, 2);
>> try, sparsity_cast(x, Sparsity.dense(3, 1)); catch e, disp(e.message); end
...Mismatching nonzero count...
julia> ca.sparsity_cast(ca.DM([1 2; 3 4]), ca.Sparsity.dense(1, 4))
DM([[1, 3, 2, 4]])
julia> ca.sparsity_cast(ca.DM.eye(3), ca.Sparsity.dense(3, 1))
DM([1, 1, 1])
julia> ca.sparsity_cast(ca.MX.sym("x", ca.Sparsity.diag(3)), ca.Sparsity.dense(3, 1))
MX(nonzeros(x))
julia> try
ca.sparsity_cast(ca.MX.sym("x", 2, 2), ca.Sparsity.dense(3, 1))
catch err
println(occursin("Mismatching nonzero count", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_24z
Definition at line 1815 of file sparsity_interface.hpp.
|
friend |
The structural rank is the size of a maximum matching between rows and columns of the pattern (via the Dulmage-Mendelsohn decomposition): an upper bound on the numerical rank that depends only on which entries are structurally nonzero, not on their values. A dense matrix always has full structural rank, even when it is numerically singular.
>>> sprank(Sparsity.diag(3)) 3 >>> sprank(Sparsity.triplet(3, 3, [0, 1, 2], [0, 0, 0])) 1 >>> sprank(DM([[1, 2], [2, 4]])) 2 >>> sprank(DM(2, 3)) 0
>> sprank(Sparsity.diag(3)) 3 >> sprank(Sparsity.triplet(3, 3, [0, 1, 2], [0, 0, 0])) 1 >> sprank(DM([1 2; 2 4])) 2 >> sprank(DM(2, 3)) 0
julia> ca.sprank(ca.Sparsity.diag(3)) 3 julia> ca.sprank(ca.Sparsity.triplet(3, 3, [0, 1, 2], [0, 0, 0])) 1 julia> ca.sprank(ca.DM([1 2; 2 4])) 2 julia> ca.sprank(ca.DM(2, 3)) 0
Extra doc: https://github.com/casadi/casadi/wiki/L_43
Definition at line 1869 of file sparsity_interface.hpp.
|
friend |
Elementwise; sparsity preserved. Not exposed as a function in Python; a symbolic power with exponent 2 is turned into this operation.
>>> SX.sym("x")**2
SX(sq(x))
>> SX.sym('x').^2
sq(x)
julia> ca.SX.sym("x")^2
SX(sq(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p2
Definition at line 1013 of file generic_expression.hpp.
|
friend |
Elementwise; sparsity preserved. A negative argument gives NaN, no error is raised. A symbolic power x**0.5 simplifies to sqrt(x).
>>> sqrt(DM([4, 9]))
DM([2, 3])
>>> SX.sym("x")**0.5
SX(sqrt(x))
>> sqrt(DM([4; 9]))
[2, 3]
>> SX.sym('x').^0.5
sqrt(x)
julia> sqrt.(ca.DM([4, 9]))
DM([2, 3])
julia> ca.SX.sym("x")^0.5
SX(sqrt(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_p1
Definition at line 975 of file generic_expression.hpp.
Wraps expr in a non-inlined Function call whose derivatives of the given order are declared zero. The value is unchanged. With order 1 the expression is treated as a constant by all differentiation; with order 2 first derivatives are propagated normally but second derivatives are zero. Other orders raise an error.
>>> x = MX.sym("x")
>>> e = x * stop_diff(x**2, 1)
>>> Function("f", [x], [e, jacobian(e, x)])(3)
(DM(27), DM(9))
>> x = MX.sym('x');
>> e = x * stop_diff(x^2, 1);
>> f = Function('f', {x}, {e, jacobian(e, x)});
>> [v, J] = f(3);
>> v, J
27
9
julia> x = ca.MX.sym("x");
julia> e = x * ca.stop_diff(x^2, 1);
julia> ca.Function("f", [x], [e, ca.jacobian(e, x)])(3)
(27, 9)
Extra doc: https://github.com/casadi/casadi/wiki/L_25l
Like stop_diff(expr, order), but only the derivatives with respect to the symbols occurring in var are stopped; derivatives with respect to the other symbols are propagated. Emits a warning that this variant is not well tested.
>>> x = MX.sym("x")
>>> y = MX.sym("y")
>>> e = stop_diff(x * y, x, 1)
>>> jacobian(e, x).nnz(), Function("f", [x, y], [jacobian(e, y)])(2, 3)
(0, DM(2))
>> x = MX.sym('x'); y = MX.sym('y');
>> e = stop_diff(x * y, x, 1);
...
>> J = jacobian(e, x);
>> f = Function('f', {x, y}, {jacobian(e, y)});
>> J.nnz(), f(2, 3)
0
2
julia> x = ca.MX.sym("x"); y = ca.MX.sym("y");
julia> e = ca.stop_diff(x * y, x, 1);
julia> ca.nnz(ca.jacobian(e, x)), ca.Function("f", [x, y], [ca.jacobian(e, y)])(2, 3)
(0, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_25o
|
friend |
v must be symbolic and have the same shape as vdef (for SX also the same sparsity). For MX, v must be a symbolic primitive as created by MX.sym; an element of such a primitive is rejected. Substituting a symbol that does not occur in ex is a no-op. Not defined for DM.
>>> x = SX.sym("x"); y = SX.sym("y"); z = SX.sym("z")
>>> substitute(x*y + x, x, 2)
SX(((2.*y)+2))
>>> substitute(x*y + x, x, z**2)
SX(@1=sq(z), ((@1*y)+@1))
>>> p = SX.sym("p", 2)
>>> substitute(sumsqr(p), p, DM([1, 2]))
SX(5)
>>> X = MX.sym("X"); Y = MX.sym("Y")
>>> substitute(X*Y + X, X, Y)
MX((sq(Y)+Y))
>> x = SX.sym('x'); y = SX.sym('y'); z = SX.sym('z');
>> substitute(x*y + x, x, 2)
((2.*y)+2)
>> substitute(x*y + x, x, z^2)
@1=sq(z), ((@1*y)+@1)
>> p = SX.sym('p', 2);
>> substitute(sumsqr(p), p, DM([1; 2]))
5
>> X = MX.sym('X'); Y = MX.sym('Y');
>> substitute(X*Y + X, X, Y)
(sq(Y)+Y)
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); z = ca.SX.sym("z");
julia> ca.substitute(x * y + x, x, 2)
SX(((2.*y)+2))
julia> ca.substitute(x * y + x, x, z^2)
SX(@1=sq(z), ((@1*y)+@1))
julia> p = ca.SX.sym("p", 2);
julia> ca.substitute(ca.sumsqr(p), p, ca.DM([1, 2]))
SX(5)
julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
julia> ca.substitute(X * Y + X, X, Y)
MX((sq(Y)+Y))
Extra doc: https://github.com/casadi/casadi/wiki/L_1cl
Definition at line 2917 of file generic_matrix.hpp.
|
friend |
All substitutions happen simultaneously: vdef[k] is not itself subject to the other substitutions, so swapping two variables works as expected.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> substitute([x*y, x + y], [x, y], [1, 2])
[SX(2), SX(3)]
>>> substitute([x + y], [x, y], [y, x])
[SX((x+y))]
>> x = SX.sym('x'); y = SX.sym('y');
>> r = substitute({x*y, x + y}, {x, y}, {1, 2});
>> r{1}, r{2}
2
3
>> r = substitute({x + y}, {x, y}, {y, x});
>> r{1}
(x+y)
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.substitute([x * y, x + y], [x, y], [1, 2])
2-element Vector{SX}:
SX(2)
SX(3)
julia> ca.substitute([x + y], [x, y], [y, x])
1-element Vector{SX}:
SX((x+y))
Extra doc: https://github.com/casadi/casadi/wiki/L_1cm
Definition at line 2965 of file generic_matrix.hpp.
|
friend |
Substitute variables v out of the expressions vdef sequentially, as well as out of a number of other expressions piggyback
Interprets vdef[k] as the definition of the symbol v[k] and resolves the definitions into each other, so that afterwards neither vdef nor ex contain any of the symbols v. Both vdef and ex are modified in place (and returned, in Python). v must consist of symbolic primitives with the shapes of vdef. reverse is only accepted for SX; MX raises "Not implemented".
>>> x = SX.sym("x"); y = SX.sym("y")
>>> substitute_inplace([x, y], [y + 1, 3], [x*y])
([SX(4), SX(3)], [SX(12)])
>>> X = MX.sym("X"); Y = MX.sym("Y")
>>> substitute_inplace([X, Y], [Y + 1, 3], [X*Y])
([MX(1), MX(3)], [MX(00)])
>> x = SX.sym('x'); y = SX.sym('y');
>> [vdef, ex] = substitute_inplace({x, y}, {y + 1, 3}, {x*y});
>> vdef{1}, vdef{2}, ex{1}
4
3
12
>> X = MX.sym('X'); Y = MX.sym('Y');
>> [vdef, ex] = substitute_inplace({X, Y}, {Y + 1, 3}, {X*Y});
>> vdef{1}, vdef{2}, ex{1}
1
3
00
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.substitute_inplace([x, y], [y + 1, ca.SX(3)], [x*y])
(SX[4, 3], SX[12])
julia> X = ca.MX.sym("X"); Y = ca.MX.sym("Y");
julia> ca.substitute_inplace([X, Y], [Y + 1, ca.MX(3)], [X*Y])
(MX[1, 3], MX[00])
Extra doc: https://github.com/casadi/casadi/wiki/L_1cn
Definition at line 3024 of file generic_matrix.hpp.
|
friend |
Returns a 1-by-1 matrix with the sum of all elements, combining sum1 and sum2. An empty matrix sums to a structural zero.
>>> sum(DM([[1, 2, 3], [4, 5, 6]]))
DM(21)
>>> sum(DM([[1, 2, 3], [4, 5, 6]]), 0)
DM([[5, 7, 9]])
>>> sum(SX.sym("x", 3))
SX(((x_0+x_1)+x_2))
>>> sum(DM(3, 0))
DM(00)
>> sum(DM([1 2 3; 4 5 6]), 'all')
21
>> sum(DM([1 2 3; 4 5 6]))
[[5, 7, 9]]
>> sum(SX.sym('x', 3))
((x_0+x_1)+x_2)
>> sum(DM(3, 0), 'all')
00
julia> sum(ca.DM([1 2 3; 4 5 6]))
DM(21)
julia> sum(ca.DM([1 2 3; 4 5 6]), dims=1)
DM([[5, 7, 9]])
julia> sum(ca.SX.sym("x", 3))
SX(((x_0+x_1)+x_2))
julia> sum(ca.DM(3, 0))
DM(00)
Extra doc: https://github.com/casadi/casadi/wiki/L_2d6
Definition at line 2490 of file sparsity_interface.hpp.
|
friend |
Returns a row vector with the sum over the rows, as MATLAB sum(x, 1); implemented as the product ones(1, size1) * x, so it is a mtimes node for MX. A column of structural zeros sums to a structural zero. For Sparsity only the pattern is computed.
>>> sum1(DM([[1, 2, 3], [4, 5, 6]]))
DM([[5, 7, 9]])
>>> sum1(SX.sym("x", 2, 2))
SX([[(x_0+x_1), (x_2+x_3)]])
>>> sum1(MX.sym("x", 2, 3))
MX(mac(ones(1x2),x,zeros(1x3)))
>>> sum1(DM(0, 3))
DM([[00, 00, 00]])
>> sum1(DM([1 2 3; 4 5 6]))
[[5, 7, 9]]
>> sum(DM([1 2 3; 4 5 6]), 1)
[[5, 7, 9]]
>> sum1(SX.sym('x', 2, 2))
[[(x_0+x_1), (x_2+x_3)]]
>> sum1(MX.sym('x', 2, 3))
mac(ones(1x2),x,zeros(1x3))
>> sum1(DM(0, 3))
[[00, 00, 00]]
julia> ca.sum1(ca.DM([1 2 3; 4 5 6]))
DM([[5, 7, 9]])
julia> ca.sum1(ca.SX.sym("x", 2, 2))
SX([[(x_0+x_1), (x_2+x_3)]])
julia> ca.sum1(ca.MX.sym("x", 2, 3))
MX(mac(ones(1x2),x,zeros(1x3)))
julia> ca.sum1(ca.DM(0, 3))
DM([[00, 00, 00]])
Extra doc: https://github.com/casadi/casadi/wiki/L_4p
Definition at line 2394 of file sparsity_interface.hpp.
|
friend |
Returns a column vector with the sum over the columns, as MATLAB sum(x, 2); implemented as the product x * ones(size2, 1). A row of structural zeros sums to a structural zero.
>>> sum2(DM([[1, 2, 3], [4, 5, 6]]))
DM([6, 15])
>>> sum2(SX.sym("x", 2, 2))
SX([(x_0+x_2), (x_1+x_3)])
>>> sum2(DM(3, 3))
DM([00, 00, 00])
>> sum2(DM([1 2 3; 4 5 6]))
[6, 15]
>> sum(DM([1 2 3; 4 5 6]), 2)
[6, 15]
>> sum2(SX.sym('x', 2, 2))
[(x_0+x_2), (x_1+x_3)]
>> sum2(DM(3, 3))
[00, 00, 00]
julia> ca.sum2(ca.DM([1 2 3; 4 5 6]))
DM([6, 15])
julia> ca.sum2(ca.SX.sym("x", 2, 2))
SX([(x_0+x_2), (x_1+x_3)])
julia> ca.sum2(ca.DM(3, 3))
DM([00, 00, 00])
Extra doc: https://github.com/casadi/casadi/wiki/L_4q
Definition at line 2439 of file sparsity_interface.hpp.
|
friend |
Defined as dot(x, x) for a matrix of any shape; structural zeros contribute nothing. Prefer this over norm_2(x)**2 in objectives: it is smooth everywhere.
>>> sumsqr(DM([[1, 2], [3, 4]]))
DM(30)
>>> sumsqr(SX.sym("x", 2))
SX((sq(x_0)+sq(x_1)))
>>> sumsqr(MX.sym("x", 2))
MX(dot(x, x))
>> sumsqr(DM([1 2; 3 4]))
30
>> sumsqr(SX.sym('x', 2))
(sq(x_0)+sq(x_1))
>> sumsqr(MX.sym('x', 2))
dot(x, x)
julia> ca.sumsqr(ca.DM([1 2; 3 4]))
DM(30)
julia> ca.sumsqr(ca.SX.sym("x", 2))
SX((sq(x_0)+sq(x_1)))
julia> ca.sumsqr(ca.MX.sym("x", 2))
MX(dot(x, x))
Extra doc: https://github.com/casadi/casadi/wiki/L_1bq
Definition at line 1312 of file generic_matrix.hpp.
|
friend |
Returns the symbols the expression was built from, in order of first appearance, each once. For SX every scalar symbol is a separate entry; for MX the entries are the symbolic matrices as created by MX.sym, even if only part of such a matrix is used. Presence in the graph is a structural notion; an expression like 0*x still lists x. Use depends_on for mathematical dependency. Not defined for DM.
>>> x = SX.sym("x"); y = SX.sym("y"); z = SX.sym("z")
>>> symvar(vertcat(z*x, y))
[SX(z), SX(x), SX(y)]
>>> symvar(SX.sym("v", 2)*3)
[SX(v_0), SX(v_1)]
>>> v = MX.sym("v", 2)
>>> symvar(v[0]*3)
[MX(v)]
>>> symvar(SX(3))
[]
>> x = SX.sym('x'); y = SX.sym('y'); z = SX.sym('z');
>> v = symvar(vertcat(z*x, y));
>> numel(v), vertcat(v{:})
3
[z, x, y]
>> v = symvar(SX.sym('v', 2)*3); disp(vertcat(v{:}))
[v_0, v_1]
>> v = MX.sym('v', 2);
>> s = symvar(v(1)*3); disp(numel(s)), disp(s{1})
1
v
>> numel(symvar(SX(3)))
0
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y"); z = ca.SX.sym("z");
julia> ca.symvar([z*x; y])
3-element Vector{SX}:
SX(z)
SX(x)
SX(y)
julia> ca.symvar(ca.SX.sym("v", 2) * 3)
2-element Vector{SX}:
SX(v_0)
SX(v_1)
julia> v = ca.MX.sym("v", 2);
julia> ca.symvar(v[1] * 3)
1-element Vector{MX}:
MX(v)
julia> ca.symvar(ca.SX(3))
SX[]
Extra doc: https://github.com/casadi/casadi/wiki/L_1bn
Definition at line 1157 of file generic_matrix.hpp.
|
friend |
Elementwise; sparsity preserved.
>>> tan(DM([0, 1])) DM([0, 1.55741])
>> tan(DM([0; 1])) [0, 1.55741]
julia> tan.(ca.DM([0, 1])) DM([0, 1.55741])
Extra doc: https://github.com/casadi/casadi/wiki/L_p5
Definition at line 1152 of file generic_expression.hpp.
|
friend |
Derivative of ex with respect to a scalar arg, computed with one forward-mode sweep and projected onto the sparsity of ex: the result has the shape and pattern of ex. A non-scalar arg raises an error (use jacobian).
>>> x = SX.sym("x")
>>> tangent(vertcat(x**2, 3*x), x)
SX([(2.*x), 3])
>> x = SX.sym('x');
>> tangent(vertcat(x^2, 3*x), x)
[(2.*x), 3]
julia> x = ca.SX.sym("x");
julia> ca.tangent([x^2; 3 * x], x)
SX([(2.*x), 3])
Extra doc: https://github.com/casadi/casadi/wiki/L_23y
Definition at line 3606 of file generic_matrix.hpp.
|
friend |
Elementwise; sparsity preserved.
>>> tanh(DM([0, 1])) DM([0, 0.761594])
>> tanh(DM([0; 1])) [0, 0.761594]
julia> tanh.(ca.DM([0, 1])) DM([0, 0.761594])
Extra doc: https://github.com/casadi/casadi/wiki/L_p9
Definition at line 1301 of file generic_expression.hpp.
|
friend |
Expands ex around a with respect to the scalar symbol x up to the given order: ex(a) + ex'(a)*(x-a) + ex''(a)*(x-a)^2/2! + ... + ex^(order)(a)*(x-a)^order/order! The expansion is done entrywise for a dense matrix ex; sparse ex raises an error. a may itself be symbolic. The two-argument form expands around 0 to first order. Only defined for SX.
| ex | Dense SX expression to expand |
| x | Scalar SX symbol |
| a | Scalar expansion point, default 0 |
| order | Highest power of (x-a) kept, default 1; 0 gives ex(a) |
>>> x = SX.sym("x"); a = SX.sym("a")
>>> taylor(sin(x), x)
SX(x)
>>> taylor(sin(x), x, a, 1)
SX((sin(a)+(cos(a)*(x-a))))
>>> taylor(exp(x), x, 0, 3)
SX(@1=sq(x), (((1+x)+(0.5*@1))+(0.166667*(@1*x))))
>>> taylor(vertcat(sin(x), cos(x)), x, 0, 2)
SX([x, (1+(-0.5*sq(x)))])
>> x = SX.sym('x'); a = SX.sym('a');
>> taylor(sin(x), x)
x
>> taylor(sin(x), x, a, 1)
(sin(a)+(cos(a)*(x-a)))
>> taylor(exp(x), x, 0, 3)
@1=sq(x), (((1+x)+(0.5*@1))+(0.166667*(@1*x)))
>> taylor([sin(x); cos(x)], x, 0, 2)
[x, (1+(-0.5*sq(x)))]
julia> x = ca.SX.sym("x"); a = ca.SX.sym("a");
julia> ca.taylor(sin(x), x)
SX(x)
julia> ca.taylor(sin(x), x, a, 1)
SX((sin(a)+(cos(a)*(x-a))))
julia> ca.taylor(exp(x), x, 0, 3)
SX(@1=sq(x), (((1+x)+(0.5*@1))+(0.166667*(@1*x))))
julia> ca.taylor([sin(x); cos(x)], x, 0, 2)
SX([x, (1+(-0.5*sq(x)))])
Extra doc: https://github.com/casadi/casadi/wiki/L_23q
Definition at line 2461 of file matrix_decl.hpp.
|
friend |
Expands ex around a with respect to the scalar symbol x up to the given order: ex(a) + ex'(a)*(x-a) + ex''(a)*(x-a)^2/2! + ... + ex^(order)(a)*(x-a)^order/order! The expansion is done entrywise for a dense matrix ex; sparse ex raises an error. a may itself be symbolic. The two-argument form expands around 0 to first order. Only defined for SX.
| ex | Dense SX expression to expand |
| x | Scalar SX symbol |
| a | Scalar expansion point, default 0 |
| order | Highest power of (x-a) kept, default 1; 0 gives ex(a) |
>>> x = SX.sym("x"); a = SX.sym("a")
>>> taylor(sin(x), x)
SX(x)
>>> taylor(sin(x), x, a, 1)
SX((sin(a)+(cos(a)*(x-a))))
>>> taylor(exp(x), x, 0, 3)
SX(@1=sq(x), (((1+x)+(0.5*@1))+(0.166667*(@1*x))))
>>> taylor(vertcat(sin(x), cos(x)), x, 0, 2)
SX([x, (1+(-0.5*sq(x)))])
>> x = SX.sym('x'); a = SX.sym('a');
>> taylor(sin(x), x)
x
>> taylor(sin(x), x, a, 1)
(sin(a)+(cos(a)*(x-a)))
>> taylor(exp(x), x, 0, 3)
@1=sq(x), (((1+x)+(0.5*@1))+(0.166667*(@1*x)))
>> taylor([sin(x); cos(x)], x, 0, 2)
[x, (1+(-0.5*sq(x)))]
julia> x = ca.SX.sym("x"); a = ca.SX.sym("a");
julia> ca.taylor(sin(x), x)
SX(x)
julia> ca.taylor(sin(x), x, a, 1)
SX((sin(a)+(cos(a)*(x-a))))
julia> ca.taylor(exp(x), x, 0, 3)
SX(@1=sq(x), (((1+x)+(0.5*@1))+(0.166667*(@1*x))))
julia> ca.taylor([sin(x); cos(x)], x, 0, 2)
SX([x, (1+(-0.5*sq(x)))])
Extra doc: https://github.com/casadi/casadi/wiki/L_23q
Definition at line 2457 of file matrix_decl.hpp.
|
friend |
Elementwise (Hadamard) product, not the matrix product; use mtimes for that. Shape rules as for plus. The result is structurally zero wherever either operand is, so the sparsity pattern is the intersection of the patterns.
>>> times(DM([1, 2]), DM([3, 4])) DM([3, 8]) >>> DM([[1, 2], [3, 4]]) * DM([[1, 2], [3, 4]]) DM( [[1, 4], [9, 16]]) >>> DM.eye(2) * DM.ones(2, 2) DM( [[1, 00], [00, 1]])
>> times(DM([1; 2]), DM([3; 4])) [3, 8] >> DM([1 2; 3 4]) .* DM([1 2; 3 4]) [[1, 4], [9, 16]] >> DM([1 2; 3 4]) * DM([1 2; 3 4]) [[7, 10], [15, 22]] >> DM.eye(2) .* DM.ones(2, 2) [[1, 00], [00, 1]]
julia> ca.times(ca.DM([1, 2]), ca.DM([3, 4])) DM([3, 8]) julia> ca.DM([1 2; 3 4]) .* ca.DM([1 2; 3 4]) DM( [[1, 4], [9, 16]]) julia> ca.DM.eye(2) .* ca.DM.ones(2, 2) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_op
Definition at line 292 of file generic_expression.hpp.
|
friend |
Sum of the diagonal entries of a square matrix (structural zeros contribute nothing). A non-square argument raises an error.
>>> trace(DM([[1, 2], [3, 4]]))
DM(5)
>>> trace(SX.sym("A", 2, 2))
SX((A_0+A_3))
>> trace(DM([1 2; 3 4]))
5
>> trace(SX.sym('A', 2, 2))
(A_0+A_3)
julia> ca.tr(ca.DM([1 2; 3 4]))
DM(5)
julia> ca.tr(ca.SX.sym("A", 2, 2))
SX((A_0+A_3))
Extra doc: https://github.com/casadi/casadi/wiki/L_1c1
Definition at line 1817 of file generic_matrix.hpp.
|
friend |
Wraps the expression in a Function of its free symbols, applies Function::transform and re-evaluates it on the original symbols. Each pass is a list starting with a verb: "simplify" (followed by task names), "expand" or "external"; an unknown verb raises an error. Without passes a default set of simplification passes is applied.
>>> x = SX.sym("x")
>>> transform(x*2*3)
SX((6*x))
>> x = SX.sym('x');
>> transform(x*2*3)
(6*x)
julia> x = ca.SX.sym("x");
julia> ca.transform(x * 2 * 3)
SX((6*x))
Extra doc: https://github.com/casadi/casadi/wiki/L_2mr
Definition at line 4521 of file generic_matrix.hpp.
|
friend |
Wraps the expression in a Function of its free symbols, applies Function::transform and re-evaluates it on the original symbols. Each pass is a list starting with a verb: "simplify" (followed by task names), "expand" or "external"; an unknown verb raises an error. Without passes a default set of simplification passes is applied.
>>> x = SX.sym("x")
>>> transform(x*2*3)
SX((6*x))
>> x = SX.sym('x');
>> transform(x*2*3)
(6*x)
julia> x = ca.SX.sym("x");
julia> ca.transform(x * 2 * 3)
SX((6*x))
Extra doc: https://github.com/casadi/casadi/wiki/L_2mr
Definition at line 4524 of file generic_matrix.hpp.
|
friend |
Wraps the expression in a Function of its free symbols, applies Function::transform and re-evaluates it on the original symbols. Each pass is a list starting with a verb: "simplify" (followed by task names), "expand" or "external"; an unknown verb raises an error. Without passes a default set of simplification passes is applied.
>>> x = SX.sym("x")
>>> transform(x*2*3)
SX((6*x))
>> x = SX.sym('x');
>> transform(x*2*3)
(6*x)
julia> x = ca.SX.sym("x");
julia> ca.transform(x * 2 * 3)
SX((6*x))
Extra doc: https://github.com/casadi/casadi/wiki/L_2mr
Definition at line 4528 of file generic_matrix.hpp.
|
friend |
Wraps the expression in a Function of its free symbols, applies Function::transform and re-evaluates it on the original symbols. Each pass is a list starting with a verb: "simplify" (followed by task names), "expand" or "external"; an unknown verb raises an error. Without passes a default set of simplification passes is applied.
>>> x = SX.sym("x")
>>> transform(x*2*3)
SX((6*x))
>> x = SX.sym('x');
>> transform(x*2*3)
(6*x)
julia> x = ca.SX.sym("x");
julia> ca.transform(x * 2 * 3)
SX((6*x))
Extra doc: https://github.com/casadi/casadi/wiki/L_2mr
Definition at line 4532 of file generic_matrix.hpp.
|
friend |
Returns the transpose of X; the sparsity pattern is transposed along. Same as X.T().
>>> transpose(DM([[1, 2, 3]]))
DM([1, 2, 3])
>>> transpose(MX.sym("x", 2, 3))
MX(x')
>>> transpose(Sparsity.lower(2)) == Sparsity.upper(2)
True
>> DM([1 2 3])'
[1, 2, 3]
>> MX.sym('x', 2, 3)'
x'
>> transpose(Sparsity.lower(2)) == Sparsity.upper(2)
1
julia> ca.DM([1 2 3])'
DM([1, 2, 3])
julia> ca.MX.sym("x", 2, 3)'
MX(x')
julia> ca.is_equal(ca.transpose(ca.Sparsity.lower(2)), ca.Sparsity.upper(2))
true
Extra doc: https://github.com/casadi/casadi/wiki/L_3y
Definition at line 1532 of file sparsity_interface.hpp.
1 - |x| for |x| < 1 and 0 otherwise, built from rectangle and fabs. Not defined for MX.
>>> triangle(DM([-1, -0.5, 0, 0.5, 1])) DM([0, 0.5, 1, 0.5, 0])
>> triangle(DM([-1; -0.5; 0; 0.5; 1])) [0, 0.5, 1, 0.5, 0]
julia> ca.triangle(ca.DM([-1, -0.5, 0, 0.5, 1])) DM([0, 0.5, 1, 0.5, 0])
Extra doc: https://github.com/casadi/casadi/wiki/L_23o
Definition at line 2299 of file matrix_decl.hpp.
|
friend |
Entries above the diagonal become structural zeros; the matrix need not be square.
>>> x = DM([[1, 2, 3], [4, 5, 6]]) >>> tril(x) DM( [[1, 00, 00], [4, 5, 00]]) >>> tril(x, False) DM( [[00, 00, 00], [4, 00, 00]])
>> x = DM([1 2 3; 4 5 6]); >> tril(x) [[1, 00, 00], [4, 5, 00]] >> tril(x, false) [[00, 00, 00], [4, 00, 00]]
julia> x = ca.DM([1 2 3; 4 5 6]); julia> ca.tril(x) DM( [[1, 00, 00], [4, 5, 00]]) julia> ca.tril(x, false) DM( [[00, 00, 00], [4, 00, 00]])
Extra doc: https://github.com/casadi/casadi/wiki/L_46
Definition at line 2036 of file sparsity_interface.hpp.
|
friend |
Returns a + a' - diag(diag(a)), i.e. mirrors the strictly lower part to the upper part. The argument must be square and have no structural nonzeros above the diagonal (a dense matrix is rejected even if numerically lower triangular).
>>> L = DM(Sparsity.lower(3), [1, 2, 3, 4, 5, 6])
>>> tril2symm(L)
DM(
[[1, 2, 3],
[2, 4, 5],
[3, 5, 6]])
>>> tril2symm(SX.sym("L", Sparsity.lower(2)))
SX(
[[L_0, L_1],
[L_1, L_2]])
>> L = DM(Sparsity.lower(3), [1; 2; 3; 4; 5; 6]);
>> tril2symm(L)
[[1, 2, 3],
[2, 4, 5],
[3, 5, 6]]
>> tril2symm(SX.sym('L', Sparsity.lower(2)))
[[L_0, L_1],
[L_1, L_2]]
julia> L = ca.DM(ca.Sparsity.lower(3), [1, 2, 3, 4, 5, 6]);
julia> ca.tril2symm(L)
DM(
[[1, 2, 3],
[2, 4, 5],
[3, 5, 6]])
julia> ca.tril2symm(ca.SX.sym("L", ca.Sparsity.lower(2)))
SX(
[[L_0, L_1],
[L_1, L_2]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1c2
Definition at line 1871 of file generic_matrix.hpp.
|
friend |
Entries below the diagonal become structural zeros; the matrix need not be square. For MX this is a projection node.
>>> x = DM([[1, 2, 3], [4, 5, 6]])
>>> triu(x)
DM(
[[1, 2, 3],
[00, 5, 6]])
>>> triu(x, False)
DM(
[[00, 2, 3],
[00, 00, 6]])
>>> triu(MX.sym("x", 2, 2))
MX(project(x))
>> x = DM([1 2 3; 4 5 6]);
>> triu(x)
[[1, 2, 3],
[00, 5, 6]]
>> triu(x, false)
[[00, 2, 3],
[00, 00, 6]]
>> triu(MX.sym('x', 2, 2))
project(x)
julia> x = ca.DM([1 2 3; 4 5 6]);
julia> ca.triu(x)
DM(
[[1, 2, 3],
[00, 5, 6]])
julia> ca.triu(x, false)
DM(
[[00, 2, 3],
[00, 00, 6]])
julia> ca.triu(ca.MX.sym("x", 2, 2))
MX(project(x))
Extra doc: https://github.com/casadi/casadi/wiki/L_45
Definition at line 1982 of file sparsity_interface.hpp.
|
friend |
Mirror image of tril2symm: the argument must be square without structural nonzeros below the diagonal.
>>> U = DM(Sparsity.upper(2), [1, 2, 3]) >>> triu2symm(U) DM( [[1, 2], [2, 3]])
>> U = DM(Sparsity.upper(2), [1; 2; 3]); >> triu2symm(U) [[1, 2], [2, 3]]
julia> U = ca.DM(ca.Sparsity.upper(2), [1, 2, 3]); julia> ca.triu2symm(U) DM( [[1, 2], [2, 3]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1c3
Definition at line 1910 of file generic_matrix.hpp.
|
friend |
The result has the union of both patterns with the nonzeros of A and B at their positions. Both must have the same shape; a shared structural nonzero raises "Pattern intersection not empty".
>>> A = DM(Sparsity.upper(2), [1, 2, 3])
>>> B = DM(Sparsity.triplet(2, 2, [1], [0]), [4])
>>> unite(A, B)
DM(
[[1, 2],
[4, 3]])
>>> try: unite(DM.eye(2), DM.eye(2))
... except Exception as e: print("error")
error
>> A = DM(Sparsity.upper(2), [1; 2; 3]);
>> B = DM(Sparsity.triplet(2, 2, 1, 0), 4);
>> unite(A, B)
[[1, 2],
[4, 3]]
>> try, unite(DM.eye(2), DM.eye(2)); catch e, disp('error'); end
error
julia> A = ca.DM(ca.Sparsity.upper(2), [1, 2, 3]);
julia> B = ca.DM(ca.Sparsity.triplet(2, 2, [1], [0]), [4]);
julia> ca.unite(A, B)
DM(
[[1, 2],
[4, 3]])
julia> try ca.unite(ca.DM.eye(2), ca.DM.eye(2)) catch e; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_1ce
Definition at line 2445 of file generic_matrix.hpp.
|
friend |
Stacks the columns of x on top of each other (column-major order), giving a column of length x.numel(). Same as reshape(x, x.numel(), 1); a column is returned unchanged. The sparsity pattern is carried along: no entries are densified.
a c
b d
turns into
a
b
c
d
>>> vec(DM([[1, 2], [3, 4]]))
DM([1, 3, 2, 4])
>>> vec(DM.eye(2))
DM([1, 00, 00, 1])
>>> vec(MX.sym("x", 1, 3))
MX(x')
>> vec(DM([1 2; 3 4]))
[1, 3, 2, 4]
>> vec(DM.eye(2))
[1, 00, 00, 1]
>> vec(MX.sym('x', 1, 3))
x'
julia> vec(ca.DM([1 2; 3 4]))
DM([1, 3, 2, 4])
julia> vec(ca.DM.eye(2))
DM([1, 00, 00, 1])
julia> vec(ca.MX.sym("x", 1, 3))
MX(x')
Extra doc: https://github.com/casadi/casadi/wiki/L_3z
Definition at line 1588 of file sparsity_interface.hpp.
|
friend |
Every argument is first turned into a column with vec (column-major), then the columns are stacked. Arguments can have any shape, so this is the common way to collect decision variables into one vector. With no arguments the result is a 0-by-1 matrix.
| x | List of matrices of any shape |
>>> veccat(DM([[1, 2], [3, 4]]), 5)
DM([1, 3, 2, 4, 5])
>>> veccat(MX.sym("x", 2, 2), MX.sym("y", 1, 3))
MX(vertcat(vec(x), y'))
>>> veccat().shape
(0, 1)
>> veccat(DM([1 2; 3 4]), 5)
[1, 3, 2, 4, 5]
>> veccat(MX.sym('x', 2, 2), MX.sym('y', 1, 3))
vertcat(vec(x), y')
julia> ca.veccat([ca.MX.sym("x", 2, 2), ca.MX.sym("y", 1, 3)])
MX(vertcat(vec(x), y'))
julia> [vec(ca.DM([1 2; 3 4])); 5]
DM([1, 3, 2, 4, 5])
Extra doc: https://github.com/casadi/casadi/wiki/L_3u
Definition at line 1287 of file sparsity_interface.hpp.
|
friend |
Same as the list form of vertcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4f
Definition at line 2253 of file sparsity_interface.hpp.
|
friend |
Same as the list form of vertcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4g
Definition at line 2262 of file sparsity_interface.hpp.
|
friend |
Same as the list form of vertcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4h
Definition at line 2271 of file sparsity_interface.hpp.
|
friend |
Same as the list form of vertcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4i
Definition at line 2281 of file sparsity_interface.hpp.
|
friend |
Same as the list form of vertcat.
Extra doc: https://github.com/casadi/casadi/wiki/L_4j
Definition at line 2291 of file sparsity_interface.hpp.
|
friend |
Stacks the matrices on top of each other, in order: the result has the column count of the inputs and a row count equal to the sum of the row counts. All inputs must have the same number of columns; a 0-by-0 matrix is ignored. Type and sparsity rules are those of horzcat. With no arguments the result is a 0-by-1 matrix.
Column vectors stack cheaply; for MX, stacking matrices with more than one column is rewritten as a horizontal concatenation of the transposes.
Alternative terminology: vertical stack, vstack, vertical append, [a;b]. Inverse of vertsplit: vertcat(vertsplit(x, ...)) == x.
| v | List of matrices with matching column count |
v stacked vertically
>>> vertcat(SX.sym("x", 2), 3)
SX([x_0, x_1, 3])
>>> vertcat(DM([[1, 2]]), DM.eye(2))
DM(
[[1, 2],
[1, 00],
[00, 1]])
>>> vertcat(MX.sym("a", 2, 3), MX.sym("b", 1, 3))
MX(horzcat(a', b')')
>>> vertcat().shape
(0, 1)
>>> vertcat(MX.sym("a", 2, 2), MX.sym("b", 2, 3))
Traceback (most recent call last):
...
RuntimeError: ...vertcat dimension mismatch...
>> [SX.sym('x', 2); 3]
[x_0, x_1, 3]
>> vertcat(DM([1 2]), DM.eye(2))
[[1, 2],
[1, 00],
[00, 1]]
>> [MX.sym('a', 2, 3); MX.sym('b', 1, 3)]
horzcat(a', b')'
>> try, [MX.sym('a', 2, 2); MX.sym('b', 2, 3)]; catch e, disp(e.message); end
...vertcat dimension mismatch...
julia> [ca.SX.sym("x", 2); 3]
SX([x_0, x_1, 3])
julia> [ca.DM([1 2]); ca.DM.eye(2)]
DM(
[[1, 2],
[1, 00],
[00, 1]])
julia> print([ca.MX.sym("a", 2, 3); ca.MX.sym("b", 1, 3)])
horzcat(a', b')'
julia> try
[ca.MX.sym("a", 2, 2); ca.MX.sym("b", 2, 3)]
catch err
println(occursin("vertcat dimension mismatch", sprint(showerror, err)))
end
false
Extra doc: https://github.com/casadi/casadi/wiki/L_3f
Definition at line 249 of file sparsity_interface.hpp.
|
friend |
Returns the consecutive row blocks of x, each with incr rows, in order. The last block is smaller when the row count is not a multiple of incr. A matrix without rows gives an empty list. Each block carries the corresponding part of the sparsity pattern. Inverse of vertcat: vertcat(vertsplit(x, incr)) == x.
x
>>> vertsplit(SX.sym("a", 4))
[SX(a_0), SX(a_1), SX(a_2), SX(a_3)]
>>> vertsplit(SX.sym("a", 4), 2)
[SX([a_0, a_1]), SX([a_2, a_3])]
>>> vertsplit(DM([0, 1, 2, 3, 4]), 2)
[DM([0, 1]), DM([2, 3]), DM(4)]
>>> vertsplit(MX.sym("x", 4), 2)
[MX(vertsplit(x){0}), MX(vertsplit(x){1})]
>>> vertsplit(MX.sym("x", 0, 2))
[]
>> v = vertsplit(SX.sym('a', 4)); disp(numel(v)), disp(v{1}), disp(v{4})
4
a_0
a_3
>> v = vertsplit(SX.sym('a', 4), 2); disp(v{1}), disp(v{2})
[a_0, a_1]
[a_2, a_3]
>> v = vertsplit(DM([0; 1; 2; 3; 4]), 2); disp(numel(v)), disp(v{3})
3
4
>> v = vertsplit(MX.sym('x', 4), 2); disp(v{1}), disp(v{2})
vertsplit(x){0}
vertsplit(x){1}
>> v = vertsplit(MX.sym('x', 0, 2)); disp(numel(v))
0
julia> ca.vertsplit(ca.SX.sym("a", 4))
4-element Vector{SX}:
SX(a_0)
SX(a_1)
SX(a_2)
SX(a_3)
julia> ca.vertsplit(ca.SX.sym("a", 4), 2)
2-element Vector{SX}:
SX([a_0, a_1])
SX([a_2, a_3])
julia> ca.vertsplit(ca.DM([0, 1, 2, 3, 4]), 2)
3-element Vector{DM}:
DM([0, 1])
DM([2, 3])
DM(4)
julia> ca.vertsplit(ca.MX.sym("x", 4), 2)
2-element Vector{MX}:
MX(vertsplit(x){0})
MX(vertsplit(x){1})
julia> ca.vertsplit(ca.MX.sym("x", 0, 2))
MX[]
Extra doc: https://github.com/casadi/casadi/wiki/L_3k
Definition at line 663 of file sparsity_interface.hpp.
|
friend |
Returns the row blocks x[offset[i]:offset[i+1], :], in order. The offsets must start at 0, be non-decreasing and end at the number of rows of x, otherwise an error is raised. Each block carries the corresponding part of the sparsity pattern. The offsets of a list of matrices that were stacked with vertcat can be recovered with offset. Inverse of vertcat: vertcat(vertsplit(x, offset)) == x.
| x | Matrix (or Sparsity) to split; any shape |
| offset | Start row of every block followed by the row count of x |
x, one per block
>>> x = SX.sym("x", 5)
>>> vertsplit(x, [0, 2, 5])
[SX([x_0, x_1]), SX([x_2, x_3, x_4])]
>>> parts = [DM.ones(2, 1), DM.ones(3, 1)]
>>> vertsplit(x, offset(parts))
[SX([x_0, x_1]), SX([x_2, x_3, x_4])]
>>> vertsplit(DM([[1, 2], [3, 4]]), [0, 1, 2])
[DM([[1, 2]]), DM([[3, 4]])]
>> x = SX.sym('x', 5);
>> v = vertsplit(x, [0, 2, 5]); disp(numel(v)), disp(v{1}), disp(v{2})
2
[x_0, x_1]
[x_2, x_3, x_4]
>> v = vertsplit(DM([1 2; 3 4]), [0, 1, 2]); disp(v{1}), disp(v{2})
[[1, 2]]
[[3, 4]]
julia> x = ca.SX.sym("x", 5);
julia> ca.vertsplit(x, [0, 2, 5])
2-element Vector{SX}:
SX([x_0, x_1])
SX([x_2, x_3, x_4])
julia> parts = [ca.DM.ones(2, 1), ca.DM.ones(3, 1)];
julia> ca.vertsplit(x, ca.offset(parts))
2-element Vector{SX}:
SX([x_0, x_1])
SX([x_2, x_3, x_4])
julia> ca.vertsplit(ca.DM([1 2; 3 4]), [0, 1, 2])
2-element Vector{DM}:
DM([[1, 2]])
DM([[3, 4]])
Extra doc: https://github.com/casadi/casadi/wiki/L_3i
Definition at line 537 of file sparsity_interface.hpp.
|
friend |
Returns n row blocks of equal height, in order. An error is raised when the row count of x is not a multiple of n or n is negative. A matrix without rows gives n copies of itself. Inverse of vertcat: vertcat(vertsplit_n(x, n)) == x.
n matrices of the same type as x
>>> vertsplit_n(DM([1, 2, 3, 4]), 2) [DM([1, 2]), DM([3, 4])] >>> vertsplit_n(DM([1, 2, 3]), 2) Traceback (most recent call last): ... RuntimeError: ...must be a multiple of n...
>> v = vertsplit_n(DM([1; 2; 3; 4]), 2); disp(v{1}), disp(v{2})
[1, 2]
[3, 4]
>> try, vertsplit_n(DM([1; 2; 3]), 2); catch e, disp(e.message); end
...must be a multiple of n...
julia> ca.vertsplit_n(ca.DM([1, 2, 3, 4]), 2)
2-element Vector{DM}:
DM([1, 2])
DM([3, 4])
julia> try
ca.vertsplit_n(ca.DM([1, 2, 3]), 2)
catch err
println(occursin("must be a multiple of n", sprint(showerror, err)))
end
true
Extra doc: https://github.com/casadi/casadi/wiki/L_278
Definition at line 717 of file sparsity_interface.hpp.
|
friend |
Structural dependency check by sparsity propagation, without forming derivatives. With order 1, an entry depends if the corresponding Jacobian entry is structurally nonzero; with order 2, if it enters nonlinearly (second derivative structurally nonzero). Operations whose derivative is structurally zero, such as floor or sign, count as not depending.
| expr | Expression |
| var | Symbolic expression |
| order | 1 or 2; other values raise an error |
| tr | When false, the result has one entry per element of var: does any element of expr depend on it. When true, one entry per element of expr: does it depend on any element of var. |
>>> x = SX.sym("x"); y = SX.sym("y")
>>> e = vertcat(x*y, x**2, 3*x)
>>> which_depends(e, vertcat(x, y), 1, False)
[True, True]
>>> which_depends(e, vertcat(x, y), 1, True)
[True, True, True]
>>> which_depends(e, vertcat(x, y), 2, True)
[True, True, False]
>> x = SX.sym('x'); y = SX.sym('y');
>> e = vertcat(x*y, x^2, 3*x);
>> which_depends(e, vertcat(x, y), 1, false)
1 1
>> which_depends(e, vertcat(x, y), 1, true)
1 1 1
>> which_depends(e, vertcat(x, y), 2, true)
1 1 0
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> e = [x * y; x^2; 3 * x];
julia> ca.which_depends(e, [x; y], 1, false)
2-element Vector{Bool}:
1
1
julia> ca.which_depends(e, [x; y], 1, true)
3-element Vector{Bool}:
1
1
1
julia> ca.which_depends(e, [x; y], 2, true)
3-element Vector{Bool}:
1
1
0
Extra doc: https://github.com/casadi/casadi/wiki/L_1cz
Definition at line 3927 of file generic_matrix.hpp.