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]
Collaboration diagram for casadi::GenericMatrix< MatType >:
Collaboration 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...
 
template<typename K >
const MatType nz (const K &k) const
 Get vector nonzero or slice of nonzeros. More...
 
template<typename K >
NonZeros< MatType, K > nz (const K &k)
 Access vector nonzero or slice of nonzeros. More...
 
template<typename RR >
const MatType operator() (const RR &rr) const
 Get vector element or slice. More...
 
template<typename RR , typename CC >
const MatType operator() (const RR &rr, const CC &cc) const
 Get Matrix element or slice. More...
 
template<typename RR >
SubIndex< MatType, RR > operator() (const RR &rr)
 Access Matrix elements (one argument) More...
 
template<typename RR , typename CC >
SubMatrix< MatType, RR, CC > operator() (const RR &rr, const CC &cc)
 Access Matrix elements (two arguments) More...
 
std::vector< casadi_int > get_row () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
std::vector< casadi_int > get_colind () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
const casadi_int * row () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
const casadi_int * 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 interp1d (const std::vector< double > &x, const MatType &v, const std::vector< double > &xq, const std::string &mode, bool equidistant)
 Functions called by friend functions defined here. More...
 
static casadi_int sprank (const MatType &x)
 Functions called by friend functions defined here. More...
 
static casadi_int norm_0_mul (const MatType &x, const MatType &y)
 Functions called by friend functions defined here. More...
 
static MatType tril (const MatType &x, bool includeDiagonal=true)
 Functions called by friend functions defined here. More...
 
static MatType triu (const MatType &x, bool includeDiagonal=true)
 Functions called by friend functions defined here. More...
 
static MatType sumsqr (const MatType &x)
 Functions called by friend functions defined here. More...
 
static MatType linspace (const MatType &a, const MatType &b, casadi_int nsteps)
 Functions called by friend functions defined here. More...
 
static MatType cross (const MatType &a, const MatType &b, casadi_int dim=-1)
 Functions called by friend functions defined here. More...
 
static MatType skew (const MatType &a)
 Functions called by friend functions defined here. More...
 
static MatType inv_skew (const MatType &a)
 Functions called by friend functions defined here. More...
 
static MatType tril2symm (const MatType &x)
 Functions called by friend functions defined here. More...
 
static MatType triu2symm (const MatType &x)
 Functions called by friend functions defined here. More...
 
static MatType repsum (const MatType &x, casadi_int n, casadi_int m=1)
 Functions called by friend functions defined here. More...
 
static MatType diff (const MatType &x, casadi_int n=1, casadi_int axis=-1)
 Functions called by friend functions defined here. More...
 
static bool is_linear (const MatType &expr, const MatType &var)
 Functions called by friend functions defined here. More...
 
static bool is_quadratic (const MatType &expr, const MatType &var)
 Functions called by friend functions defined here. More...
 
static void quadratic_coeff (const MatType &expr, const MatType &var, MatType &A, MatType &b, MatType &c, bool check)
 Functions called by friend functions defined here. More...
 
static void linear_coeff (const MatType &expr, const MatType &var, MatType &A, MatType &b, bool check)
 Functions called by friend functions defined here. More...
 
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...
 
static 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, 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 rank1 (const MatType &A, const MatType &alpha, const MatType &x, const MatType &y)
 Make a rank-1 update to a matrix A. 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...
 

Member Function Documentation

◆ colind() [1/2]

template<typename MatType >
const casadi_int* casadi::GenericMatrix< MatType >::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 606 of file generic_matrix.hpp.

606 { return sparsity().colind(); }
Sparsity sparsity() const
Get the sparsity pattern.
const casadi_int * colind() const
Get a reference to the colindex of all column element (see class description)
Definition: sparsity.cpp:170

References casadi::Sparsity::colind(), and casadi::GenericMatrix< MatType >::sparsity().

Referenced by casadi::Matrix< Scalar >::densify(), casadi::SnoptInterface::init(), casadi::Conic::sdp_to_socp_init(), casadi::MX::set(), casadi::SnoptInterface::solve(), and casadi::SnoptInterface::userfun().

◆ colind() [2/2]

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.

609 { return sparsity().colind(col); }

References casadi::Sparsity::colind(), and casadi::GenericMatrix< MatType >::sparsity().

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

295 {return size2();}
casadi_int size2() const
Get the second dimension (i.e. number of columns)

References casadi::GenericMatrix< MatType >::size2().

◆ cross()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::cross ( const MatType &  a,
const MatType &  b,
casadi_int  dim = -1 
)
static

Definition at line 5326 of file generic_matrix.hpp.

5326  {
5327  casadi_assert(a.size1()==b.size1() && a.size2()==b.size2(),
5328  "cross(a, b): Inconsistent dimensions. Dimension of a ("
5329  + a.dim() + " ) must equal that of b (" + b.dim() + ").");
5330 
5331  casadi_assert(a.size1()==3 || a.size2()==3,
5332  "cross(a, b): One of the dimensions of a should have length 3, but got "
5333  + a.dim() + ".");
5334  casadi_assert(dim==-1 || dim==1 || dim==2,
5335  "cross(a, b, dim): Dim must be 1, 2 or -1 (automatic).");
5336 
5337  std::vector<MatType> ret(3);
5338 
5339  bool t = a.size1()==3;
5340 
5341  if (dim==1) t = true;
5342  if (dim==2) t = false;
5343 
5344  MatType a1 = t ? a(0, Slice()) : a(Slice(), 0);
5345  MatType a2 = t ? a(1, Slice()) : a(Slice(), 1);
5346  MatType a3 = t ? a(2, Slice()) : a(Slice(), 2);
5347 
5348  MatType b1 = t ? b(0, Slice()) : b(Slice(), 0);
5349  MatType b2 = t ? b(1, Slice()) : b(Slice(), 1);
5350  MatType b3 = t ? b(2, Slice()) : b(Slice(), 2);
5351 
5352  ret[0] = a2*b3-a3*b2;
5353  ret[1] = a3*b1-a1*b3;
5354  ret[2] = a1*b2-a2*b1;
5355 
5356  return t ? vertcat(ret) : horzcat(ret);
5357  }
std::string dim(bool with_nz=false) const
Get string representation of dimensions.
friend MatType vertcat(const std::vector< MatType > &v)
Concatenate a list of matrices vertically.
friend MatType horzcat(const std::vector< MatType > &v)
Concatenate a list of matrices horizontally.

