List of all members | Public Member Functions | Static Public Member Functions | Friends
casadi::GenericMatrix< MatType > Class Template Reference

Matrix base class. More...

#include <generic_matrix.hpp>

Detailed Description

template<typename MatType>
class casadi::GenericMatrix< MatType >

This is a common base class for MX and Matrix<>, introducing a uniform syntax and implementing common functionality using the curiously recurring template pattern (CRTP) idiom.
The class 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.
The syntax tries to stay as close as possible to the ublas syntax when it comes to vector/matrix operations.
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.
The sparsity pattern, which is reference counted and cached, can be accessed with Sparsity& sparsity()

Author
Joel Andersson
Date
2012

Extra doc: https://github.com/casadi/casadi/wiki/L_1am

Definition at line 75 of file generic_matrix.hpp.

Inheritance diagram for casadi::GenericMatrix< MatType >:
Inheritance graph
[legend]

Public Member Functions

casadi_int nnz () const
 Get the number of structural nonzeros. More...
 
casadi_int nnz_lower () const
 Get the number of structural nonzeros on or below the diagonal. More...
 
casadi_int nnz_upper () const
 Get the number of structural nonzeros on or above the diagonal. More...
 
casadi_int nnz_diag () const
 Get the number of structural nonzeros on the diagonal. More...
 
casadi_int numel () const
 Get the number of elements, size1()*size2() More...
 
casadi_int size1 () const
 Get the first dimension (i.e. number of rows) More...
 
casadi_int rows () const
 Get the number of rows, Octave-style syntax (same as size1()) More...
 
casadi_int size2 () const
 Get the second dimension (i.e. number of columns) More...
 
casadi_int columns () const
 Get the number of columns, Octave-style syntax (same as size2()) More...
 
std::string dim (bool with_nz=false) const
 Get string representation of dimensions. More...
 
std::pair< casadi_int, casadi_int > size () const
 Get the shape as a pair (number of rows, number of columns) More...
 
casadi_int size (casadi_int axis) const
 Get the size along a particular dimension. More...
 
bool is_empty (bool both=false) const
 Check if the matrix is empty, i.e. if one of the dimensions is zero. More...
 
bool is_dense () const
 Check if the matrix is dense, i.e. nnz() equals numel() More...
 
bool is_scalar (bool scalar_and_dense=false) const
 Check if the matrix is scalar, i.e. 1-by-1. More...
 
bool is_square () const
 Check if the matrix is square, i.e. size1() equals size2() More...
 
bool is_vector () const
 Check if the matrix is a row or column vector. More...
 
bool is_row () const
 Check if the matrix is a row vector (i.e. size1()==1) More...
 
bool is_column () const
 Check if the matrix is a column vector (i.e. size2()==1) More...
 
bool is_triu () const
 Check if the matrix is upper triangular. More...
 
bool is_tril () const
 Check if the matrix is lower triangular. More...
 
Sparsity sparsity () const
 Get the sparsity pattern. More...
 
std::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 MatType logsumexp (const MatType &x)
 
static MatType jtimes (const MatType &ex, const MatType &arg, const MatType &v, bool tr=false, const Dict &opts=Dict())
 
static MatType gradient (const MatType &ex, const MatType &arg, const Dict &opts=Dict())
 
static MatType tangent (const MatType &ex, const MatType &arg, const Dict &opts=Dict())
 
static MatType linearize (const MatType &f, const MatType &x, const MatType &x0, const Dict &opts=Dict())
 
static MatType mpower (const MatType &x, const MatType &y)
 
