Sparse matrix class. SX and DM are specializations. More...
#include <matrix_decl.hpp>
General sparse matrix class that is designed with the idea that "everything is a matrix", that is, also scalars and vectors.
This philosophy makes it easy to use and to interface in particularly with Python and Matlab/Octave.
Index starts with 0.
Index vec happens as follows: (rr, cc) -> k = rr+cc*size1()
Vectors are column vectors.
The storage format is Compressed Column Storage (CCS), similar to that used for sparse matrices in Matlab,
but unlike this format, we do allow for elements to be structurally non-zero but numerically zero.
Matrix<Scalar> is polymorphic with a std::vector<Scalar> that contain all non-identical-zero elements.
The sparsity can be accessed with Sparsity& sparsity()
SX holds symbolic scalar entries (SXElem), DM holds doubles. A structural zero prints as 00, a numerical zero as 0. The structural nonzeros are available as a flat column-major vector with nonzeros().
>>> A = DM([[1, 2], [3, 4]])
>>> A.sparsity().dim(), A.nonzeros()
('2x2', [1.0, 3.0, 2.0, 4.0])
>>> S = DM(Sparsity.diag(2))
>>> S
DM(
[[1, 00],
[00, 1]])
>>> S.nnz(), S.numel()
(2, 4)
>> A = DM([1 2; 3 4]);
>> A.sparsity().dim(), A.nonzeros()
2x2
1 3 2 4
>> S = DM(Sparsity.diag(2));
>> S
[[1, 00],
[00, 1]]
>> fprintf('%d %d\n', S.nnz(), S.numel())
2 4
julia> A = ca.DM([1 2; 3 4]);
julia> ca.dim(ca.sparsity(A)), ca.nonzeros(A)
("2x2", [1.0, 3.0, 2.0, 4.0])
julia> S = ca.DM(ca.Sparsity.diag(2))
DM(
[[1, 00],
[00, 1]])
julia> ca.nnz(S), ca.numel(S)
(2, 4)
Extra doc: https://github.com/casadi/casadi/wiki/L_18e
Definition at line 143 of file matrix_decl.hpp.