◆ diff()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::diff ( const MatType &  x,
casadi_int  n = 1,
casadi_int  axis = -1 
)
static

Definition at line 5709 of file generic_matrix.hpp.

5709  {
5710  casadi_assert(axis==-1 || axis==0 || axis==1, "Axis argument invalid");
5711  casadi_assert(n>=1, "n argument invalid");
5712 
5713  MatType ret = x;
5714  for (casadi_int i=0;i<n;++i) {
5715  // Matlab's special case
5716  if (axis==-1 && ret.is_scalar()) return MatType();
5717 
5718  casadi_int local_axis = (axis==-1) ? ret.is_row() : axis;
5719  if (local_axis==0) {
5720  if (ret.size1()<=1) {
5721  ret = MatType::zeros(0, ret.size2());
5722  } else {
5723  ret = ret(Slice(1, ret.size1()), Slice())-ret(Slice(0, ret.size1()-1), Slice());
5724  }
5725  } else {
5726  if (ret.size2()<=1) {
5727  ret = MatType::zeros(ret.size1(), 0);
5728  } else {
5729  ret = ret(Slice(), Slice(1, ret.size2()))-ret(Slice(), Slice(0, ret.size2()-1));
5730  }
5731  }
5732  }
5733  return ret;
5734  }

◆ 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

Definition at line 5274 of file generic_matrix.hpp.

5274  {
5275  return sparsity().dim(with_nz);
5276  }
std::string dim(bool with_nz=false) const
Dimensions as a string "nrow x ncol", optionally with the number of nonzeros.
Definition: sparsity.cpp:595

Referenced by casadi::Assertion::Assertion(), casadi::MX::attachAssert(), casadi::MX::binary(), casadi::OptiNode::canon_expr(), casadi::BSplineParametric::create(), casadi::BSpline::create(), casadi::OptiNode::describe(), casadi::SymbolicQr::det(), casadi::Determinant::Determinant(), casadi::MXNode::get_find(), casadi::MXNode::get_mac(), casadi::MX::interpn_linear(), casadi::Inverse::Inverse(), casadi::Low::Low(), casadi::MX::mac(), casadi::OptiNode::minimize(), casadi::Multiplication::Multiplication(), casadi::MX::MX(), casadi::MX::project(), casadi::OptiNode::set_linear_scale(), casadi::Linsol::solve(), casadi::Solve< Tr >::Solve(), and casadi::OptiNode::subject_to().

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

603 { return sparsity().get_colind(); }
std::vector< casadi_int > get_colind() const
Column offsets of the compressed column storage.
Definition: sparsity.cpp:366

References casadi::Sparsity::get_colind(), and casadi::GenericMatrix< MatType >::sparsity().

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

602 { return sparsity().get_row(); }
std::vector< casadi_int > get_row() const
Row index of every nonzero, in nonzero (column-major) order.
Definition: sparsity.cpp:374

References casadi::Sparsity::get_row(), and casadi::GenericMatrix< MatType >::sparsity().

◆ interp1d()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::interp1d ( const std::vector< double > &  x,
const MatType &  v,
const std::vector< double > &  xq,
const std::string &  mode,
bool  equidistant 
)
static

Definition at line 5363 of file generic_matrix.hpp.

5364  {
5365 
5366  bool mode_floor = false;
5367  bool mode_ceil = false;
5368  if (mode=="floor") {
5369  mode_floor = true;
5370  } else if (mode=="ceil") {
5371  mode_ceil = true;
5372  } else if (mode=="linear") {
5373  //
5374  } else {
5375  casadi_error("interp1d(x, v, xq, mode): "
5376  "Mode must be 'floor', 'ceil' or 'linear'. Got '" + mode + "' instead.");
5377  }
5378 
5379  casadi_assert(is_increasing(x), "interp1d(x, v, xq): x must be increasing.");
5380 
5381  casadi_assert(x.size()==v.size1(),
5382  "interp1d(x, v, xq): dimensions mismatch. v expected to have " + str(x.size()) + " rows,"
5383  " but got " + str(v.size1()) + " instead.");
5384 
5385  // Need at least two elements
5386  casadi_assert(x.size()>=2, "interp1d(x, v, xq): x must be at least length 2.");
5387 
5388  // Vectors to compose a sparse matrix
5389  std::vector<double> val;
5390  std::vector<casadi_int> colind(1, 0);
5391  std::vector<casadi_int> row;
5392 
5393  // Number of nonzeros in to-be composed matrix
5394  casadi_int nnz = 0;
5395  for (casadi_int i=0;i<xq.size();++i) {
5396  // Obtain index corresponding to xq[i]
5397  double ind = index_interp1d(x, xq[i], equidistant);
5398 
5399  if (mode_floor) ind = floor(ind);
5400  if (mode_ceil) ind = ceil(ind);
5401 
5402  // Split into integer and fractional part
5403  double int_partd;
5404  double frac_part = modf(ind, &int_partd);
5405  casadi_int int_part = static_cast<casadi_int>(int_partd);
5406 
5407  if (frac_part==0) {
5408  // Create a single entry
5409  val.push_back(1);
5410  row.push_back(int_part);
5411  nnz+=1;
5412  colind.push_back(nnz);
5413  } else {
5414  // Create a double entry
5415  val.push_back(1-frac_part);
5416  val.push_back(frac_part);
5417  row.push_back(int_part);
5418  row.push_back(int_part+1);
5419  nnz+=2;
5420  colind.push_back(nnz);
5421  }
5422  }
5423 
5424  // Construct sparsity for composed matrix
5425  Sparsity sp(x.size(), xq.size() , colind, row);
5426 
5427  return MatType::mtimes(MatType(sp, val).T(), v);
5428 
5429  }
casadi_int nnz() const
Get the number of structural nonzeros.
const casadi_int * colind() const
Get the sparsity pattern. See the Sparsity class for details.
const casadi_int * row() const
Get the sparsity pattern. See the Sparsity class for details.
double index_interp1d(const std::vector< double > &x, double xq, bool equidistant)
bool is_increasing(const std::vector< T > &v)
Check if the vector is strictly increasing.
std::string str(const T &v)
String representation, any type.