static MatType soc (const MatType &x, const MatType &y)
 
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 MatType sym (const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
 Create an nrow-by-ncol symbolic primitive. More...
 
static MatType 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 MatType sym (const std::string &name, const Sparsity &sp)
 Create symbolic primitive with a given sparsity pattern. More...
 
static std::vector< MatType > 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< MatType > 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< MatType > > 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< MatType > > 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 MatType 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 MatType zeros (const Sparsity &sp)
 Create a dense matrix or a matrix with specified sparsity with all entries zero. More...
 
static MatType 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 MatType 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 MatType ones (const Sparsity &sp)
 Create a dense matrix or a matrix with specified sparsity with all entries one. More...
 
static MatType 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

MatType interp1d (const std::vector< double > &x, const MatType &v, const std::vector< double > &xq, const std::string &mode, bool equidistant=false)
 Performs 1d linear interpolation. More...
 
MatType mpower (const MatType &x, const MatType &n)
 Matrix power x^n. More...
 
MatType soc (const MatType &x, const MatType &y)
 Construct second-order-cone matrix. More...
 
MatType mrdivide (const MatType &x, const MatType &n)
 Matrix right divide, x/A (cf. slash '/' in MATLAB) More...
 
MatType mldivide (const MatType &x, const MatType &n)
 Matrix left divide, A\b (cf. backslash '\' in MATLAB) More...
 
std::vector< MatType > symvar (const MatType &x)
 Get all symbolic primitives present in an expression. More...
 
MatType sumsqr (const MatType &x)
 Calculate sum of squares: sum_ij X_ij^2. More...
 
MatType logsumexp (const MatType &x)
 x -> log(sum_i exp(x_i)) More...
 
MatType logsumexp (const MatType &x, const MatType &margin)
 Scaled version of logsumexp. More...
 
MatType linspace (const MatType &a, const MatType &b, casadi_int nsteps)
 Matlab's linspace command. More...
 
MatType cross (const MatType &a, const MatType &b, casadi_int dim=-1)
 Matlab's cross command. More...
 
MatType skew (const MatType &a)
 Generate a skew symmetric matrix from a 3-vector. More...
 
MatType inv_skew (const MatType &a)
 Generate the 3-vector progenitor of a skew symmetric matrix. More...
 
MatType det (const MatType &A)
 Matrix determinant (experimental) More...
 
MatType det (const MatType &A, const std::string &lsolver, const Dict &dict=Dict())
 Matrix determinant through a linear solver factorization (experimental) More...
 
MatType inv_minor (const MatType &A)
 Matrix inverse by the adjugate (experimental) More...
 
MatType inv (const MatType &A)
 Matrix inverse. More...
 
MatType inv (const MatType &A, const std::string &lsolver, const Dict &options=Dict())
 Matrix inverse using a linear solver plugin. More...
 
MatType trace (const MatType &x)
 Matrix trace. More...
 
MatType tril2symm (const MatType &a)
 Convert a lower triangular matrix to a symmetric one. More...
 
MatType triu2symm (const MatType &a)
 Convert a upper triangular matrix to a symmetric one. More...
 
MatType norm_fro (const MatType &x)
 Frobenius norm. More...
 
MatType norm_2 (const MatType &x)
 2-norm More...
 
MatType norm_1 (const MatType &x)
 1-norm More...
 
MatType norm_inf (const MatType &x)
 Infinity-norm. More...
 
MatType diff (const MatType &x, casadi_int n=1, casadi_int axis=-1)
 Returns difference (n-th order) along given axis (MATLAB convention) More...
 
MatType cumsum (const MatType &x, casadi_int axis=-1)
 Returns cumulative sum along given axis (MATLAB convention) More...
 
MatType dot (const MatType &x, const MatType &y)
 Inner product of two matrices. More...
 
MatType nullspace (const MatType &A)
 Computes the nullspace of a matrix A. More...
 
MatType polyval (const MatType &p, const MatType &x)
 Evaluate a polynomial with coefficients p in x. More...
 
MatType diag (const MatType &A)
 Get the diagonal of a matrix or construct a diagonal. More...
 
MatType unite (const MatType &A, const MatType &B)
 Unite two matrices with non-overlapping sparsity patterns. More...
 
MatType densify (const MatType &x)
 Make the matrix dense if not already. More...
 
MatType densify (const MatType &x, const MatType &val)
 Make the matrix dense and assign nonzeros to a value. More...
 
MatType project (const MatType &A, const Sparsity &sp, bool intersect=false)
 Create a new matrix with a given sparsity pattern but with the. More...
 
MatType if_else (const MatType &cond, const MatType &if_true, const MatType &if_false, bool short_circuit=false)
 Branching on MX nodes. More...
 
MatType conditional (const MatType &ind, const std::vector< MatType > &x, const MatType &x_default, bool short_circuit=false)
 Create a switch. More...
 
bool depends_on (const MatType &f, const MatType &arg)
 Check if expression depends on the argument. More...
 
MatType substitute (const MatType &ex, const MatType &v, const MatType &vdef)
 Substitute variable v with expression vdef in an expression ex. More...
 
std::vector< MatType > substitute (const std::vector< MatType > &ex, const std::vector< MatType > &v, const std::vector< MatType > &vdef)
 Substitute variables v with expressions vdef in multiple expressions ex. More...
 
void substitute_inplace (const std::vector< MatType > &v, std::vector< MatType > &inout_vdef, std::vector< MatType > &inout_ex, bool reverse=false)
 Inplace substitution with piggyback expressions. More...
 
MatType cse (const MatType &e)
 Common subexpression elimination. More...
 
std::vector< MatType > cse (const std::vector< MatType > &e)
 Common subexpression elimination over a list of expressions. More...
 
MatType solve (const MatType &A, const MatType &b)
 Solve a system of equations: A*x = b. More...
 
MatType solve (const MatType &A, const MatType &b, const std::string &lsolver, const Dict &dict=Dict())
 Solve a system of equations: A*x = b, using a linear solver plugin. More...
 
MatType linearize (const MatType &f, const MatType &x, const MatType &x0, const Dict &opts=Dict())
 Linearize an expression. More...
 
MatType pinv (const MatType &A)
 Computes the Moore-Penrose pseudo-inverse. More...
 
MatType pinv (const MatType &A, const std::string &lsolver, const Dict &dict=Dict())
 Computes the Moore-Penrose pseudo-inverse using a linear solver plugin. More...
 
MatType expm_const (const MatType &A, const MatType &t)
 Calculate Matrix exponential. More...
 
MatType expm (const MatType &A)
 Calculate Matrix exponential. More...
 
MatType jacobian (const MatType &ex, const MatType &arg, const Dict &opts=Dict())
 Calculate Jacobian. More...
 
MatType gradient (const MatType &ex, const MatType &arg, const Dict &opts=Dict())
 Calculate the gradient of an expression. More...
 
MatType tangent (const MatType &ex, const MatType &arg, const Dict &opts=Dict())
 Calculate the tangent of an expression. More...
 
MatType jtimes (const MatType &ex, const MatType &arg, const MatType &v, bool tr=false, const Dict &opts=Dict())
 Calculate the Jacobian and multiply by a vector from the right. More...
 
std::vector< std::vector< MatType > > forward (const std::vector< MatType > &ex, const std::vector< MatType > &arg, const std::vector< std::vector< MatType > > &v, const Dict &opts=Dict())
 Forward directional derivative. More...
 
std::vector< std::vector< MatType > > reverse (const std::vector< MatType > &ex, const std::vector< MatType > &arg, const std::vector< std::vector< MatType > > &v, const Dict &opts=Dict())
 Reverse directional derivative. More...
 
std::vector< bool > which_depends (const MatType &expr, const MatType &var, casadi_int order, bool tr)
 Find out which variables enter with some order. More...
 
Sparsity jacobian_sparsity (const MatType &f, const MatType &x)
 Get the sparsity pattern of a jacobian. More...
 
bool is_linear (const MatType &expr, const MatType &var)
 Is expr linear in var? More...
 
bool is_quadratic (const MatType &expr, const MatType &var)
 Is expr quadratic in var? More...
 
void quadratic_coeff (const MatType &expr, const MatType &var, MatType &A, MatType &b, MatType &c, bool check=true)
 Recognizes quadratic form in scalar expression. More...
 
void linear_coeff (const MatType &expr, const MatType &var, MatType &A, MatType &b, bool check=true)
 Recognizes linear form in vector expression. More...
 
void extract_parametric (const MatType &expr, const MatType &par, MatType &expr_ret, std::vector< MatType > &symbols, std::vector< MatType > &parametric, const Dict &opts=Dict())
 Extract purely parametric parts from an expression graph. More...
 
void extract_parametric (const std::vector< MatType > &expr, const MatType &par, std::vector< MatType > &expr_ret, std::vector< MatType > &symbols, std::vector< MatType > &parametric, const Dict &opts=Dict())
 
void extract_parametric (const std::vector< MatType > &expr, const std::vector< MatType > &par, std::vector< MatType > &expr_ret, std::vector< MatType > &symbols, std::vector< MatType > &parametric, const Dict &opts=Dict())
 
void extract_parametric (const MatType &expr, const std::vector< MatType > &par, MatType &expr_ret, std::vector< MatType > &symbols, std::vector< MatType > &parametric, const Dict &opts=Dict())
 
void separate_linear (const MatType &expr, const MatType &sym_lin, const MatType &sym_const, MatType &expr_const, MatType &expr_lin, MatType &expr_nonlin)
 Separate an expression into subexpressions that are constant, linear and nonlinear. More...
 
void separate_linear (const MatType &expr, const std::vector< MatType > &sym_lin, const std::vector< MatType > &sym_const, MatType &expr_const, MatType &expr_lin, MatType &expr_nonlin)
 
casadi_int n_nodes (const MatType &A)
 Count the number of nodes in an expression graph. More...
 
MatType simplify (const MatType &x)
 Simplify an expression. More...
 
std::string print_operator (const MatType &xb, const std::vector< std::string > &args)
 Get a string representation for a binary MatType, using custom arguments. More...
 
void extract (std::vector< MatType > &ex, std::vector< MatType > &v, std::vector< MatType > &vdef, const Dict &opts=Dict())
 Introduce intermediate variables for selected nodes in a graph. More...
 
void shared (std::vector< MatType > &ex, std::vector< MatType > &v, std::vector< MatType > &vdef, const std::string &v_prefix="v_", const std::string &v_suffix="")
 Extract shared subexpressions from an set of expressions. More...
 
MatType repsum (const MatType &A, casadi_int n, casadi_int m=1)
 Given a repeated matrix, computes the sum of repeated parts. More...
 
MatType einstein (const MatType &A, const MatType &B, const MatType &C, const std::vector< casadi_int > &dim_a, const std::vector< casadi_int > &dim_b, const std::vector< casadi_int > &dim_c, const std::vector< casadi_int > &a, const std::vector< casadi_int > &b, const std::vector< casadi_int > &c)
 Compute any contraction of two dense tensors, using index/einstein notation. More...
 
MatType einstein (const MatType &A, const MatType &B, const std::vector< casadi_int > &dim_a, const std::vector< casadi_int > &dim_b, const std::vector< casadi_int > &dim_c, const std::vector< casadi_int > &a, const std::vector< casadi_int > &b, const std::vector< casadi_int > &c)
 Compute any contraction of two dense tensors, using index/einstein notation. More...
 
bool contains (const std::vector< MatType > &v, const MatType &n)
 Check if expression n is listed in v. More...
 
bool contains_all (const std::vector< MatType > &v, const std::vector< MatType > &n)
 Check if expression n is listed in v. More...
 
bool contains_any (const std::vector< MatType > &v, const std::vector< MatType > &n)
 Check if expression n is listed in v. More...
 
MatType hessian (const MatType &ex, const MatType &arg, const Dict &opts=Dict())
 Hessian and (optionally) gradient. More...
 
MatType hessian (const MatType &ex, const MatType &arg, MatType &output_g, const Dict &opts=Dict())
 Hessian and (optionally) gradient. More...
 
MatType transform (const MatType &x, const Dict &opts=Dict())
 Apply transformation passes to an expression. More...
 
MatType transform (const MatType &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict())
 Apply transformation passes to an expression. More...
 
std::vector< MatType > transform (const std::vector< MatType > &x, const Dict &opts=Dict())
 Apply transformation passes to an expression. More...
 
std::vector< MatType > transform (const std::vector< MatType > &x, const std::vector< std::vector< GenericType > > &passes, const Dict &opts=Dict())
 Apply transformation passes to an expression. More...
 
MatType mmin (const MatType &x)
 Smallest element in a matrix. More...
 
MatType mmax (const MatType &x)
 Largest element in a matrix. More...
 
MatType bilin (const MatType &A, const MatType &x, const MatType &y)
 Calculate bilinear/quadratic form x^T A y. More...
 
MatType bilin (const MatType &A, const MatType &x)
 Calculate bilinear/quadratic form x^T A y. More...
 
static MatType bilin (const MatType &A, const MatType &x, const MatType &y)
 Calculate bilinear/quadratic form x^T A y. More...
 
MatType rank1 (const MatType &A, const MatType &alpha, const MatType &x, const MatType &y)
 Make a rank-1 update to a matrix A. More...
 
static MatType rank1 (const MatType &A, const MatType &alpha, const MatType &x, const MatType &y)
 Make a rank-1 update to a matrix A. More...
 

Member Function Documentation

◆ colind()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::colind ( casadi_int  col) const
inline

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.

◆ columns()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::columns ( ) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_1av

Definition at line 295 of file generic_matrix.hpp.

◆ dim()

template<typename MatType >
std::string casadi::GenericMatrix< MatType >::dim ( bool  with_nz = false) const

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")

See also
size, nnz

Extra doc: https://github.com/casadi/casadi/wiki/L_1aw

◆ get_colind()

template<typename MatType >
std::vector<casadi_int> casadi::GenericMatrix< MatType >::get_colind ( ) const
inline

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.

◆ get_row()

template<typename MatType >
std::vector<casadi_int> casadi::GenericMatrix< MatType >::get_row ( ) const
inline

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.

◆ is_column()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_column ( ) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_1b5

Definition at line 517 of file generic_matrix.hpp.

◆ is_dense()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_dense ( ) const
inline

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)

See also
nnz, numel, densify

Extra doc: https://github.com/casadi/casadi/wiki/L_1b0

Definition at line 434 of file generic_matrix.hpp.

◆ is_empty()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_empty ( bool  both = false) const
inline

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.

◆ is_row()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_row ( ) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_1b4

Definition at line 512 of file generic_matrix.hpp.

◆ is_scalar()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_scalar ( bool  scalar_and_dense = false) const
Parameters
scalar_and_denseWhen 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

◆ is_square()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_square ( ) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_1b2

Definition at line 470 of file generic_matrix.hpp.

◆ is_tril()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_tril ( ) const
inline

Decided on the sparsity pattern alone, see is_triu.

See also
is_triu, tril, tril2symm

Extra doc: https://github.com/casadi/casadi/wiki/L_1b7

Definition at line 560 of file generic_matrix.hpp.

◆ is_triu()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_triu ( ) const
inline

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)