Public Member Functions | |
| Matrix () | |
| Empty 0-by-0 matrix. More... | |
| Matrix (const Matrix< Scalar > &m) | |
| Copy constructor: the copy has its own sparsity pattern and nonzeros. More... | |
| Matrix (casadi_int nrow, casadi_int ncol) | |
| Create a matrix of the given shape with all structural zeros (no nonzeros) More... | |
| Matrix (const Sparsity &sp) | |
| Create a matrix with the given sparsity pattern and all nonzeros equal to one. More... | |
| Matrix (const Sparsity &sp, const Matrix< Scalar > &d) | |
| Create a matrix with a given sparsity pattern and given nonzeros. More... | |
| Matrix (double val) | |
| Dense 1-by-1 matrix holding a number; enables implicit conversion from a numeric type. More... | |
| Matrix (const std::vector< std::vector< double > > &m) | |
| Dense matrix from a list of rows. More... | |
| template<typename A > | |
| Matrix (const std::vector< A > &x) | |
| Dense column vector from a flat list of numbers. More... | |
| template<typename A > | |
| Matrix (const Matrix< A > &x) | |
| Create a matrix from another matrix with a different entry type. More... | |
| bool | has_nz (casadi_int rr, casadi_int cc) const |
| Check whether element (rr, cc) is a structural nonzero. More... | |
| bool | __nonzero__ () const |
| Truth value of a 1-by-1 matrix (Python: bool(x)) More... | |
| Matrix< Scalar > | operator+ () const |
| Matrix< Scalar > | operator- () const |
| Matrix< Scalar > | printme (const Matrix< Scalar > &y) const |
| Matrix< Scalar > | T () const |
| Transpose the matrix. More... | |
| void | print_split (std::vector< std::string > &nz, std::vector< std::string > &inter) const |
| String representation of each nonzero and of the shared subexpressions. More... | |
| void | disp (std::ostream &stream, bool more=false) const |
| Print a representation of the object to a stream. More... | |
| std::string | get_str (bool more=false) const |
| Get the string representation that disp prints. More... | |
| void | print_scalar (std::ostream &stream) const |
| Print a 1-by-1 matrix as a bare number or expression. More... | |
| void | print_vector (std::ostream &stream, bool truncate=true) const |
| Print a column vector as [a, b, ...], structural zeros as 00. More... | |
| void | print_dense (std::ostream &stream, bool truncate=true) const |
| Print as a dense matrix, one row per line, structural zeros as 00. More... | |
| void | print_sparse (std::ostream &stream, bool truncate=true) const |
| Print as a list of (row, col) -> value triplets, column-major order. More... | |
| void | clear () |
| Reset to an empty 0-by-0 matrix, in place. More... | |
| void | resize (casadi_int nrow, casadi_int ncol) |
| Change the shape in place, keeping nonzeros that remain inside the new bounds. More... | |
| void | reserve (casadi_int nnz) |
| Reserve storage for the given number of nonzeros (performance hint, no visible effect) More... | |
| void | reserve (casadi_int nnz, casadi_int ncol) |
| void | erase (const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false) |
| Erase the block at the given rows and columns, leaving structural zeros. More... | |
| void | erase (const std::vector< casadi_int > &rr, bool ind1=false) |
| Erase the elements at the given linear indices, leaving structural zeros. More... | |
| void | remove (const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc) |
| Delete rows and columns, shrinking the matrix in place. More... | |
| void | enlarge (casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false) |
| Enlarge the matrix in place, moving the existing rows and columns to new positions. More... | |
| Sparsity | get_sparsity () const |
| Get the sparsity pattern (Python: sparsity()) More... | |
| Matrix< Scalar > | get_output (casadi_int oind) const |
| Get an output. More... | |
| casadi_int | element_hash () const |
| Hash of the node of a 1-by-1 SX expression. More... | |
| bool | is_regular () const |
| Check that no entry is nan, inf or -inf. More... | |
| bool | is_smooth () const |
| Check whether an SX expression contains only smooth operations. More... | |
| bool | is_leaf () const |
| Check if SX is a leaf of the SX graph. More... | |
| bool | is_commutative () const |
| Check whether a binary SX is commutative. More... | |
| bool | is_symbolic () const |
| Check if symbolic (Dense) More... | |
| bool | is_valid_input () const |
| Check if matrix can be used to define function inputs. More... | |
| bool | is_constant () const |
| Check if every entry is a numerical constant (no symbols) More... | |
| bool | is_call () const |
| Check if function call. More... | |
| bool | is_output () const |
| Check if evaluation output. More... | |
| bool | has_output () const |
| Check if a multiple output node. More... | |
| casadi_int | which_output () const |
| Get the index of evaluation output - only valid when is_output() is true. More... | |
| Function | which_function () const |
| Get function - only valid when is_call() is true. More... | |
| bool | is_integer () const |
| Check if the matrix is integer-valued. More... | |
| bool | is_zero () const |
| check if the matrix is 0 (note that false negative answers are possible) More... | |
| bool | is_one () const |
| check if the matrix is 1 (note that false negative answers are possible) More... | |
| bool | is_minus_one () const |
| check if the matrix is -1 (note that false negative answers are possible) More... | |
| bool | is_half () const |
| check if the matrix is 0.5 (note that false negative answers are possible) More... | |
| bool | is_value (double val) const |
| check if the matrix is value More... | |
| bool | is_inf () const |
| check if the matrix is inf (note that false negative answers are possible) More... | |
| bool | is_minus_inf () const |
| check if the matrix is -inf (note that false negative answers are possible) More... | |
| bool | is_nonnegative () const |
| check if the matrix is not negative More... | |
| bool | is_eye () const |
| check if the matrix is an identity matrix (note that false negative answers More... | |
| casadi_int | op () const |
| Get operation type. More... | |
| bool | is_op (casadi_int op) const |
| Is it a certain operation. More... | |
| bool | has_zeros () const |
| Check if any structural nonzero is known to be numerically zero. More... | |
| std::vector< Scalar > | get_nonzeros () const |
| Get all structural nonzeros as a flat list in column-major order (Python: nonzeros()) More... | |
| std::vector< Scalar > | get_elements () const |
| Get all elements as a flat list in column-major order (Python: elements()) More... | |
| operator double () const | |
| Conversion of a 1-by-1 matrix to a double (Python: float(x)) More... | |
| operator casadi_int () const | |
| Conversion of a 1-by-1 matrix to an integer (Python: int(x)), truncating. More... | |
| std::string | name () const |
| Name of a 1-by-1 symbolic SX primitive. More... | |
| Matrix< Scalar > | dep (casadi_int ch=0) const |
| Get operand ch of a 1-by-1 SX expression. More... | |
| casadi_int | n_dep () const |
| Number of operands of a 1-by-1 SX expression (0 for symbols and constants) More... | |
| void | export_code (const std::string &lang, std::ostream &stream=casadi::uout(), const Dict &options=Dict()) const |
| Export matrix in specific language. More... | |
| Dict | info () const |
| Dictionary with the sparsity pattern and the nonzeros (DM only) More... | |
| std::string | serialize () const |
| Serialize to a string. More... | |
| void | serialize (SerializingStream &s) const |
| Serialize an object. More... | |
| void | to_file (const std::string &filename, const std::string &format="") const |
| Write a numerical matrix to a text file (DM only) More... | |
| template<typename Scalar > | |
| Matrix (const std::vector< Scalar > &x) | |
| casadi_int | nnz () const |
| Get the number of structural nonzeros. More... | |
| casadi_int | nnz_lower () const |
| Get the number of structural nonzeros on or below the diagonal. More... | |
| casadi_int | nnz_upper () const |
| Get the number of structural nonzeros on or above the diagonal. More... | |
| casadi_int | nnz_diag () const |
| Get the number of structural nonzeros on the diagonal. More... | |
| casadi_int | numel () const |
| Get the number of elements, size1()*size2() More... | |
| casadi_int | size1 () const |
| Get the first dimension (i.e. number of rows) More... | |
| casadi_int | rows () const |
| Get the number of rows, Octave-style syntax (same as size1()) More... | |
| casadi_int | size2 () const |
| Get the second dimension (i.e. number of columns) More... | |
| casadi_int | columns () const |
| Get the number of columns, Octave-style syntax (same as size2()) More... | |
| std::string | dim (bool with_nz=false) const |
| Get string representation of dimensions. More... | |
| std::pair< casadi_int, casadi_int > | size () const |
| Get the shape as a pair (number of rows, number of columns) More... | |
| casadi_int | size (casadi_int axis) const |
| Get the size along a particular dimension. More... | |
| bool | is_empty (bool both=false) const |
| Check if the matrix is empty, i.e. if one of the dimensions is zero. More... | |
| bool | is_dense () const |
| Check if the matrix is dense, i.e. nnz() equals numel() More... | |
| bool | is_scalar (bool scalar_and_dense=false) const |
| Check if the matrix is scalar, i.e. 1-by-1. More... | |
| bool | is_square () const |
| Check if the matrix is square, i.e. size1() equals size2() More... | |
| bool | is_vector () const |
| Check if the matrix is a row or column vector. More... | |
| bool | is_row () const |
| Check if the matrix is a row vector (i.e. size1()==1) More... | |
| bool | is_column () const |
| Check if the matrix is a column vector (i.e. size2()==1) More... | |
| bool | is_triu () const |
| Check if the matrix is upper triangular. More... | |
| bool | is_tril () const |
| Check if the matrix is lower triangular. More... | |
| Sparsity | sparsity () const |
| Get the sparsity pattern. More... | |
| void | get (Matrix< Scalar > &m, bool ind1, const Slice &rr) const |
| Get elements by a single (linear) index. More... | |
| void | get (Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr) const |
| Get elements by a single (linear) index. More... | |
| void | get (Matrix< Scalar > &m, bool ind1, const Sparsity &sp) const |
| Get elements by a single (linear) index. More... | |
| void | get (Matrix< Scalar > &m, bool ind1, const Slice &rr, const Slice &cc) const |
| Get a submatrix by row and column indices. More... | |
| void | get (Matrix< Scalar > &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc) const |
| Get a submatrix by row and column indices. More... | |
| void | get (Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc) const |
| Get a submatrix by row and column indices. More... | |
| void | get (Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc) const |
| Get a submatrix by row and column indices. More... | |
| void | set (const Matrix< Scalar > &m, bool ind1, const Slice &rr) |
| Assign elements by a single (linear) index. More... | |
| void | set (const Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr) |
| Assign elements by a single (linear) index. More... | |
| void | set (const Matrix< Scalar > &m, bool ind1, const Sparsity &sp) |
| Assign elements by a single (linear) index. More... | |
| void | set (const Matrix< Scalar > &m, bool ind1, const Slice &rr, const Slice &cc) |
| Assign a submatrix by row and column indices. More... | |
| void | set (const Matrix< Scalar > &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc) |
| Assign a submatrix by row and column indices. More... | |
| void | set (const Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc) |
| Assign a submatrix by row and column indices. More... | |
| void | set (const Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc) |
| Assign a submatrix by row and column indices. More... | |
| void | get_nz (Matrix< Scalar > &m, bool ind1, const Slice &k) const |
| Get structural nonzeros by their position in the nonzero storage. More... | |
| void | get_nz (Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &k) const |
| Get structural nonzeros by their position in the nonzero storage. More... | |
| void | set_nz (const Matrix< Scalar > &m, bool ind1, const Slice &k) |
| Assign structural nonzeros by their position in the nonzero storage. More... | |
| void | set_nz (const Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &k) |
| Assign structural nonzeros by their position in the nonzero storage. More... | |
| std::vector< casadi_int > | get_row () const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
| std::vector< casadi_int > | get_colind () const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
| casadi_int | row (casadi_int el) const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
| casadi_int | colind (casadi_int col) const |
| Get the sparsity pattern. See the Sparsity class for details. More... | |
Static Public Member Functions | |
| static void | set_max_depth (casadi_int eq_depth=1) |
| Set the depth to which SX subexpressions are compared during simplification. More... | |
| static casadi_int | get_max_depth () |
| Get the depth to which SX subexpressions are compared during simplification. More... | |
| static std::vector< Matrix< Scalar > > | get_input (const Function &f) |
| Get the symbolic input expressions of an SX Function. More... | |
| static std::vector< Matrix< Scalar > > | get_free (const Function &f) |
| Get the free symbols of an SX Function. More... | |
| static std::string | type_name () |
| Name of the class: "DM" or "SX". More... | |
| static Matrix< Scalar > | eye (casadi_int n) |
| Create an n-by-n identity matrix. More... | |
| static void | set_precision (casadi_int precision) |
| Set the precision, field width and scientific flag used when printing nonzeros. More... | |
| static void | set_width (casadi_int width) |
| static void | set_scientific (bool scientific) |
| static casadi_int | get_precision () |
| Get the precision, field width and scientific flag used when printing nonzeros. More... | |
| static casadi_int | get_width () |
| static bool | get_scientific () |
| static void | rng (casadi_int seed) |
| Seed the random number generator used by rand. More... | |
| static Matrix< Scalar > | deserialize (std::istream &stream) |
| Build a matrix from a serialization stream. More... | |
| static Matrix< Scalar > | deserialize (const std::string &s) |
| Build a matrix from a string produced by serialize. More... | |
| static Matrix< Scalar > | deserialize (DeserializingStream &s) |
| static Matrix< double > | from_file (const std::string &filename, const std::string &format_hint="") |
| Read a numerical matrix from a text file written by to_file (DM only) More... | |
| static Matrix< Scalar > | logsumexp (const Matrix< Scalar > &x) |
| static Matrix< Scalar > | triplet (const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d) |
| Construct a sparse matrix from triplet form (row indices, column indices, values) More... | |
| static Matrix< Scalar > | triplet (const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d, casadi_int nrow, casadi_int ncol) |
| Construct a sparse matrix from triplet form (row indices, column indices, values) More... | |
| static Matrix< Scalar > | triplet (const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d, const std::pair< casadi_int, casadi_int > &rc) |
| Construct a sparse matrix from triplet form (row indices, column indices, values) More... | |
| static Matrix< Scalar > | inf (const Sparsity &sp) |
| Create a matrix with every nonzero equal to +inf. More... | |
| static Matrix< Scalar > | inf (casadi_int nrow=1, casadi_int ncol=1) |
| Create a matrix with every nonzero equal to +inf. More... | |
| static Matrix< Scalar > | inf (const std::pair< casadi_int, casadi_int > &rc) |
| Create a matrix with every nonzero equal to +inf. More... | |
| static Matrix< Scalar > | nan (const Sparsity &sp) |
| Create a matrix with every nonzero equal to nan. More... | |
| static Matrix< Scalar > | nan (casadi_int nrow=1, casadi_int ncol=1) |
| Create a matrix with every nonzero equal to nan. More... | |
| static Matrix< Scalar > | nan (const std::pair< casadi_int, casadi_int > &rc) |
| Create a matrix with every nonzero equal to nan. More... | |
| static Matrix< Scalar > | rand (casadi_int nrow=1, casadi_int ncol=1) |
| Create a matrix with uniformly distributed random numbers in [0, 1) More... | |
| static Matrix< Scalar > | rand (const Sparsity &sp) |
| Create a matrix with uniformly distributed random numbers in [0, 1) More... | |
| static Matrix< Scalar > | rand (const std::pair< casadi_int, casadi_int > &rc) |
| Create a matrix with uniformly distributed random numbers in [0, 1) More... | |
| static Matrix< Scalar > | mpower (const Matrix< Scalar > &x, const Matrix< Scalar > &y) |
| static Matrix< Scalar > | soc (const Matrix< Scalar > &x, const Matrix< Scalar > &y) |
| static Matrix< Scalar > | linearize (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &x0, const Dict &opts=Dict()) |
| static Matrix< Scalar > | gradient (const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Dict &opts=Dict()) |
| static Matrix< Scalar > | tangent (const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Dict &opts=Dict()) |
| static Matrix< Scalar > | jtimes (const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Matrix< Scalar > &v, bool tr=false, const Dict &opts=Dict()) |
| static Matrix< Scalar > | bilin (const Matrix< Scalar > &A, const Matrix< Scalar > &x, const Matrix< Scalar > &y) |
| Calculate bilinear/quadratic form x^T A y. More... | |
| static Matrix< Scalar > | rank1 (const Matrix< Scalar > &A, const Matrix< Scalar > &alpha, const Matrix< Scalar > &x, const Matrix< Scalar > &y) |
| Make a rank-1 update to a matrix A. More... | |
Construct symbolic primitives | |
The "sym" function is intended to work in a similar way as "sym" used in the Symbolic Toolbox for Matlab but instead creating a CasADi symbolic primitive. | |
| static Matrix< Scalar > | sym (const std::string &name, casadi_int nrow=1, casadi_int ncol=1) |
| Create an nrow-by-ncol symbolic primitive. More... | |
| static Matrix< Scalar > | sym (const std::string &name, const std::pair< casadi_int, casadi_int > &rc) |
| Construct a symbolic primitive with given dimensions, as a pair (nrow, ncol) More... | |
| static Matrix< Scalar > | sym (const std::string &name, const Sparsity &sp) |
| Create symbolic primitive with a given sparsity pattern. More... | |
| static std::vector< Matrix< Scalar > > | sym (const std::string &name, const Sparsity &sp, casadi_int p) |
| Create a list of length p of symbolic primitives with a given sparsity. More... | |
| static std::vector< Matrix< Scalar > > | sym (const std::string &name, casadi_int nrow, casadi_int ncol, casadi_int p) |
| Create a list of length p of nrow-by-ncol symbolic primitives. More... | |
| static std::vector< std::vector< Matrix< Scalar > > > | sym (const std::string &name, const Sparsity &sp, casadi_int p, casadi_int r) |
| Create a list of length r of lists of length p of symbolic primitives. More... | |
| static std::vector< std::vector< Matrix< Scalar > > > | sym (const std::string &name, casadi_int nrow, casadi_int ncol, casadi_int p, casadi_int r) |
| Create a list of length r of lists of length p of nrow-by-ncol symbolic primitives. More... | |
| static Matrix< Scalar > | zeros (casadi_int nrow=1, casadi_int ncol=1) |
| Create a dense matrix or a matrix with specified sparsity with all entries zero. More... | |
| static Matrix< Scalar > | zeros (const Sparsity &sp) |
| Create a dense matrix or a matrix with specified sparsity with all entries zero. More... | |
| static Matrix< Scalar > | zeros (const std::pair< casadi_int, casadi_int > &rc) |
| Create a dense matrix or a matrix with specified sparsity with all entries zero. More... | |
| static Matrix< Scalar > | ones (casadi_int nrow=1, casadi_int ncol=1) |
| Create a dense matrix or a matrix with specified sparsity with all entries one. More... | |
| static Matrix< Scalar > | ones (const Sparsity &sp) |
| Create a dense matrix or a matrix with specified sparsity with all entries one. More... | |
| static Matrix< Scalar > | ones (const std::pair< casadi_int, casadi_int > &rc) |
| Create a dense matrix or a matrix with specified sparsity with all entries one. More... | |
Friends | |
| Matrix< Scalar > | adj (const Matrix< Scalar > &A) |
| Adjugate (classical adjoint) of a square matrix. More... | |
| 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 > | 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 | qr (const Matrix< Scalar > &A, Matrix< Scalar > &Q, Matrix< Scalar > &R) |
| Dense QR factorization using the modified Gram-Schmidt algorithm. More... | |
| void | 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 > | 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 > | chol (const Matrix< Scalar > &A) |
| Cholesky factorization of a symmetric positive definite matrix. More... | |
| void | 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 > | 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 > | any (const Matrix< Scalar > &x) |
| True if any entry equals one. More... | |
| Matrix< Scalar > | all (const Matrix< Scalar > &x) |
| True if every entry equals one. More... | |
| 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 > | sparsify (const Matrix< Scalar > &A, double tol=0) |
| Make a matrix sparse by turning numerical zeros into structural zeros. More... | |
| void | 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 > | 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 > | 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 > | heaviside (const Matrix< Scalar > &x) |
| Heaviside step function, elementwise. More... | |
| Matrix< Scalar > | rectangle (const Matrix< Scalar > &x) |
| Rectangle (gate, pulse, window) function, elementwise. More... | |
| Matrix< Scalar > | triangle (const Matrix< Scalar > &x) |
| Triangle (hat) function, elementwise. More... | |
| Matrix< Scalar > | ramp (const Matrix< Scalar > &x) |
| Ramp function, elementwise. More... | |
| 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 > | 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 > | poly_coeff (const Matrix< Scalar > &f, const Matrix< Scalar > &x) |
| Extract the polynomial coefficients of a scalar expression in one symbol. More... | |
| Matrix< Scalar > | poly_roots (const Matrix< Scalar > &p) |
| Roots of a polynomial given by its coefficients, in closed form. More... | |
| Matrix< Scalar > | eig_symbolic (const Matrix< Scalar > &m) |
| Eigenvalues of a square SX matrix in closed form. More... | |
| Matrix< double > | evalf (const Matrix< Scalar > &expr) |
| Evaluate a constant expression numerically, returning a DM. More... | |
| 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 > | 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 > | taylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order=1) |
| Univariate Taylor series expansion. More... | |
| Matrix< Scalar > | taylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x) |
| Univariate Taylor series expansion. More... | |
| casadi::Matrix< Scalar >::Matrix |
>>> DM().dim(), SX().is_empty()
('0x0', True)
>> fprintf('%s %d\n', DM().dim(), SX().is_empty())
0x0 1
julia> ca.dim(ca.DM()), ca.is_empty(ca.SX())
("0x0", true)
Extra doc: https://github.com/casadi/casadi/wiki/L_18f
Definition at line 586 of file matrix_impl.hpp.
| casadi::Matrix< Scalar >::Matrix | ( | const Matrix< Scalar > & | m | ) |
Definition at line 590 of file matrix_impl.hpp.
| casadi::Matrix< Scalar >::Matrix | ( | casadi_int | nrow, |
| casadi_int | ncol | ||
| ) |
The result has nnz()==0. Use zeros(nrow, ncol) for a dense matrix of numerical zeros. Structural zeros print as 00.
| nrow | Number of rows, nonnegative |
| ncol | Number of columns, nonnegative |
>>> DM(2, 3) DM( [[00, 00, 00], [00, 00, 00]]) >>> DM(2, 3).nnz(), DM.zeros(2, 3).nnz() (0, 6) >>> SX(2, 0).dim() '2x0'
>> DM(2, 3)
[[00, 00, 00],
[00, 00, 00]]
>> fprintf('%d %d\n', DM(2, 3).nnz(), DM.zeros(2, 3).nnz())
0 6
>> SX(2, 0).dim()
2x0
julia> ca.DM(2, 3) DM( [[00, 00, 00], [00, 00, 00]]) julia> ca.nnz(ca.DM(2, 3)), ca.nnz(ca.DM.zeros(2, 3)) (0, 6) julia> ca.dim(ca.SX(2, 0)) "2x0"
Extra doc: https://github.com/casadi/casadi/wiki/L_18g
|
explicit |
Same as ones(sp).
>>> DM(Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
>> DM(Sparsity.diag(2)) [[1, 00], [00, 1]]
julia> ca.DM(ca.Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_18k
| casadi::Matrix< Scalar >::Matrix | ( | const Sparsity & | sp, |
| const Matrix< Scalar > & | d | ||
| ) |
| sp | Sparsity pattern of the result |
| d | Either a scalar, which is used for every structural nonzero, or a dense vector (row or column) with exactly sp.nnz() entries, in column-major order of the pattern. Anything else raises an error. |
>>> DM(Sparsity.diag(2), [5, 6])
DM(
[[5, 00],
[00, 6]])
>>> DM(Sparsity.diag(2), 5)
DM(
[[5, 00],
[00, 5]])
>>> SX(Sparsity.lower(2), SX.sym("v", 3))
SX(
[[v_0, 00],
[v_1, v_2]])
>>> try: DM(Sparsity.diag(3), [1, 2])
... except Exception as e: print("error")
error
>> DM(Sparsity.diag(2), [5; 6])
[[5, 00],
[00, 6]]
>> DM(Sparsity.diag(2), 5)
[[5, 00],
[00, 5]]
>> SX(Sparsity.lower(2), SX.sym('v', 3))
[[v_0, 00],
[v_1, v_2]]
>> try, DM(Sparsity.diag(3), [1; 2]); catch e, disp('error'); end
error
julia> ca.DM(ca.Sparsity.diag(2), [5, 6])
DM(
[[5, 00],
[00, 6]])
julia> ca.DM(ca.Sparsity.diag(2), 5)
DM(
[[5, 00],
[00, 5]])
julia> ca.SX(ca.Sparsity.lower(2), ca.SX.sym("v", 3))
SX(
[[v_0, 00],
[v_1, v_2]])
julia> try ca.DM(ca.Sparsity.diag(3), [1, 2]); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_18l
| casadi::Matrix< Scalar >::Matrix | ( | double | val | ) |
|
explicit |
Every row must have the same length; a ragged input raises an error. An empty outer list gives a 0-by-1 matrix. At the Python level, 2-D NumPy arrays and SciPy sparse matrices are accepted as well; a sparse input keeps its sparsity pattern.
>>> DM([[1, 2], [3, 4]])
DM(
[[1, 2],
[3, 4]])
>>> DM(np.array([[1, 2], [3, 4]])).dim()
'2x2'
>>> try: DM([[1, 2], [3]])
... except Exception as e: print("error")
error
julia> ca.DM([1 2; 3 4])
DM(
[[1, 2],
[3, 4]])
julia> try ca.DM([[1, 2], [3]]); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2oo
|
inline |
A 1-D NumPy array also gives a column vector.
>>> DM([1, 2, 3]).dim(), DM(np.array([1, 2, 3])).dim(), DM([]).dim()
('3x1', '3x1', '0x1')
julia> ca.dim(ca.DM([1, 2, 3])), ca.dim(ca.DM(Float64[]))
("3x1", "0x1")
Extra doc: https://github.com/casadi/casadi/wiki/L_18m
Definition at line 409 of file matrix_decl.hpp.
|
inline |
The sparsity pattern is kept and every nonzero is converted. SX(DM) always works. DM(SX) requires constant entries: a symbolic entry is converted to nan without an error. Use evalf to get an error instead.
>>> SX(DM(Sparsity.diag(2))).dim()
'2x2'
>>> DM(SX([1, 2]))
DM([1, 2])
>>> DM(SX.sym("x"))
DM(nan)
>> SX(DM(Sparsity.diag(2))).dim()
2x2
>> DM(SX([1; 2]))
[1, 2]
>> DM(SX.sym('x'))
nan
julia> ca.dim(ca.SX(ca.DM(ca.Sparsity.diag(2))))
"2x2"
julia> ca.DM(ca.SX([1, 2]))
DM([1, 2])
julia> ca.DM(ca.SX.sym("x"))
DM(nan)
Extra doc: https://github.com/casadi/casadi/wiki/L_18n
Definition at line 459 of file matrix_decl.hpp.
| casadi::Matrix< Scalar >::Matrix | ( | const std::vector< Scalar > & | x | ) |
Definition at line 594 of file matrix_impl.hpp.
| bool casadi::SX::__nonzero__ | ( | ) | const |
Only defined for 1-by-1 matrices; other shapes raise an error. A structurally empty 1-by-1 matrix is false. A symbolic SX entry raises an error unless the on-the-fly simplifications already decided its value (x==x is true).
>>> bool(DM(2)), bool(DM(0)), bool(DM(1, 1))
(True, False, False)
>>> x = SX.sym("x")
>>> bool(x == x)
True
>>> try: bool(x > 0)
... except Exception as e: print("error")
error
julia> Bool(ca.DM(1)), Bool(ca.DM(0)), Bool(ca.DM(1, 1))
(true, false, false)
julia> x = ca.SX.sym("x");
julia> Bool(x == x)
true
julia> try Bool(x > 0); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2oq
Definition at line 80 of file matrix_impl.hpp.
|
staticinherited |
x and y must be vectors (row vectors are transposed, sparse vectors densified) with x.numel() == A.size1() and y.numel() == A.size2(); otherwise an error is raised. The result is scalar. When y is omitted, the quadratic form x^T A x is calculated.
>>> A = DM([[1, 2], [3, 4]])
>>> bilin(A, DM([1, 1]), DM([1, 2]))
DM(16)
>>> bilin(A, DM([1, 1]))
DM(10)
>>> bilin(MX.sym("A", 2, 2), MX.sym("x", 2), MX.sym("y", 2))
MX(bilin(A, x, y))
>> A = DM([1 2; 3 4]);
>> bilin(A, DM([1; 1]), DM([1; 2]))
16
>> bilin(A, DM([1; 1]))
10
>> bilin(MX.sym('A', 2, 2), MX.sym('x', 2), MX.sym('y', 2))
bilin(A, x, y)
julia> A = ca.DM([1 2; 3 4]);
julia> ca.bilin(A, ca.DM([1, 1]), ca.DM([1, 2]))
DM(16)
julia> ca.bilin(A, ca.DM([1, 1]))
DM(10)
julia> ca.bilin(ca.MX.sym("A", 2, 2), ca.MX.sym("x", 2), ca.MX.sym("y", 2))
MX(bilin(A, x, y))
Extra doc: https://github.com/casadi/casadi/wiki/L_1bo
| void casadi::Matrix< Scalar >::clear | ( | ) |
|
inlineinherited |
The pattern is stored in compressed column format: colind has size2()+1 entries, the nonzeros of column j are the entries colind(j) up to colind(j+1) (exclusive), and row(el) is the row index of nonzero el. Without argument, the full vectors are returned. Out-of-range indices raise an error.
>>> x = DM(Sparsity.diag(2), [5, 6]) >>> x.row(), x.colind() ([0, 1], [0, 1, 2]) >>> x.row(1), x.colind(2) (1, 2)
>> x = DM(Sparsity.diag(2), [5; 6]);
>> x.row(), x.colind()
0 1
0 1 2
>> fprintf('%d %d\n', x.row(1), x.colind(2))
1 2
julia> x = ca.DM(ca.Sparsity.diag(2), [5, 6]); julia> ca.row(x), ca.colind(x) ([0, 1], [0, 1, 2]) julia> ca.row(x, 1), ca.colind(x, 2) (1, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b8
Definition at line 609 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1av
Definition at line 295 of file generic_matrix.hpp.
| SX casadi::SX::dep | ( | casadi_int | ch = 0 | ) | const |
Only defined for a scalar SX that is the result of an operation; a symbol, a constant or a DM raises an error.
| ch | Operand index, 0 or 1 |
>>> x = SX.sym("x"); y = SX.sym("y")
>>> e = x * y
>>> e.dep(0), e.dep(1), e.n_dep()
(SX(x), SX(y), 2)
>> x = SX.sym('x'); y = SX.sym('y');
>> e = x * y;
>> e.dep(0), e.dep(1), e.n_dep()
x
y
2
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> e = x * y;
julia> ca.dep(e, 0), ca.dep(e, 1), ca.n_dep(e)
(x, y, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1a9
|
static |
A string that is not a CasADi serialization raises an error.
Extra doc: https://github.com/casadi/casadi/wiki/L_1ag
|
static |
|
static |
Extra doc: https://github.com/casadi/casadi/wiki/L_1af
|
inherited |
The representation is e.g. "4x5" or, with with_nz true, "4x5,10nz".
>>> DM.eye(3).dim(), DM.eye(3).dim(True), DM.ones(3, 3).dim(True)
('3x3', '3x3,3nz', '3x3,9nz')
>> fprintf('%s %s %s\n', DM.eye(3).dim(), DM.eye(3).dim(true), DM.ones(3, 3).dim(true))
3x3 3x3,3nz 3x3,9nz
julia> ca.dim(ca.DM.eye(3)), ca.dim(ca.DM.eye(3), true), ca.dim(ca.DM.ones(3, 3), true)
("3x3", "3x3,3nz", "3x3,9nz")
Extra doc: https://github.com/casadi/casadi/wiki/L_1aw
| void casadi::Matrix< Scalar >::disp | ( | std::ostream & | stream, |
| bool | more = false |
||
| ) | const |
Picks the layout automatically: scalar, vector, dense matrix (small or at least half full) or sparse coordinate list. This is what str() and print() use. more has no effect for matrices.
Extra doc: https://github.com/casadi/casadi/wiki/L_2oz
| casadi_int casadi::SX::element_hash | ( | ) | const |
Equal expressions (same node) have the same hash. Only defined for a scalar SX; a vector or a DM raises an error.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> x.element_hash() == x.element_hash(), x.element_hash() == y.element_hash()
(True, False)
>> x = SX.sym('x'); y = SX.sym('y');
>> h = x.element_hash();
>> fprintf('%d %d\n', h == x.element_hash(), h == y.element_hash())
1 0
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.element_hash(x) == ca.element_hash(x), ca.element_hash(x) == ca.element_hash(y)
(true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_19n
| void casadi::Matrix< Scalar >::enlarge | ( | casadi_int | nrow, |
| casadi_int | ncol, | ||
| const std::vector< casadi_int > & | rr, | ||
| const std::vector< casadi_int > & | cc, | ||
| bool | ind1 = false |
||
| ) |
The new shape is nrow-by-ncol. rr lists, for every existing row, its index in the enlarged matrix; cc does the same for the columns. Both must have exactly size1() and size2() entries. All other rows and columns are structurally zero.
| nrow | New number of rows |
| ncol | New number of columns |
| rr | New position of each existing row, length size1() |
| cc | New position of each existing column, length size2() |
| ind1 | True for one-based indices |
>>> A = DM([[1, 2], [3, 4]])
>>> A.enlarge(3, 4, [0, 2], [0, 1])
>>> A
DM(
[[1, 2, 00, 00],
[00, 00, 00, 00],
[3, 4, 00, 00]])
>>> try: A.enlarge(4, 4, [0, 1], [0, 1])
... except Exception as e: print("error")
error
>> A = DM([1 2; 3 4]);
>> A.enlarge(3, 4, [1 3], [1 2], true);
>> A
[[1, 2, 00, 00],
[00, 00, 00, 00],
[3, 4, 00, 00]]
>> try, A.enlarge(4, 4, [1 2], [1 2], true); catch e, disp('error'); end
error
julia> A = ca.DM([1 2; 3 4]);
julia> ca.enlarge(A, 3, 4, [0, 2], [0, 1])
julia> A
DM(
[[1, 2, 00, 00],
[00, 00, 00, 00],
[3, 4, 00, 00]])
julia> try ca.enlarge(A, 4, 4, [0, 1], [0, 1]); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_19i
| void casadi::Matrix< Scalar >::erase | ( | const std::vector< casadi_int > & | rr, |
| bool | ind1 = false |
||
| ) |
Column-major linear indices, as in get. The shape is unchanged.
>>> A = DM([[1, 2, 3], [4, 5, 6]]) >>> A.erase([0, -1]) >>> A DM( [[00, 2, 3], [4, 5, 00]])
>> A = DM([1 2 3; 4 5 6]); >> A.erase([1 6], true); >> A [[00, 2, 3], [4, 5, 00]]
julia> A = ca.DM([1 2 3; 4 5 6]); julia> ca.erase(A, [0, 5]) julia> A DM( [[00, 2, 3], [4, 5, 00]])
Extra doc: https://github.com/casadi/casadi/wiki/L_19g
| void casadi::Matrix< Scalar >::erase | ( | const std::vector< casadi_int > & | rr, |
| const std::vector< casadi_int > & | cc, | ||
| bool | ind1 = false |
||
| ) |
The shape is unchanged; the entries of the submatrix rr x cc are removed from the sparsity pattern. Negative indices count from the end; out-of-range indices raise an error.
| rr | Row indices |
| cc | Column indices |
| ind1 | True for one-based indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A.erase([0], [1])
>>> A
DM(
[[1, 00, 3],
[4, 5, 6]])
>>> A.dim(), A.nnz()
('2x3', 5)
>> A = DM([1 2 3; 4 5 6]);
>> A.erase(1, 2, true);
>> A
[[1, 00, 3],
[4, 5, 6]]
>> fprintf('%s %d\n', A.dim(), A.nnz())
2x3 5
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> ca.erase(A, [0], [1])
julia> A
DM(
[[1, 00, 3],
[4, 5, 6]])
julia> ca.dim(A), ca.nnz(A)
("2x3", 5)
Extra doc: https://github.com/casadi/casadi/wiki/L_19f
| void casadi::Matrix< Scalar >::export_code | ( | const std::string & | lang, |
| std::ostream & | stream = casadi::uout(), |
||
| const Dict & | options = Dict() |
||
| ) | const |
lang: only 'matlab' supported for now
* options: * inline: Indicates if you want everything on a single line (default: False) * name: Name of exported variable (default: 'm') * indent_level: Level of indentation (default: 0) * spoof_zero: Replace numerical zero by a 1e-200 (default: false) * might be needed for matlab sparse construct, * which doesn't allow numerical zero *
Extra doc: https://github.com/casadi/casadi/wiki/L_1ac
|
static |
The result is sparse: only the n diagonal entries are structural nonzeros.
>>> DM.eye(2) DM( [[1, 00], [00, 1]]) >>> DM.eye(3).nnz(), DM.eye(0).dim() (3, '0x0')
>> DM.eye(2)
[[1, 00],
[00, 1]]
>> fprintf('%d %s\n', DM.eye(3).nnz(), DM.eye(0).dim())
3 0x0
julia> ca.DM.eye(2) DM( [[1, 00], [00, 1]]) julia> ca.nnz(ca.DM.eye(3)), ca.dim(ca.DM.eye(0)) (3, "0x0")
Extra doc: https://github.com/casadi/casadi/wiki/L_19m
|
static |
Same formats as to_file. In txt format, lines starting with #, % or / and empty lines are skipped, 00 marks a structural zero and a plain 0 a stored zero; every row must have the same number of columns, otherwise an error is raised. An empty file gives a 0-by-0 matrix. A missing file raises an error.
| filename | Input path |
| format_hint | "mtx" or "txt"; empty means deduce from the extension |
>>> import os, tempfile
>>> fn = os.path.join(tempfile.mkdtemp(), "a.txt")
>>> with open(fn, "w") as f: n = f.write("# comment\n1 00\n0 2\n")
>>> A = DM.from_file(fn)
>>> A
DM(
[[1, 00],
[0, 2]])
>>> A.nnz()
3
>>> os.remove(fn); os.rmdir(os.path.dirname(fn))
>> fn = [tempname '.txt']; >> fid = fopen(fn, 'w'); fprintf(fid, '# comment\n1 00\n0 2\n'); fclose(fid); >> A = DM.from_file(fn); >> A [[1, 00], [0, 2]] >> A.nnz() 3 >> delete(fn);
julia> fn = joinpath(mktempdir(), "a.txt"); julia> write(fn, "# comment\n1 00\n0 2\n"); julia> A = ca.DM.from_file(fn) DM( [[1, 00], [0, 2]]) julia> ca.nnz(A) 3 julia> rm(dirname(fn), recursive=true)
Extra doc: https://github.com/casadi/casadi/wiki/L_2pa
| void casadi::Matrix< Scalar >::get | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | rr | ||
| ) | const |
Backs the Python expressions x[k] and x[sp]. The index addresses elements, not nonzeros, in column-major order: element (i, j) has linear index i + j*size1(). Negative indices count from the end; out-of-range indices raise an error.
Note that the result of a comparison such as A > 2 is a DM of zeros and ones, not a boolean mask: indexing with it uses those values as linear indices. Use a Sparsity pattern or the nz accessor for masking.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Linear index, Slice or list/matrix of indices |
| sp | Sparsity pattern of the same shape as the matrix |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[1], A[2], A[-1]
(DM(4), DM(2), DM(6))
>>> A[[0, 5]]
DM([1, 6])
>>> A[Sparsity.diag(2, 3)]
DM(
[[1, 00, 00],
[00, 5, 00]])
>>> S = DM(Sparsity.diag(2))
>>> S[1]
DM(00)
>>> A.get(False, Slice(0, 2))
DM([1, 4])
>>> try: A[6]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(2), A(3), A(end)
4
2
6
>> A([1 6])
[[1, 6]]
>> A(Sparsity.diag(2, 3))
[[1, 00, 00],
[00, 5, 00]]
>> S = DM(Sparsity.diag(2));
>> S(2)
00
>> A.get(true, [1; 2])
[1, 4]
>> try, A(7); catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[2], A[3], A[end]
(4, 2, 6)
julia> A[[1, 6]]
DM([1, 6])
julia> S = ca.DM(ca.Sparsity.diag(2));
julia> S[2]
DM(00)
julia> try A[7]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2or
Definition at line 162 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::get | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | rr, | ||
| const Matrix< casadi_int > & | cc | ||
| ) | const |
Backs the Python expression x[i, j]. Each of rr and cc is a scalar, a Slice or a list/vector of indices (any order, repetitions allowed, negative counts from the end). The result has len(rr) rows and len(cc) columns and keeps the sparsity of the selected entries. Two scalar indices give a 1-by-1 matrix (structurally empty when the entry is a structural zero). Out-of-range indices raise an error.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Row index, Slice or list/matrix of row indices |
| cc | Column index, Slice or list/matrix of column indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[0, 1], A[1, -1]
(DM(2), DM(6))
>>> A[:, 1]
DM([2, 5])
>>> A[[1, 0], [0, 2]]
DM(
[[4, 6],
[1, 3]])
>>> A[1:1, :].dim()
'0x3'
>>> x = SX.sym("x", 2, 2)
>>> x[0, :]
SX([[x_0, x_2]])
>>> DM(Sparsity.diag(2))[1, 0]
DM(00)
>>> try: A[2, 0]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(1, 2), A(2, end)
2
6
>> A(:, 2)
[2, 5]
>> A([2 1], [1 3])
[[4, 6],
[1, 3]]
>> B = A(2:1, :); disp(B.dim())
0x3
>> x = SX.sym('x', 2, 2);
>> x(1, :)
[[x_0, x_2]]
>> S = DM(Sparsity.diag(2));
>> S(2, 1)
00
>> try, A(3, 1); catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[1, 2], A[2, end]
(2, 6)
julia> A[:, 2]
DM([2, 5])
julia> A[[2, 1], [1, 3]]
DM(
[[4, 6],
[1, 3]])
julia> ca.dim(A[2:1, :])
"0x3"
julia> x = ca.SX.sym("x", 2, 2);
julia> x[1, :]
SX([[x_0, x_2]])
julia> ca.DM(ca.Sparsity.diag(2))[2, 1]
DM(00)
julia> try A[3, 1]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2os
Definition at line 121 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::get | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | rr, | ||
| const Slice & | cc | ||
| ) | const |
Backs the Python expression x[i, j]. Each of rr and cc is a scalar, a Slice or a list/vector of indices (any order, repetitions allowed, negative counts from the end). The result has len(rr) rows and len(cc) columns and keeps the sparsity of the selected entries. Two scalar indices give a 1-by-1 matrix (structurally empty when the entry is a structural zero). Out-of-range indices raise an error.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Row index, Slice or list/matrix of row indices |
| cc | Column index, Slice or list/matrix of column indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[0, 1], A[1, -1]
(DM(2), DM(6))
>>> A[:, 1]
DM([2, 5])
>>> A[[1, 0], [0, 2]]
DM(
[[4, 6],
[1, 3]])
>>> A[1:1, :].dim()
'0x3'
>>> x = SX.sym("x", 2, 2)
>>> x[0, :]
SX([[x_0, x_2]])
>>> DM(Sparsity.diag(2))[1, 0]
DM(00)
>>> try: A[2, 0]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(1, 2), A(2, end)
2
6
>> A(:, 2)
[2, 5]
>> A([2 1], [1 3])
[[4, 6],
[1, 3]]
>> B = A(2:1, :); disp(B.dim())
0x3
>> x = SX.sym('x', 2, 2);
>> x(1, :)
[[x_0, x_2]]
>> S = DM(Sparsity.diag(2));
>> S(2, 1)
00
>> try, A(3, 1); catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[1, 2], A[2, end]
(2, 6)
julia> A[:, 2]
DM([2, 5])
julia> A[[2, 1], [1, 3]]
DM(
[[4, 6],
[1, 3]])
julia> ca.dim(A[2:1, :])
"0x3"
julia> x = ca.SX.sym("x", 2, 2);
julia> x[1, :]
SX([[x_0, x_2]])
julia> ca.DM(ca.Sparsity.diag(2))[2, 1]
DM(00)
julia> try A[3, 1]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2os
Definition at line 114 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::get | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Slice & | rr | ||
| ) | const |
Backs the Python expressions x[k] and x[sp]. The index addresses elements, not nonzeros, in column-major order: element (i, j) has linear index i + j*size1(). Negative indices count from the end; out-of-range indices raise an error.
Note that the result of a comparison such as A > 2 is a DM of zeros and ones, not a boolean mask: indexing with it uses those values as linear indices. Use a Sparsity pattern or the nz accessor for masking.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Linear index, Slice or list/matrix of indices |
| sp | Sparsity pattern of the same shape as the matrix |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[1], A[2], A[-1]
(DM(4), DM(2), DM(6))
>>> A[[0, 5]]
DM([1, 6])
>>> A[Sparsity.diag(2, 3)]
DM(
[[1, 00, 00],
[00, 5, 00]])
>>> S = DM(Sparsity.diag(2))
>>> S[1]
DM(00)
>>> A.get(False, Slice(0, 2))
DM([1, 4])
>>> try: A[6]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(2), A(3), A(end)
4
2
6
>> A([1 6])
[[1, 6]]
>> A(Sparsity.diag(2, 3))
[[1, 00, 00],
[00, 5, 00]]
>> S = DM(Sparsity.diag(2));
>> S(2)
00
>> A.get(true, [1; 2])
[1, 4]
>> try, A(7); catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[2], A[3], A[end]
(4, 2, 6)
julia> A[[1, 6]]
DM([1, 6])
julia> S = ca.DM(ca.Sparsity.diag(2));
julia> S[2]
DM(00)
julia> try A[7]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2or
Definition at line 144 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::get | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Slice & | rr, | ||
| const Matrix< casadi_int > & | cc | ||
| ) | const |
Backs the Python expression x[i, j]. Each of rr and cc is a scalar, a Slice or a list/vector of indices (any order, repetitions allowed, negative counts from the end). The result has len(rr) rows and len(cc) columns and keeps the sparsity of the selected entries. Two scalar indices give a 1-by-1 matrix (structurally empty when the entry is a structural zero). Out-of-range indices raise an error.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Row index, Slice or list/matrix of row indices |
| cc | Column index, Slice or list/matrix of column indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[0, 1], A[1, -1]
(DM(2), DM(6))
>>> A[:, 1]
DM([2, 5])
>>> A[[1, 0], [0, 2]]
DM(
[[4, 6],
[1, 3]])
>>> A[1:1, :].dim()
'0x3'
>>> x = SX.sym("x", 2, 2)
>>> x[0, :]
SX([[x_0, x_2]])
>>> DM(Sparsity.diag(2))[1, 0]
DM(00)
>>> try: A[2, 0]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(1, 2), A(2, end)
2
6
>> A(:, 2)
[2, 5]
>> A([2 1], [1 3])
[[4, 6],
[1, 3]]
>> B = A(2:1, :); disp(B.dim())
0x3
>> x = SX.sym('x', 2, 2);
>> x(1, :)
[[x_0, x_2]]
>> S = DM(Sparsity.diag(2));
>> S(2, 1)
00
>> try, A(3, 1); catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[1, 2], A[2, end]
(2, 6)
julia> A[:, 2]
DM([2, 5])
julia> A[[2, 1], [1, 3]]
DM(
[[4, 6],
[1, 3]])
julia> ca.dim(A[2:1, :])
"0x3"
julia> x = ca.SX.sym("x", 2, 2);
julia> x[1, :]
SX([[x_0, x_2]])
julia> ca.DM(ca.Sparsity.diag(2))[2, 1]
DM(00)
julia> try A[3, 1]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2os
Definition at line 107 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::get | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Slice & | rr, | ||
| const Slice & | cc | ||
| ) | const |
Backs the Python expression x[i, j]. Each of rr and cc is a scalar, a Slice or a list/vector of indices (any order, repetitions allowed, negative counts from the end). The result has len(rr) rows and len(cc) columns and keeps the sparsity of the selected entries. Two scalar indices give a 1-by-1 matrix (structurally empty when the entry is a structural zero). Out-of-range indices raise an error.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Row index, Slice or list/matrix of row indices |
| cc | Column index, Slice or list/matrix of column indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[0, 1], A[1, -1]
(DM(2), DM(6))
>>> A[:, 1]
DM([2, 5])
>>> A[[1, 0], [0, 2]]
DM(
[[4, 6],
[1, 3]])
>>> A[1:1, :].dim()
'0x3'
>>> x = SX.sym("x", 2, 2)
>>> x[0, :]
SX([[x_0, x_2]])
>>> DM(Sparsity.diag(2))[1, 0]
DM(00)
>>> try: A[2, 0]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(1, 2), A(2, end)
2
6
>> A(:, 2)
[2, 5]
>> A([2 1], [1 3])
[[4, 6],
[1, 3]]
>> B = A(2:1, :); disp(B.dim())
0x3
>> x = SX.sym('x', 2, 2);
>> x(1, :)
[[x_0, x_2]]
>> S = DM(Sparsity.diag(2));
>> S(2, 1)
00
>> try, A(3, 1); catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[1, 2], A[2, end]
(2, 6)
julia> A[:, 2]
DM([2, 5])
julia> A[[2, 1], [1, 3]]
DM(
[[4, 6],
[1, 3]])
julia> ca.dim(A[2:1, :])
"0x3"
julia> x = ca.SX.sym("x", 2, 2);
julia> x[1, :]
SX([[x_0, x_2]])
julia> ca.DM(ca.Sparsity.diag(2))[2, 1]
DM(00)
julia> try A[3, 1]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2os
Definition at line 89 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::get | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Sparsity & | sp | ||
| ) | const |
Backs the Python expressions x[k] and x[sp]. The index addresses elements, not nonzeros, in column-major order: element (i, j) has linear index i + j*size1(). Negative indices count from the end; out-of-range indices raise an error.
Note that the result of a comparison such as A > 2 is a DM of zeros and ones, not a boolean mask: indexing with it uses those values as linear indices. Use a Sparsity pattern or the nz accessor for masking.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Linear index, Slice or list/matrix of indices |
| sp | Sparsity pattern of the same shape as the matrix |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[1], A[2], A[-1]
(DM(4), DM(2), DM(6))
>>> A[[0, 5]]
DM([1, 6])
>>> A[Sparsity.diag(2, 3)]
DM(
[[1, 00, 00],
[00, 5, 00]])
>>> S = DM(Sparsity.diag(2))
>>> S[1]
DM(00)
>>> A.get(False, Slice(0, 2))
DM([1, 4])
>>> try: A[6]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(2), A(3), A(end)
4
2
6
>> A([1 6])
[[1, 6]]
>> A(Sparsity.diag(2, 3))
[[1, 00, 00],
[00, 5, 00]]
>> S = DM(Sparsity.diag(2));
>> S(2)
00
>> A.get(true, [1; 2])
[1, 4]
>> try, A(7); catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[2], A[3], A[end]
(4, 2, 6)
julia> A[[1, 6]]
DM([1, 6])
julia> S = ca.DM(ca.Sparsity.diag(2));
julia> S[2]
DM(00)
julia> try A[7]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2or
Definition at line 186 of file matrix_impl.hpp.
|
inlineinherited |
The pattern is stored in compressed column format: colind has size2()+1 entries, the nonzeros of column j are the entries colind(j) up to colind(j+1) (exclusive), and row(el) is the row index of nonzero el. Without argument, the full vectors are returned. Out-of-range indices raise an error.
>>> x = DM(Sparsity.diag(2), [5, 6]) >>> x.row(), x.colind() ([0, 1], [0, 1, 2]) >>> x.row(1), x.colind(2) (1, 2)
>> x = DM(Sparsity.diag(2), [5; 6]);
>> x.row(), x.colind()
0 1
0 1 2
>> fprintf('%d %d\n', x.row(1), x.colind(2))
1 2
julia> x = ca.DM(ca.Sparsity.diag(2), [5, 6]); julia> ca.row(x), ca.colind(x) ([0, 1], [0, 1, 2]) julia> ca.row(x, 1), ca.colind(x, 2) (1, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b8
Definition at line 603 of file generic_matrix.hpp.
| std::vector<Scalar> casadi::Matrix< Scalar >::get_elements | ( | ) | const |
Like nonzeros, but structural zeros are included as 0, so the list has numel() entries.
>>> DM(Sparsity.diag(2)).elements() [1.0, 0.0, 0.0, 1.0]
>> DM(Sparsity.diag(2)).elements() 1 0 0 1
julia> ca.elements(ca.DM(ca.Sparsity.diag(2)))
4-element Vector{Float64}:
1.0
0.0
0.0
1.0
Extra doc: https://github.com/casadi/casadi/wiki/L_1a3
Same as Function::free_sx. Only defined for SX.
>>> x = SX.sym("x"); y = SX.sym("y")
>>> SX.get_free(Function("f", [x], [x + y], {"allow_free": True}))
[SX(y)]
>> x = SX.sym('x'); y = SX.sym('y');
>> v = SX.get_free(Function('f', {x}, {x + y}, struct('allow_free', true)));
>> v{1}
y
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> ca.SX.get_free(ca.Function("f", [x], [x + y], Dict("allow_free" => true)))
1-element Vector{SX}:
SX(y)
Extra doc: https://github.com/casadi/casadi/wiki/L_19e
Same as Function::sx_in. Only defined for SX.
>>> x = SX.sym("x")
>>> SX.get_input(Function("f", [x], [x + 1]))
[SX(x)]
>> x = SX.sym('x');
>> v = SX.get_input(Function('f', {x}, {x + 1}));
>> numel(v), v{1}
1
x
julia> x = ca.SX.sym("x");
julia> ca.SX.get_input(ca.Function("f", [x], [x + 1]))
1-element Vector{SX}:
SX(x)
Extra doc: https://github.com/casadi/casadi/wiki/L_19d
|
static |
Extra doc: https://github.com/casadi/casadi/wiki/L_19c
| std::vector< A > casadi::Matrix< Scalar >::get_nonzeros | ( | ) | const |
Implementation of Matrix::get_nonzeros (in public API)
Returns floats for DM and 1-by-1 SX objects for SX. Structural zeros are skipped.
>>> DM([[1, 2], [3, 4]]).nonzeros()
[1.0, 3.0, 2.0, 4.0]
>>> DM(Sparsity.diag(2)).nonzeros(), DM(2, 0).nonzeros()
([1.0, 1.0], [])
>>> SX.sym("x", 2).nonzeros()
[SX(x_0), SX(x_1)]
>> DM([1 2; 3 4]).nonzeros()
1 3 2 4
>> DM(Sparsity.diag(2)).nonzeros(), size(DM(2, 0).nonzeros())
1 1
1 0
>> v = SX.sym('x', 2).nonzeros();
>> class(v), v{2}
cell
x_1
julia> ca.nonzeros(ca.DM([1 2; 3 4]))
4-element Vector{Float64}:
1.0
3.0
2.0
4.0
julia> ca.nonzeros(ca.DM(ca.Sparsity.diag(2))), ca.nonzeros(ca.DM(2, 0))
([1.0, 1.0], Float64[])
Extra doc: https://github.com/casadi/casadi/wiki/L_1a2
Definition at line 4699 of file matrix_decl.hpp.
| void casadi::Matrix< Scalar >::get_nz | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | k | ||
| ) | const |
Backs the Python expression x.nz[k]. Index k runs over the nonzeros in column-major order, 0 <= k < nnz(); negative values count from the end and out-of-range values raise an error. Structural zeros are skipped, so for a dense matrix this coincides with linear indexing. The result is a column vector shaped like the index (a row vector when indexing a row vector; a matrix for a matrix index). Iterating over x.nz in Python yields the nonzeros one by one.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| k | Nonzero index, Slice or list/matrix of indices |
>>> S = DM(Sparsity.diag(3)); S[0, 2] = 7
>>> S.nz[:]
DM([1, 1, 7, 1])
>>> S.nz[2], S.nz[-1], len(S.nz)
(DM(7), DM(1), 4)
>>> x = SX.sym("x", Sparsity.lower(2))
>>> x.nz[[0, 2]]
SX([x_0, x_2])
>>> SX.sym("e", 2, 0).nz[:].dim()
'0x1'
>>> try: S.nz[4]
... except Exception as e: print("error")
error
>> S = DM(Sparsity.diag(3)); S(1, 3) = 7;
>> S.get_nz(true, Slice())
[1, 1, 7, 1]
>> S.get_nz(true, 3), S.get_nz(true, [1; 3])
7
[1, 7]
>> x = SX.sym('x', Sparsity.lower(2));
>> x.get_nz(true, [1; 3])
[x_0, x_2]
>> SX.sym('e', 2, 0).get_nz(true, Slice()).dim()
0x1
>> try, S.get_nz(true, 5); catch e, disp('error'); end
error
julia> S = ca.DM(ca.Sparsity.diag(3)); S[1, 3] = 7;
julia> S.nz[:]
DM([1, 1, 7, 1])
julia> S.nz[3], S.nz[end], length(S.nz)
(7, 1, 4)
julia> x = ca.SX.sym("x", ca.Sparsity.lower(2));
julia> x.nz[[1, 3]]
SX([x_0, x_2])
julia> ca.dim(ca.SX.sym("e", 2, 0).nz[:])
"0x1"
julia> try S.nz[5]; catch e; println(typeof(e)) end
BoundsError
Extra doc: https://github.com/casadi/casadi/wiki/L_2ov
Definition at line 416 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::get_nz | ( | Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Slice & | k | ||
| ) | const |
Backs the Python expression x.nz[k]. Index k runs over the nonzeros in column-major order, 0 <= k < nnz(); negative values count from the end and out-of-range values raise an error. Structural zeros are skipped, so for a dense matrix this coincides with linear indexing. The result is a column vector shaped like the index (a row vector when indexing a row vector; a matrix for a matrix index). Iterating over x.nz in Python yields the nonzeros one by one.
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| k | Nonzero index, Slice or list/matrix of indices |
>>> S = DM(Sparsity.diag(3)); S[0, 2] = 7
>>> S.nz[:]
DM([1, 1, 7, 1])
>>> S.nz[2], S.nz[-1], len(S.nz)
(DM(7), DM(1), 4)
>>> x = SX.sym("x", Sparsity.lower(2))
>>> x.nz[[0, 2]]
SX([x_0, x_2])
>>> SX.sym("e", 2, 0).nz[:].dim()
'0x1'
>>> try: S.nz[4]
... except Exception as e: print("error")
error
>> S = DM(Sparsity.diag(3)); S(1, 3) = 7;
>> S.get_nz(true, Slice())
[1, 1, 7, 1]
>> S.get_nz(true, 3), S.get_nz(true, [1; 3])
7
[1, 7]
>> x = SX.sym('x', Sparsity.lower(2));
>> x.get_nz(true, [1; 3])
[x_0, x_2]
>> SX.sym('e', 2, 0).get_nz(true, Slice()).dim()
0x1
>> try, S.get_nz(true, 5); catch e, disp('error'); end
error
julia> S = ca.DM(ca.Sparsity.diag(3)); S[1, 3] = 7;
julia> S.nz[:]
DM([1, 1, 7, 1])
julia> S.nz[3], S.nz[end], length(S.nz)
(7, 1, 4)
julia> x = ca.SX.sym("x", ca.Sparsity.lower(2));
julia> x.nz[[1, 3]]
SX([x_0, x_2])
julia> ca.dim(ca.SX.sym("e", 2, 0).nz[:])
"0x1"
julia> try S.nz[5]; catch e; println(typeof(e)) end
BoundsError
Extra doc: https://github.com/casadi/casadi/wiki/L_2ov
Definition at line 404 of file matrix_impl.hpp.
| SX casadi::SX::get_output | ( | casadi_int | oind | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_28i
|
static |
Definition at line 49 of file matrix_impl.hpp.
|
inlineinherited |
The pattern is stored in compressed column format: colind has size2()+1 entries, the nonzeros of column j are the entries colind(j) up to colind(j+1) (exclusive), and row(el) is the row index of nonzero el. Without argument, the full vectors are returned. Out-of-range indices raise an error.
>>> x = DM(Sparsity.diag(2), [5, 6]) >>> x.row(), x.colind() ([0, 1], [0, 1, 2]) >>> x.row(1), x.colind(2) (1, 2)
>> x = DM(Sparsity.diag(2), [5; 6]);
>> x.row(), x.colind()
0 1
0 1 2
>> fprintf('%d %d\n', x.row(1), x.colind(2))
1 2
julia> x = ca.DM(ca.Sparsity.diag(2), [5, 6]); julia> ca.row(x), ca.colind(x) ([0, 1], [0, 1, 2]) julia> ca.row(x, 1), ca.colind(x, 2) (1, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b8
Definition at line 602 of file generic_matrix.hpp.
|
static |
Definition at line 55 of file matrix_impl.hpp.
| Sparsity casadi::Matrix< Scalar >::get_sparsity | ( | ) | const |
Returns a copy of the Sparsity object; patterns are reference counted, so this is cheap.
>>> DM(Sparsity.diag(2)).sparsity() Sparsity(2x2,2nz)
>> DM(Sparsity.diag(2)).sparsity() 2x2,2nz
julia> ca.sparsity(ca.DM(ca.Sparsity.diag(2))) Sparsity(2x2,2nz)
Extra doc: https://github.com/casadi/casadi/wiki/L_19j
| std::string casadi::Matrix< Scalar >::get_str | ( | bool | more = false | ) | const |
|
static |
Definition at line 52 of file matrix_impl.hpp.
|
staticinherited |
Functions called by friend functions defined here
| bool casadi::Matrix< Scalar >::has_nz | ( | casadi_int | rr, |
| casadi_int | cc | ||
| ) | const |
Looks only at the sparsity pattern; a stored numerical zero still counts as a nonzero. Negative indices count from the end. An index past the end raises an error.
>>> S = DM(Sparsity.diag(2)) >>> S.has_nz(0, 0), S.has_nz(0, 1), DM([0, 1]).has_nz(0, 0) (True, False, True)
>> S = DM(Sparsity.diag(2));
>> fprintf('%d %d %d\n', S.has_nz(0, 0), S.has_nz(0, 1), DM([0; 1]).has_nz(0, 0))
1 0 1
julia> S = ca.DM(ca.Sparsity.diag(2)); julia> ca.has_nz(S, 0, 0), ca.has_nz(S, 0, 1), ca.has_nz(ca.DM([0, 1]), 0, 0) (true, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_2op
Definition at line 75 of file matrix_impl.hpp.
| bool casadi::SX::has_output | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_28l
| bool casadi::Matrix< Scalar >::has_zeros | ( | ) | const |
For SX only entries that are the constant 0 count. Use sparsify to remove them.
>>> DM([1, 0]).has_zeros(), DM([1, 2]).has_zeros(), DM(2, 2).has_zeros()
(True, False, False)
>>> x = SX.sym("x")
>>> vertcat(x, 0).has_zeros(), vertcat(x, x * 0).has_zeros()
(True, True)
>> fprintf('%d %d\n', DM([1; 0]).has_zeros(), DM([1; 2]).has_zeros())
1 0
>> DM(2, 2).has_zeros()
0
>> x = SX.sym('x');
>> fprintf('%d %d\n', vertcat(x, 0).has_zeros(), vertcat(x, x * 0).has_zeros())
1 1
julia> ca.has_zeros(ca.DM([1, 0])), ca.has_zeros(ca.DM([1, 2])), ca.has_zeros(ca.DM(2, 2))
(true, false, false)
julia> x = ca.SX.sym("x");
julia> ca.has_zeros([x; 0]), ca.has_zeros([x; x * 0])
(true, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_1a1
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern.
>>> DM.inf(), DM.inf(2, 1).is_inf() (DM(inf), True) >>> DM.inf(Sparsity.diag(2)) DM( [[inf, 00], [00, inf]])
>> DM.inf(), DM.inf(2, 1).is_inf() inf 1 >> DM.inf(Sparsity.diag(2)) [[inf, 00], [00, inf]]
julia> ca.DM.inf(), ca.is_inf(ca.DM.inf(2, 1)) (inf, true) julia> ca.DM.inf(ca.Sparsity.diag(2)) DM( [[inf, 00], [00, inf]])
Extra doc: https://github.com/casadi/casadi/wiki/L_19k
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern.
>>> DM.inf(), DM.inf(2, 1).is_inf() (DM(inf), True) >>> DM.inf(Sparsity.diag(2)) DM( [[inf, 00], [00, inf]])
>> DM.inf(), DM.inf(2, 1).is_inf() inf 1 >> DM.inf(Sparsity.diag(2)) [[inf, 00], [00, inf]]
julia> ca.DM.inf(), ca.is_inf(ca.DM.inf(2, 1)) (inf, true) julia> ca.DM.inf(ca.Sparsity.diag(2)) DM( [[inf, 00], [00, inf]])
Extra doc: https://github.com/casadi/casadi/wiki/L_19k
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern.
>>> DM.inf(), DM.inf(2, 1).is_inf() (DM(inf), True) >>> DM.inf(Sparsity.diag(2)) DM( [[inf, 00], [00, inf]])
>> DM.inf(), DM.inf(2, 1).is_inf() inf 1 >> DM.inf(Sparsity.diag(2)) [[inf, 00], [00, inf]]
julia> ca.DM.inf(), ca.is_inf(ca.DM.inf(2, 1)) (inf, true) julia> ca.DM.inf(ca.Sparsity.diag(2)) DM( [[inf, 00], [00, inf]])
Extra doc: https://github.com/casadi/casadi/wiki/L_19k
| Dict CASADI_EXPORT casadi::SX::info | ( | ) | const |
>>> sorted(DM([1, 2]).info().keys()) ['data', 'sparsity']
>> s = DM([1; 2]).info(); >> strjoin(sort(fieldnames(s))', ' ') data sparsity
julia> sort(collect(keys(ca.info(ca.DM([1, 2])))))
2-element Vector{String}:
"data"
"sparsity"
Extra doc: https://github.com/casadi/casadi/wiki/L_2p8
| bool casadi::SX::is_call | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_28j
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1b5
Definition at line 517 of file generic_matrix.hpp.
| bool casadi::SX::is_commutative | ( | ) | const |
Only defined if symbolic scalar.
Extra doc: https://github.com/casadi/casadi/wiki/L_19q
| bool casadi::Matrix< Scalar >::is_constant | ( | ) | const |
Always true for DM. For SX, true when no entry depends on a symbol; the simplifications make x*0 and x-x constant. A false negative is possible for expressions that are constant only in value, e.g. x - x after other operations.
>>> x = SX.sym("x")
>>> SX([1, 2]).is_constant(), x.is_constant(), (x * 0).is_constant()
(True, False, True)
>>> vertcat(x, 1).is_constant(), SX.sym("e", 2, 0).is_constant()
(False, True)
>> x = SX.sym('x'); z = x * 0;
>> fprintf('%d %d %d\n', SX([1; 2]).is_constant(), x.is_constant(), z.is_constant())
1 0 1
>> fprintf('%d %d\n', vertcat(x, 1).is_constant(), SX.sym('e', 2, 0).is_constant())
0 1
julia> x = ca.SX.sym("x");
julia> ca.is_constant(ca.SX([1, 2])), ca.is_constant(x), ca.is_constant(x * 0)
(true, false, true)
julia> ca.is_constant([x; 1]), ca.is_constant(ca.SX.sym("e", 2, 0))
(false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_19v
|
inlineinherited |
Based on the sparsity pattern only: stored numerical zeros still count as nonzeros. Empty matrices are dense.
>>> DM.zeros(2, 2).is_dense(), DM(2, 2).is_dense(), DM(0, 3).is_dense() (True, False, True)
>> Z = DM.zeros(2, 2);
>> fprintf('%d %d %d\n', Z.is_dense(), DM(2, 2).is_dense(), DM(0, 3).is_dense())
1 0 1
julia> ca.is_dense(ca.DM.zeros(2, 2)), ca.is_dense(ca.DM(2, 2)), ca.is_dense(ca.DM(0, 3)) (true, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b0
Definition at line 434 of file generic_matrix.hpp.
|
inlineinherited |
With both true, only a 0-by-0 matrix counts as empty.
>>> DM(0, 3).is_empty(), DM(0, 3).is_empty(True), DM(0, 0).is_empty(True) (True, False, True) >>> DM(1, 1).is_empty() False
>> E = DM(0, 3);
>> fprintf('%d %d %d\n', E.is_empty(), E.is_empty(true), DM(0, 0).is_empty(true))
1 0 1
>> DM(1, 1).is_empty()
0
julia> E = ca.DM(0, 3); julia> ca.is_empty(E), ca.is_empty(E, true), ca.is_empty(ca.DM(0, 0), true) (true, false, true) julia> ca.is_empty(ca.DM(1, 1)) false
Extra doc: https://github.com/casadi/casadi/wiki/L_1az
Definition at line 402 of file generic_matrix.hpp.
| bool casadi::Matrix< Scalar >::is_eye | ( | ) | const |
are possible)
Extra doc: https://github.com/casadi/casadi/wiki/L_1a0
| bool casadi::Matrix< Scalar >::is_half | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_2en
| bool casadi::Matrix< Scalar >::is_inf | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_2e9
| bool casadi::Matrix< Scalar >::is_integer | ( | ) | const |
(note that false negative answers are possible)
Extra doc: https://github.com/casadi/casadi/wiki/L_19w
| bool casadi::SX::is_leaf | ( | ) | const |
Only defined if symbolic scalar.
Extra doc: https://github.com/casadi/casadi/wiki/L_19p
| bool casadi::Matrix< Scalar >::is_minus_inf | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_2ea
| bool casadi::Matrix< Scalar >::is_minus_one | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_19z
| bool casadi::Matrix< Scalar >::is_nonnegative | ( | ) | const |
(note that false negative answers are possible)
Extra doc: https://github.com/casadi/casadi/wiki/L_2eb
| bool casadi::Matrix< Scalar >::is_one | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_19y
| bool casadi::SX::is_op | ( | casadi_int | op | ) | const |
| bool casadi::SX::is_output | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_28k
| bool casadi::SX::is_regular | ( | ) | const |
Structural zeros are ignored. For SX, every entry must be a constant: the check raises an error when it reaches a symbolic entry (an infinite constant found before it still gives false).
>>> DM([1, 2]).is_regular(), DM([1, inf]).is_regular(), DM.nan(2, 2).is_regular()
(True, False, False)
>>> DM(2, 2).is_regular(), SX([1, 2]).is_regular()
(True, True)
>>> try: SX.sym("x").is_regular()
... except Exception as e: print("error")
error
>> fprintf('%d %d\n', DM([1; 2]).is_regular(), DM([1; inf]).is_regular())
1 0
>> fprintf('%d %d\n', DM.nan(2, 2).is_regular(), DM(2, 2).is_regular())
0 1
>> SX([1; 2]).is_regular()
1
>> try, SX.sym('x').is_regular(); catch e, disp('error'); end
error
julia> ca.is_regular(ca.DM([1, 2])), ca.is_regular(ca.DM([1, Inf]))
(true, false)
julia> ca.is_regular(ca.DM.nan(2, 2))
false
julia> ca.is_regular(ca.DM(2, 2)), ca.is_regular(ca.SX([1, 2]))
(true, true)
julia> try ca.is_regular(ca.SX.sym("x")); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2p5
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1b4
Definition at line 512 of file generic_matrix.hpp.
|
inherited |
| scalar_and_dense | When true, a 1-by-1 matrix with a structural zero does not count |
>>> x = SX.sym("x", Sparsity(1, 1))
>>> x.is_scalar(), x.is_scalar(True), SX.sym("y").is_scalar(True)
(True, False, True)
>> x = SX.sym('x', Sparsity(1, 1));
>> fprintf('%d %d %d\n', x.is_scalar(), x.is_scalar(true), SX.sym('y').is_scalar(true))
1 0 1
julia> x = ca.SX.sym("x", ca.Sparsity(1, 1));
julia> ca.is_scalar(x), ca.is_scalar(x, true), ca.is_scalar(ca.SX.sym("y"), true)
(true, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b1
| bool casadi::SX::is_smooth | ( | ) | const |
False when any node is a non-smooth operation such as floor, ceil, sign, a comparison or if_else. Operations such as fabs, fmin and fmax count as smooth. Always true for DM.
>>> x = SX.sym("x")
>>> sin(x).is_smooth(), fabs(x).is_smooth(), floor(x).is_smooth()
(True, True, False)
>>> if_else(x > 0, x, 0).is_smooth(), (x > 0).is_smooth(), DM(1).is_smooth()
(False, False, True)
>> x = SX.sym('x');
>> fprintf('%d %d %d\n', sin(x).is_smooth(), abs(x).is_smooth(), floor(x).is_smooth())
1 1 0
>> c = x > 0; b = if_else(c, x, 0);
>> fprintf('%d %d %d\n', b.is_smooth(), c.is_smooth(), DM(1).is_smooth())
0 0 1
julia> x = ca.SX.sym("x");
julia> ca.is_smooth(sin(x)), ca.is_smooth(abs(x)), ca.is_smooth(floor(x))
(true, true, false)
julia> ca.is_smooth(ifelse(x > 0, x, 0)), ca.is_smooth(x > 0), ca.is_smooth(ca.DM(1))
(false, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_19o
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1b2
Definition at line 470 of file generic_matrix.hpp.
| bool casadi::SX::is_symbolic | ( | ) | const |
Check if an expression is a pure symbol. Pure means that no operations should happen on the symbol (not even vec, transpose, index, concatenation, ...) By consequence, a slice of a vector-shaped MX symbol is not a symbol. However, the SX type is really a container format with scalar entries. Therefore, a slice of a vector-shaped SX symbol is still a symbol.
Sparse matrices invariable return false
\seealso is_valid_input
Extra doc: https://github.com/casadi/casadi/wiki/L_19r
|
inlineinherited |
Decided on the sparsity pattern alone, see is_triu.
Extra doc: https://github.com/casadi/casadi/wiki/L_1b7
Definition at line 560 of file generic_matrix.hpp.
|
inlineinherited |
Decided on the sparsity pattern alone: all structural nonzeros must lie on or above the diagonal. A dense matrix with numerical zeros below the diagonal is not upper triangular. Also defined for non-square matrices.
>>> DM(Sparsity.upper(3), 1).is_triu(), DM.zeros(2, 2).is_triu(), DM(2, 2).is_triu() (True, False, True)
>> U = DM(Sparsity.upper(3), 1);
>> fprintf('%d %d %d\n', U.is_triu(), DM.zeros(2, 2).is_triu(), DM(2, 2).is_triu())
1 0 1
julia> U = ca.DM(ca.Sparsity.upper(3), 1); julia> ca.is_triu(U), ca.is_triu(ca.DM.zeros(2, 2)), ca.is_triu(ca.DM(2, 2)) (true, false, true)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b6
Definition at line 551 of file generic_matrix.hpp.
| bool casadi::SX::is_valid_input | ( | ) | const |
is_valid_input is more forgiving than is_symbolic. Some compositions are allowed: vec, vertcat.
Sparse matrices can return true if all non-zero elements are symbolic
\seealso is_symbolic
Extra doc: https://github.com/casadi/casadi/wiki/L_19s
| bool casadi::Matrix< Scalar >::is_value | ( | double | val | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_2eo
|
inlineinherited |
True when size1() or size2() is one, so scalars and n-by-1 or 1-by-n empties count. A 0-by-0 matrix does not.
>>> DM(3, 1).is_vector(), DM(1, 3).is_vector(), DM(1, 1).is_vector() (True, True, True) >>> DM(3, 3).is_vector(), DM(0, 1).is_vector(), DM(0, 0).is_vector() (False, True, False)
>> fprintf('%d %d %d\n', DM(3, 1).is_vector(), DM(1, 3).is_vector(), DM(1, 1).is_vector())
1 1 1
>> fprintf('%d %d %d\n', DM(3, 3).is_vector(), DM(0, 1).is_vector(), DM(0, 0).is_vector())
0 1 0
julia> ca.is_vector(ca.DM(3, 1)), ca.is_vector(ca.DM(1, 3)), ca.is_vector(ca.DM(1, 1)) (true, true, true) julia> ca.is_vector(ca.DM(3, 3)), ca.is_vector(ca.DM(0, 1)), ca.is_vector(ca.DM(0, 0)) (false, true, false)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b3
Definition at line 507 of file generic_matrix.hpp.
| bool casadi::Matrix< Scalar >::is_zero | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_19x
|
staticinherited |
Functions called by friend functions defined here
|
staticinherited |
Functions called by friend functions defined here
|
staticinherited |
|
staticinherited |
Functions called by friend functions defined here
| casadi_int casadi::SX::n_dep | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_1aa
| std::string casadi::SX::name | ( | ) | const |
Raises an error for a non-scalar, for an expression that is not a pure symbol, and for DM.
>>> SX.sym("x").name(), SX.sym("v", 2)[1].name()
('x', 'v_1')
>> v = SX.sym('v', 2); v2 = v(2);
>> fprintf('%s %s\n', SX.sym('x').name(), v2.name())
x v_1
julia> ca.name(ca.SX.sym("x")), ca.name(ca.SX.sym("v", 2)[2])
("x", "v_1")
Extra doc: https://github.com/casadi/casadi/wiki/L_1a8
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern. Useful as a placeholder that is easy to detect with is_regular.
>>> DM.nan(), DM.nan((2, 1)).dim() (DM(nan), '2x1') >>> DM.nan(2, 2).is_regular() False
>> DM.nan(), DM.nan([2 1]).dim() nan 2x1 >> DM.nan(2, 2).is_regular() 0
julia> ca.DM.nan(), ca.dim(ca.DM.nan(2, 1)) (nan, "2x1") julia> ca.is_regular(ca.DM.nan(2, 2)) false
Extra doc: https://github.com/casadi/casadi/wiki/L_19l
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern. Useful as a placeholder that is easy to detect with is_regular.
>>> DM.nan(), DM.nan((2, 1)).dim() (DM(nan), '2x1') >>> DM.nan(2, 2).is_regular() False
>> DM.nan(), DM.nan([2 1]).dim() nan 2x1 >> DM.nan(2, 2).is_regular() 0
julia> ca.DM.nan(), ca.dim(ca.DM.nan(2, 1)) (nan, "2x1") julia> ca.is_regular(ca.DM.nan(2, 2)) false
Extra doc: https://github.com/casadi/casadi/wiki/L_19l
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern. Useful as a placeholder that is easy to detect with is_regular.
>>> DM.nan(), DM.nan((2, 1)).dim() (DM(nan), '2x1') >>> DM.nan(2, 2).is_regular() False
>> DM.nan(), DM.nan([2 1]).dim() nan 2x1 >> DM.nan(2, 2).is_regular() 0
julia> ca.DM.nan(), ca.dim(ca.DM.nan(2, 1)) (nan, "2x1") julia> ca.is_regular(ca.DM.nan(2, 2)) false
Extra doc: https://github.com/casadi/casadi/wiki/L_19l
|
inherited |
Counts the entries present in the sparsity pattern. Entries that are stored but numerically zero still count; structural zeros (not stored) do not. For a dense matrix this equals numel().
>>> DM.eye(3).nnz(), DM.ones(3, 3).nnz(), DM(3, 3).nnz()
(3, 9, 0)
>>> DM([[1, 0], [0, 2]]).nnz()
4
>>> MX.sym("x", 2, 0).nnz()
0
>> fprintf('%d %d %d\n', DM.eye(3).nnz(), DM.ones(3, 3).nnz(), DM(3, 3).nnz())
3 9 0
>> DM([1 0; 0 2]).nnz()
4
>> MX.sym('x', 2, 0).nnz()
0
julia> ca.nnz(ca.DM.eye(3)), ca.nnz(ca.DM.ones(3, 3)), ca.nnz(ca.DM(3, 3))
(3, 9, 0)
julia> ca.nnz(ca.DM([1 0; 0 2]))
4
julia> ca.nnz(ca.MX.sym("x", 2, 0))
0
Extra doc: https://github.com/casadi/casadi/wiki/L_1an
|
inherited |
Also defined for non-square matrices.
>>> DM.ones(3, 3).nnz_diag(), DM.eye(3).nnz_diag(), DM.ones(2, 3).nnz_diag() (3, 3, 2)
>> A = DM.ones(3, 3); I = DM.eye(3); B = DM.ones(2, 3);
>> fprintf('%d %d %d\n', A.nnz_diag(), I.nnz_diag(), B.nnz_diag())
3 3 2
julia> A = ca.DM.ones(3, 3); I = ca.DM.eye(3); B = ca.DM.ones(2, 3); julia> ca.nnz_diag(A), ca.nnz_diag(I), ca.nnz_diag(B) (3, 3, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1aq
|
inherited |
>>> DM.ones(3, 3).nnz_lower(), DM.eye(3).nnz_lower(), DM.ones(2, 3).nnz_lower() (6, 3, 3)
>> A = DM.ones(3, 3); I = DM.eye(3); B = DM.ones(2, 3);
>> fprintf('%d %d %d\n', A.nnz_lower(), I.nnz_lower(), B.nnz_lower())
6 3 3
julia> A = ca.DM.ones(3, 3); I = ca.DM.eye(3); B = ca.DM.ones(2, 3); julia> ca.nnz_lower(A), ca.nnz_lower(I), ca.nnz_lower(B) (6, 3, 3)
Extra doc: https://github.com/casadi/casadi/wiki/L_1ao
|
inherited |
>>> DM.ones(3, 3).nnz_upper(), DM.eye(3).nnz_upper(), DM.ones(2, 3).nnz_upper() (6, 3, 5)
>> A = DM.ones(3, 3); I = DM.eye(3); B = DM.ones(2, 3);
>> fprintf('%d %d %d\n', A.nnz_upper(), I.nnz_upper(), B.nnz_upper())
6 3 5
julia> A = ca.DM.ones(3, 3); I = ca.DM.eye(3); B = ca.DM.ones(2, 3); julia> ca.nnz_upper(A), ca.nnz_upper(I), ca.nnz_upper(B) (6, 3, 5)
Extra doc: https://github.com/casadi/casadi/wiki/L_1ap
|
inherited |
Counts all entries, structural zeros included.
>>> DM.eye(3).numel(), MX.sym("x", 2, 0).numel(), SX.sym("x").numel()
(9, 0, 1)
>> fprintf('%d %d %d\n', DM.eye(3).numel(), MX.sym('x', 2, 0).numel(), SX.sym('x').numel())
9 0 1
julia> ca.numel(ca.DM.eye(3)), ca.numel(ca.MX.sym("x", 2, 0)), ca.numel(ca.SX.sym("x"))
(9, 0, 1)
julia> length(ca.DM.eye(3))
9
Extra doc: https://github.com/casadi/casadi/wiki/L_1ar
|
inlinestaticinherited |
ones(sp) sets every structural nonzero of sp to one; other entries stay structurally zero.
>>> DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) >>> DM.ones(Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
>> DM.ones(2, 3) [[1, 1, 1], [1, 1, 1]] >> DM.ones(Sparsity.diag(2)) [[1, 00], [00, 1]]
julia> ca.DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) julia> ca.DM.ones(ca.Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1di
Definition at line 5206 of file generic_matrix.hpp.
|
inlinestaticinherited |
ones(sp) sets every structural nonzero of sp to one; other entries stay structurally zero.
>>> DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) >>> DM.ones(Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
>> DM.ones(2, 3) [[1, 1, 1], [1, 1, 1]] >> DM.ones(Sparsity.diag(2)) [[1, 00], [00, 1]]
julia> ca.DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) julia> ca.DM.ones(ca.Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1di
Definition at line 5209 of file generic_matrix.hpp.
|
inlinestaticinherited |
ones(sp) sets every structural nonzero of sp to one; other entries stay structurally zero.
>>> DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) >>> DM.ones(Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
>> DM.ones(2, 3) [[1, 1, 1], [1, 1, 1]] >> DM.ones(Sparsity.diag(2)) [[1, 00], [00, 1]]
julia> ca.DM.ones(2, 3) DM( [[1, 1, 1], [1, 1, 1]]) julia> ca.DM.ones(ca.Sparsity.diag(2)) DM( [[1, 00], [00, 1]])
Extra doc: https://github.com/casadi/casadi/wiki/L_1di
Definition at line 5210 of file generic_matrix.hpp.
| casadi_int casadi::SX::op | ( | ) | const |
|
explicit |
>>> int(DM(3.7)) 3
>> DM(3.7).to_int() 3
julia> ca.to_int(ca.DM(3.7)) 3
Extra doc: https://github.com/casadi/casadi/wiki/L_1a6
|
explicit |
Other shapes raise an error. A symbolic SX entry converts to nan without an error.
>>> float(DM(2.5)), float(SX(3))
(2.5, 3.0)
>>> try: float(DM([1, 2]))
... except Exception as e: print("error")
error
>> fprintf('%g %g\n', full(DM(2.5)), SX(3).to_double())
2.5 3
>> try, DM([1; 2]).to_double(); catch e, disp('error'); end
error
julia> Float64(ca.DM(2.5)), Float64(ca.SX(3))
(2.5, 3.0)
julia> try Float64(ca.DM([1, 2])); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_1a5
| Matrix<Scalar> casadi::Matrix< Scalar >::operator+ | ( | ) | const |
| Matrix<Scalar> casadi::Matrix< Scalar >::operator- | ( | ) | const |
| void casadi::Matrix< Scalar >::print_dense | ( | std::ostream & | stream, |
| bool | truncate = true |
||
| ) | const |
Shared SX subexpressions are printed first as @1=..., @2=....
| truncate | Print only 3 leading and trailing rows and columns when the matrix has more than 1000 elements and at least 7 rows or columns |
>>> DM(Sparsity.diag(2)).print_dense() [[1, 00], [00, 1]]
julia> ca.print_dense(ca.DM(ca.Sparsity.diag(2))) [[1, 00], [00, 1]]
Extra doc: https://github.com/casadi/casadi/wiki/L_2p2
Definition at line 691 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::print_scalar | ( | std::ostream & | stream | ) | const |
A structurally empty 1-by-1 matrix prints as 00; other shapes raise an error.
>>> DM(3).print_scalar() 3 >>> DM(1, 1).print_scalar() 00
julia> ca.print_scalar(ca.DM(3)) 3 julia> ca.print_scalar(ca.DM(1, 1)) 00
Extra doc: https://github.com/casadi/casadi/wiki/L_2p0
Definition at line 619 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::print_sparse | ( | std::ostream & | stream, |
| bool | truncate = true |
||
| ) | const |
| truncate | Print only the first and last 3 nonzeros when there are more than 1000 |
>>> DM(Sparsity.diag(2)).print_sparse() sparse: 2-by-2, 2 nnz (0, 0) -> 1 (1, 1) -> 1 >>> DM(2, 2).print_sparse() all zero sparse: 2-by-2
julia> ca.print_sparse(ca.DM(ca.Sparsity.diag(2))) sparse: 2-by-2, 2 nnz (0, 0) -> 1 (1, 1) -> 1 julia> ca.print_sparse(ca.DM(2, 2)) all zero sparse: 2-by-2
Extra doc: https://github.com/casadi/casadi/wiki/L_2p3
Definition at line 696 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::print_split | ( | std::vector< std::string > & | nz, |
| std::vector< std::string > & | inter | ||
| ) | const |
Returns two lists: one string per nonzero (in storage order) and the definitions of the intermediate expressions "@1", "@2", ... that the nonzero strings refer to (always empty for DM).
>>> DM([[1, 2], [3, 4]]).print_split()
(['1', '3', '2', '4'], [])
>>> x = SX.sym("x"); y = SX.sym("y")
>>> e = x * y
>>> vertcat(e + 1, e - 1).print_split()
(['(@1+@2)', '(@1-@2)'], ['(x*y)', '1'])
>> [nz, inter] = DM([1 2; 3 4]).print_split();
>> disp(strjoin(cellstr(nz)', ' ')), disp(isempty(inter))
1 3 2 4
1
>> x = SX.sym('x'); y = SX.sym('y');
>> e = x * y;
>> [nz, inter] = vertcat(e + 1, e - 1).print_split();
>> disp(strjoin(cellstr(nz)', ' ')), disp(strjoin(cellstr(inter)', ' '))
(@1+@2) (@1-@2)
(x*y) 1
julia> ca.print_split(ca.DM([1 2; 3 4]))
(["1", "3", "2", "4"], String[])
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> e = x * y;
julia> ca.print_split([e + 1; e - 1])
(["(@1+@2)", "(@1-@2)"], ["(x*y)", "1"])
Extra doc: https://github.com/casadi/casadi/wiki/L_2oy
Definition at line 701 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::print_vector | ( | std::ostream & | stream, |
| bool | truncate = true |
||
| ) | const |
Only column vectors are accepted; a row vector raises an error.
| truncate | Print only the first and last 3 entries of vectors longer than 1000 |
>>> DM(Sparsity.unit(3, 1)).print_vector() [00, 1, 00]
julia> ca.print_vector(ca.DM(ca.Sparsity.unit(3, 1))) [00, 1, 00]
Extra doc: https://github.com/casadi/casadi/wiki/L_2p1
Definition at line 641 of file matrix_impl.hpp.
| Matrix<Scalar> casadi::Matrix< Scalar >::printme | ( | const Matrix< Scalar > & | y | ) | const |
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern, in which case only the structural nonzeros get a random value. Only available for DM.
>>> DM.rand(2, 3).dim(), DM.rand().dim(), DM.rand(Sparsity.diag(3)).nnz()
('2x3', '1x1', 3)
>>> try: SX.rand(2)
... except Exception as e: print("error")
error
>> fprintf('%s %s\n', DM.rand(2, 3).dim(), DM.rand().dim())
2x3 1x1
>> DM.rand(Sparsity.diag(3)).nnz()
3
>> try, SX.rand(2); catch e, disp('error'); end
error
julia> ca.dim(ca.DM.rand(2, 3)), ca.dim(ca.DM.rand())
("2x3", "1x1")
julia> ca.nnz(ca.DM.rand(ca.Sparsity.diag(3)))
3
julia> try ca.SX.rand(2); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_1ab
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern, in which case only the structural nonzeros get a random value. Only available for DM.
>>> DM.rand(2, 3).dim(), DM.rand().dim(), DM.rand(Sparsity.diag(3)).nnz()
('2x3', '1x1', 3)
>>> try: SX.rand(2)
... except Exception as e: print("error")
error
>> fprintf('%s %s\n', DM.rand(2, 3).dim(), DM.rand().dim())
2x3 1x1
>> DM.rand(Sparsity.diag(3)).nnz()
3
>> try, SX.rand(2); catch e, disp('error'); end
error
julia> ca.dim(ca.DM.rand(2, 3)), ca.dim(ca.DM.rand())
("2x3", "1x1")
julia> ca.nnz(ca.DM.rand(ca.Sparsity.diag(3)))
3
julia> try ca.SX.rand(2); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_1ab
|
static |
Takes a shape (dense result, default 1-by-1) or a sparsity pattern, in which case only the structural nonzeros get a random value. Only available for DM.
>>> DM.rand(2, 3).dim(), DM.rand().dim(), DM.rand(Sparsity.diag(3)).nnz()
('2x3', '1x1', 3)
>>> try: SX.rand(2)
... except Exception as e: print("error")
error
>> fprintf('%s %s\n', DM.rand(2, 3).dim(), DM.rand().dim())
2x3 1x1
>> DM.rand(Sparsity.diag(3)).nnz()
3
>> try, SX.rand(2); catch e, disp('error'); end
error
julia> ca.dim(ca.DM.rand(2, 3)), ca.dim(ca.DM.rand())
("2x3", "1x1")
julia> ca.nnz(ca.DM.rand(ca.Sparsity.diag(3)))
3
julia> try ca.SX.rand(2); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_1ab
|
staticinherited |
Calculates A + alpha * x*y'
| alpha | Scalar; if it is a structural zero, A is returned unchanged |
| x | Vector with x.numel() == A.size1() (row vectors are transposed) |
| y | Vector with y.numel() == A.size2() |
>>> A = DM([[1, 2], [3, 4]])
>>> rank1(A, 2, DM([1, 0]), DM([0, 1]))
DM(
[[1, 4],
[3, 4]])
>>> rank1(MX.sym("A", 2, 2), MX.sym("a"), MX.sym("x", 2), MX.sym("y", 2))
MX(rank1(A, a, x, y))
>> A = DM([1 2; 3 4]);
>> rank1(A, 2, DM([1; 0]), DM([0; 1]))
[[1, 4],
[3, 4]]
>> rank1(MX.sym('A', 2, 2), MX.sym('a'), MX.sym('x', 2), MX.sym('y', 2))
rank1(A, a, x, y)
julia> A = ca.DM([1 2; 3 4]);
julia> ca.rank1(A, 2, ca.DM([1, 0]), ca.DM([0, 1]))
DM(
[[1, 4],
[3, 4]])
julia> ca.rank1(ca.MX.sym("A", 2, 2), ca.MX.sym("a"), ca.MX.sym("x", 2), ca.MX.sym("y", 2))
MX(rank1(A, a, x, y))
Extra doc: https://github.com/casadi/casadi/wiki/L_1bp
| void casadi::Matrix< Scalar >::remove | ( | const std::vector< casadi_int > & | rr, |
| const std::vector< casadi_int > & | cc | ||
| ) |
Both lists may be empty; duplicates are ignored, out-of-range indices raise an error.
>>> A = DM([[1, 2, 3], [4, 5, 6]]) >>> A.remove([0], [1]) >>> A DM([[4, 6]])
>> A = DM([1 2 3; 4 5 6]); >> A.remove(0, 1); >> A [[4, 6]]
julia> A = ca.DM([1 2 3; 4 5 6]); julia> ca.remove(A, [0], [1]) julia> A DM([[4, 6]])
Extra doc: https://github.com/casadi/casadi/wiki/L_19h
| void casadi::Matrix< Scalar >::reserve | ( | casadi_int | nnz | ) |
| void casadi::Matrix< Scalar >::reserve | ( | casadi_int | nnz, |
| casadi_int | ncol | ||
| ) |
| void casadi::Matrix< Scalar >::resize | ( | casadi_int | nrow, |
| casadi_int | ncol | ||
| ) |
Growing appends structural zeros; shrinking drops the entries outside the new shape.
>>> A = DM([[1, 2], [3, 4]]) >>> A.resize(3, 3) >>> A DM( [[1, 2, 00], [3, 4, 00], [00, 00, 00]]) >>> A.resize(1, 1) >>> A DM(1)
>> A = DM([1 2; 3 4]); >> A.resize(3, 3); >> A [[1, 2, 00], [3, 4, 00], [00, 00, 00]] >> A.resize(1, 1); >> A 1
julia> A = ca.DM([1 2; 3 4]); julia> ca.resize(A, 3, 3) julia> A DM( [[1, 2, 00], [3, 4, 00], [00, 00, 00]]) julia> ca.resize(A, 1, 1) julia> A DM(1)
Extra doc: https://github.com/casadi/casadi/wiki/L_2p4
|
static |
The generator is global to the class and is seeded from the clock at startup; seeding it makes subsequent rand calls reproducible.
>>> DM.rng(1); a = DM.rand(2, 2) >>> DM.rng(1); b = DM.rand(2, 2) >>> norm_inf(a - b) DM(0)
>> DM.rng(1); a = DM.rand(2, 2); >> DM.rng(1); b = DM.rand(2, 2); >> norm_inf(a - b) 0
julia> ca.DM.rng(1); a = ca.DM.rand(2, 2); julia> ca.DM.rng(1); b = ca.DM.rand(2, 2); julia> ca.norm_inf(a - b) DM(0)
Extra doc: https://github.com/casadi/casadi/wiki/L_2p7
Definition at line 70 of file matrix_impl.hpp.
|
inlineinherited |
The pattern is stored in compressed column format: colind has size2()+1 entries, the nonzeros of column j are the entries colind(j) up to colind(j+1) (exclusive), and row(el) is the row index of nonzero el. Without argument, the full vectors are returned. Out-of-range indices raise an error.
>>> x = DM(Sparsity.diag(2), [5, 6]) >>> x.row(), x.colind() ([0, 1], [0, 1, 2]) >>> x.row(1), x.colind(2) (1, 2)
>> x = DM(Sparsity.diag(2), [5; 6]);
>> x.row(), x.colind()
0 1
0 1 2
>> fprintf('%d %d\n', x.row(1), x.colind(2))
1 2
julia> x = ca.DM(ca.Sparsity.diag(2), [5, 6]); julia> ca.row(x), ca.colind(x) ([0, 1], [0, 1, 2]) julia> ca.row(x, 1), ca.colind(x, 2) (1, 2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1b8
Definition at line 608 of file generic_matrix.hpp.
|
inlineinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1at
Definition at line 283 of file generic_matrix.hpp.
| std::string casadi::Matrix< Scalar >::serialize | ( | ) | const |
The string can be restored with deserialize of the same class (DM or SX). For SX the whole expression graph is stored, symbols included.
>>> s = DM([[1, 2], [3, 4]]).serialize()
>>> DM.deserialize(s)
DM(
[[1, 2],
[3, 4]])
>>> x = SX.sym("x")
>>> SX.deserialize((sin(x) + x).serialize())
SX((sin(x)+x))
>> s = DM([1 2; 3 4]).serialize();
>> DM.deserialize(s)
[[1, 2],
[3, 4]]
>> x = SX.sym('x'); e = sin(x) + x;
>> SX.deserialize(e.serialize())
(sin(x)+x)
julia> s = ca.serialize(ca.DM([1 2; 3 4]));
julia> ca.DM.deserialize(s)
DM(
[[1, 2],
[3, 4]])
julia> x = ca.SX.sym("x");
julia> ca.SX.deserialize(ca.serialize(sin(x) + x))
SX((sin(x)+x))
Extra doc: https://github.com/casadi/casadi/wiki/L_1ae
| void casadi::Matrix< Scalar >::serialize | ( | SerializingStream & | s | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_1ah
| void casadi::Matrix< Scalar >::set | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | rr | ||
| ) |
Backs the Python statements x[k] = v and x[sp] = v. Indices are linear, column-major and zero-based (see get). The matrix is modified in place.
m must be a scalar (assigned to every selected element) or have as many entries as there are indices (a vector of the other orientation is transposed). Any other shape raises an error.m (a scalar) or the corresponding entries of m (a matrix).| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Linear index, Slice or list/matrix of indices |
| sp | Sparsity pattern of the same shape as the matrix |
>>> A = DM([[1, 2], [3, 4]])
>>> A[1] = 10; A[[0, 3]] = [7, 8]
>>> A
DM(
[[7, 2],
[10, 8]])
>>> A[Sparsity.diag(2)] = 0
>>> A
DM(
[[0, 2],
[10, 0]])
>>> S = DM(Sparsity.diag(2))
>>> S[1] = 5
>>> S.nnz(), S[0, 1]
(3, DM(00))
>>> try: A[[0, 1]] = [1, 2, 3]
... except Exception as e: print("error")
error
>> A = DM([1 2; 3 4]);
>> A(2) = 10; A([1 4]) = [7 8];
>> A
[[7, 2],
[10, 8]]
>> A(Sparsity.diag(2)) = 0;
>> A
[[0, 2],
[10, 0]]
>> S = DM(Sparsity.diag(2));
>> S(2) = 5;
>> S.nnz(), S(1, 2)
3
00
>> try, A([1 2]) = [1 2 3]; catch e, disp('error'); end
error
julia> A = ca.DM([1 2; 3 4]);
julia> A[2] = 10; A[[1, 4]] = [7, 8];
julia> A
DM(
[[7, 2],
[10, 8]])
julia> S = ca.DM(ca.Sparsity.diag(2));
julia> S[2] = 5;
julia> ca.nnz(S), S[1, 2]
(3, 00)
julia> try A[[1, 2]] = [1, 2, 3]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ot
Definition at line 314 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::set | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | rr, | ||
| const Matrix< casadi_int > & | cc | ||
| ) |
Backs the Python statement x[i, j] = v. The matrix is modified in place. m must be len(rr)-by-len(cc), a scalar (broadcast to all selected entries) or a vector of the transposed orientation (transposed automatically); other shapes raise an error. Assigning into structural zeros inserts nonzeros; assigning a sparse m first erases the selected block, so its structural zeros become structural zeros.
| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Row index, Slice or list/matrix of row indices |
| cc | Column index, Slice or list/matrix of column indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[0, 1] = 9; A[1, :] = 0
>>> A
DM(
[[1, 9, 3],
[0, 0, 0]])
>>> A[0, :] = DM([7, 8, 9])
>>> A[0, :]
DM([[7, 8, 9]])
>>> A[:, 0] = DM(2, 1)
>>> A.nnz()
4
>>> x = SX.sym("x", 2, 2)
>>> x[0, 0] = 0
>>> x
SX(
[[0, x_2],
[x_1, x_3]])
>>> try: A[0, :] = [1, 2]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(1, 2) = 9; A(2, :) = 0;
>> A
[[1, 9, 3],
[0, 0, 0]]
>> A(1, :) = DM([7; 8; 9]);
>> A(1, :)
[[7, 8, 9]]
>> A(:, 1) = DM(2, 1);
>> A.nnz()
4
>> x = SX.sym('x', 2, 2);
>> x(1, 1) = 0;
>> x
[[0, x_2],
[x_1, x_3]]
>> try, A(1, :) = [1 2]; catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[1, 2] = 9; A[2, :] = 0;
julia> A
DM(
[[1, 9, 3],
[0, 0, 0]])
julia> A[1, :] = ca.DM([7, 8, 9]);
julia> A[1, :]
DM([[7, 8, 9]])
julia> A[:, 1] = ca.DM(2, 1);
julia> ca.nnz(A)
4
julia> x = ca.SX.sym("x", 2, 2);
julia> x[1, 1] = 0;
julia> x
SX(
[[0, x_2],
[x_1, x_3]])
julia> try A[1, :] = [1, 2]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ou
Definition at line 228 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::set | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | rr, | ||
| const Slice & | cc | ||
| ) |
Backs the Python statement x[i, j] = v. The matrix is modified in place. m must be len(rr)-by-len(cc), a scalar (broadcast to all selected entries) or a vector of the transposed orientation (transposed automatically); other shapes raise an error. Assigning into structural zeros inserts nonzeros; assigning a sparse m first erases the selected block, so its structural zeros become structural zeros.
| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Row index, Slice or list/matrix of row indices |
| cc | Column index, Slice or list/matrix of column indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[0, 1] = 9; A[1, :] = 0
>>> A
DM(
[[1, 9, 3],
[0, 0, 0]])
>>> A[0, :] = DM([7, 8, 9])
>>> A[0, :]
DM([[7, 8, 9]])
>>> A[:, 0] = DM(2, 1)
>>> A.nnz()
4
>>> x = SX.sym("x", 2, 2)
>>> x[0, 0] = 0
>>> x
SX(
[[0, x_2],
[x_1, x_3]])
>>> try: A[0, :] = [1, 2]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(1, 2) = 9; A(2, :) = 0;
>> A
[[1, 9, 3],
[0, 0, 0]]
>> A(1, :) = DM([7; 8; 9]);
>> A(1, :)
[[7, 8, 9]]
>> A(:, 1) = DM(2, 1);
>> A.nnz()
4
>> x = SX.sym('x', 2, 2);
>> x(1, 1) = 0;
>> x
[[0, x_2],
[x_1, x_3]]
>> try, A(1, :) = [1 2]; catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[1, 2] = 9; A[2, :] = 0;
julia> A
DM(
[[1, 9, 3],
[0, 0, 0]])
julia> A[1, :] = ca.DM([7, 8, 9]);
julia> A[1, :]
DM([[7, 8, 9]])
julia> A[:, 1] = ca.DM(2, 1);
julia> ca.nnz(A)
4
julia> x = ca.SX.sym("x", 2, 2);
julia> x[1, 1] = 0;
julia> x
SX(
[[0, x_2],
[x_1, x_3]])
julia> try A[1, :] = [1, 2]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ou
Definition at line 221 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::set | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Slice & | rr | ||
| ) |
Backs the Python statements x[k] = v and x[sp] = v. Indices are linear, column-major and zero-based (see get). The matrix is modified in place.
m must be a scalar (assigned to every selected element) or have as many entries as there are indices (a vector of the other orientation is transposed). Any other shape raises an error.m (a scalar) or the corresponding entries of m (a matrix).| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Linear index, Slice or list/matrix of indices |
| sp | Sparsity pattern of the same shape as the matrix |
>>> A = DM([[1, 2], [3, 4]])
>>> A[1] = 10; A[[0, 3]] = [7, 8]
>>> A
DM(
[[7, 2],
[10, 8]])
>>> A[Sparsity.diag(2)] = 0
>>> A
DM(
[[0, 2],
[10, 0]])
>>> S = DM(Sparsity.diag(2))
>>> S[1] = 5
>>> S.nnz(), S[0, 1]
(3, DM(00))
>>> try: A[[0, 1]] = [1, 2, 3]
... except Exception as e: print("error")
error
>> A = DM([1 2; 3 4]);
>> A(2) = 10; A([1 4]) = [7 8];
>> A
[[7, 2],
[10, 8]]
>> A(Sparsity.diag(2)) = 0;
>> A
[[0, 2],
[10, 0]]
>> S = DM(Sparsity.diag(2));
>> S(2) = 5;
>> S.nnz(), S(1, 2)
3
00
>> try, A([1 2]) = [1 2 3]; catch e, disp('error'); end
error
julia> A = ca.DM([1 2; 3 4]);
julia> A[2] = 10; A[[1, 4]] = [7, 8];
julia> A
DM(
[[7, 2],
[10, 8]])
julia> S = ca.DM(ca.Sparsity.diag(2));
julia> S[2] = 5;
julia> ca.nnz(S), S[1, 2]
(3, 00)
julia> try A[[1, 2]] = [1, 2, 3]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ot
Definition at line 295 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::set | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Slice & | rr, | ||
| const Matrix< casadi_int > & | cc | ||
| ) |
Backs the Python statement x[i, j] = v. The matrix is modified in place. m must be len(rr)-by-len(cc), a scalar (broadcast to all selected entries) or a vector of the transposed orientation (transposed automatically); other shapes raise an error. Assigning into structural zeros inserts nonzeros; assigning a sparse m first erases the selected block, so its structural zeros become structural zeros.
| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Row index, Slice or list/matrix of row indices |
| cc | Column index, Slice or list/matrix of column indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[0, 1] = 9; A[1, :] = 0
>>> A
DM(
[[1, 9, 3],
[0, 0, 0]])
>>> A[0, :] = DM([7, 8, 9])
>>> A[0, :]
DM([[7, 8, 9]])
>>> A[:, 0] = DM(2, 1)
>>> A.nnz()
4
>>> x = SX.sym("x", 2, 2)
>>> x[0, 0] = 0
>>> x
SX(
[[0, x_2],
[x_1, x_3]])
>>> try: A[0, :] = [1, 2]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(1, 2) = 9; A(2, :) = 0;
>> A
[[1, 9, 3],
[0, 0, 0]]
>> A(1, :) = DM([7; 8; 9]);
>> A(1, :)
[[7, 8, 9]]
>> A(:, 1) = DM(2, 1);
>> A.nnz()
4
>> x = SX.sym('x', 2, 2);
>> x(1, 1) = 0;
>> x
[[0, x_2],
[x_1, x_3]]
>> try, A(1, :) = [1 2]; catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[1, 2] = 9; A[2, :] = 0;
julia> A
DM(
[[1, 9, 3],
[0, 0, 0]])
julia> A[1, :] = ca.DM([7, 8, 9]);
julia> A[1, :]
DM([[7, 8, 9]])
julia> A[:, 1] = ca.DM(2, 1);
julia> ca.nnz(A)
4
julia> x = ca.SX.sym("x", 2, 2);
julia> x[1, 1] = 0;
julia> x
SX(
[[0, x_2],
[x_1, x_3]])
julia> try A[1, :] = [1, 2]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ou
Definition at line 214 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::set | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Slice & | rr, | ||
| const Slice & | cc | ||
| ) |
Backs the Python statement x[i, j] = v. The matrix is modified in place. m must be len(rr)-by-len(cc), a scalar (broadcast to all selected entries) or a vector of the transposed orientation (transposed automatically); other shapes raise an error. Assigning into structural zeros inserts nonzeros; assigning a sparse m first erases the selected block, so its structural zeros become structural zeros.
| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Row index, Slice or list/matrix of row indices |
| cc | Column index, Slice or list/matrix of column indices |
>>> A = DM([[1, 2, 3], [4, 5, 6]])
>>> A[0, 1] = 9; A[1, :] = 0
>>> A
DM(
[[1, 9, 3],
[0, 0, 0]])
>>> A[0, :] = DM([7, 8, 9])
>>> A[0, :]
DM([[7, 8, 9]])
>>> A[:, 0] = DM(2, 1)
>>> A.nnz()
4
>>> x = SX.sym("x", 2, 2)
>>> x[0, 0] = 0
>>> x
SX(
[[0, x_2],
[x_1, x_3]])
>>> try: A[0, :] = [1, 2]
... except Exception as e: print("error")
error
>> A = DM([1 2 3; 4 5 6]);
>> A(1, 2) = 9; A(2, :) = 0;
>> A
[[1, 9, 3],
[0, 0, 0]]
>> A(1, :) = DM([7; 8; 9]);
>> A(1, :)
[[7, 8, 9]]
>> A(:, 1) = DM(2, 1);
>> A.nnz()
4
>> x = SX.sym('x', 2, 2);
>> x(1, 1) = 0;
>> x
[[0, x_2],
[x_1, x_3]]
>> try, A(1, :) = [1 2]; catch e, disp('error'); end
error
julia> A = ca.DM([1 2 3; 4 5 6]);
julia> A[1, 2] = 9; A[2, :] = 0;
julia> A
DM(
[[1, 9, 3],
[0, 0, 0]])
julia> A[1, :] = ca.DM([7, 8, 9]);
julia> A[1, :]
DM([[7, 8, 9]])
julia> A[:, 1] = ca.DM(2, 1);
julia> ca.nnz(A)
4
julia> x = ca.SX.sym("x", 2, 2);
julia> x[1, 1] = 0;
julia> x
SX(
[[0, x_2],
[x_1, x_3]])
julia> try A[1, :] = [1, 2]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ou
Definition at line 195 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::set | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Sparsity & | sp | ||
| ) |
Backs the Python statements x[k] = v and x[sp] = v. Indices are linear, column-major and zero-based (see get). The matrix is modified in place.
m must be a scalar (assigned to every selected element) or have as many entries as there are indices (a vector of the other orientation is transposed). Any other shape raises an error.m (a scalar) or the corresponding entries of m (a matrix).| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| rr | Linear index, Slice or list/matrix of indices |
| sp | Sparsity pattern of the same shape as the matrix |
>>> A = DM([[1, 2], [3, 4]])
>>> A[1] = 10; A[[0, 3]] = [7, 8]
>>> A
DM(
[[7, 2],
[10, 8]])
>>> A[Sparsity.diag(2)] = 0
>>> A
DM(
[[0, 2],
[10, 0]])
>>> S = DM(Sparsity.diag(2))
>>> S[1] = 5
>>> S.nnz(), S[0, 1]
(3, DM(00))
>>> try: A[[0, 1]] = [1, 2, 3]
... except Exception as e: print("error")
error
>> A = DM([1 2; 3 4]);
>> A(2) = 10; A([1 4]) = [7 8];
>> A
[[7, 2],
[10, 8]]
>> A(Sparsity.diag(2)) = 0;
>> A
[[0, 2],
[10, 0]]
>> S = DM(Sparsity.diag(2));
>> S(2) = 5;
>> S.nnz(), S(1, 2)
3
00
>> try, A([1 2]) = [1 2 3]; catch e, disp('error'); end
error
julia> A = ca.DM([1 2; 3 4]);
julia> A[2] = 10; A[[1, 4]] = [7, 8];
julia> A
DM(
[[7, 2],
[10, 8]])
julia> S = ca.DM(ca.Sparsity.diag(2));
julia> S[2] = 5;
julia> ca.nnz(S), S[1, 2]
(3, 00)
julia> try A[[1, 2]] = [1, 2, 3]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ot
Definition at line 390 of file matrix_impl.hpp.
|
static |
The on-the-fly simplifications (x - x -> 0, x/x -> 1, x == x -> 1, ...) recognise two operands as equal when they are the same node, or, up to this depth, when they are the same operation applied to equal operands. Depth 1 (the default) recognises (x+y) - (x+y); depth 2 also sin(x+y) - sin(x+y). Depth 0 compares nodes only. Global setting, SX only; calling without an argument restores the default.
| eq_depth | Comparison depth, default 1 |
>>> x = SX.sym("x"); y = SX.sym("y")
>>> sin(x + y) - sin(x + y)
SX((sin((x+y))-sin((x+y))))
>>> SX.set_max_depth(2)
>>> sin(x + y) - sin(x + y)
SX(0)
>>> SX.set_max_depth()
>>> SX.get_max_depth()
1
>> x = SX.sym('x'); y = SX.sym('y');
>> sin(x + y) - sin(x + y)
(sin((x+y))-sin((x+y)))
>> SX.set_max_depth(2);
>> sin(x + y) - sin(x + y)
0
>> SX.set_max_depth();
>> SX.get_max_depth()
1
julia> x = ca.SX.sym("x"); y = ca.SX.sym("y");
julia> sin(x + y) - sin(x + y)
SX((sin((x+y))-sin((x+y))))
julia> ca.SX.set_max_depth(2)
julia> sin(x + y) - sin(x + y)
SX(0)
julia> ca.SX.set_max_depth()
julia> ca.SX.get_max_depth()
1
Extra doc: https://github.com/casadi/casadi/wiki/L_19b
| void casadi::Matrix< Scalar >::set_nz | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Matrix< casadi_int > & | k | ||
| ) |
Backs the Python statement x.nz[k] = v. The sparsity pattern never changes: only stored values are overwritten (writing 0 keeps the entry as a structural nonzero). m must be a scalar (assigned to every selected nonzero) or have as many entries as there are indices; a mismatch raises an error.
| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| k | Nonzero index, Slice or list/matrix of indices |
>>> S = DM(Sparsity.diag(3))
>>> S.nz[:] = [4, 5, 6]; S.nz[0] = 0
>>> S
DM(
[[0, 00, 00],
[00, 5, 00],
[00, 00, 6]])
>>> S.nnz()
3
>>> try: S.nz[[0, 1]] = [1, 2, 3]
... except Exception as e: print("error")
error
>> S = DM(Sparsity.diag(3));
>> S.set_nz([4 5 6], true, 1:3); S.set_nz(0, true, 1);
>> S
[[0, 00, 00],
[00, 5, 00],
[00, 00, 6]]
>> S.nnz()
3
>> try, S.set_nz([1 2 3], true, [1 2]); catch e, disp('error'); end
error
julia> S = ca.DM(ca.Sparsity.diag(3));
julia> S.nz[:] = [4, 5, 6]; S.nz[1] = 0;
julia> S
DM(
[[0, 00, 00],
[00, 5, 00],
[00, 00, 6]])
julia> ca.nnz(S)
3
julia> try S.nz[[1, 2]] = [1, 2, 3]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ow
Definition at line 457 of file matrix_impl.hpp.
| void casadi::Matrix< Scalar >::set_nz | ( | const Matrix< Scalar > & | m, |
| bool | ind1, | ||
| const Slice & | k | ||
| ) |
Backs the Python statement x.nz[k] = v. The sparsity pattern never changes: only stored values are overwritten (writing 0 keeps the entry as a structural nonzero). m must be a scalar (assigned to every selected nonzero) or have as many entries as there are indices; a mismatch raises an error.
| m | Value(s) to assign |
| ind1 | True for one-based indices (MATLAB); Python always passes false |
| k | Nonzero index, Slice or list/matrix of indices |
>>> S = DM(Sparsity.diag(3))
>>> S.nz[:] = [4, 5, 6]; S.nz[0] = 0
>>> S
DM(
[[0, 00, 00],
[00, 5, 00],
[00, 00, 6]])
>>> S.nnz()
3
>>> try: S.nz[[0, 1]] = [1, 2, 3]
... except Exception as e: print("error")
error
>> S = DM(Sparsity.diag(3));
>> S.set_nz([4 5 6], true, 1:3); S.set_nz(0, true, 1);
>> S
[[0, 00, 00],
[00, 5, 00],
[00, 00, 6]]
>> S.nnz()
3
>> try, S.set_nz([1 2 3], true, [1 2]); catch e, disp('error'); end
error
julia> S = ca.DM(ca.Sparsity.diag(3));
julia> S.nz[:] = [4, 5, 6]; S.nz[1] = 0;
julia> S
DM(
[[0, 00, 00],
[00, 5, 00],
[00, 00, 6]])
julia> ca.nnz(S)
3
julia> try S.nz[[1, 2]] = [1, 2, 3]; catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_2ow
Definition at line 445 of file matrix_impl.hpp.
|
static |
Global settings per class (DM and SX each keep their own), applied by str(), print() and the print_* methods. Defaults: precision 6, width 0, scientific false.
>>> DM.set_precision(3) >>> DM(1/3) DM(0.333) >>> DM.set_precision(6) >>> DM(1/3) DM(0.333333)
>> DM.set_precision(3); >> DM(1/3) 0.333 >> DM.set_precision(6); >> DM(1/3) 0.333333
julia> ca.DM.set_precision(3) julia> ca.DM(1/3) DM(0.333) julia> ca.DM.set_precision(6) julia> ca.DM(1/3) DM(0.333333)
Extra doc: https://github.com/casadi/casadi/wiki/L_2p6
Definition at line 40 of file matrix_impl.hpp.
|
static |
Definition at line 46 of file matrix_impl.hpp.
|
static |
Definition at line 43 of file matrix_impl.hpp.
|
inherited |
>>> x = MX.sym("x", 2, 3)
>>> x.size(), x.size(1), x.size(2)
((2, 3), 2, 3)
>> x = MX.sym('x', 2, 3);
>> size(x)
2 3
>> fprintf('%d %d\n', size(x, 1), size(x, 2))
2 3
julia> x = ca.MX.sym("x", 2, 3);
julia> size(x), size(x, 1), size(x, 2)
((2, 3), 2, 3)
Extra doc: https://github.com/casadi/casadi/wiki/L_1ax
|
inherited |
| axis | 1 for the number of rows, 2 for the number of columns; any other value raises an error |
Extra doc: https://github.com/casadi/casadi/wiki/L_1ay
|
inherited |
>>> x = MX.sym("x", 2, 3)
>>> x.size1(), x.size2()
(2, 3)
>> x = MX.sym('x', 2, 3);
>> fprintf('%d %d\n', x.size1(), x.size2())
2 3
julia> x = ca.MX.sym("x", 2, 3);
julia> ca.size1(x), ca.size2(x)
(2, 3)
Extra doc: https://github.com/casadi/casadi/wiki/L_1as
|
inherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1au
|
staticinherited |
Functions called by friend functions defined here
|
inherited |
>>> DM.eye(2).sparsity() Sparsity(2x2,2nz) >>> DM.eye(2).sparsity() == Sparsity.diag(2) True
>> DM.eye(2).sparsity() 2x2,2nz >> DM.eye(2).sparsity() == Sparsity.diag(2) 1
julia> ca.sparsity(ca.DM.eye(2)) Sparsity(2x2,2nz) julia> ca.is_equal(ca.sparsity(ca.DM.eye(2)), ca.Sparsity.diag(2)) true
Extra doc: https://github.com/casadi/casadi/wiki/L_1b9
|
inlinestaticinherited |
>>> SX.sym("x", 1, 1, 2)
[SX(x0), SX(x1)]
>> v = SX.sym('x', 1, 1, 2);
>> v{1}, v{2}
x0
x1
julia> ca.SX.sym("x", 1, 1, 2)
2-element Vector{SX}:
SX(x0)
SX(x1)
Extra doc: https://github.com/casadi/casadi/wiki/L_1de
Definition at line 5063 of file generic_matrix.hpp.
|
inlinestaticinherited |
>>> MX.sym("x", 1, 1, 2, 2)
[[MX(x_00), MX(x_01)], [MX(x_10), MX(x_11)]]
>> v = MX.sym('x', 1, 1, 2, 2);
>> numel(v), v{1}{2}, v{2}{1}
2
x_01
x_10
julia> ca.MX.sym("x", 1, 1, 2, 2)
2-element Vector{Vector{MX}}:
MX[x_00, x_01]
MX[x_10, x_11]
Extra doc: https://github.com/casadi/casadi/wiki/L_1dg
Definition at line 5107 of file generic_matrix.hpp.
|
inlinestaticinherited |
Creates a new, dense symbol; two symbols with the same name are still different symbols. For SX each entry is a separate scalar symbol named name_k (k the column-major index), while an MX symbol is a single node with the given name. Only SX and MX have symbols; DM.sym raises an error.
| name | Name used for printing. For SX, a name of the form "[a,b,c]" assigns individual names to the numel() entries. |
| nrow | Number of rows, default 1 |
| ncol | Number of columns, default 1 |
>>> SX.sym("x"), MX.sym("x", 2, 3).dim()
(SX(x), '2x3')
>>> SX.sym("x", 2, 2)
SX(
[[x_0, x_2],
[x_1, x_3]])
>>> SX.sym("[a,b,c]", 3)
SX([a, b, c])
>>> is_equal(SX.sym("x"), SX.sym("x"))
False
>> SX.sym('x'), MX.sym('x', 2, 3).dim()
x
2x3
>> SX.sym('x', 2, 2)
[[x_0, x_2],
[x_1, x_3]]
>> SX.sym('[a,b,c]', 3)
[a, b, c]
>> is_equal(SX.sym('x'), SX.sym('x'))
0
julia> ca.SX.sym("x"), ca.dim(ca.MX.sym("x", 2, 3))
(x, "2x3")
julia> ca.SX.sym("x", 2, 2)
SX(
[[x_0, x_2],
[x_1, x_3]])
julia> ca.SX.sym("[a,b,c]", 3)
SX([a, b, c])
julia> isequal(ca.SX.sym("x"), ca.SX.sym("x"))
false
Extra doc: https://github.com/casadi/casadi/wiki/L_1da
Definition at line 4948 of file generic_matrix.hpp.
|
inlinestaticinherited |
Only the structural nonzeros of sp become symbolic entries; for SX they are numbered by nonzero index.
>>> SX.sym("p", Sparsity.diag(2))
SX(
[[p_0, 00],
[00, p_1]])
>>> MX.sym("p", Sparsity.diag(2)).dim(True)
'2x2,2nz'
>> SX.sym('p', Sparsity.diag(2))
[[p_0, 00],
[00, p_1]]
>> MX.sym('p', Sparsity.diag(2)).dim(true)
2x2,2nz
julia> ca.SX.sym("p", ca.Sparsity.diag(2))
SX(
[[p_0, 00],
[00, p_1]])
julia> ca.dim(ca.MX.sym("p", ca.Sparsity.diag(2)), true)
"2x2,2nz"
Extra doc: https://github.com/casadi/casadi/wiki/L_1dc
Definition at line 4997 of file generic_matrix.hpp.
|
staticinherited |
The k-th symbol is named name followed by k (no separator).
>>> MX.sym("x", Sparsity.dense(2, 1), 3)
[MX(x0), MX(x1), MX(x2)]
>> v = MX.sym('x', Sparsity.dense(2, 1), 3);
>> numel(v), v{1}, v{3}
3
x0
x2
julia> ca.MX.sym("x", ca.Sparsity.dense(2, 1), 3)
3-element Vector{MX}:
MX(x0)
MX(x1)
MX(x2)
Extra doc: https://github.com/casadi/casadi/wiki/L_1dd
Definition at line 5033 of file generic_matrix.hpp.
|
staticinherited |
with given sparsity. The symbol at outer index i and inner index k is named name_ik.
Extra doc: https://github.com/casadi/casadi/wiki/L_1df
Definition at line 5075 of file generic_matrix.hpp.
|
inlinestaticinherited |
Extra doc: https://github.com/casadi/casadi/wiki/L_1db
Definition at line 4955 of file generic_matrix.hpp.
| Matrix<Scalar> casadi::Matrix< Scalar >::T | ( | ) | const |
|
staticinherited |
Functions called by friend functions defined here
| void casadi::Matrix< Scalar >::to_file | ( | const std::string & | filename, |
| const std::string & | format = "" |
||
| ) | const |
Supported formats, selected by the file extension unless format is given:
| filename | Output path |
| format | "mtx" or "txt"; empty means deduce from the extension |
>>> import os, tempfile >>> fn = os.path.join(tempfile.mkdtemp(), "a.txt") >>> A = DM(Sparsity.diag(2)) * 2.5 >>> A.to_file(fn) >>> DM.from_file(fn) DM( [[2.5, 00], [00, 2.5]]) >>> os.remove(fn); os.rmdir(os.path.dirname(fn))
>> fn = [tempname '.txt']; >> A = DM(Sparsity.diag(2)) * 2.5; >> A.to_file(fn); >> DM.from_file(fn) [[2.5, 00], [00, 2.5]] >> delete(fn);
julia> fn = joinpath(mktempdir(), "a.txt"); julia> A = ca.DM(ca.Sparsity.diag(2)) * 2.5; julia> ca.to_file(A, fn) julia> ca.DM.from_file(fn) DM( [[2.5, 00], [00, 2.5]]) julia> rm(dirname(fn), recursive=true)
Extra doc: https://github.com/casadi/casadi/wiki/L_2p9
|
static |
Entry k of the result is at (row[k], col[k]) with value d[k]. The three lists must have the same length; indices are zero-based and must be within the matrix bounds. The nonzeros are reordered into column-major order. When the same (row, col) pair appears more than once, only the first value is kept; duplicates are not summed.
| row | Row index of each entry |
| col | Column index of each entry |
| d | Dense vector of values, one per entry |
| nrow | Number of rows of the result [default: largest row index plus one] |
| ncol | Number of columns of the result [default: largest column index plus one] |
>>> DM.triplet([0, 1], [1, 0], [5, 6], 3, 3)
DM(
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]])
>>> DM.triplet([0, 1], [1, 0], [5, 6], (3, 3)).nonzeros()
[6.0, 5.0]
>>> SX.triplet([0, 1], [0, 1], SX.sym("v", 2), 2, 2)
SX(
[[v_0, 00],
[00, v_1]])
>>> DM.triplet([], [], [], 2, 2).nnz()
0
>>> try: DM.triplet([0, 1], [1, 0], [5], 3, 3)
... except Exception as e: print("error")
error
>> DM.triplet([0 1], [1 0], [5 6], 3, 3)
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]]
>> DM.triplet([0 1], [1 0], [5 6], [3 3]).nonzeros()
6 5
>> SX.triplet([0 1], [0 1], SX.sym('v', 2), 2, 2)
[[v_0, 00],
[00, v_1]]
>> DM.triplet([], [], [], 2, 2).nnz()
0
>> try, DM.triplet([0 1], [1 0], 5, 3, 3); catch e, disp('error'); end
error
julia> ca.DM.triplet([0, 1], [1, 0], [5, 6], 3, 3)
DM(
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]])
julia> ca.SX.triplet([0, 1], [0, 1], ca.SX.sym("v", 2), 2, 2)
SX(
[[v_0, 00],
[00, v_1]])
julia> ca.nnz(ca.DM.triplet([], [], [], 2, 2))
0
julia> try ca.DM.triplet([0, 1], [1, 0], [5], 3, 3); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_23t
|
static |
Entry k of the result is at (row[k], col[k]) with value d[k]. The three lists must have the same length; indices are zero-based and must be within the matrix bounds. The nonzeros are reordered into column-major order. When the same (row, col) pair appears more than once, only the first value is kept; duplicates are not summed.
| row | Row index of each entry |
| col | Column index of each entry |
| d | Dense vector of values, one per entry |
| nrow | Number of rows of the result [default: largest row index plus one] |
| ncol | Number of columns of the result [default: largest column index plus one] |
>>> DM.triplet([0, 1], [1, 0], [5, 6], 3, 3)
DM(
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]])
>>> DM.triplet([0, 1], [1, 0], [5, 6], (3, 3)).nonzeros()
[6.0, 5.0]
>>> SX.triplet([0, 1], [0, 1], SX.sym("v", 2), 2, 2)
SX(
[[v_0, 00],
[00, v_1]])
>>> DM.triplet([], [], [], 2, 2).nnz()
0
>>> try: DM.triplet([0, 1], [1, 0], [5], 3, 3)
... except Exception as e: print("error")
error
>> DM.triplet([0 1], [1 0], [5 6], 3, 3)
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]]
>> DM.triplet([0 1], [1 0], [5 6], [3 3]).nonzeros()
6 5
>> SX.triplet([0 1], [0 1], SX.sym('v', 2), 2, 2)
[[v_0, 00],
[00, v_1]]
>> DM.triplet([], [], [], 2, 2).nnz()
0
>> try, DM.triplet([0 1], [1 0], 5, 3, 3); catch e, disp('error'); end
error
julia> ca.DM.triplet([0, 1], [1, 0], [5, 6], 3, 3)
DM(
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]])
julia> ca.SX.triplet([0, 1], [0, 1], ca.SX.sym("v", 2), 2, 2)
SX(
[[v_0, 00],
[00, v_1]])
julia> ca.nnz(ca.DM.triplet([], [], [], 2, 2))
0
julia> try ca.DM.triplet([0, 1], [1, 0], [5], 3, 3); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_23t
|
static |
Entry k of the result is at (row[k], col[k]) with value d[k]. The three lists must have the same length; indices are zero-based and must be within the matrix bounds. The nonzeros are reordered into column-major order. When the same (row, col) pair appears more than once, only the first value is kept; duplicates are not summed.
| row | Row index of each entry |
| col | Column index of each entry |
| d | Dense vector of values, one per entry |
| nrow | Number of rows of the result [default: largest row index plus one] |
| ncol | Number of columns of the result [default: largest column index plus one] |
>>> DM.triplet([0, 1], [1, 0], [5, 6], 3, 3)
DM(
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]])
>>> DM.triplet([0, 1], [1, 0], [5, 6], (3, 3)).nonzeros()
[6.0, 5.0]
>>> SX.triplet([0, 1], [0, 1], SX.sym("v", 2), 2, 2)
SX(
[[v_0, 00],
[00, v_1]])
>>> DM.triplet([], [], [], 2, 2).nnz()
0
>>> try: DM.triplet([0, 1], [1, 0], [5], 3, 3)
... except Exception as e: print("error")
error
>> DM.triplet([0 1], [1 0], [5 6], 3, 3)
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]]
>> DM.triplet([0 1], [1 0], [5 6], [3 3]).nonzeros()
6 5
>> SX.triplet([0 1], [0 1], SX.sym('v', 2), 2, 2)
[[v_0, 00],
[00, v_1]]
>> DM.triplet([], [], [], 2, 2).nnz()
0
>> try, DM.triplet([0 1], [1 0], 5, 3, 3); catch e, disp('error'); end
error
julia> ca.DM.triplet([0, 1], [1, 0], [5, 6], 3, 3)
DM(
[[00, 5, 00],
[6, 00, 00],
[00, 00, 00]])
julia> ca.SX.triplet([0, 1], [0, 1], ca.SX.sym("v", 2), 2, 2)
SX(
[[v_0, 00],
[00, v_1]])
julia> ca.nnz(ca.DM.triplet([], [], [], 2, 2))
0
julia> try ca.DM.triplet([0, 1], [1, 0], [5], 3, 3); catch; println("error") end
error
Extra doc: https://github.com/casadi/casadi/wiki/L_23t
|
static |
>>> DM.type_name(), SX.type_name()
('DM', 'SX')
>> fprintf('%s %s\n', DM.type_name(), SX.type_name())
DM SX
julia> ca.DM.type_name(), ca.SX.type_name()
("DM", "SX")
Extra doc: https://github.com/casadi/casadi/wiki/L_2ox
Definition at line 616 of file matrix_impl.hpp.
| Function casadi::SX::which_function | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_28n
| casadi_int casadi::SX::which_output | ( | ) | const |
Extra doc: https://github.com/casadi/casadi/wiki/L_28m
|
inlinestaticinherited |
zeros(nrow, ncol) stores nrow*ncol numerical zeros; zeros(sp) stores a zero at every structural nonzero of sp. To get structural zeros instead, construct from a shape, e.g. DM(2, 2).
>>> DM.zeros(2, 2).nnz(), DM.zeros(Sparsity.diag(2)).nnz(), DM(2, 2).nnz() (4, 2, 0) >>> MX.zeros(2, 3) MX(zeros(2x3))
>> Z = DM.zeros(Sparsity.diag(2));
>> fprintf('%d %d %d\n', DM.zeros(2, 2).nnz(), Z.nnz(), DM(2, 2).nnz())
4 2 0
>> MX.zeros(2, 3)
zeros(2x3)
julia> Z = ca.DM.zeros(ca.Sparsity.diag(2)); julia> ca.nnz(ca.DM.zeros(2, 2)), ca.nnz(Z), ca.nnz(ca.DM(2, 2)) (4, 2, 0) julia> ca.MX.zeros(2, 3) MX(zeros(2x3))
Extra doc: https://github.com/casadi/casadi/wiki/L_1dh
Definition at line 5151 of file generic_matrix.hpp.
|
inlinestaticinherited |
zeros(nrow, ncol) stores nrow*ncol numerical zeros; zeros(sp) stores a zero at every structural nonzero of sp. To get structural zeros instead, construct from a shape, e.g. DM(2, 2).
>>> DM.zeros(2, 2).nnz(), DM.zeros(Sparsity.diag(2)).nnz(), DM(2, 2).nnz() (4, 2, 0) >>> MX.zeros(2, 3) MX(zeros(2x3))
>> Z = DM.zeros(Sparsity.diag(2));
>> fprintf('%d %d %d\n', DM.zeros(2, 2).nnz(), Z.nnz(), DM(2, 2).nnz())
4 2 0
>> MX.zeros(2, 3)
zeros(2x3)
julia> Z = ca.DM.zeros(ca.Sparsity.diag(2)); julia> ca.nnz(ca.DM.zeros(2, 2)), ca.nnz(Z), ca.nnz(ca.DM(2, 2)) (4, 2, 0) julia> ca.MX.zeros(2, 3) MX(zeros(2x3))
Extra doc: https://github.com/casadi/casadi/wiki/L_1dh
Definition at line 5154 of file generic_matrix.hpp.
|
inlinestaticinherited |
zeros(nrow, ncol) stores nrow*ncol numerical zeros; zeros(sp) stores a zero at every structural nonzero of sp. To get structural zeros instead, construct from a shape, e.g. DM(2, 2).
>>> DM.zeros(2, 2).nnz(), DM.zeros(Sparsity.diag(2)).nnz(), DM(2, 2).nnz() (4, 2, 0) >>> MX.zeros(2, 3) MX(zeros(2x3))
>> Z = DM.zeros(Sparsity.diag(2));
>> fprintf('%d %d %d\n', DM.zeros(2, 2).nnz(), Z.nnz(), DM(2, 2).nnz())
4 2 0
>> MX.zeros(2, 3)
zeros(2x3)
julia> Z = ca.DM.zeros(ca.Sparsity.diag(2)); julia> ca.nnz(ca.DM.zeros(2, 2)), ca.nnz(Z), ca.nnz(ca.DM(2, 2)) (4, 2, 0) julia> ca.MX.zeros(2, 3) MX(zeros(2x3))
Extra doc: https://github.com/casadi/casadi/wiki/L_1dh
Definition at line 5155 of file generic_matrix.hpp.