References casadi::index_interp1d(), casadi::is_increasing(), casadi::str(), and casadi::T.

◆ inv_skew()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::inv_skew ( const MatType &  a)
static

Definition at line 5443 of file generic_matrix.hpp.

5443  {
5444  casadi_assert(a.size1()==3 && a.size2()==3,
5445  "inv_skew(a): Expecting 3-by-3 matrix, got " + a.dim() + ".");
5446 
5447  return 0.5*vertcat(std::vector<MatType>({a(2, 1)-a(1, 2), a(0, 2)-a(2, 0), a(1, 0)-a(0, 1)}));
5448  }

◆ is_column()

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

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

434 { return sparsity().is_dense();}
bool is_dense() const
Check whether every entry is a structural nonzero, i.e. nnz() == numel()
Definition: sparsity.cpp:275

References casadi::Sparsity::is_dense(), and casadi::GenericMatrix< MatType >::sparsity().

Referenced by casadi::MXNode::_get_binary(), casadi::GetNonzerosParam::create(), casadi::SetNonzerosParam< Add >::create(), casadi::Matrix< Scalar >::densify(), casadi::MX::densify(), casadi::DaeBuilderInternal::eq(), casadi::Function::generate_in(), casadi::Function::generate_out(), casadi::Matrix< Scalar >::get(), casadi::MX::get(), casadi::MXNode::get_mac(), casadi::is_slice(), casadi::Low::Low(), casadi::MX::MX(), casadi::MX::polyval(), casadi::Matrix< Scalar >::set(), casadi::MX::set(), casadi::MX::set_nz(), casadi::DenseKron::try_create(), casadi::DenseSparseKron::try_create(), casadi::SparseDenseKron::try_create(), casadi::DenseKronContract::try_create(), casadi::DenseSparseKronContract::try_create(), casadi::SparseDenseKronContract::try_create(), casadi::DenseMultiplication::try_create(), and casadi::DenseSparseMultiplication::try_create().

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

402 { return sparsity().is_empty(both);}
bool is_empty(bool both=false) const
Check whether the pattern has a zero dimension.
Definition: sparsity.cpp:146

References casadi::Sparsity::is_empty(), and casadi::GenericMatrix< MatType >::sparsity().

Referenced by casadi::activation(), casadi::Call::ad_reverse(), casadi::OptiNode::assert_empty(), casadi::OptiNode::bake(), casadi::MX::binary(), casadi::Call::common_cond(), casadi::DaeBuilderInternal::create(), casadi::DaeBuilderInternal::disp(), casadi::Function::generate_in(), casadi::Function::generate_out(), casadi::MXNode::get_nzadd(), casadi::AmplInterface::init(), casadi::BSpline::jac_cached(), casadi::BSplineParametric::jac_cached(), casadi::MX::project(), casadi::Call::projectArg(), casadi::DaeBuilderInternal::set_init(), and casadi::OptiNode::subject_to().

◆ is_linear()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_linear ( const MatType &  expr,
const MatType &  var 
)
static

Definition at line 5678 of file generic_matrix.hpp.

5678  {
5679  return !any(MatType::which_depends(expr, var, 2, true));
5680  }
bool any(const std::vector< bool > &v)
Check if any arguments are true.
Definition: casadi_misc.cpp:88

References casadi::any().

◆ is_quadratic()

template<typename MatType >
bool casadi::GenericMatrix< MatType >::is_quadratic ( const MatType &  expr,
const MatType &  var 
)
static

Definition at line 5683 of file generic_matrix.hpp.

5683  {
5684  return is_linear(gradient(expr, var), var);
5685  }
static bool is_linear(const MatType &expr, const MatType &var)
Functions called by friend functions defined here.
friend MatType gradient(const MatType &ex, const MatType &arg, const Dict &opts=Dict())
Calculate the gradient of an expression.

◆ is_row()

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

◆ 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

Definition at line 5279 of file generic_matrix.hpp.

5279  {
5280  return sparsity().is_scalar(scalar_and_dense);
5281  }
bool is_scalar(bool scalar_and_dense=false) const
Check whether the pattern is 1-by-1.
Definition: sparsity.cpp:271