See also
is_tril, triu, triu2symm

Extra doc: https://github.com/casadi/casadi/wiki/L_1b6

Definition at line 551 of file generic_matrix.hpp.

◆ is_vector()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_vector ( ) const
inline

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)

See also
is_row, is_column

Extra doc: https://github.com/casadi/casadi/wiki/L_1b3

Definition at line 507 of file generic_matrix.hpp.

◆ nnz()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::nnz ( ) const

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

See also
numel, nnz_lower, nnz_upper, nnz_diag, sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1an

◆ nnz_diag()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::nnz_diag ( ) const

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)

See also
nnz, nnz_lower, nnz_upper

Extra doc: https://github.com/casadi/casadi/wiki/L_1aq

◆ nnz_lower()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::nnz_lower ( ) const

>>> 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)

See also
nnz, nnz_upper, nnz_diag

Extra doc: https://github.com/casadi/casadi/wiki/L_1ao

◆ nnz_upper()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::nnz_upper ( ) const

>>> 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)

See also
nnz, nnz_lower, nnz_diag

Extra doc: https://github.com/casadi/casadi/wiki/L_1ap

◆ numel()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::numel ( ) const

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

See also
nnz, size

Extra doc: https://github.com/casadi/casadi/wiki/L_1ar

◆ ones() [1/3]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::ones ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestatic

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]])

See also
zeros, Sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1di

Definition at line 5206 of file generic_matrix.hpp.

◆ ones() [2/3]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::ones ( const Sparsity &  sp)
inlinestatic

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]])

See also
zeros, Sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1di

Definition at line 5209 of file generic_matrix.hpp.

◆ ones() [3/3]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::ones ( const std::pair< casadi_int, casadi_int > &  rc)
inlinestatic

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]])

See also
zeros, Sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1di

Definition at line 5210 of file generic_matrix.hpp.

◆ row()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::row ( casadi_int  el) const
inline

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.

◆ rows()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::rows ( ) const
inline

Extra doc: https://github.com/casadi/casadi/wiki/L_1at

Definition at line 283 of file generic_matrix.hpp.

◆ size() [1/2]

template<typename MatType >
std::pair<casadi_int, casadi_int> casadi::GenericMatrix< MatType >::size ( ) const

>>> 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)

See also
size1, size2, numel, dim

Extra doc: https://github.com/casadi/casadi/wiki/L_1ax

◆ size() [2/2]

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::size ( casadi_int  axis) const
Parameters
axis1 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

◆ size1()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::size1 ( ) const

>>> 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)

See also
size2, size, rows

Extra doc: https://github.com/casadi/casadi/wiki/L_1as

◆ size2()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::size2 ( ) const