Referenced by casadi::MXNode::_get_binary(), casadi::BinaryMX< ScX, ScY >::ad_reverse(), casadi::Call::ad_reverse(), casadi::Assertion::Assertion(), casadi::MX::attachAssert(), casadi::MX::binary(), casadi::OptiNode::canon_expr(), casadi::ConstantMX::create(), casadi::Matrix< Scalar >::densify(), casadi::MX::densify(), casadi::MXFunction::export_code_body(), casadi::Matrix< Scalar >::get(), casadi::MXNode::get_binary(), casadi::Matrix< Scalar >::get_nz(), casadi::is_slice(), casadi::MX::mac(), casadi::OptiNode::minimize(), casadi::MX::mldivide(), casadi::MX::mrdivide(), casadi::MX::mtimes(), casadi::MX::MX(), casadi::Call::projectArg(), casadi::qr_block_det(), casadi::Matrix< Scalar >::set(), casadi::MX::set(), casadi::OptiNode::set_linear_scale(), casadi::Matrix< Scalar >::set_nz(), casadi::MX::set_nz(), and casadi::to_slice().

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

470 { return sparsity().is_square();}
bool is_square() const
Check whether the number of rows equals the number of columns.
Definition: sparsity.cpp:295

References casadi::Sparsity::is_square(), and casadi::GenericMatrix< MatType >::sparsity().

Referenced by casadi::SymbolicQr::det(), casadi::Determinant::Determinant(), and casadi::MX::trace().

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

560 { return sparsity().is_tril();}
bool is_tril(bool strictly=false) const
Check whether all nonzeros are on or below the diagonal (row >= col)
Definition: sparsity.cpp:323

References casadi::Sparsity::is_tril(), and casadi::GenericMatrix< MatType >::sparsity().

Referenced by casadi::MX::solve().

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

551 { return sparsity().is_triu();}
bool is_triu(bool strictly=false) const
Check whether all nonzeros are on or above the diagonal (row <= col)
Definition: sparsity.cpp:327

References casadi::Sparsity::is_triu(), and casadi::GenericMatrix< MatType >::sparsity().

Referenced by casadi::MX::solve().

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

507 { return sparsity().is_vector();}
bool is_vector() const
Check whether the pattern is a row or a column vector.
Definition: sparsity.cpp:291

References casadi::Sparsity::is_vector(), and casadi::GenericMatrix< MatType >::sparsity().

Referenced by casadi::OptiNode::canon_expr(), casadi::BSplineParametric::create(), casadi::GetNonzerosParam::create(), casadi::BSpline::create(), casadi::SetNonzerosParam< Add >::create(), casadi::Function::generate_in(), casadi::Function::generate_out(), casadi::Matrix< Scalar >::get(), casadi::MX::get(), casadi::MXNode::get_find(), casadi::MX::interpn_linear(), casadi::Low::Low(), casadi::MX::norm_2(), casadi::orient_vector(), and casadi::MX::polyval().

◆ linear_coeff()

template<typename MatType >
void casadi::GenericMatrix< MatType >::linear_coeff ( const MatType &  expr,
const MatType &  var,
MatType &  A,
MatType &  b,
bool  check 
)
static

Definition at line 5699 of file generic_matrix.hpp.

5700  {
5701  casadi_assert(expr.is_vector(), "'linear_coeff' only defined for vector expressions.");
5702  if (check)
5703  casadi_assert(is_linear(expr, var), "'linear_coeff' called on non-linear expression.");
5704  A = substitute(jacobian(expr, var), var, 0);
5705  b = vec(substitute(expr, var, 0));
5706  }
static MatType vec(const MatType &x)
friend MatType substitute(const MatType &ex, const MatType &v, const MatType &vdef)
Substitute variable v with expression vdef in an expression ex.
friend MatType jacobian(const MatType &ex, const MatType &arg, const Dict &opts=Dict())
Calculate Jacobian.

◆ linspace()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::linspace ( const MatType &  a,
const MatType &  b,
casadi_int  nsteps 
)
static

Definition at line 5312 of file generic_matrix.hpp.

5312  {
5313  casadi_assert(nsteps>=1, "linspace: nsteps (" + str(nsteps) + ") must be at least 1");
5314  std::vector<MatType> ret(nsteps);
5315  ret[0] = a;
5316  MatType step = (b-a)/static_cast<MatType>(nsteps-1);
5317 
5318  for (casadi_int i=1; i<nsteps-1; ++i)
5319  ret[i] = a + i * step;
5320 
5321  ret[nsteps-1] = b;
5322  return vertcat(ret);
5323  }

References casadi::str().

◆ nnz()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::nnz

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

Definition at line 5229 of file generic_matrix.hpp.

5229  {
5230  return sparsity().nnz();
5231  }
casadi_int nnz() const
Number of structural nonzeros.
Definition: sparsity.cpp:150

Referenced by casadi::Constant< Value >::_get_binary(), casadi::OptiNode::bake(), casadi::ConstantMX::create(), casadi::GetNonzerosParam::create(), casadi::SetNonzeros< Add >::create(), casadi::GetNonzeros::create(), casadi::MX::depends_on(), casadi::Diagsplit::Diagsplit(), casadi::Dump::Dump(), casadi::Find::eval(), casadi::Low::eval(), casadi::GetNonzerosParamVector::eval(), casadi::GetNonzerosSliceParam::eval(), casadi::GetNonzerosParamSlice::eval(), casadi::GetNonzerosParamParam::eval(), casadi::HorzRepmat::eval_gen(), casadi::Concat::eval_gen(), casadi::Transpose::eval_gen(), casadi::Find::generate(), casadi::Low::generate(), casadi::Concat::generate(), casadi::GetNonzerosParamVector::generate(), casadi::GetNonzerosSliceParam::generate(), casadi::GetNonzerosParamSlice::generate(), casadi::GetNonzerosParamParam::generate(), casadi::Output::generate(), casadi::HorzRepmat::generate(), casadi::MXNode::get_binary(), casadi::MXNode::get_kron_contract(), casadi::MX::get_nonzeros(), casadi::MX::get_nz(), casadi::Concat::get_nzref(), casadi::HorzRepmat::get_nzref(), casadi::AmplInterface::init(), casadi::SnoptInterface::init(), casadi::SuperscsInterface::init(), casadi::Scpgen::init(), casadi::CplexInterface::init_mem(), casadi::SnoptInterface::init_mem(), casadi::SymbolicQr::linsol_eval_sx(), casadi::Monitor::Monitor(), casadi::mtaylor_recursive(), casadi::MX::polyval(), casadi::MXFunction::print_arg(), casadi::Reshape::Reshape(), casadi::Matrix< Scalar >::set(), casadi::MX::set(), casadi::MX::set_nz(), casadi::SuperscsInterface::solve(), casadi::MX::solve(), casadi::SnoptInterface::solve(), casadi::MXNode::sp_forward(), casadi::Concat::sp_forward(), casadi::Dot::sp_forward(), casadi::MXNode::sp_reverse(), casadi::Concat::sp_reverse(), casadi::Dot::sp_reverse(), casadi::GetNonzerosParam::sp_reverse(), casadi::HorzRepmat::sp_reverse(), casadi::MX::sparsity_cast(), casadi::SparsityCast::SparsityCast(), casadi::OptiNode::subject_to(), casadi::GetNonzerosParamSlice::sz_iw(), casadi::GetNonzerosParamParam::sz_iw(), and casadi::PseudoDenseMultiplication::try_create().

◆ nnz_diag()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::nnz_diag

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

Definition at line 5244 of file generic_matrix.hpp.

5244  {
5245  return sparsity().nnz_diag();
5246  }
casadi_int nnz_diag() const
Number of nonzeros on the main diagonal, i.e. entries (i, i)
Definition: sparsity.cpp:362

◆ nnz_lower()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::nnz_lower

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

Definition at line 5234 of file generic_matrix.hpp.

5234  {
5235  return sparsity().nnz_lower();
5236  }
casadi_int nnz_lower(bool strictly=false) const
Number of nonzeros in the lower triangular part, i.e. entries (i, j) with i >= j.
Definition: sparsity.cpp:354

◆ nnz_upper()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::nnz_upper

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

Definition at line 5239 of file generic_matrix.hpp.

5239  {
5240  return sparsity().nnz_upper();
5241  }
casadi_int nnz_upper(bool strictly=false) const
Number of nonzeros in the upper triangular part, i.e. entries (i, j) with i <= j.
Definition: sparsity.cpp:358

◆ norm_0_mul()

template<typename MatType >
static casadi_int casadi::GenericMatrix< MatType >::norm_0_mul ( const MatType &  x,
const MatType &  y 
)
inlinestatic

Definition at line 651 of file generic_matrix.hpp.

651  {
652  return Sparsity::norm_0_mul(x.sparsity(), y.sparsity());
653  }
static casadi_int norm_0_mul(const Sparsity &x, const Sparsity &A)
Accessed by SparsityInterface.
Definition: sparsity.cpp:1744

References casadi::Sparsity::norm_0_mul().

◆ numel()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::numel

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

Definition at line 5249 of file generic_matrix.hpp.

5249  {
5250  return sparsity().numel();
5251  }
casadi_int numel() const
Total number of entries, structural zeros included, i.e. size1()*size2()
Definition: sparsity.cpp:132

Referenced by casadi::BSpline::BSpline(), casadi::constant_ints(), casadi::BSplineParametric::create(), casadi::GetNonzerosParam::create(), casadi::BSpline::create(), casadi::OptiNode::g_describe(), casadi::Function::generate_in(), casadi::Function::generate_out(), casadi::DaeBuilderInternal::hess_v_v_from_calls(), casadi::init_gen(), casadi::MX::interpn_linear(), casadi::DaeBuilderInternal::jac_vdef_v_from_calls(), casadi::Low::Low(), casadi::orient_vector(), and casadi::KronContract::sz_w().

◆ nz() [1/2]

template<typename MatType >
template<typename K >
NonZeros<MatType, K> casadi::GenericMatrix< MatType >::nz ( const K &  k)
inline

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

Definition at line 693 of file generic_matrix.hpp.

693  {
694  return NonZeros<MatType, K>(self(), k);
695  }

◆ nz() [2/2]

template<typename MatType >
template<typename K >
const MatType casadi::GenericMatrix< MatType >::nz ( const K &  k) const
inline

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

Definition at line 683 of file generic_matrix.hpp.

683  {
684  MatType ret;
685  self().get_nz(ret, false, k);
686  return ret;
687  }

Referenced by casadi::SnoptInterface::init(), and casadi::MX::polyval().

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

5206  {
5207  return ones(Sparsity::dense(nrow, ncol));
5208  }
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.
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern.
Definition: sparsity.cpp:1041

References casadi::Sparsity::dense().

Referenced by casadi::OptiNode::bake(), casadi::OptiNode::canon_expr(), casadi::GenericMatrix< MatType >::ones(), and casadi::OptiNode::variable().

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

5209 { return MatType(sp, 1, false);}

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

5210  {
5211  return ones(rc.first, rc.second);
5212  }

References casadi::GenericMatrix< MatType >::ones().

◆ operator()() [1/4]

template<typename MatType >
template<typename RR >
SubIndex<MatType, RR> casadi::GenericMatrix< MatType >::operator() ( const RR &  rr)
inline

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

Definition at line 721 of file generic_matrix.hpp.

721  {
722  return SubIndex<MatType, RR>(self(), rr);
723  }

◆ operator()() [2/4]

template<typename MatType >
template<typename RR >
const MatType casadi::GenericMatrix< MatType >::operator() ( const RR &  rr) const
inline

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

Definition at line 701 of file generic_matrix.hpp.

701  {
702  MatType ret;
703  self().get(ret, false, rr);
704  return ret;
705  }

◆ operator()() [3/4]

template<typename MatType >
template<typename RR , typename CC >
SubMatrix<MatType, RR, CC> casadi::GenericMatrix< MatType >::operator() ( const RR &  rr,
const CC &  cc 
)
inline

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

Definition at line 729 of file generic_matrix.hpp.

729  {
730  return SubMatrix<MatType, RR, CC>(self(), rr, cc);
731  }

◆ operator()() [4/4]

template<typename MatType >
template<typename RR , typename CC >
const MatType casadi::GenericMatrix< MatType >::operator() ( const RR &  rr,
const CC &  cc 
) const
inline

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

Definition at line 711 of file generic_matrix.hpp.

711  {
712  MatType ret;
713  self().get(ret, false, rr, cc);
714  return ret;
715  }

◆ quadratic_coeff()

template<typename MatType >
void casadi::GenericMatrix< MatType >::quadratic_coeff ( const MatType &  expr,
const MatType &  var,
MatType &  A,
MatType &  b,
MatType &  c,
bool  check 
)
static

Definition at line 5688 of file generic_matrix.hpp.

5689  {
5690  casadi_assert(expr.is_scalar(), "'quadratic_coeff' only defined for scalar expressions.");
5691  A = hessian(expr, var);
5692  b = substitute(jacobian(expr, var), var, 0).T();
5693  if (check)
5694  casadi_assert(!depends_on(A, var), "'quadratic_coeff' called on non-quadratic expression.");
5695  c = substitute(expr, var, 0);
5696  }
friend bool depends_on(const MatType &f, const MatType &arg)
Check if expression depends on the argument.
friend MatType hessian(const MatType &ex, const MatType &arg, const Dict &opts=Dict())
Hessian and (optionally) gradient.

◆ repsum()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::repsum ( const MatType &  x,
casadi_int  n,
casadi_int  m = 1 
)
static

Definition at line 5461 of file generic_matrix.hpp.

5461  {
5462  casadi_assert(n>0 && x.size1() % n==0,
5463  "repsum: x.size1() (" + str(x.size1()) + ") must be a multiple of n (" + str(n) + ")");
5464  casadi_assert(m>0 && x.size2() % m==0,
5465  "repsum: x.size2() (" + str(x.size2()) + ") must be a multiple of m (" + str(m) + ")");
5466  std::vector< std::vector< MatType> > s =
5467  blocksplit(x, x.size1()/n, x.size2()/m);
5468  MatType sum = 0;
5469  for (casadi_int i=0;i<s.size();++i) {
5470  for (casadi_int j=0;j<s[i].size();++j) {
5471  sum = sum + s[i][j];
5472  }
5473  }
5474  return sum;
5475  }
static std::vector< std::vector< MatType > > blocksplit(const MatType &x, const std::vector< casadi_int > &vert_offset, const std::vector< casadi_int > &horz_offset)
friend MatType sum(const MatType &x)
Sum all elements.

References casadi::str(), and casadi::sum().

Referenced by casadi::MXNode::get_repsum().

◆ row() [1/2]

template<typename MatType >
const casadi_int* casadi::GenericMatrix< MatType >::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 605 of file generic_matrix.hpp.

605 { return sparsity().row(); }
const casadi_int * row() const
Get a reference to row-vector,.
Definition: sparsity.cpp:166

References casadi::Sparsity::row(), and casadi::GenericMatrix< MatType >::sparsity().

Referenced by casadi::Matrix< Scalar >::densify(), casadi::Transpose::eval_gen(), casadi::MX::set(), casadi::SnoptInterface::solve(), casadi::Transpose::sp_forward(), casadi::Transpose::sp_reverse(), and casadi::SnoptInterface::userfun().

◆ row() [2/2]

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.

608 { return sparsity().row(el); }

References casadi::Sparsity::row(), and casadi::GenericMatrix< MatType >::sparsity().

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

283 {return size1();}
casadi_int size1() const
Get the first dimension (i.e. number of rows)

References casadi::GenericMatrix< MatType >::size1().

◆ size() [1/2]

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

◆ 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

Definition at line 5269 of file generic_matrix.hpp.

5269  {
5270  return sparsity().size(axis);
5271  }

◆ size1()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::size1

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

Definition at line 5254 of file generic_matrix.hpp.

5254  {
5255  return sparsity().size1();
5256  }
casadi_int size1() const
Number of rows.
Definition: sparsity.cpp:124

Referenced by casadi::Constant< Value >::_get_binary(), casadi::SXFunction::ad_reverse(), casadi::MX::binary(), casadi::broadcastable(), casadi::BSplineParametric::BSplineParametric(), casadi::OptiNode::canon_expr(), casadi::BSplineInterpolant::construct_graph(), casadi::Matrix< Scalar >::cumsum(), casadi::Matrix< Scalar >::densify(), casadi::derivative_coeff_mx(), casadi::MX::diagsplit(), casadi::do_inline(), casadi::dplesol(), casadi::DaeBuilderInternal::eq(), casadi::Find::eval(), casadi::DenseTranspose::eval_gen(), casadi::DenseKronContract::eval_kernel(), casadi::Find::generate(), casadi::DenseKron::generate(), casadi::DenseSparseKron::generate(), casadi::SparseDenseKron::generate(), casadi::DenseKronContract::generate(), casadi::SparseDenseKronContract::generate(), casadi::DenseTranspose::generate(), casadi::get_boor(), casadi::MXNode::get_dot(), casadi::MXNode::get_mac(), casadi::MXNode::get_vertsplit(), casadi::SuperscsInterface::init(), casadi::SuperscsInterface::init_mem(), casadi::MX::inv(), casadi::Inverse::Inverse(), casadi::knot_size(), casadi::KronContract::KronContract(), casadi::SymbolicQr::linsol_eval_sx(), casadi::Onnx::load(), casadi::MX::mac(), casadi::Multiplication::Multiplication(), casadi::MX::MX(), casadi::orient_vector(), casadi::MX::pinv(), casadi::Call::projectArg(), casadi::MX::repmat(), casadi::MX::reshape(), casadi::GenericMatrix< MatType >::rows(), casadi::Matrix< Scalar >::set(), casadi::MX::set(), casadi::MX::set_nz(), casadi::simpleIRK(), casadi::Linsol::solve(), casadi::SuperscsInterface::solve(), casadi::Solve< Tr >::Solve(), casadi::DenseTranspose::sp_forward(), casadi::DenseTranspose::sp_reverse(), casadi::MX::sum1(), and casadi::MX::vertsplit().

◆ size2()

template<typename MatType >
casadi_int casadi::GenericMatrix< MatType >::size2
See also
size1, size, columns

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

Definition at line 5259 of file generic_matrix.hpp.

5259  {
5260  return sparsity().size2();
5261  }
casadi_int size2() const
Number of columns.
Definition: sparsity.cpp:128

Referenced by casadi::Constant< Value >::_get_binary(), casadi::SXFunction::ad_reverse(), casadi::MX::binary(), casadi::broadcastable(), casadi::OptiNode::canon_expr(), casadi::GenericMatrix< MatType >::columns(), casadi::BSplineInterpolant::construct_graph(), casadi::MX::cumsum(), casadi::Matrix< Scalar >::densify(), casadi::MX::diagsplit(), casadi::do_inline(), casadi::DenseTranspose::eval_gen(), casadi::DenseKronContract::eval_kernel(), casadi::DenseKron::generate(), casadi::DenseSparseKron::generate(), casadi::SparseDenseKron::generate(), casadi::DenseKronContract::generate(), casadi::SparseDenseKronContract::generate(), casadi::DenseTranspose::generate(), casadi::get_boor(), casadi::MXNode::get_dot(), casadi::MXNode::get_horzsplit(), casadi::MXNode::get_mac(), casadi::HorzRepsum::HorzRepsum(), casadi::MX::horzsplit(), casadi::CplexInterface::init_mem(), casadi::SnoptInterface::init_mem(), casadi::SuperscsInterface::init_mem(), casadi::Inverse::Inverse(), casadi::KronContract::KronContract(), casadi::Onnx::load(), casadi::MX::mac(), casadi::Multiplication::Multiplication(), casadi::CsparseInterface::nfact(), casadi::orient_vector(), casadi::MX::pinv(), casadi::Call::projectArg(), casadi::MX::repmat(), casadi::MX::reshape(), casadi::Conic::sdp_to_socp_init(), casadi::Matrix< Scalar >::set(), casadi::MX::set(), casadi::MX::set_nz(), casadi::Linsol::solve(), casadi::SuperscsInterface::solve(), casadi::Solve< Tr >::Solve(), casadi::DenseTranspose::sp_forward(), casadi::DenseTranspose::sp_reverse(), casadi::MX::sum2(), and casadi::MX::trace().

◆ skew()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::skew ( const MatType &  a)
static

Definition at line 5432 of file generic_matrix.hpp.

5432  {
5433  casadi_assert(a.is_vector() && (a.size1()==3 || a.size2()==3),
5434  "skew(a): Expecting 3-vector, got " + a.dim() + ".");
5435 
5436  MatType x = a(0);
5437  MatType y = a(1);
5438  MatType z = a(2);
5439  return blockcat(std::vector< std::vector<MatType> >({{0, -z, y}, {z, 0, -x}, {-y, x, 0}}));
5440  }
friend MatType blockcat(const std::vector< std::vector< MatType > > &v)
Construct a matrix from a list of lists of blocks.

◆ sparsity()

template<typename MatType >
const Sparsity & casadi::GenericMatrix< MatType >::sparsity

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

Definition at line 5224 of file generic_matrix.hpp.

5224  {
5225  return self().sparsity();
5226  }

Referenced by casadi::GenericMatrix< MatType >::colind(), casadi::GenericMatrix< MatType >::get_colind(), casadi::GenericMatrix< MatType >::get_row(), casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_empty(), casadi::GenericMatrix< MatType >::is_row(), casadi::GenericMatrix< MatType >::is_square(), casadi::GenericMatrix< MatType >::is_tril(), casadi::GenericMatrix< MatType >::is_triu(), casadi::GenericMatrix< MatType >::is_vector(), casadi::GenericMatrix< MatType >::row(), and casadi::MX::unite().

◆ sprank()

template<typename MatType >
static casadi_int casadi::GenericMatrix< MatType >::sprank ( const MatType &  x)
inlinestatic

Definition at line 650 of file generic_matrix.hpp.

650 { return Sparsity::sprank(x.sparsity());}
static casadi_int sprank(const Sparsity &x)
Accessed by SparsityInterface.
Definition: sparsity.cpp:1734

References casadi::Sparsity::sprank().

◆ sumsqr()

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::sumsqr ( const MatType &  x)
inlinestatic

Definition at line 660 of file generic_matrix.hpp.

660 { return dot(x, x);}
friend MatType dot(const MatType &x, const MatType &y)
Inner product of two matrices.

References casadi::GenericMatrix< MatType >::dot.

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

5064  {
5065  return sym(name, Sparsity::dense(nrow, ncol), p);
5066  }
static MatType sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.

References casadi::Sparsity::dense(), and casadi::GenericMatrix< MatType >::sym().

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

5107  {
5108  return sym(name, Sparsity::dense(nrow, ncol), p, r);
5109  }

References casadi::Sparsity::dense(), and casadi::GenericMatrix< MatType >::sym().

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

4948  {
4949  return sym(name, Sparsity::dense(nrow, ncol));
4950  }

References casadi::Sparsity::dense().

Referenced by casadi::GenericMatrix< MatType >::sym().

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

4997  {
4998  return MatType::_sym(name, sp);
4999  }

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

5287  {
5288  std::vector<MatType> ret(p);
5289  std::stringstream ss;
5290  for (casadi_int k=0; k<p; ++k) {
5291  ss.str("");
5292  ss << name << k;
5293  ret[k] = sym(ss.str(), sp);
5294  }
5295  return ret;
5296  }

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

5301  {
5302  std::vector<std::vector<MatType> > ret(r);
5303  for (casadi_int k=0; k<r; ++k) {
5304  std::stringstream ss;
5305  ss << name << "_" << k;
5306  ret[k] = sym(ss.str(), sp, p);
5307  }
5308  return ret;
5309  }

◆ 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

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

Definition at line 4955 of file generic_matrix.hpp.

4955  {
4956  return sym(name, rc.first, rc.second);
4957  }

References casadi::GenericMatrix< MatType >::sym().

◆ tril()

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::tril ( const MatType &  x,
bool  includeDiagonal = true 
)
inlinestatic

Definition at line 654 of file generic_matrix.hpp.

654  {
655  return project(x, Sparsity::tril(x.sparsity(), includeDiagonal));
656  }
static Sparsity tril(const Sparsity &x, bool includeDiagonal=true)
Accessed by SparsityInterface.
Definition: sparsity.cpp:1008
friend MatType project(const MatType &A, const Sparsity &sp, bool intersect=false)
Create a new matrix with a given sparsity pattern but with the.

References casadi::GenericMatrix< MatType >::project, and casadi::Sparsity::tril().

◆ tril2symm()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::tril2symm ( const MatType &  x)
static

Definition at line 5452 of file generic_matrix.hpp.

5452  {
5453  casadi_assert(x.is_square(),
5454  "Shape error in tril2symm. Expecting square shape but got " + x.dim());
5455  casadi_assert(x.nnz_upper()-x.nnz_diag()==0,
5456  "Sparsity error in tril2symm. Found above-diagonal entries in argument: " + x.dim());
5457  return x + x.T() - diag(diag(x));
5458  }
friend MatType diag(const MatType &A)
Get the diagonal of a matrix or construct a diagonal.

◆ triu()

template<typename MatType >
static MatType casadi::GenericMatrix< MatType >::triu ( const MatType &  x,
bool  includeDiagonal = true 
)
inlinestatic

Definition at line 657 of file generic_matrix.hpp.

657  {
658  return project(x, Sparsity::triu(x.sparsity(), includeDiagonal));
659  }
static Sparsity triu(const Sparsity &x, bool includeDiagonal=true)
Accessed by SparsityInterface.
Definition: sparsity.cpp:1012

References casadi::GenericMatrix< MatType >::project, and casadi::Sparsity::triu().

◆ triu2symm()

template<typename MatType >
MatType casadi::GenericMatrix< MatType >::triu2symm ( const MatType &  x)
static

Definition at line 5478 of file generic_matrix.hpp.

5478  {
5479  casadi_assert(x.is_square(),
5480  "Shape error in triu2symm. Expecting square shape but got " + x.dim());
5481  casadi_assert(x.nnz_lower()-x.nnz_diag()==0,
5482  "Sparsity error in triu2symm. Found below-diagonal entries in argument: " + x.dim());
5483  return x + x.T() - diag(diag(x));
5484  }

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

5151  {
5152  return zeros(Sparsity::dense(nrow, ncol));
5153  }
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.

References casadi::Sparsity::dense().

Referenced by casadi::GetNonzeros::ad_reverse(), casadi::GetNonzerosParamVector::ad_reverse(), casadi::GetNonzerosSliceParam::ad_reverse(), casadi::GetNonzerosParamSlice::ad_reverse(), casadi::GetNonzerosParamParam::ad_reverse(), casadi::HpmpcInterface::blocksparsity(), casadi::HpipmInterface::blocksparsity(), casadi::FatropConicInterface::blocksparsity(), casadi::OptiNode::canon_expr(), casadi::Sparsity::diagsplit(), casadi::FunctionInternal::dm_in(), casadi::FunctionInternal::dm_out(), casadi::Blocksqp::feasibilityRestorationPhase(), casadi::get_boor(), casadi::Expm::get_forward(), casadi::Expm::get_reverse(), casadi::init_gen(), casadi::MX::set(), casadi::OptiNode::variable(), and casadi::GenericMatrix< MatType >::zeros().

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

5154 { return MatType(sp, 0, false);}

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

5155  {
5156  return zeros(rc.first, rc.second);
5157  }

References casadi::GenericMatrix< MatType >::zeros().


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