◆ sparsity()

template<typename MatType >
Sparsity casadi::GenericMatrix< MatType >::sparsity ( ) const

>>> 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

◆ sym() [1/7]

template<typename MatType >
static std::vector<MatType > casadi::GenericMatrix< MatType >::sym ( const std::string &  name,
casadi_int  nrow,
casadi_int  ncol,
casadi_int  p 
)
inlinestatic

>>> 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.

◆ sym() [2/7]

template<typename MatType >
static std::vector<std::vector<MatType> > casadi::GenericMatrix< MatType >::sym ( const std::string &  name,
casadi_int  nrow,
casadi_int  ncol,
casadi_int  p,
casadi_int  r 
)
inlinestatic

>>> 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.

◆ sym() [3/7]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::sym ( const std::string &  name,
casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestatic

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.

Parameters
nameName used for printing. For SX, a name of the form "[a,b,c]" assigns individual names to the numel() entries.
nrowNumber of rows, default 1
ncolNumber 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

See also
symvar, zeros, ones

Extra doc: https://github.com/casadi/casadi/wiki/L_1da

Definition at line 4948 of file generic_matrix.hpp.

◆ sym() [4/7]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::sym ( const std::string &  name,
const Sparsity &  sp 
)
inlinestatic

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.

◆ sym() [5/7]

template<typename MatType >
std::vector< MatType > casadi::GenericMatrix< MatType >::sym ( const std::string &  name,
const Sparsity &  sp,
casadi_int  p 
)
static

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 5286 of file generic_matrix.hpp.

◆ sym() [6/7]

template<typename MatType >
std::vector< std::vector< MatType > > casadi::GenericMatrix< MatType >::sym ( const std::string &  name,
const Sparsity &  sp,
casadi_int  p,
casadi_int  r 
)
static

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 5299 of file generic_matrix.hpp.

◆ sym() [7/7]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::sym ( const std::string &  name,
const std::pair< casadi_int, casadi_int > &  rc 
)
inlinestatic

◆ zeros() [1/3]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::zeros ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestatic

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))

See also
ones, Sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1dh

Examples
misc/all.cc.

Definition at line 5151 of file generic_matrix.hpp.

◆ zeros() [2/3]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::zeros ( const Sparsity &  sp)
inlinestatic

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))

See also
ones, Sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1dh

Definition at line 5154 of file generic_matrix.hpp.

◆ zeros() [3/3]

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::zeros ( const std::pair< casadi_int, casadi_int > &  rc)
inlinestatic

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))

See also
ones, Sparsity

Extra doc: https://github.com/casadi/casadi/wiki/L_1dh

Definition at line 5155 of file generic_matrix.hpp.


The documentation for this class was generated from the following file: