List of all members | Public Types | Public Member Functions | Static Public Member Functions | Friends
casadi::Matrix< Scalar > Class Template Reference

Sparse matrix class. SX and DM are specializations. More...

#include <matrix_decl.hpp>

Detailed Description

template<typename Scalar>
class casadi::Matrix< Scalar >

General sparse matrix class that is designed with the idea that "everything is a matrix", that is, also scalars and vectors.
This philosophy makes it easy to use and to interface in particularly with Python and Matlab/Octave.
Index starts with 0.
Index vec happens as follows: (rr, cc) -> k = rr+cc*size1()
Vectors are column vectors.
The storage format is Compressed Column Storage (CCS), similar to that used for sparse matrices in Matlab,
but unlike this format, we do allow for elements to be structurally non-zero but numerically zero.
Matrix<Scalar> is polymorphic with a std::vector<Scalar> that contain all non-identical-zero elements.
The sparsity can be accessed with Sparsity& sparsity()

Author
Joel Andersson
Date
2010-2014

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

Definition at line 95 of file matrix_decl.hpp.

Inheritance diagram for casadi::Matrix< Scalar >:
Inheritance graph
[legend]
Collaboration diagram for casadi::Matrix< Scalar >:
Collaboration graph
[legend]

Public Types

typedef Scalar ScalarType
 Scalar type. More...
 
typedef GenericMatrix< Matrix< Scalar > > B
 Base class. More...
 

Public Member Functions

 Matrix ()
 constructors More...
 
 Matrix (const Matrix< Scalar > &m)
 Copy constructor. More...
 
Matrix< Scalar > & operator= (const Matrix< Scalar > &m)
 Assignment (normal) More...
 
 Matrix (casadi_int nrow, casadi_int ncol)
 Create a sparse matrix with all structural zeros. More...
 
 Matrix (const std::pair< casadi_int, casadi_int > &rc)
 Create a sparse matrix with all structural zeros. More...
 
std::vector< Scalar > * operator-> ()
 Access functions of the node. More...
 
const std::vector< Scalar > * operator-> () const
 Const access functions of the node. More...
 
 Matrix (const Sparsity &sp)
 Create a sparse matrix from a sparsity pattern. More...
 
 Matrix (const Sparsity &sp, const Matrix< Scalar > &d)
 Construct matrix with a given sparsity and nonzeros. More...
 
 Matrix (double val)
 This constructor enables implicit type conversion from a numeric type. More...
 
 Matrix (const std::vector< std::vector< double > > &m)
 Dense matrix constructor with data given as vector of vectors. More...
 
template<typename A >
 Matrix (const std::vector< A > &x)
 Create an expression from a vector. More...
 
template<typename A >
 Matrix (const Matrix< A > &x)
 Create a matrix from another matrix with a different entry type. More...
 
 Matrix (const std::vector< Scalar > &x)
 Construct from a vector. More...
 
 Matrix (std::initializer_list< Scalar > x)
 Construct from initializer list. More...
 
const Scalar scalar () const
 Convert to scalar type. More...
 
bool has_nz (casadi_int rr, casadi_int cc) const
 Returns true if the matrix has a non-zero at location rr, cc. More...
 
bool __nonzero__ () const
 Returns the truth value of a Matrix. More...
 
Matrix< Scalar > operator+ () const
 
Matrix< Scalar > operator- () const
 
Matrix< Scalar > printme (const Matrix< Scalar > &y) const
 
Matrix< Scalar > T () const
 Transpose the matrix. More...
 
void print_split (std::vector< std::string > &nz, std::vector< std::string > &inter) const
 Get strings corresponding to the nonzeros and the interdependencies. More...
 
void disp (std::ostream &stream, bool more=false) const
 Print a representation of the object. More...
 
std::string get_str (bool more=false) const
 Get string representation. More...
 
void print_scalar (std::ostream &stream) const
 Print scalar. More...
 
void print_vector (std::ostream &stream, bool truncate=true) const
 Print vector-style. More...
 
void print_dense (std::ostream &stream, bool truncate=true) const
 Print dense matrix-stype. More...
 
void print_sparse (std::ostream &stream, bool truncate=true) const
 Print sparse matrix style. More...
 
void clear ()
 
void resize (casadi_int nrow, casadi_int ncol)
 
void reserve (casadi_int nnz)
 
void reserve (casadi_int nnz, casadi_int ncol)
 
void erase (const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
 Erase a submatrix (leaving structural zeros in its place) More...
 
void erase (const std::vector< casadi_int > &rr, bool ind1=false)
 Erase a submatrix (leaving structural zeros in its place) More...
 
void remove (const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc)
 Remove columns and rows. More...
 
void enlarge (casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
 Enlarge matrix. More...
 
const Sparsitysparsity () const
 Const access the sparsity - reference to data member. More...
 
Sparsity get_sparsity () const
 Get an owning reference to the sparsity pattern. More...
 
Matrix< Scalar > get_output (casadi_int oind) const
 Get an output. More...
 
casadi_int element_hash () const
 Returns a number that is unique for a given symbolic scalar. More...
 
bool is_regular () const
 Checks if expression does not contain NaN or Inf. More...
 
bool is_smooth () const
 Check if smooth. More...
 
bool is_leaf () const
 Check if SX is a leaf of the SX graph. More...
 
bool is_commutative () const
 Check whether a binary SX is commutative. More...
 
bool is_symbolic () const
 Check if symbolic (Dense) More...
 
bool is_valid_input () const
 Check if matrix can be used to define function inputs. More...
 
bool has_duplicates () const
 Detect duplicate symbolic expressions. More...
 
void reset_input () const
 Reset the marker for an input expression. More...
 
bool is_constant () const
 Check if the matrix is constant (note that false negative answers are possible) More...
 
bool is_call () const
 Check if function call. More...
 
bool is_output () const
 Check if evaluation output. More...
 
bool has_output () const
 Check if a multiple output node. More...
 
casadi_int which_output () const
 Get the index of evaluation output - only valid when is_output() is true. More...
 
Function which_function () const
 Get function - only valid when is_call() is true. More...
 
bool is_integer () const
 Check if the matrix is integer-valued. More...
 
bool is_zero () const
 check if the matrix is 0 (note that false negative answers are possible) More...
 
bool is_one () const
 check if the matrix is 1 (note that false negative answers are possible) More...
 
bool is_minus_one () const
 check if the matrix is -1 (note that false negative answers are possible) More...
 
bool is_eye () const
 check if the matrix is an identity matrix (note that false negative answers More...
 
casadi_int op () const
 Get operation type. More...
 
bool is_op (casadi_int op) const
 Is it a certain operation. More...
 
bool has_zeros () const
 Check if the matrix has any zero entries which are not structural zeros. More...
 
std::vector< Scalar > get_nonzeros () const
 Get all nonzeros. More...
 
std::vector< Scalar > get_elements () const
 Get all elements. More...
 
template<typename A >
std::vector< A > get_nonzeros () const
 Get all nonzeros. More...
 
 operator double () const
 Type conversion to double. More...
 
 operator casadi_int () const
 Type conversion to casadi_int. More...
 
template<typename A >
 operator std::vector< A > () const
 Type conversion to a vector. More...
 
std::string name () const
 Get name (only if symbolic scalar) More...
 
Matrix< Scalar > dep (casadi_int ch=0) const
 Get expressions of the children of the expression. More...
 
casadi_int n_dep () const
 Get the number of dependencies of a binary SXElem. More...
 
void export_code (const std::string &lang, std::ostream &stream=casadi::uout(), const Dict &options=Dict()) const
 Export matrix in specific language. More...
 
Dict info () const
 
void serialize (std::ostream &stream) const
 Serialize an object. More...
 
std::string serialize () const
 Serialize. More...
 
void serialize (SerializingStream &s) const
 Serialize an object. More...
 
void to_file (const std::string &filename, const std::string &format="") const
 
 Matrix (const Sparsity &sp, const Scalar &val, bool dummy)
 Sparse matrix with a given sparsity with all values same. More...
 
 Matrix (const Sparsity &sp, const std::vector< Scalar > &d, bool dummy)
 Sparse matrix with a given sparsity and non-zero elements. More...
 
casadi_int nnz () const
 Get the number of (structural) non-zero elements. More...
 
casadi_int nnz_lower () const
 Get the number of non-zeros in the lower triangular half. More...
 
casadi_int nnz_upper () const
 Get the number of non-zeros in the upper triangular half. More...
 
casadi_int nnz_diag () const
 Get get the number of non-zeros on the diagonal. More...
 
casadi_int numel () const
 Get the number of elements. 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. 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. 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. More...
 
casadi_int size (casadi_int axis) const
 Get the size along a particular dimensions. More...
 
bool is_empty (bool both=false) const
 Check if the sparsity is empty, i.e. if one of the dimensions is zero. More...
 
bool is_dense () const
 Check if the matrix expression is dense. More...
 
bool is_scalar (bool scalar_and_dense=false) const
 Check if the matrix expression is scalar. More...
 
bool is_square () const
 Check if the matrix expression is square. More...
 
bool is_vector () const
 Check if the matrix is a row or column vector. More...
 
bool is_row () const
 Check if the matrix is a row vector (i.e. size1()==1) More...
 
bool is_column () const
 Check if the matrix is a column vector (i.e. size2()==1) More...
 
bool is_triu () const
 Check if the matrix is upper triangular. More...
 
bool is_tril () const
 Check if the matrix is lower triangular. More...
 
const Matrix< Scalar > nz (const K &k) const
 Get vector nonzero or slice of nonzeros. More...
 
NonZeros< Matrix< Scalar >, K > nz (const K &k)
 Access vector nonzero or slice of nonzeros. More...
 
const Matrix< Scalar > operator() (const RR &rr) const
 Get vector element or slice. More...
 
const Matrix< Scalar > operator() (const RR &rr, const CC &cc) const
 Get Matrix element or slice. More...
 
SubIndex< Matrix< Scalar >, RR > operator() (const RR &rr)
 Access Matrix elements (one argument) More...
 
SubMatrix< Matrix< Scalar >, RR, CC > operator() (const RR &rr, const CC &cc)
 Access Matrix elements (two arguments) More...
 
void get (Matrix< Scalar > &m, bool ind1, const Slice &rr) const
 
void get (Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr) const
 
void get (Matrix< Scalar > &m, bool ind1, const Sparsity &sp) const
 
void get (Matrix< Scalar > &m, bool ind1, const Slice &rr, const Slice &cc) const
 
void get (Matrix< Scalar > &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc) const
 
void get (Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc) const
 
void get (Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc) const
 
void set (const Matrix< Scalar > &m, bool ind1, const Slice &rr)
 
void set (const Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr)
 
void set (const Matrix< Scalar > &m, bool ind1, const Sparsity &sp)
 
void set (const Matrix< Scalar > &m, bool ind1, const Slice &rr, const Slice &cc)
 
void set (const Matrix< Scalar > &m, bool ind1, const Slice &rr, const Matrix< casadi_int > &cc)
 
void set (const Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr, const Slice &cc)
 
void set (const Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &rr, const Matrix< casadi_int > &cc)
 
void get_nz (Matrix< Scalar > &m, bool ind1, const Slice &k) const
 
void get_nz (Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &k) const
 
void set_nz (const Matrix< Scalar > &m, bool ind1, const Slice &k)
 
void set_nz (const Matrix< Scalar > &m, bool ind1, const Matrix< casadi_int > &k)
 
std::vector< Scalar > & nonzeros ()
 
const std::vector< Scalar > & nonzeros () const
 
std::vector< casadi_int > get_row () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
std::vector< casadi_int > get_colind () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
const casadi_int * row () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
casadi_int row (casadi_int el) const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
const casadi_int * colind () const
 Get the sparsity pattern. See the Sparsity class for details. More...
 
casadi_int colind (casadi_int col) const
 Get the sparsity pattern. See the Sparsity class for details. More...
 

Static Public Member Functions

static void set_max_depth (casadi_int eq_depth=1)
 Set or reset the depth to which equalities are being checked for simplifications. More...
 
static casadi_int get_max_depth ()
 Get the depth to which equalities are being checked for simplifications. More...
 
static std::vector< Matrix< Scalar > > get_input (const Function &f)
 Get function input. More...
 
static std::vector< Matrix< Scalar > > get_free (const Function &f)
 Get free. More...
 
static std::string type_name ()
 Get name of the class. More...
 
static void print_default (std::ostream &stream, const Sparsity &sp, const Scalar *nonzeros, bool truncate=true)
 Print default style. More...
 
static void print_scalar (std::ostream &stream, const Scalar &e)
 Print scalar. More...
 
static void print_vector (std::ostream &stream, const Sparsity &sp, const Scalar *nonzeros, bool truncate=true)
 Print vector-style. More...
 
static void print_sparse (std::ostream &stream, const Sparsity &sp, const Scalar *nonzeros, bool truncate=true)
 Print scalar. More...
 
static void print_split (casadi_int nnz, const Scalar *nonzeros, std::vector< std::string > &nz, std::vector< std::string > &inter)
 Get strings corresponding to the nonzeros and the interdependencies. More...
 
static void print_dense (std::ostream &stream, const Sparsity &sp, const Scalar *nonzeros, bool truncate=true)
 Print dense matrix-stype. More...
 
static Matrix< Scalar > eye (casadi_int n)
 create an n-by-n identity matrix More...
 
static void set_precision (casadi_int precision)
 Set the 'precision, width & scientific' used in printing and serializing to streams. More...
 
static void set_width (casadi_int width)
 
static void set_scientific (bool scientific)
 
static void rng (casadi_int seed)
 Seed the random number generator. More...
 
static Matrix< Scalar > deserialize (std::istream &stream)
 Build Sparsity from serialization. More...
 
static Matrix< Scalar > deserialize (const std::string &s)
 Build Sparsity from serialization. More...
 
static Matrix< Scalar > deserialize (DeserializingStream &s)
 
static void to_file (const std::string &filename, const Sparsity &sp, const Scalar *nonzeros, const std::string &format="")
 
static Matrix< double > from_file (const std::string &filename, const std::string &format_hint="")
 
static Matrix< Scalar > _sym (const std::string &name, const Sparsity &sp)
 
static Matrix< Scalar > logsumexp (const Matrix< Scalar > &x)
 
static Matrix< Scalar > binary (casadi_int op, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 Create nodes by their ID. More...
 
static Matrix< Scalar > unary (casadi_int op, const Matrix< Scalar > &x)
 Create nodes by their ID. More...
 
static Matrix< Scalar > scalar_matrix (casadi_int op, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 Create nodes by their ID. More...
 
static Matrix< Scalar > matrix_scalar (casadi_int op, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 Create nodes by their ID. More...
 
static Matrix< Scalar > matrix_matrix (casadi_int op, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 Create nodes by their ID. More...
 
static std::vector< Matrix< Scalar > > call (const Function &f, const std::vector< Matrix< Scalar > > &x)
 Create nodes by their ID. More...
 
static std::vector< Scalar > call (const Function &f, const std::vector< Scalar > &x)
 Create nodes by their ID. More...
 
static bool is_equal (const Matrix< Scalar > &x, const Matrix< Scalar > &y, casadi_int depth=0)
 
static Matrix< Scalar > mmin (const Matrix< Scalar > &x)
 
static Matrix< Scalar > mmax (const Matrix< Scalar > &x)
 
static Matrix< Scalar > simplify (const Matrix< Scalar > &x)
 
static Matrix< Scalar > jacobian (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Dict &opts=Dict())
 
static Sparsity jacobian_sparsity (const Matrix< Scalar > &f, const Matrix< Scalar > &x)
 
static Matrix< Scalar > hessian (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Dict &opts=Dict())
 
static Matrix< Scalar > hessian (const Matrix< Scalar > &f, const Matrix< Scalar > &x, Matrix< Scalar > &g, const Dict &opts=Dict())
 
static Matrix< Scalar > substitute (const Matrix< Scalar > &ex, const Matrix< Scalar > &v, const Matrix< Scalar > &vdef)
 
static std::vector< Matrix< Scalar > > substitute (const std::vector< Matrix< Scalar > > &ex, const std::vector< Matrix< Scalar > > &v, const std::vector< Matrix< Scalar > > &vdef)
 
static void substitute_inplace (const std::vector< Matrix< Scalar > > &v, std::vector< Matrix< Scalar > > &vdef, std::vector< Matrix< Scalar > > &ex, bool revers)
 
static Matrix< Scalar > pinv (const Matrix< Scalar > &x)
 
static Matrix< Scalar > pinv (const Matrix< Scalar > &A, const std::string &lsolver, const Dict &opts)
 
static Matrix< Scalar > expm_const (const Matrix< Scalar > &A, const Matrix< Scalar > &t)
 
static Matrix< Scalar > expm (const Matrix< Scalar > &A)
 
static Matrix< Scalar > solve (const Matrix< Scalar > &A, const Matrix< Scalar > &b)
 
static Matrix< Scalar > solve (const Matrix< Scalar > &A, const Matrix< Scalar > &b, const std::string &lsolver, const Dict &opts)
 
static Matrix< Scalar > inv (const Matrix< Scalar > &A)
 
static Matrix< Scalar > inv (const Matrix< Scalar > &A, const std::string &lsolver, const Dict &opts)
 
static casadi_int n_nodes (const Matrix< Scalar > &x)
 
static std::string print_operator (const Matrix< Scalar > &x, const std::vector< std::string > &args)
 
static void extract (std::vector< Matrix< Scalar >> &ex, std::vector< Matrix< Scalar >> &v, std::vector< Matrix< Scalar >> &vdef, const Dict &opts=Dict())
 
static void shared (std::vector< Matrix< Scalar > > &ex, std::vector< Matrix< Scalar > > &v, std::vector< Matrix< Scalar > > &vdef, const std::string &v_prefix, const std::string &v_suffix)
 
static Matrix< Scalar > _bilin (const Matrix< Scalar > &A, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > _rank1 (const Matrix< Scalar > &A, const Matrix< Scalar > &alpha, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > if_else (const Matrix< Scalar > &x, const Matrix< Scalar > &if_true, const Matrix< Scalar > &if_false, bool short_circuit=false)
 
static Matrix< Scalar > conditional (const Matrix< Scalar > &ind, const std::vector< Matrix< Scalar > > &x, const Matrix< Scalar > &x_default, bool short_circuit=false)
 
static bool depends_on (const Matrix< Scalar > &x, const Matrix< Scalar > &arg)
 
static bool contains (const std::vector< Matrix< Scalar > > &v, const Matrix< Scalar > &n)
 
static bool contains_all (const std::vector< Matrix< Scalar > > &v, const std::vector< Matrix< Scalar > > &n)
 
static bool contains_any (const std::vector< Matrix< Scalar > > &v, const std::vector< Matrix< Scalar > > &n)
 
static Matrix< Scalar > mrdivide (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > mldivide (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static std::vector< Matrix< Scalar > > symvar (const Matrix< Scalar > &x)
 
static Matrix< Scalar > det (const Matrix< Scalar > &x)
 
static Matrix< Scalar > inv_minor (const Matrix< Scalar > &x)
 
static Matrix< Scalar > trace (const Matrix< Scalar > &x)
 
static Matrix< Scalar > norm_1 (const Matrix< Scalar > &x)
 
static Matrix< Scalar > norm_2 (const Matrix< Scalar > &x)
 
static Matrix< Scalar > norm_fro (const Matrix< Scalar > &x)
 
static Matrix< Scalar > norm_inf (const Matrix< Scalar > &x)
 
static Matrix< Scalar > sum2 (const Matrix< Scalar > &x)
 
static Matrix< Scalar > sum1 (const Matrix< Scalar > &x)
 
static Matrix< Scalar > dot (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > nullspace (const Matrix< Scalar > &x)
 
static Matrix< Scalar > diag (const Matrix< Scalar > &x)
 
static Matrix< Scalar > unite (const Matrix< Scalar > &A, const Matrix< Scalar > &B)
 
static Matrix< Scalar > project (const Matrix< Scalar > &x, const Sparsity &sp, bool intersect=false)
 
static Matrix< Scalar > polyval (const Matrix< Scalar > &p, const Matrix< Scalar > &x)
 
static Matrix< Scalar > densify (const Matrix< Scalar > &x, const Matrix< Scalar > &val)
 
static Matrix< Scalar > densify (const Matrix< Scalar > &x)
 
static Matrix< Scalar > einstein (const Matrix< Scalar > &A, const Matrix< Scalar > &B, const Matrix< Scalar > &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)
 
static Matrix< Scalar > einstein (const Matrix< Scalar > &A, const Matrix< Scalar > &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)
 
static Matrix< Scalar > cumsum (const Matrix< Scalar > &x, casadi_int axis=-1)
 
static Matrix< Scalar > _logsumexp (const Matrix< Scalar > &x)
 
static std::vector< Matrix< Scalar > > cse (const std::vector< Matrix< Scalar > > &e)
 
static Matrix< Scalar > blockcat (const std::vector< std::vector< Matrix< Scalar > > > &v)
 
static Matrix< Scalar > horzcat (const std::vector< Matrix< Scalar > > &v)
 
static std::vector< Matrix< Scalar > > horzsplit (const Matrix< Scalar > &x, const std::vector< casadi_int > &offset)
 
static Matrix< Scalar > vertcat (const std::vector< Matrix< Scalar > > &v)
 
static std::vector< Matrix< Scalar > > vertsplit (const Matrix< Scalar > &x, const std::vector< casadi_int > &offset)
 
static std::vector< Matrix< Scalar > > diagsplit (const Matrix< Scalar > &x, const std::vector< casadi_int > &offset1, const std::vector< casadi_int > &offset2)
 
static Matrix< Scalar > reshape (const Matrix< Scalar > &x, casadi_int nrow, casadi_int ncol)
 
static Matrix< Scalar > reshape (const Matrix< Scalar > &x, const Sparsity &sp)
 
static Matrix< Scalar > sparsity_cast (const Matrix< Scalar > &x, const Sparsity &sp)
 
static Matrix< Scalar > kron (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > mtimes (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > mac (const Matrix< Scalar > &x, const Matrix< Scalar > &y, const Matrix< Scalar > &z)
 
static void extract_parametric (const Matrix< Scalar > &expr, const Matrix< Scalar > &par, Matrix< Scalar > &expr_ret, std::vector< Matrix< Scalar > > &symbols, std::vector< Matrix< Scalar >> &parametric, const Dict &opts)
 
static void separate_linear (const Matrix< Scalar > &expr, const Matrix< Scalar > &sym_lin, const Matrix< Scalar > &sym_const, Matrix< Scalar > &expr_const, Matrix< Scalar > &expr_lin, Matrix< Scalar > &expr_nonlin)
 
static Matrix< Scalar > sparsify (const Matrix< Scalar > &x, double tol=0)
 
static void expand (const Matrix< Scalar > &x, Matrix< Scalar > &weights, Matrix< Scalar > &terms)
 
static Matrix< Scalar > pw_const (const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
 
static Matrix< Scalar > pw_lin (const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
 
static Matrix< Scalar > heaviside (const Matrix< Scalar > &x)
 
static Matrix< Scalar > rectangle (const Matrix< Scalar > &x)
 
static Matrix< Scalar > triangle (const Matrix< Scalar > &x)
 
static Matrix< Scalar > ramp (const Matrix< Scalar > &x)
 
static Matrix< Scalar > gauss_quadrature (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order=5)
 
static Matrix< Scalar > gauss_quadrature (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order, const Matrix< Scalar > &w)
 
static std::vector< std::vector< Matrix< Scalar > > > forward (const std::vector< Matrix< Scalar > > &ex, const std::vector< Matrix< Scalar > > &arg, const std::vector< std::vector< Matrix< Scalar > > > &v, const Dict &opts=Dict())
 
static std::vector< std::vector< Matrix< Scalar > > > reverse (const std::vector< Matrix< Scalar > > &ex, const std::vector< Matrix< Scalar > > &arg, const std::vector< std::vector< Matrix< Scalar > > > &v, const Dict &opts=Dict())
 
static std::vector< bool > which_depends (const Matrix< Scalar > &expr, const Matrix< Scalar > &var, casadi_int order=1, bool tr=false)
 
static Matrix< Scalar > taylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order)
 
static Matrix< Scalar > mtaylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order)
 
static Matrix< Scalar > mtaylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order, const std::vector< casadi_int > &order_contributions)
 
static Matrix< Scalar > poly_coeff (const Matrix< Scalar > &ex, const Matrix< Scalar > &x)
 
static Matrix< Scalar > poly_roots (const Matrix< Scalar > &p)
 
static Matrix< Scalar > eig_symbolic (const Matrix< Scalar > &m)
 
static Matrix< double > evalf (const Matrix< Scalar > &m)
 
static void qr_sparse (const Matrix< Scalar > &A, Matrix< Scalar > &V, Matrix< Scalar > &R, Matrix< Scalar > &beta, std::vector< casadi_int > &prinv, std::vector< casadi_int > &pc, bool amd=true)
 
static Matrix< Scalar > qr_solve (const Matrix< Scalar > &b, const Matrix< Scalar > &v, const Matrix< Scalar > &r, const Matrix< Scalar > &beta, const std::vector< casadi_int > &prinv, const std::vector< casadi_int > &pc, bool tr=false)
 
static void qr (const Matrix< Scalar > &A, Matrix< Scalar > &Q, Matrix< Scalar > &R)
 
static void ldl (const Matrix< Scalar > &A, Matrix< Scalar > &D, Matrix< Scalar > &LT, std::vector< casadi_int > &p, bool amd=true)
 
static Matrix< Scalar > ldl_solve (const Matrix< Scalar > &b, const Matrix< Scalar > &D, const Matrix< Scalar > &LT, const std::vector< casadi_int > &p)
 
static Matrix< Scalar > all (const Matrix< Scalar > &x)
 
static Matrix< Scalar > any (const Matrix< Scalar > &x)
 
static Matrix< Scalar > adj (const Matrix< Scalar > &x)
 
static Matrix< Scalar > minor (const Matrix< Scalar > &x, casadi_int i, casadi_int j)
 
static Matrix< Scalar > cofactor (const Matrix< Scalar > &A, casadi_int i, casadi_int j)
 
static Matrix< Scalar > chol (const Matrix< Scalar > &A)
 
static Matrix< Scalar > norm_inf_mul (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > diagcat (const std::vector< Matrix< Scalar > > &A)
 
static Matrix< Scalar > triplet (const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d)
 Construct a sparse matrix from triplet form. More...
 
static Matrix< Scalar > triplet (const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d, casadi_int nrow, casadi_int ncol)
 Construct a sparse matrix from triplet form. More...
 
static Matrix< Scalar > triplet (const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d, const std::pair< casadi_int, casadi_int > &rc)
 Construct a sparse matrix from triplet form. More...
 
static Matrix< Scalar > inf (const Sparsity &sp)
 create a matrix with all inf More...
 
static Matrix< Scalar > inf (casadi_int nrow=1, casadi_int ncol=1)
 create a matrix with all inf More...
 
static Matrix< Scalar > inf (const std::pair< casadi_int, casadi_int > &rc)
 create a matrix with all inf More...
 
static Matrix< Scalar > nan (const Sparsity &sp)
 create a matrix with all nan More...
 
static Matrix< Scalar > nan (casadi_int nrow=1, casadi_int ncol=1)
 create a matrix with all nan More...
 
static Matrix< Scalar > nan (const std::pair< casadi_int, casadi_int > &rc)
 create a matrix with all nan More...
 
static Matrix< Scalar > rand (casadi_int nrow=1, casadi_int ncol=1)
 Create a matrix with uniformly distributed random numbers. More...
 
static Matrix< Scalar > rand (const Sparsity &sp)
 Create a matrix with uniformly distributed random numbers. More...
 
static Matrix< Scalar > rand (const std::pair< casadi_int, casadi_int > &rc)
 Create a matrix with uniformly distributed random numbers. More...
 
static Matrix< Scalar > interp1d (const std::vector< double > &x, const Matrix< Scalar > &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 Matrix< Scalar > &x)
 Functions called by friend functions defined here. More...
 
static casadi_int norm_0_mul (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > tril (const Matrix< Scalar > &x, bool includeDiagonal=true)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > triu (const Matrix< Scalar > &x, bool includeDiagonal=true)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > sumsqr (const Matrix< Scalar > &x)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > linspace (const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int nsteps)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > cross (const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int dim=-1)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > skew (const Matrix< Scalar > &a)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > inv_skew (const Matrix< Scalar > &a)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > tril2symm (const Matrix< Scalar > &x)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > triu2symm (const Matrix< Scalar > &x)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > repsum (const Matrix< Scalar > &x, casadi_int n, casadi_int m=1)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > diff (const Matrix< Scalar > &x, casadi_int n=1, casadi_int axis=-1)
 Functions called by friend functions defined here. More...
 
static bool is_linear (const Matrix< Scalar > &expr, const Matrix< Scalar > &var)
 Functions called by friend functions defined here. More...
 
static bool is_quadratic (const Matrix< Scalar > &expr, const Matrix< Scalar > &var)
 Functions called by friend functions defined here. More...
 
static void quadratic_coeff (const Matrix< Scalar > &expr, const Matrix< Scalar > &var, Matrix< Scalar > &A, Matrix< Scalar > &b, Matrix< Scalar > &c, bool check)
 Functions called by friend functions defined here. More...
 
static void linear_coeff (const Matrix< Scalar > &expr, const Matrix< Scalar > &var, Matrix< Scalar > &A, Matrix< Scalar > &b, bool check)
 Functions called by friend functions defined here. More...
 
static Matrix< Scalar > mpower (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > soc (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 
static Matrix< Scalar > linearize (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &x0, const Dict &opts=Dict())
 
static Matrix< Scalar > gradient (const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Dict &opts=Dict())
 
static Matrix< Scalar > tangent (const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Dict &opts=Dict())
 
static Matrix< Scalar > jtimes (const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Matrix< Scalar > &v, bool tr=false, const Dict &opts=Dict())
 
static Matrix< Scalar > bilin (const Matrix< Scalar > &A, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 Calculate bilinear/quadratic form x^T A y. More...
 
static Matrix< Scalar > rank1 (const Matrix< Scalar > &A, const Matrix< Scalar > &alpha, const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 Make a rank-1 update to a matrix A. More...
 
Construct symbolic primitives

The "sym" function is intended to work in a similar way as "sym" used in the Symbolic Toolbox for Matlab but instead creating a CasADi symbolic primitive.

static Matrix< Scalar > sym (const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
 Create an nrow-by-ncol symbolic primitive. More...
 
static Matrix< Scalar > sym (const std::string &name, const std::pair< casadi_int, casadi_int > &rc)
 Construct a symbolic primitive with given dimensions. More...
 
static Matrix< Scalar > sym (const std::string &name, const Sparsity &sp)
 Create symbolic primitive with a given sparsity pattern. More...
 
static std::vector< Matrix< Scalar > > sym (const std::string &name, const Sparsity &sp, casadi_int p)
 Create a vector of length p with with matrices. More...
 
static std::vector< Matrix< Scalar > > sym (const std::string &name, casadi_int nrow, casadi_int ncol, casadi_int p)
 Create a vector of length p with nrow-by-ncol symbolic primitives. More...
 
static std::vector< std::vector< Matrix< Scalar > > > sym (const std::string &name, const Sparsity &sp, casadi_int p, casadi_int r)
 Create a vector of length r of vectors of length p with. More...
 
static std::vector< std::vector< Matrix< Scalar > > > sym (const std::string &name, casadi_int nrow, casadi_int ncol, casadi_int p, casadi_int r)
 Create a vector of length r of vectors of length p. More...
 
static Matrix< Scalar > zeros (casadi_int nrow=1, casadi_int ncol=1)
 Create a dense matrix or a matrix with specified sparsity with all entries zero. More...
 
static Matrix< Scalar > zeros (const Sparsity &sp)
 Create a dense matrix or a matrix with specified sparsity with all entries zero. More...
 
static Matrix< Scalar > zeros (const std::pair< casadi_int, casadi_int > &rc)
 Create a dense matrix or a matrix with specified sparsity with all entries zero. More...
 
static Matrix< Scalar > ones (casadi_int nrow=1, casadi_int ncol=1)
 Create a dense matrix or a matrix with specified sparsity with all entries one. More...
 
static Matrix< Scalar > ones (const Sparsity &sp)
 Create a dense matrix or a matrix with specified sparsity with all entries one. More...
 
static Matrix< Scalar > ones (const std::pair< casadi_int, casadi_int > &rc)
 Create a dense matrix or a matrix with specified sparsity with all entries one. More...
 

Static Private Member Functions

static Matrix< Scalar > printme (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 

Friends

Matrix< Scalar > adj (const Matrix< Scalar > &A)
 Matrix adjoint. More...
 
Matrix< Scalar > minor (const Matrix< Scalar > &x, casadi_int i, casadi_int j)
 Get the (i,j) minor matrix. More...
 
Matrix< Scalar > cofactor (const Matrix< Scalar > &x, casadi_int i, casadi_int j)
 Get the (i,j) cofactor matrix. More...
 
void qr (const Matrix< Scalar > &A, Matrix< Scalar > &Q, Matrix< Scalar > &R)
 QR factorization using the modified Gram-Schmidt algorithm. More...
 
void qr_sparse (const Matrix< Scalar > &A, Matrix< Scalar > &V, Matrix< Scalar > &R, Matrix< Scalar > &beta, std::vector< casadi_int > &prinv, std::vector< casadi_int > &pc, bool amd=true)
 Sparse direct QR factorization. More...
 
Matrix< Scalar > qr_solve (const Matrix< Scalar > &b, const Matrix< Scalar > &v, const Matrix< Scalar > &r, const Matrix< Scalar > &beta, const std::vector< casadi_int > &prinv, const std::vector< casadi_int > &pc, bool tr=false)
 Solve using a sparse QR factorization. More...
 
Matrix< Scalar > chol (const Matrix< Scalar > &A)
 Obtain a Cholesky factorisation of a matrix. More...
 
void ldl (const Matrix< Scalar > &A, Matrix< Scalar > &D, Matrix< Scalar > &LT, std::vector< casadi_int > &p, bool amd=true)
 Sparse LDL^T factorization. More...
 
Matrix< Scalar > ldl_solve (const Matrix< Scalar > &b, const Matrix< Scalar > &D, const Matrix< Scalar > &LT, const std::vector< casadi_int > &p)
 Solve using a sparse LDL^T factorization. More...
 
Matrix< Scalar > any (const Matrix< Scalar > &x)
 Returns true only if any element in the matrix is true. More...
 
Matrix< Scalar > all (const Matrix< Scalar > &x)
 Returns true only if every element in the matrix is true. More...
 
Matrix< Scalar > norm_inf_mul (const Matrix< Scalar > &x, const Matrix< Scalar > &y)
 Inf-norm of a Matrix-Matrix product. More...
 
Matrix< Scalar > sparsify (const Matrix< Scalar > &A, double tol=0)
 Make a matrix sparse by removing numerical zeros. More...
 
void expand (const Matrix< Scalar > &ex, Matrix< Scalar > &weights, Matrix< Scalar > &terms)
 Expand the expression as a weighted sum (with constant weights) More...
 
Matrix< Scalar > pw_const (const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
 Create a piecewise constant function. More...
 
Matrix< Scalar > pw_lin (const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
 t a scalar variable (e.g. time) More...
 
Matrix< Scalar > heaviside (const Matrix< Scalar > &x)
 Heaviside function. More...
 
Matrix< Scalar > rectangle (const Matrix< Scalar > &x)
 rectangle function More...
 
Matrix< Scalar > triangle (const Matrix< Scalar > &x)
 triangle function More...
 
Matrix< Scalar > ramp (const Matrix< Scalar > &x)
 ramp function More...
 
Matrix< Scalar > mtaylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order=1)
 multivariate Taylor series expansion More...
 
Matrix< Scalar > mtaylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order, const std::vector< casadi_int > &order_contributions)
 multivariate Taylor series expansion More...
 
Matrix< Scalar > poly_coeff (const Matrix< Scalar > &f, const Matrix< Scalar > &x)
 extracts polynomial coefficients from an expression More...
 
Matrix< Scalar > poly_roots (const Matrix< Scalar > &p)
 Attempts to find the roots of a polynomial. More...
 
Matrix< Scalar > eig_symbolic (const Matrix< Scalar > &m)
 Attempts to find the eigenvalues of a symbolic matrix. More...
 
Matrix< double > evalf (const Matrix< Scalar > &expr)
 Evaluates the expression numerically. More...
 
Matrix< Scalar > gauss_quadrature (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order=5)
 Integrate f from a to b using Gaussian quadrature with n points. More...
 
Matrix< Scalar > gauss_quadrature (const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order, const Matrix< Scalar > &w)
 Integrate f from a to b using Gaussian quadrature with n points. More...
 
Matrix< Scalar > taylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order=1)
 univariate Taylor series expansion More...
 
Matrix< Scalar > taylor (const Matrix< Scalar > &ex, const Matrix< Scalar > &x)
 univariate Taylor series expansion More...
 
Scalar * ptr ()
 
const Scalar * ptr () const
 
Scalar * get_ptr (Matrix< Scalar > &v)
 
const Scalar * get_ptr (const Matrix< Scalar > &v)
 

Member Typedef Documentation

◆ B

template<typename Scalar >
typedef GenericMatrix<Matrix<Scalar> > casadi::Matrix< Scalar >::B

Definition at line 193 of file matrix_decl.hpp.

◆ ScalarType

template<typename Scalar >
typedef Scalar casadi::Matrix< Scalar >::ScalarType

Definition at line 190 of file matrix_decl.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix

Extra doc: https://github.com/casadi/casadi/wiki/L_18f empty 0-by-0 matrix constructor

Definition at line 576 of file matrix_impl.hpp.

576  : sparsity_(Sparsity(0, 0)) {
577  }

◆ Matrix() [2/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( const Matrix< Scalar > &  m)

Definition at line 580 of file matrix_impl.hpp.

580  : sparsity_(m.sparsity_), nonzeros_(m.nonzeros_) {
581  }

◆ Matrix() [3/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( casadi_int  nrow,
casadi_int  ncol 
)

◆ Matrix() [4/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( const std::pair< casadi_int, casadi_int > &  rc)
explicit

◆ Matrix() [5/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( const Sparsity sp)
explicit

Same as Matrix::ones(sparsity)

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

◆ Matrix() [6/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( const Sparsity sp,
const Matrix< Scalar > &  d 
)

◆ Matrix() [7/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( double  val)

◆ Matrix() [8/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( const std::vector< std::vector< double > > &  m)
explicit

◆ Matrix() [9/14]

template<typename Scalar >
template<typename A >
casadi::Matrix< Scalar >::Matrix ( const std::vector< A > &  x)
inline

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

Definition at line 161 of file matrix_decl.hpp.

161  : sparsity_(Sparsity::dense(x.size(), 1)),
162  nonzeros_(std::vector<Scalar>(x.size())) {
163  auto x_it = x.begin();
164  for (auto&& d : nonzeros_) d = static_cast<Scalar>(*x_it++);
165  }
static Sparsity dense(casadi_int nrow, casadi_int ncol=1)
Create a dense rectangular sparsity pattern *.
Definition: sparsity.cpp:1012

◆ Matrix() [10/14]

template<typename Scalar >
template<typename A >
casadi::Matrix< Scalar >::Matrix ( const Matrix< A > &  x)
inline

Assumes that the scalar conversion is valid.

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

Definition at line 174 of file matrix_decl.hpp.

174  : sparsity_(x.sparsity()), nonzeros_(std::vector<Scalar>(x.nnz())) {
175  auto x_it = x->begin();
176  for (auto&& d : nonzeros_) d = static_cast<Scalar>(*x_it++);
177  }

◆ Matrix() [11/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( const std::vector< Scalar > &  x)

Definition at line 584 of file matrix_impl.hpp.

584  :
585  sparsity_(Sparsity::dense(x.size(), 1)), nonzeros_(x) {
586  }

◆ Matrix() [12/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( std::initializer_list< Scalar >  x)
inline

Definition at line 184 of file matrix_decl.hpp.

184 : Matrix<Scalar>(std::vector<Scalar>(x)) {}

◆ Matrix() [13/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( const Sparsity sp,
const Scalar &  val,
bool  dummy 
)

◆ Matrix() [14/14]

template<typename Scalar >
casadi::Matrix< Scalar >::Matrix ( const Sparsity sp,
const std::vector< Scalar > &  d,
bool  dummy 
)

Member Function Documentation

◆ __nonzero__()

bool CASADI_EXPORT casadi::SX::__nonzero__

Definition at line 70 of file matrix_impl.hpp.

70  {
71  if (numel()!=1) {
72  casadi_error("Only scalar Matrix could have a truth value, but you "
73  "provided a shape" + dim());
74  }
75  return nonzeros().at(0)!=0;
76  }
casadi_int numel() const
Get the number of elements.
std::string dim(bool with_nz=false) const
Get string representation of dimensions.
std::vector< Scalar > & nonzeros()

◆ _bilin()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::_bilin ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

Functions called by friend functions defined for GenericMatrix

◆ _logsumexp()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::_logsumexp ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ _rank1()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::_rank1 ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  alpha,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

Functions called by friend functions defined for GenericMatrix

◆ _sym()

SX CASADI_EXPORT casadi::SX::_sym ( const std::string &  name,
const Sparsity sp 
)
static

Definition at line 52 of file sx_instantiator.cpp.

52  {
53  // Create a dense n-by-m matrix
54  std::vector<SXElem> retv;
55 
56  // Check if individial names have been provided
57  if (name[0]=='[') {
58 
59  // Make a copy of the string and modify it as to remove the special characters
60  std::string modname = name;
61  for (std::string::iterator it=modname.begin(); it!=modname.end(); ++it) {
62  switch (*it) {
63  case '(': case ')': case '[': case ']': case '{': case '}': case ',': case ';': *it = ' ';
64  }
65  }
66 
67  std::istringstream iss(modname);
68  std::string varname;
69 
70  // Loop over elements
71  while (!iss.fail()) {
72  // Read the name
73  iss >> varname;
74 
75  // Append to the return vector
76  if (!iss.fail())
77  retv.push_back(SXElem::sym(varname));
78  }
79  } else if (sp.is_scalar(true)) {
80  retv.push_back(SXElem::sym(name));
81  } else {
82  // Scalar
83  std::stringstream ss;
84  for (casadi_int k=0; k<sp.nnz(); ++k) {
85  ss.str("");
86  ss << name << "_" << k;
87  retv.push_back(SXElem::sym(ss.str()));
88  }
89  }
90 
91  // Determine dimensions automatically if empty
92  if (sp.is_scalar(true)) {
93  return SX(retv);
94  } else {
95  return SX(sp, retv, false);
96  }
97  }
std::string name() const
Get name (only if symbolic scalar)
static SXElem sym(const std::string &name)
Create a symbolic primitive.
Definition: sx_elem.cpp:90
Matrix< SXElem > SX
Definition: sx_fwd.hpp:32

References casadi::Sparsity::is_scalar(), casadi::Matrix< Scalar >::name(), casadi::Sparsity::nnz(), and casadi::SXElem::sym().

◆ adj()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::adj ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined here

◆ all()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::all ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined here

◆ any()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::any ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined here

◆ bilin()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::bilin ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
staticinherited
Parameters
[in]ycan be omitted, in which case x^T A x is calculated

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

◆ binary()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::binary ( casadi_int  op,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

◆ blockcat()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::blockcat ( const std::vector< std::vector< Matrix< Scalar > > > &  v)
static

Functions called by friend functions defined for SparsityInterface

◆ call() [1/2]

template<typename Scalar >
static std::vector< Matrix<Scalar> > casadi::Matrix< Scalar >::call ( const Function f,
const std::vector< Matrix< Scalar > > &  x 
)
static

◆ call() [2/2]

template<typename Scalar >
static std::vector< Scalar > casadi::Matrix< Scalar >::call ( const Function f,
const std::vector< Scalar > &  x 
)
static

◆ chol()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::chol ( const Matrix< Scalar > &  A)
static

Functions called by friend functions defined here

◆ clear()

template<typename Scalar >
void casadi::Matrix< Scalar >::clear ( )

◆ cofactor()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::cofactor ( const Matrix< Scalar > &  A,
casadi_int  i,
casadi_int  j 
)
static

Functions called by friend functions defined here

◆ colind() [1/2]

const casadi_int* casadi::GenericMatrix< Matrix< Scalar > >::colind ( ) const
inlineinherited

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

Definition at line 198 of file generic_matrix.hpp.

198 { 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:168

◆ colind() [2/2]

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::colind ( casadi_int  col) const
inlineinherited

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

Definition at line 201 of file generic_matrix.hpp.

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

◆ columns()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::columns ( ) const
inlineinherited

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

Definition at line 124 of file generic_matrix.hpp.

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

◆ conditional()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::conditional ( const Matrix< Scalar > &  ind,
const std::vector< Matrix< Scalar > > &  x,
const Matrix< Scalar > &  x_default,
bool  short_circuit = false 
)
static

Functions called by friend functions defined for GenericMatrix

◆ contains()

template<typename Scalar >
static bool casadi::Matrix< Scalar >::contains ( const std::vector< Matrix< Scalar > > &  v,
const Matrix< Scalar > &  n 
)
static

Functions called by friend functions defined for GenericMatrix

◆ contains_all()

template<typename Scalar >
static bool casadi::Matrix< Scalar >::contains_all ( const std::vector< Matrix< Scalar > > &  v,
const std::vector< Matrix< Scalar > > &  n 
)
static

Functions called by friend functions defined for GenericMatrix

◆ contains_any()

template<typename Scalar >
static bool casadi::Matrix< Scalar >::contains_any ( const std::vector< Matrix< Scalar > > &  v,
const std::vector< Matrix< Scalar > > &  n 
)
static

Functions called by friend functions defined for GenericMatrix

◆ cross()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::cross ( const Matrix< Scalar > &  a,
const Matrix< Scalar > &  b,
casadi_int  dim = -1 
)
staticinherited

Definition at line 227 of file generic_matrix.hpp.

1394  {
1395  casadi_assert(a.size1()==b.size1() && a.size2()==b.size2(),
1396  "cross(a, b): Inconsistent dimensions. Dimension of a ("
1397  + a.dim() + " ) must equal that of b (" + b.dim() + ").");
1398 
1399  casadi_assert(a.size1()==3 || a.size2()==3,
1400  "cross(a, b): One of the dimensions of a should have length 3, but got "
1401  + a.dim() + ".");
1402  casadi_assert(dim==-1 || dim==1 || dim==2,
1403  "cross(a, b, dim): Dim must be 1, 2 or -1 (automatic).");
1404 
1405  std::vector<MatType> ret(3);
1406 
1407  bool t = a.size1()==3;
1408 
1409  if (dim==1) t = true;
1410  if (dim==2) t = false;
1411 
1412  MatType a1 = t ? a(0, Slice()) : a(Slice(), 0);
1413  MatType a2 = t ? a(1, Slice()) : a(Slice(), 1);
1414  MatType a3 = t ? a(2, Slice()) : a(Slice(), 2);
1415 
1416  MatType b1 = t ? b(0, Slice()) : b(Slice(), 0);
1417  MatType b2 = t ? b(1, Slice()) : b(Slice(), 1);
1418  MatType b3 = t ? b(2, Slice()) : b(Slice(), 2);
1419 
1420  ret[0] = a2*b3-a3*b2;
1421  ret[1] = a3*b1-a1*b3;
1422  ret[2] = a1*b2-a2*b1;
1423 
1424  return t ? vertcat(ret) : horzcat(ret);
1425  }
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.

◆ cse()

template<typename Scalar >
static std::vector< Matrix<Scalar> > casadi::Matrix< Scalar >::cse ( const std::vector< Matrix< Scalar > > &  e)
static

Functions called by friend functions defined for GenericMatrix

◆ cumsum()

template<typename Scalar >
Matrix< Scalar > casadi::Matrix< Scalar >::cumsum ( const Matrix< Scalar > &  x,
casadi_int  axis = -1 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 527 of file matrix_impl.hpp.

527  {
528  if (axis==-1) axis = x.is_row();
529  Matrix<Scalar> ret = x;
530  if (axis==0) {
531  for (casadi_int i=1;i<x.size1();++i)
532  ret(i, Slice()) += ret(i-1, Slice());
533  } else {
534  for (casadi_int i=1;i<x.size2();++i)
535  ret(Slice(), i) += ret(Slice(), i-1);
536  }
537  return ret;
538  }

References casadi::GenericMatrix< MatType >::is_row(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().

◆ densify() [1/2]

template<typename Scalar >
Matrix< Scalar > casadi::Matrix< Scalar >::densify ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 492 of file matrix_impl.hpp.

492  {
493  return densify(x, 0);
494  }
static Matrix< Scalar > densify(const Matrix< Scalar > &x, const Matrix< Scalar > &val)

◆ densify() [2/2]

template<typename Scalar >
Matrix< Scalar > casadi::Matrix< Scalar >::densify ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  val 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 497 of file matrix_impl.hpp.

498  {
499  // Check argument
500  casadi_assert_dev(val.is_scalar());
501 
502  // Quick return if possible
503  if (x.is_dense()) return x;
504 
505  // Get sparsity pattern
506  casadi_int nrow = x.size1();
507  casadi_int ncol = x.size2();
508  const casadi_int* colind = x.colind();
509  const casadi_int* row = x.row();
510  auto it = x.nonzeros().cbegin();
511 
512  // New data vector
513  std::vector<Scalar> d(nrow*ncol, val.scalar());
514 
515  // Copy nonzeros
516  for (casadi_int cc=0; cc<ncol; ++cc) {
517  for (casadi_int el=colind[cc]; el<colind[cc+1]; ++el) {
518  d[cc*nrow + row[el]] = *it++;
519  }
520  }
521 
522  // Construct return matrix
523  return Matrix<Scalar>(Sparsity::dense(x.size()), d);
524  }

References casadi::GenericMatrix< MatType >::colind(), casadi::Sparsity::dense(), casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::Matrix< Scalar >::nonzeros(), casadi::GenericMatrix< MatType >::row(), casadi::Matrix< Scalar >::scalar(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::size1(), and casadi::GenericMatrix< MatType >::size2().

◆ dep()

SX CASADI_EXPORT casadi::SX::dep ( casadi_int  ch = 0) const

Only defined if symbolic scalar. Wraps SXElem SXElem::dep(casadi_int ch=0) const.

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

Definition at line 223 of file sx_instantiator.cpp.

223  {
224  return scalar().dep(ch);
225  }
const Scalar scalar() const
Convert to scalar type.

References casadi::Matrix< Scalar >::scalar().

◆ depends_on()

template<typename Scalar >
static bool casadi::Matrix< Scalar >::depends_on ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  arg 
)
static

Functions called by friend functions defined for GenericMatrix

◆ deserialize() [1/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::deserialize ( const std::string &  s)
static

◆ deserialize() [2/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::deserialize ( DeserializingStream s)
static

◆ deserialize() [3/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::deserialize ( std::istream &  stream)
static

◆ det()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::det ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ diag()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::diag ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ diagcat()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::diagcat ( const std::vector< Matrix< Scalar > > &  A)
static

Functions called by friend functions defined here

◆ diagsplit()

template<typename Scalar >
static std::vector< Matrix<Scalar> > casadi::Matrix< Scalar >::diagsplit ( const Matrix< Scalar > &  x,
const std::vector< casadi_int > &  offset1,
const std::vector< casadi_int > &  offset2 
)
static

Functions called by friend functions defined for SparsityInterface

◆ diff()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::diff ( const Matrix< Scalar > &  x,
casadi_int  n = 1,
casadi_int  axis = -1 
)
staticinherited

Definition at line 233 of file generic_matrix.hpp.

1774  {
1775  casadi_assert(axis==-1 || axis==0 || axis==1, "Axis argument invalid");
1776  casadi_assert(n>=1, "n argument invalid");
1777 
1778  MatType ret = x;
1779  for (casadi_int i=0;i<n;++i) {
1780  // Matlab's special case
1781  if (axis==-1 && ret.is_scalar()) return MatType();
1782 
1783  casadi_int local_axis = (axis==-1) ? ret.is_row() : axis;
1784  if (local_axis==0) {
1785  if (ret.size1()<=1) {
1786  ret = MatType::zeros(0, ret.size2());
1787  } else {
1788  ret = ret(Slice(1, ret.size1()), Slice())-ret(Slice(0, ret.size1()-1), Slice());
1789  }
1790  } else {
1791  if (ret.size2()<=1) {
1792  ret = MatType::zeros(ret.size1(), 0);
1793  } else {
1794  ret = ret(Slice(), Slice(1, ret.size2()))-ret(Slice(), Slice(0, ret.size2()-1));
1795  }
1796  }
1797  }
1798  return ret;
1799  }

◆ dim()

std::string casadi::GenericMatrix< Matrix< Scalar > >::dim ( bool  with_nz = false) const
inherited

The representation is e.g. "4x5" or "4x5,10nz"

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

Definition at line 131 of file generic_matrix.hpp.

1343  {
1344  return sparsity().dim(with_nz);
1345  }
std::string dim(bool with_nz=false) const
Get the dimension as a string.
Definition: sparsity.cpp:587

◆ disp()

template<typename Scalar >
void casadi::Matrix< Scalar >::disp ( std::ostream &  stream,
bool  more = false 
) const

◆ dot()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::dot ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

Functions called by friend functions defined for GenericMatrix

◆ eig_symbolic()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::eig_symbolic ( const Matrix< Scalar > &  m)
static

Functions called by friend functions defined here

◆ einstein() [1/2]

template<typename Scalar >
Matrix< Scalar > casadi::Matrix< Scalar >::einstein ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  B,
const Matrix< Scalar > &  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 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 541 of file matrix_impl.hpp.

546  {
547  std::vector<casadi_int> iter_dims;
548  std::vector<casadi_int> strides_a;
549  std::vector<casadi_int> strides_b;
550  std::vector<casadi_int> strides_c;
551  casadi_int n_iter = einstein_process(A, B, C, dim_a, dim_b, dim_c, a, b, c,
552  iter_dims, strides_a, strides_b, strides_c);
553 
554  const std::vector<Scalar>& Av = A.nonzeros();
555  const std::vector<Scalar>& Bv = B.nonzeros();
556 
557  Matrix<Scalar> ret = C;
558  std::vector<Scalar>& Cv = ret.nonzeros();
559 
560  einstein_eval(n_iter, iter_dims, strides_a, strides_b, strides_c,
561  get_ptr(Av), get_ptr(Bv), get_ptr(Cv));
562  return ret;
563  }
friend Scalar * get_ptr(Matrix< Scalar > &v)
GenericMatrix< Matrix< Scalar > > B
Base class.
void einstein_eval(casadi_int n_iter, const std::vector< casadi_int > &iter_dims, const std::vector< casadi_int > &strides_a, const std::vector< casadi_int > &strides_b, const std::vector< casadi_int > &strides_c, const T *a_in, const T *b_in, T *c_in)
Definition: shared.hpp:161
casadi_int einstein_process(const T &A, const T &B, const T &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, std::vector< casadi_int > &iter_dims, std::vector< casadi_int > &strides_a, std::vector< casadi_int > &strides_b, std::vector< casadi_int > &strides_c)
Definition: shared.hpp:35

References casadi::C, casadi::einstein_eval(), casadi::einstein_process(), casadi::get_ptr(), and casadi::Matrix< Scalar >::nonzeros().

Referenced by casadi::Matrix< Scalar >::einstein().

◆ einstein() [2/2]

template<typename Scalar >
Matrix< Scalar > casadi::Matrix< Scalar >::einstein ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  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 
)
static

Functions called by friend functions defined for GenericMatrix

Definition at line 566 of file matrix_impl.hpp.

570  {
572  dim_a, dim_b, dim_c, a, b, c);
573  }
static Matrix< Scalar > zeros(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries zero.
static Matrix< Scalar > einstein(const Matrix< Scalar > &A, const Matrix< Scalar > &B, const Matrix< Scalar > &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)
T product(const std::vector< T > &values)
product

References casadi::Matrix< Scalar >::einstein(), and casadi::product().

◆ element_hash()

casadi_int CASADI_EXPORT casadi::SX::element_hash

Only defined if symbolic scalar.

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

Definition at line 126 of file sx_instantiator.cpp.

126  {
127  return scalar().__hash__();
128  }

References casadi::Matrix< Scalar >::scalar().

◆ enlarge()

template<typename Scalar >
void casadi::Matrix< Scalar >::enlarge ( casadi_int  nrow,
casadi_int  ncol,
const std::vector< casadi_int > &  rr,
const std::vector< casadi_int > &  cc,
bool  ind1 = false 
)

Make the matrix larger by inserting empty rows and columns, keeping the existing non-zeros

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

◆ erase() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::erase ( const std::vector< casadi_int > &  rr,
bool  ind1 = false 
)

Erase elements of a matrix

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

◆ erase() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::erase ( const std::vector< casadi_int > &  rr,
const std::vector< casadi_int > &  cc,
bool  ind1 = false 
)

Erase rows and/or columns of a matrix

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

◆ evalf()

template<typename Scalar >
static Matrix<double> casadi::Matrix< Scalar >::evalf ( const Matrix< Scalar > &  m)
static

Functions called by friend functions defined here

◆ expand()

template<typename Scalar >
static void casadi::Matrix< Scalar >::expand ( const Matrix< Scalar > &  x,
Matrix< Scalar > &  weights,
Matrix< Scalar > &  terms 
)
static

Functions called by friend functions defined here

◆ expm()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::expm ( const Matrix< Scalar > &  A)
static

Functions called by friend functions defined for GenericMatrix

◆ expm_const()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::expm_const ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  t 
)
static

Functions called by friend functions defined for GenericMatrix

◆ export_code()

template<typename Scalar >
void casadi::Matrix< Scalar >::export_code ( const std::string &  lang,
std::ostream &  stream = casadi::uout(),
const Dict options = Dict() 
) const

lang: only 'matlab' supported for now

* options:
*   inline: Indicates if you want everything on a single line (default: False)
*   name: Name of exported variable (default: 'm')
*   indent_level: Level of indentation (default: 0)
*   spoof_zero: Replace numerical zero by a 1e-200 (default: false)
*               might be needed for matlab sparse construct,
*               which doesn't allow numerical zero
* 

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

Referenced by casadi::MXFunction::export_code_body().

◆ extract()

template<typename Scalar >
static void casadi::Matrix< Scalar >::extract ( std::vector< Matrix< Scalar >> &  ex,
std::vector< Matrix< Scalar >> &  v,
std::vector< Matrix< Scalar >> &  vdef,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

◆ extract_parametric()

template<typename Scalar >
static void casadi::Matrix< Scalar >::extract_parametric ( const Matrix< Scalar > &  expr,
const Matrix< Scalar > &  par,
Matrix< Scalar > &  expr_ret,
std::vector< Matrix< Scalar > > &  symbols,
std::vector< Matrix< Scalar >> &  parametric,
const Dict opts 
)
static

Functions called by friend functions defined for SparsityInterface

◆ eye()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::eye ( casadi_int  n)
static

◆ forward()

template<typename Scalar >
static std::vector<std::vector<Matrix<Scalar> > > casadi::Matrix< Scalar >::forward ( const std::vector< Matrix< Scalar > > &  ex,
const std::vector< Matrix< Scalar > > &  arg,
const std::vector< std::vector< Matrix< Scalar > > > &  v,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined here

◆ from_file()

template<typename Scalar >
static Matrix<double> casadi::Matrix< Scalar >::from_file ( const std::string &  filename,
const std::string &  format_hint = "" 
)
static

◆ gauss_quadrature() [1/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::gauss_quadrature ( const Matrix< Scalar > &  f,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  a,
const Matrix< Scalar > &  b,
casadi_int  order,
const Matrix< Scalar > &  w 
)
static

Functions called by friend functions defined here

◆ gauss_quadrature() [2/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::gauss_quadrature ( const Matrix< Scalar > &  f,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  a,
const Matrix< Scalar > &  b,
casadi_int  order = 5 
)
static

Functions called by friend functions defined here

◆ get() [1/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::get ( Matrix< Scalar > &  m,
bool  ind1,
const Matrix< casadi_int > &  rr 
) const

Get a submatrix, single argument

Definition at line 152 of file matrix_impl.hpp.

152  {
153  // Scalar
154  if (rr.is_scalar(true)) {
155  return get(m, ind1, to_slice(rr, ind1));
156  }
157 
158  // If the indexed matrix is dense, use nonzero indexing
159  if (is_dense()) {
160  return get_nz(m, ind1, rr);
161  }
162 
163  // Get the sparsity pattern - does bounds checking
164  std::vector<casadi_int> mapping;
165  Sparsity sp = sparsity().sub(rr.nonzeros(), rr.sparsity(), mapping, ind1);
166 
167  // If indexed matrix was a row/column vector, make sure that the result is too
168  bool tr = (is_column() && rr.is_row()) || (is_row() && rr.is_column());
169 
170  // Copy nonzeros
171  m = Matrix<Scalar>::zeros(tr ? sp.T() : sp);
172  for (casadi_int k=0; k<mapping.size(); ++k) m->at(k) = nonzeros().at(mapping[k]);
173  }
bool is_dense() const
Check if the matrix expression is dense.
bool is_column() const
Check if the matrix is a column vector (i.e. size2()==1)
bool is_row() const
Check if the matrix is a row vector (i.e. size1()==1)
bool is_scalar(bool scalar_and_dense=false) const
Check if the matrix expression is scalar.
void get(Matrix< Scalar > &m, bool ind1, const Slice &rr) const
const Sparsity & sparsity() const
Const access the sparsity - reference to data member.
void get_nz(Matrix< Scalar > &m, bool ind1, const Slice &k) const
Sparsity sub(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, std::vector< casadi_int > &mapping, bool ind1=false) const
Get a submatrix.
Definition: sparsity.cpp:334
Slice CASADI_EXPORT to_slice(const IM &x, bool ind1=false)
Convert IM to Slice.

References casadi::GenericMatrix< MatType >::is_column(), casadi::GenericMatrix< MatType >::is_row(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::Matrix< Scalar >::nonzeros(), casadi::Matrix< Scalar >::sparsity(), casadi::Sparsity::sub(), casadi::Sparsity::T(), casadi::to_slice(), and casadi::GenericMatrix< Matrix< Scalar > >::zeros().

◆ get() [2/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::get ( Matrix< Scalar > &  m,
bool  ind1,
const Matrix< casadi_int > &  rr,
const Matrix< casadi_int > &  cc 
) const

Get a submatrix, two arguments

Definition at line 111 of file matrix_impl.hpp.

112  {
113  // Scalar
114  if (rr.is_scalar(true) && cc.is_scalar(true)) {
115  return get(m, ind1, to_slice(rr, ind1), to_slice(cc, ind1));
116  }
117 
118  // Make sure dense vectors
119  casadi_assert(rr.is_dense() && rr.is_vector(),
120  "Marix::get: First index must be a dense vector");
121  casadi_assert(cc.is_dense() && cc.is_vector(),
122  "Marix::get: Second index must be a dense vector");
123 
124  // Get the sparsity pattern - does bounds checking
125  std::vector<casadi_int> mapping;
126  Sparsity sp = sparsity().sub(rr.nonzeros(), cc.nonzeros(), mapping, ind1);
127 
128  // Copy nonzeros
129  m = Matrix<Scalar>::zeros(sp);
130  for (casadi_int k=0; k<mapping.size(); ++k) m->at(k) = nonzeros().at(mapping[k]);
131  }
bool is_vector() const
Check if the matrix is a row or column vector.

◆ get() [3/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::get ( Matrix< Scalar > &  m,
bool  ind1,
const Matrix< casadi_int > &  rr,
const Slice cc 
) const

Get a submatrix, two arguments

Definition at line 104 of file matrix_impl.hpp.

105  {
106  // Fall back on IM-IM
107  get(m, ind1, rr, cc.all(size2(), ind1));
108  }

◆ get() [4/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::get ( Matrix< Scalar > &  m,
bool  ind1,
const Slice rr 
) const

Get a submatrix, single argument

Definition at line 134 of file matrix_impl.hpp.

134  {
135  // Scalar
136  if (rr.is_scalar(numel())) {
137  casadi_int r = rr.scalar(numel());
138  casadi_int k = sparsity().get_nz(r % size1(), r / size1());
139  if (k>=0) {
140  m = nonzeros().at(k);
141  } else {
142  m = Matrix<Scalar>(1, 1);
143  }
144  return;
145  }
146 
147  // Fall back on IM
148  get(m, ind1, rr.all(numel(), ind1));
149  }
casadi_int size1() const
Get the first dimension (i.e. number of rows)
casadi_int get_nz(casadi_int rr, casadi_int cc) const
Get the index of an existing non-zero element.
Definition: sparsity.cpp:246

◆ get() [5/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::get ( Matrix< Scalar > &  m,
bool  ind1,
const Slice rr,
const Matrix< casadi_int > &  cc 
) const

Get a submatrix, two arguments

Definition at line 97 of file matrix_impl.hpp.

98  {
99  // Fall back on IM-IM
100  get(m, ind1, rr.all(size1(), ind1), cc);
101  }

References casadi::Slice::all().

◆ get() [6/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::get ( Matrix< Scalar > &  m,
bool  ind1,
const Slice rr,
const Slice cc 
) const

Get a submatrix, two arguments

Definition at line 79 of file matrix_impl.hpp.

80  {
81  // Both are scalar
82  if (rr.is_scalar(size1()) && cc.is_scalar(size2())) {
83  casadi_int k = sparsity().get_nz(rr.scalar(size1()), cc.scalar(size2()));
84  if (k>=0) {
85  m = nonzeros().at(k);
86  } else {
87  m = Matrix<Scalar>(1, 1);
88  }
89  return;
90  }
91 
92  // Fall back on IM-IM
93  get(m, ind1, rr.all(size1(), ind1), cc.all(size2(), ind1));
94  }

References casadi::Slice::all(), casadi::Slice::is_scalar(), and casadi::Slice::scalar().

◆ get() [7/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::get ( Matrix< Scalar > &  m,
bool  ind1,
const Sparsity sp 
) const

Get a submatrix, single argument

Definition at line 176 of file matrix_impl.hpp.

176  {
177  casadi_assert(size()==sp.size(),
178  "Shape mismatch. This matrix has shape "
179  + str(size()) + ", but supplied sparsity index has shape "
180  + str(sp.size()) + ".");
181  m = project(*this, sp);
182  }
std::pair< casadi_int, casadi_int > size() const
Get the shape.
static Matrix< Scalar > project(const Matrix< Scalar > &x, const Sparsity &sp, bool intersect=false)
std::string str(const T &v)
String representation, any type.

References casadi::Sparsity::size(), and casadi::str().

◆ get_colind()

std::vector<casadi_int> casadi::GenericMatrix< Matrix< Scalar > >::get_colind ( ) const
inlineinherited

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

Definition at line 195 of file generic_matrix.hpp.

195 { return sparsity().get_colind(); }
std::vector< casadi_int > get_colind() const
Get the column index for each column.
Definition: sparsity.cpp:364

◆ get_elements()

template<typename Scalar >
std::vector<Scalar> casadi::Matrix< Scalar >::get_elements ( ) const

◆ get_free()

std::vector< SX > CASADI_EXPORT casadi::SX::get_free ( const Function f)
static

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

Definition at line 1554 of file sx_instantiator.cpp.

1554  {
1555  return f.free_sx();
1556  }

References casadi::Function::free_sx().

◆ get_input()

std::vector< SX > CASADI_EXPORT casadi::SX::get_input ( const Function f)
static

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

Definition at line 1550 of file sx_instantiator.cpp.

1550  {
1551  return f.sx_in();
1552  }

References casadi::Function::sx_in().

◆ get_max_depth()

casadi_int CASADI_EXPORT casadi::SX::get_max_depth
static

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

Definition at line 47 of file sx_instantiator.cpp.

47  {
48  return SXNode::eq_depth_;
49  }
static casadi_int eq_depth_
Definition: sx_node.hpp:179

References casadi::SXNode::eq_depth_.

◆ get_nonzeros() [1/2]

template<typename Scalar >
std::vector< A > casadi::Matrix< Scalar >::get_nonzeros ( ) const

Implementation of Matrix::get_nonzeros (in public API)

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

Definition at line 1392 of file matrix_decl.hpp.

1392  {
1393  std::vector<A> ret(nnz());
1394  auto r = ret.begin();
1395  for (auto&& e : nonzeros()) *r++ = static_cast<A>(e);
1396  return ret;
1397  }
casadi_int nnz() const
Get the number of (structural) non-zero elements.

◆ get_nonzeros() [2/2]

template<typename Scalar >
template<typename A >
std::vector<A> casadi::Matrix< Scalar >::get_nonzeros ( ) const

◆ get_nz() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::get_nz ( Matrix< Scalar > &  m,
bool  ind1,
const Matrix< casadi_int > &  k 
) const

Get a set of nonzeros

Definition at line 406 of file matrix_impl.hpp.

406  {
407  // Scalar
408  if (kk.is_scalar(true)) {
409  return get_nz(m, ind1, to_slice(kk, ind1));
410  }
411 
412  // Get nonzeros of kk
413  const std::vector<casadi_int>& k = kk.nonzeros();
414  casadi_int sz = nnz();
415 
416  // Check bounds
417  casadi_assert_in_range(k, -sz+ind1, sz+ind1);
418 
419  // If indexed matrix was a row/column vector, make sure that the result is too
420  bool tr = (is_column() && kk.is_row()) || (is_row() && kk.is_column());
421 
422  // Copy nonzeros
423  m = zeros(tr ? kk.sparsity().T() : kk.sparsity());
424  for (casadi_int el=0; el<k.size(); ++el) {
425  casadi_assert(!(ind1 && k[el]<=0), "Matlab is 1-based, but requested index "
426  + str(k[el]) + ". Note that negative slices are"
427  " disabled in the Matlab interface. "
428  "Possibly you may want to use 'end'.");
429  casadi_int k_el = k[el]-ind1;
430  m->at(el) = nonzeros().at(k_el>=0 ? k_el : k_el+sz);
431  }
432  }

◆ get_nz() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::get_nz ( Matrix< Scalar > &  m,
bool  ind1,
const Slice k 
) const

Get a set of nonzeros

Definition at line 394 of file matrix_impl.hpp.

394  {
395  // Scalar
396  if (kk.is_scalar(nnz())) {
397  m = nonzeros().at(kk.scalar(nnz()));
398  return;
399  }
400 
401  // Fall back on IM
402  get_nz(m, ind1, kk.all(nnz(), ind1));
403  }

◆ get_output()

SX CASADI_EXPORT casadi::SX::get_output ( casadi_int  oind) const

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

Definition at line 165 of file sx_instantiator.cpp.

165  {
166  return scalar().get_output(oind);
167  }

References casadi::Matrix< Scalar >::scalar().

◆ get_row()

std::vector<casadi_int> casadi::GenericMatrix< Matrix< Scalar > >::get_row ( ) const
inlineinherited

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

Definition at line 194 of file generic_matrix.hpp.

194 { return sparsity().get_row(); }
std::vector< casadi_int > get_row() const
Get the row for each non-zero entry.
Definition: sparsity.cpp:372

◆ get_sparsity()

template<typename Scalar >
Sparsity casadi::Matrix< Scalar >::get_sparsity ( ) const

◆ get_str()

template<typename Scalar >
std::string casadi::Matrix< Scalar >::get_str ( bool  more = false) const

◆ gradient()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::gradient ( const Matrix< Scalar > &  ex,
const Matrix< Scalar > &  arg,
const Dict opts = Dict() 
)
staticinherited

Functions called by friend functions defined here

◆ has_duplicates()

bool CASADI_EXPORT casadi::SX::has_duplicates

If there are symbolic primitives appearing more than once, the function will return true and the names of the duplicate expressions will be passed to casadi_warning. Note: Will mark the node using SXElem::set_temp. Make sure to call reset_input() after usage.

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

Definition at line 198 of file sx_instantiator.cpp.

198  {
199  bool has_duplicates = false;
200  for (auto&& i : nonzeros_) {
201  bool is_duplicate = i.get_temp()!=0;
202  if (is_duplicate) {
203  casadi_warning("Duplicate expression: " + str(i));
204  }
205  has_duplicates = has_duplicates || is_duplicate;
206  i.set_temp(1);
207  }
208  return has_duplicates;
209  }
bool has_duplicates() const
Detect duplicate symbolic expressions.

References casadi::str().

◆ has_nz()

template<typename Scalar >
bool casadi::Matrix< Scalar >::has_nz ( casadi_int  rr,
casadi_int  cc 
) const

Definition at line 65 of file matrix_impl.hpp.

65  {
66  return sparsity().has_nz(rr, cc);
67  }
bool has_nz(casadi_int rr, casadi_int cc) const
Returns true if the pattern has a non-zero at location rr, cc.
Definition: sparsity.cpp:241

◆ has_output()

bool CASADI_EXPORT casadi::SX::has_output

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

Definition at line 160 of file sx_instantiator.cpp.

160  {
161  return scalar().has_output();
162  }

References casadi::Matrix< Scalar >::scalar().

◆ has_zeros()

template<typename Scalar >
bool casadi::Matrix< Scalar >::has_zeros ( ) const

◆ heaviside()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::heaviside ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined here

◆ hessian() [1/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::hessian ( const Matrix< Scalar > &  f,
const Matrix< Scalar > &  x,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

◆ hessian() [2/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::hessian ( const Matrix< Scalar > &  f,
const Matrix< Scalar > &  x,
Matrix< Scalar > &  g,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

◆ horzcat()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::horzcat ( const std::vector< Matrix< Scalar > > &  v)
static

Functions called by friend functions defined for SparsityInterface

◆ horzsplit()

template<typename Scalar >
static std::vector<Matrix<Scalar> > casadi::Matrix< Scalar >::horzsplit ( const Matrix< Scalar > &  x,
const std::vector< casadi_int > &  offset 
)
static

Functions called by friend functions defined for SparsityInterface

◆ if_else()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::if_else ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  if_true,
const Matrix< Scalar > &  if_false,
bool  short_circuit = false 
)
static

Functions called by friend functions defined for GenericMatrix

◆ inf() [1/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::inf ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
static

◆ inf() [2/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::inf ( const Sparsity sp)
static

◆ inf() [3/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::inf ( const std::pair< casadi_int, casadi_int > &  rc)
static

◆ info()

Dict CASADI_EXPORT casadi::SX::info

Obtain information about sparsity

Definition at line 1559 of file sx_instantiator.cpp.

1559  {
1560  return {{"function", Function("f", std::vector<SX>{}, std::vector<SX>{*this})}};
1561  }

◆ interp1d()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::interp1d ( const std::vector< double > &  x,
const Matrix< Scalar > &  v,
const std::vector< double > &  xq,
const std::string &  mode,
bool  equidistant 
)
staticinherited

Definition at line 213 of file generic_matrix.hpp.

1432  {
1433 
1434  bool mode_floor = false;
1435  bool mode_ceil = false;
1436  if (mode=="floor") {
1437  mode_floor = true;
1438  } else if (mode=="ceil") {
1439  mode_ceil = true;
1440  } else if (mode=="linear") {
1441  //
1442  } else {
1443  casadi_error("interp1d(x, v, xq, mode): "
1444  "Mode must be 'floor', 'ceil' or 'linear'. Got '" + mode + "' instead.");
1445  }
1446 
1447  casadi_assert(is_increasing(x), "interp1d(x, v, xq): x must be increasing.");
1448 
1449  casadi_assert(x.size()==v.size1(),
1450  "interp1d(x, v, xq): dimensions mismatch. v expected to have " + str(x.size()) + " rows,"
1451  " but got " + str(v.size1()) + " instead.");
1452 
1453  // Need at least two elements
1454  casadi_assert(x.size()>=2, "interp1d(x, v, xq): x must be at least length 2.");
1455 
1456  // Vectors to compose a sparse matrix
1457  std::vector<double> val;
1458  std::vector<casadi_int> colind(1, 0);
1459  std::vector<casadi_int> row;
1460 
1461  // Number of nonzeros in to-be composed matrix
1462  casadi_int nnz = 0;
1463  for (casadi_int i=0;i<xq.size();++i) {
1464  // Obtain index corresponding to xq[i]
1465  double ind = index_interp1d(x, xq[i], equidistant);
1466 
1467  if (mode_floor) ind = floor(ind);
1468  if (mode_ceil) ind = ceil(ind);
1469 
1470  // Split into integer and fractional part
1471  double int_partd;
1472  double frac_part = modf(ind, &int_partd);
1473  casadi_int int_part = static_cast<casadi_int>(int_partd);
1474 
1475  if (frac_part==0) {
1476  // Create a single entry
1477  val.push_back(1);
1478  row.push_back(int_part);
1479  nnz+=1;
1480  colind.push_back(nnz);
1481  } else {
1482  // Create a double entry
1483  val.push_back(1-frac_part);
1484  val.push_back(frac_part);
1485  row.push_back(int_part);
1486  row.push_back(int_part+1);
1487  nnz+=2;
1488  colind.push_back(nnz);
1489  }
1490  }
1491 
1492  // Construct sparsity for composed matrix
1493  Sparsity sp(x.size(), xq.size() , colind, row);
1494 
1495  return MatType::mtimes(MatType(sp, val).T(), v);
1496 
1497  }
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.

◆ inv() [1/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::inv ( const Matrix< Scalar > &  A)
static

Functions called by friend functions defined for GenericMatrix

◆ inv() [2/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::inv ( const Matrix< Scalar > &  A,
const std::string &  lsolver,
const Dict opts 
)
static

Functions called by friend functions defined for GenericMatrix

◆ inv_minor()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::inv_minor ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ inv_skew()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::inv_skew ( const Matrix< Scalar > &  a)
staticinherited

Definition at line 229 of file generic_matrix.hpp.

1511  {
1512  casadi_assert(a.size1()==3 && a.size2()==3,
1513  "inv_skew(a): Expecting 3-by-3 matrix, got " + a.dim() + ".");
1514 
1515  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)}));
1516  }

◆ is_call()

bool CASADI_EXPORT casadi::SX::is_call

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

Definition at line 150 of file sx_instantiator.cpp.

150  {
151  return scalar().is_call();
152  }

References casadi::Matrix< Scalar >::scalar().

◆ is_column()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_column ( ) const
inlineinherited

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

Definition at line 178 of file generic_matrix.hpp.

178 { return sparsity().is_column();}
bool is_column() const
Check if the pattern is a column vector (i.e. size2()==1)
Definition: sparsity.cpp:285

◆ is_commutative()

bool CASADI_EXPORT casadi::SX::is_commutative

Only defined if symbolic scalar.

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

Definition at line 136 of file sx_instantiator.cpp.

136  {
137  return scalar().is_commutative();
138  }

References casadi::Matrix< Scalar >::scalar().

◆ is_constant()

template<typename Scalar >
bool casadi::Matrix< Scalar >::is_constant ( ) const

◆ is_dense()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_dense ( ) const
inlineinherited

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

Definition at line 153 of file generic_matrix.hpp.

153 { return sparsity().is_dense();}
bool is_dense() const
Is dense?
Definition: sparsity.cpp:273

◆ is_empty()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_empty ( bool  both = false) const
inlineinherited

(or optionally both dimensions)

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

Definition at line 148 of file generic_matrix.hpp.

148 { return sparsity().is_empty(both);}
bool is_empty(bool both=false) const
Check if the sparsity is empty.
Definition: sparsity.cpp:144

◆ is_equal()

template<typename Scalar >
static bool casadi::Matrix< Scalar >::is_equal ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y,
casadi_int  depth = 0 
)
static

Functions called by friend functions defined for GenericExpression

◆ is_eye()

template<typename Scalar >
bool casadi::Matrix< Scalar >::is_eye ( ) const

◆ is_integer()

template<typename Scalar >
bool casadi::Matrix< Scalar >::is_integer ( ) const

(note that false negative answers are possible)

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

◆ is_leaf()

bool CASADI_EXPORT casadi::SX::is_leaf

Only defined if symbolic scalar.

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

Definition at line 131 of file sx_instantiator.cpp.

131  {
132  return scalar().is_leaf();
133  }

References casadi::Matrix< Scalar >::scalar().

◆ is_linear()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_linear ( const Matrix< Scalar > &  expr,
const Matrix< Scalar > &  var 
)
staticinherited

Definition at line 235 of file generic_matrix.hpp.

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

◆ is_minus_one()

template<typename Scalar >
bool casadi::Matrix< Scalar >::is_minus_one ( ) const

◆ is_one()

template<typename Scalar >
bool casadi::Matrix< Scalar >::is_one ( ) const

◆ is_op()

bool CASADI_EXPORT casadi::SX::is_op ( casadi_int  op) const

Definition at line 194 of file sx_instantiator.cpp.

194  {
195  return scalar().is_op(op);
196  }
casadi_int op() const
Get operation type.

References casadi::Matrix< Scalar >::op(), and casadi::Matrix< Scalar >::scalar().

◆ is_output()

bool CASADI_EXPORT casadi::SX::is_output

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

Definition at line 155 of file sx_instantiator.cpp.

155  {
156  return scalar().is_output();
157  }

References casadi::Matrix< Scalar >::scalar().

◆ is_quadratic()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_quadratic ( const Matrix< Scalar > &  expr,
const Matrix< Scalar > &  var 
)
staticinherited

Definition at line 236 of file generic_matrix.hpp.

1748  {
1749  return is_linear(gradient(expr, var), var);
1750  }
static bool is_linear(const Matrix< Scalar > &expr, const Matrix< Scalar > &var)
friend Matrix< Scalar > gradient(const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Dict &opts=Dict())
Calculate the gradient of an expression.

◆ is_regular()

bool CASADI_EXPORT casadi::SX::is_regular

Definition at line 100 of file sx_instantiator.cpp.

100  {
101  // First pass: ignore symbolics
102  for (casadi_int i=0; i<nnz(); ++i) {
103  const SXElem& x = nonzeros().at(i);
104  if (x.is_constant()) {
105  if (x.is_nan() || x.is_inf() || x.is_minus_inf()) return false;
106  }
107  }
108  // Second pass: don't ignore symbolics
109  for (casadi_int i=0; i<nnz(); ++i) {
110  if (!nonzeros().at(i).is_regular()) return false;
111  }
112  return true;
113  }

References casadi::SXElem::is_constant(), casadi::SXElem::is_inf(), casadi::SXElem::is_minus_inf(), casadi::SXElem::is_nan(), casadi::GenericMatrix< Matrix< Scalar > >::nnz(), and casadi::Matrix< Scalar >::nonzeros().

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

◆ is_row()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_row ( ) const
inlineinherited

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

Definition at line 173 of file generic_matrix.hpp.

173 { return sparsity().is_row();}
bool is_row() const
Check if the pattern is a row vector (i.e. size1()==1)
Definition: sparsity.cpp:281

◆ is_scalar()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_scalar ( bool  scalar_and_dense = false) const
inherited

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

Definition at line 158 of file generic_matrix.hpp.

1348  {
1349  return sparsity().is_scalar(scalar_and_dense);
1350  }
bool is_scalar(bool scalar_and_dense=false) const
Is scalar?
Definition: sparsity.cpp:269

◆ is_smooth()

bool CASADI_EXPORT casadi::SX::is_smooth

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

Definition at line 116 of file sx_instantiator.cpp.

116  {
117  // Make a function
118  Function temp("tmp_is_smooth", {SX()}, {*this}, Dict{{"max_io", 0}, {"allow_free", true}});
119 
120  // Run the function on the temporary variable
121  SXFunction* t = temp.get<SXFunction>();
122  return t->is_smooth();
123  }
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.

References casadi::SXFunction::is_smooth().

◆ is_square()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_square ( ) const
inlineinherited

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

Definition at line 163 of file generic_matrix.hpp.

163 { return sparsity().is_square();}
bool is_square() const
Is square?
Definition: sparsity.cpp:293

◆ is_symbolic()

bool CASADI_EXPORT casadi::SX::is_symbolic

Check if an expression is a pure symbol. Pure means that no operations should happen on the symbol (not even vec, transpose, index, concatenation, ...) By consequence, a slice of a vector-shaped MX symbol is not a symbol. However, the SX type is really a container format with scalar entries. Therefore, a slice of a vector-shaped SX symbol is still a symbol.

Sparse matrices invariable return false

\seealso is_valid_input

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

Definition at line 180 of file sx_instantiator.cpp.

180  {
181  if (is_dense()) {
182  return is_valid_input();
183  } else {
184  return false;
185  }
186  }
bool is_valid_input() const
Check if matrix can be used to define function inputs.

References casadi::GenericMatrix< Matrix< Scalar > >::is_dense(), and casadi::Matrix< Scalar >::is_valid_input().

◆ is_tril()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_tril ( ) const
inlineinherited

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

Definition at line 188 of file generic_matrix.hpp.

188 { return sparsity().is_tril();}
bool is_tril(bool strictly=false) const
Is lower triangular?
Definition: sparsity.cpp:321

◆ is_triu()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_triu ( ) const
inlineinherited

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

Definition at line 183 of file generic_matrix.hpp.

183 { return sparsity().is_triu();}
bool is_triu(bool strictly=false) const
Is upper triangular?
Definition: sparsity.cpp:325

◆ is_valid_input()

bool CASADI_EXPORT casadi::SX::is_valid_input

is_valid_input is more forgiving than is_symbolic. Some compositions are allowed: vec, vertcat.

Sparse matrices can return true if all non-zero elements are symbolic

\seealso is_symbolic

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

Definition at line 141 of file sx_instantiator.cpp.

141  {
142  for (casadi_int k=0; k<nnz(); ++k) // loop over non-zero elements
143  if (!nonzeros().at(k)->is_symbolic()) // if an element is not symbolic
144  return false;
145 
146  return true;
147  }

References casadi::GenericMatrix< Matrix< Scalar > >::nnz(), and casadi::Matrix< Scalar >::nonzeros().

Referenced by casadi::Matrix< Scalar >::is_symbolic().

◆ is_vector()

bool casadi::GenericMatrix< Matrix< Scalar > >::is_vector ( ) const
inlineinherited

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

Definition at line 168 of file generic_matrix.hpp.

168 { return sparsity().is_vector();}
bool is_vector() const
Check if the pattern is a row or column vector.
Definition: sparsity.cpp:289

◆ is_zero()

template<typename Scalar >
bool casadi::Matrix< Scalar >::is_zero ( ) const

◆ jacobian()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::jacobian ( const Matrix< Scalar > &  f,
const Matrix< Scalar > &  x,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined for GenericMatrix

Referenced by casadi::AmplInterface::init().

◆ jacobian_sparsity()

template<typename Scalar >
static Sparsity casadi::Matrix< Scalar >::jacobian_sparsity ( const Matrix< Scalar > &  f,
const Matrix< Scalar > &  x 
)
static

Functions called by friend functions defined for GenericMatrix

◆ jtimes()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::jtimes ( const Matrix< Scalar > &  ex,
const Matrix< Scalar > &  arg,
const Matrix< Scalar > &  v,
bool  tr = false,
const Dict opts = Dict() 
)
staticinherited

Functions called by friend functions defined here

◆ kron()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::kron ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

Functions called by friend functions defined for SparsityInterface

◆ ldl()

template<typename Scalar >
static void casadi::Matrix< Scalar >::ldl ( const Matrix< Scalar > &  A,
Matrix< Scalar > &  D,
Matrix< Scalar > &  LT,
std::vector< casadi_int > &  p,
bool  amd = true 
)
static

Functions called by friend functions defined here

◆ ldl_solve()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::ldl_solve ( const Matrix< Scalar > &  b,
const Matrix< Scalar > &  D,
const Matrix< Scalar > &  LT,
const std::vector< casadi_int > &  p 
)
static

Functions called by friend functions defined here

◆ linear_coeff()

void casadi::GenericMatrix< Matrix< Scalar > >::linear_coeff ( const Matrix< Scalar > &  expr,
const Matrix< Scalar > &  var,
Matrix< Scalar > &  A,
Matrix< Scalar > &  b,
bool  check 
)
staticinherited

Definition at line 239 of file generic_matrix.hpp.

1765  {
1766  casadi_assert(expr.is_vector(), "'linear_coeff' only defined for vector expressions.");
1767  if (check)
1768  casadi_assert(is_linear(expr, var), "'linear_coeff' called on non-linear expression.");
1769  A = substitute(jacobian(expr, var), var, 0);
1770  b = vec(substitute(expr, var, 0));
1771  }
static MatType vec(const MatType &x)
friend Matrix< Scalar > substitute(const Matrix< Scalar > &ex, const Matrix< Scalar > &v, const Matrix< Scalar > &vdef)
Substitute variable v with expression vdef in an expression ex.
friend Matrix< Scalar > jacobian(const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Dict &opts=Dict())
Calculate Jacobian.

◆ linearize()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::linearize ( const Matrix< Scalar > &  f,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  x0,
const Dict opts = Dict() 
)
staticinherited

Functions called by friend functions defined here

◆ linspace()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::linspace ( const Matrix< Scalar > &  a,
const Matrix< Scalar > &  b,
casadi_int  nsteps 
)
staticinherited

Definition at line 226 of file generic_matrix.hpp.

1381  {
1382  std::vector<MatType> ret(nsteps);
1383  ret[0] = a;
1384  MatType step = (b-a)/static_cast<MatType>(nsteps-1);
1385 
1386  for (casadi_int i=1; i<nsteps-1; ++i)
1387  ret[i] = a + i * step;
1388 
1389  ret[nsteps-1] = b;
1390  return vertcat(ret);
1391  }

◆ logsumexp()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::logsumexp ( const Matrix< Scalar > &  x)
staticinherited

◆ mac()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::mac ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y,
const Matrix< Scalar > &  z 
)
static

Functions called by friend functions defined for SparsityInterface

◆ matrix_matrix()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::matrix_matrix ( casadi_int  op,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

◆ matrix_scalar()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::matrix_scalar ( casadi_int  op,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

◆ minor()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::minor ( const Matrix< Scalar > &  x,
casadi_int  i,
casadi_int  j 
)
static

Functions called by friend functions defined here

◆ mldivide()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::mldivide ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

Functions called by friend functions defined for GenericMatrix

◆ mmax()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::mmax ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericExpression

◆ mmin()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::mmin ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericExpression

◆ mpower()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::mpower ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
staticinherited

Functions called by friend functions defined here

◆ mrdivide()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::mrdivide ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

Functions called by friend functions defined for GenericMatrix

◆ mtaylor() [1/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::mtaylor ( const Matrix< Scalar > &  ex,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  a,
casadi_int  order 
)
static

Functions called by friend functions defined here

◆ mtaylor() [2/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::mtaylor ( const Matrix< Scalar > &  ex,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  a,
casadi_int  order,
const std::vector< casadi_int > &  order_contributions 
)
static

Functions called by friend functions defined here

◆ mtimes()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::mtimes ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

Functions called by friend functions defined for SparsityInterface

◆ n_dep()

casadi_int CASADI_EXPORT casadi::SX::n_dep

Only defined if symbolic scalar.

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

Definition at line 228 of file sx_instantiator.cpp.

228  {
229  return scalar().n_dep();
230  }

References casadi::Matrix< Scalar >::scalar().

◆ n_nodes()

template<typename Scalar >
static casadi_int casadi::Matrix< Scalar >::n_nodes ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ name()

std::string CASADI_EXPORT casadi::SX::name

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

Definition at line 218 of file sx_instantiator.cpp.

218  {
219  return scalar().name();
220  }

References casadi::Matrix< Scalar >::scalar().

Referenced by casadi::Matrix< Scalar >::_sym().

◆ nan() [1/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::nan ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
static

◆ nan() [2/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::nan ( const Sparsity sp)
static

◆ nan() [3/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::nan ( const std::pair< casadi_int, casadi_int > &  rc)
static

◆ nnz()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::nnz
inherited

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

Definition at line 84 of file generic_matrix.hpp.

1298  {
1299  return sparsity().nnz();
1300  }
casadi_int nnz() const
Get the number of (structural) non-zeros.
Definition: sparsity.cpp:148

◆ nnz_diag()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::nnz_diag
inherited

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

Definition at line 99 of file generic_matrix.hpp.

1313  {
1314  return sparsity().nnz_diag();
1315  }
casadi_int nnz_diag() const
Number of non-zeros on the diagonal, i.e. the number of elements (i, j) with j==i.
Definition: sparsity.cpp:360

◆ nnz_lower()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::nnz_lower
inherited

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

Definition at line 89 of file generic_matrix.hpp.

1303  {
1304  return sparsity().nnz_lower();
1305  }
casadi_int nnz_lower(bool strictly=false) const
Number of non-zeros in the lower triangular half,.
Definition: sparsity.cpp:352

◆ nnz_upper()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::nnz_upper
inherited

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

Definition at line 94 of file generic_matrix.hpp.

1308  {
1309  return sparsity().nnz_upper();
1310  }
casadi_int nnz_upper(bool strictly=false) const
Number of non-zeros in the upper triangular half,.
Definition: sparsity.cpp:356

◆ nonzeros() [1/2]

template<typename Scalar >
std::vector<Scalar>& casadi::Matrix< Scalar >::nonzeros ( )

◆ nonzeros() [2/2]

template<typename Scalar >
const std::vector<Scalar>& casadi::Matrix< Scalar >::nonzeros ( ) const

Access the non-zero elements

◆ norm_0_mul()

static casadi_int casadi::GenericMatrix< Matrix< Scalar > >::norm_0_mul ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
inlinestaticinherited

Definition at line 216 of file generic_matrix.hpp.

216  {
217  return Sparsity::norm_0_mul(x.sparsity(), y.sparsity());
218  }

◆ norm_1()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::norm_1 ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ norm_2()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::norm_2 ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ norm_fro()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::norm_fro ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ norm_inf()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::norm_inf ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ norm_inf_mul()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::norm_inf_mul ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

Functions called by friend functions defined here

◆ nullspace()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::nullspace ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

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

◆ numel()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::numel
inherited

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

Definition at line 104 of file generic_matrix.hpp.

1318  {
1319  return sparsity().numel();
1320  }
casadi_int numel() const
The total number of elements, including structural zeros, i.e. size2()*size1()
Definition: sparsity.cpp:132

◆ nz() [1/2]

NonZeros<Matrix< Scalar > , K> casadi::GenericMatrix< Matrix< Scalar > >::nz ( const K &  k)
inlineinherited

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

Definition at line 258 of file generic_matrix.hpp.

258  {
259  return NonZeros<MatType, K>(self(), k);
260  }

◆ nz() [2/2]

const Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::nz ( const K &  k) const
inlineinherited

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

Definition at line 248 of file generic_matrix.hpp.

248  {
249  MatType ret;
250  self().get_nz(ret, false, k);
251  return ret;
252  }

◆ ones() [1/3]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::ones ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestaticinherited

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

Definition at line 1275 of file generic_matrix.hpp.

1275  {
1276  return ones(Sparsity::dense(nrow, ncol));
1277  }
static Matrix< Scalar > ones(casadi_int nrow=1, casadi_int ncol=1)
Create a dense matrix or a matrix with specified sparsity with all entries one.

◆ ones() [2/3]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::ones ( const Sparsity sp)
inlinestaticinherited

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

Definition at line 1278 of file generic_matrix.hpp.

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

◆ ones() [3/3]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::ones ( const std::pair< casadi_int, casadi_int > &  rc)
inlinestaticinherited

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

Definition at line 1279 of file generic_matrix.hpp.

1279  {
1280  return ones(rc.first, rc.second);
1281  }

◆ op()

casadi_int CASADI_EXPORT casadi::SX::op

Definition at line 189 of file sx_instantiator.cpp.

189  {
190  return scalar().op();
191  }

References casadi::Matrix< Scalar >::scalar().

Referenced by casadi::Matrix< Scalar >::is_op().

◆ operator casadi_int()

template<typename Scalar >
casadi::Matrix< Scalar >::operator casadi_int ( ) const
explicit

◆ operator double()

template<typename Scalar >
casadi::Matrix< Scalar >::operator double ( ) const
explicit

◆ operator std::vector< A >()

template<typename Scalar >
template<typename A >
casadi::Matrix< Scalar >::operator std::vector< A >
explicit

Implementation of std::vector(Matrix) (in public API)

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

Definition at line 1402 of file matrix_decl.hpp.

1402  {
1403  // Get sparsity pattern
1404  casadi_int size1 = this->size1(), size2 = this->size2();
1405  const casadi_int *colind = this->colind(), *row = this->row();
1406  // Copy the nonzeros
1407  auto it = nonzeros().begin();
1408  std::vector<A> ret(numel(), 0);
1409  for (casadi_int cc=0; cc<size2; ++cc) {
1410  for (casadi_int el=colind[cc]; el<colind[cc+1]; ++el) {
1411  ret[row[el] + cc*size1] = static_cast<A>(*it++);
1412  }
1413  }
1414  return ret;
1415  }

◆ operator()() [1/4]

SubIndex<Matrix< Scalar > , RR> casadi::GenericMatrix< Matrix< Scalar > >::operator() ( const RR &  rr)
inlineinherited

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

Definition at line 286 of file generic_matrix.hpp.

286  {
287  return SubIndex<MatType, RR>(self(), rr);
288  }

◆ operator()() [2/4]

const Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::operator() ( const RR &  rr) const
inlineinherited

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

Definition at line 266 of file generic_matrix.hpp.

266  {
267  MatType ret;
268  self().get(ret, false, rr);
269  return ret;
270  }

◆ operator()() [3/4]

SubMatrix<Matrix< Scalar > , RR, CC> casadi::GenericMatrix< Matrix< Scalar > >::operator() ( const RR &  rr,
const CC &  cc 
)
inlineinherited

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

Definition at line 294 of file generic_matrix.hpp.

294  {
295  return SubMatrix<MatType, RR, CC>(self(), rr, cc);
296  }

◆ operator()() [4/4]

const Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::operator() ( const RR &  rr,
const CC &  cc 
) const
inlineinherited

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

Definition at line 276 of file generic_matrix.hpp.

276  {
277  MatType ret;
278  self().get(ret, false, rr, cc);
279  return ret;
280  }

◆ operator+()

template<typename Scalar >
Matrix<Scalar> casadi::Matrix< Scalar >::operator+ ( ) const
Examples
SX/SXaddition.cc.

◆ operator-()

template<typename Scalar >
Matrix<Scalar> casadi::Matrix< Scalar >::operator- ( ) const

◆ operator->() [1/2]

template<typename Scalar >
std::vector< Scalar > * casadi::Matrix< Scalar >::operator->

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

Definition at line 596 of file matrix_impl.hpp.

596  {
597  return &nonzeros_;
598  }

◆ operator->() [2/2]

template<typename Scalar >
const std::vector< Scalar > * casadi::Matrix< Scalar >::operator->

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

Definition at line 601 of file matrix_impl.hpp.

601  {
602  return &nonzeros_;
603  }

◆ operator=()

template<typename Scalar >
Matrix< Scalar > & casadi::Matrix< Scalar >::operator= ( const Matrix< Scalar > &  m)

Definition at line 589 of file matrix_impl.hpp.

589  {
590  sparsity_ = m.sparsity_;
591  nonzeros_ = m.nonzeros_;
592  return *this;
593  }

◆ pinv() [1/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::pinv ( const Matrix< Scalar > &  A,
const std::string &  lsolver,
const Dict opts 
)
static

Functions called by friend functions defined for GenericMatrix

◆ pinv() [2/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::pinv ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ poly_coeff()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::poly_coeff ( const Matrix< Scalar > &  ex,
const Matrix< Scalar > &  x 
)
static

Functions called by friend functions defined here

◆ poly_roots()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::poly_roots ( const Matrix< Scalar > &  p)
static

Functions called by friend functions defined here

◆ polyval()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::polyval ( const Matrix< Scalar > &  p,
const Matrix< Scalar > &  x 
)
static

Functions called by friend functions defined for GenericMatrix

◆ print_default()

template<typename Scalar >
void casadi::Matrix< Scalar >::print_default ( std::ostream &  stream,
const Sparsity sp,
const Scalar *  nonzeros,
bool  truncate = true 
)
static

Definition at line 703 of file matrix_impl.hpp.

704  {
705  if (sp.is_empty()) {
706  stream << sp.size1() << "x" << sp.size2();
707  } else if (sp.numel()==1) {
708  if (sp.nnz()==0) {
709  stream << "00";
710  } else {
711  print_scalar(stream, *nonzeros);
712  }
713  } else if (sp.is_column()) {
714  print_vector(stream, sp, nonzeros, truncate);
715  } else if (std::max(sp.size1(), sp.size2())<=10 ||
716  static_cast<double>(sp.nnz())/static_cast<double>(sp.numel())>=0.5) {
717  // if "small" or "dense"
718  print_dense(stream, sp, nonzeros, truncate);
719  } else {
720  print_sparse(stream, sp, nonzeros, truncate);
721  }
722  }
void print_sparse(std::ostream &stream, bool truncate=true) const
Print sparse matrix style.
void print_dense(std::ostream &stream, bool truncate=true) const
Print dense matrix-stype.
void print_vector(std::ostream &stream, bool truncate=true) const
Print vector-style.
void print_scalar(std::ostream &stream) const
Print scalar.

References casadi::Sparsity::is_column(), casadi::Sparsity::is_empty(), casadi::Sparsity::nnz(), casadi::Sparsity::numel(), casadi::Sparsity::size1(), and casadi::Sparsity::size2().

◆ print_dense() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_dense ( std::ostream &  stream,
bool  truncate = true 
) const

Definition at line 686 of file matrix_impl.hpp.

686  {
687  print_dense(stream, sparsity(), ptr(), truncate);
688  }
Scalar * ptr()

◆ print_dense() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_dense ( std::ostream &  stream,
const Sparsity sp,
const Scalar *  nonzeros,
bool  truncate = true 
)
static

◆ print_operator()

template<typename Scalar >
static std::string casadi::Matrix< Scalar >::print_operator ( const Matrix< Scalar > &  x,
const std::vector< std::string > &  args 
)
static

Functions called by friend functions defined for GenericMatrix

◆ print_scalar() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_scalar ( std::ostream &  stream) const

Definition at line 609 of file matrix_impl.hpp.

609  {
610  casadi_assert(numel()==1, "Not a scalar");
611 
612  std::streamsize precision = stream.precision();
613  std::streamsize width = stream.width();
614  std::ios_base::fmtflags flags = stream.flags();
615 
616  stream.precision(stream_precision_);
617  stream.width(stream_width_);
618  if (stream_scientific_) {
619  stream.setf(std::ios::scientific);
620  } else {
621  stream.unsetf(std::ios::scientific);
622  }
623 
624  if (nnz()==0) {
625  stream << "00";
626  } else {
627  stream << scalar();
628  }
629  stream << std::flush;
630  stream.precision(precision);
631  stream.width(width);
632  stream.flags(flags);
633  }

◆ print_scalar() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_scalar ( std::ostream &  stream,
const Scalar &  e 
)
static

Definition at line 725 of file matrix_impl.hpp.

725  {
726  std::streamsize precision = stream.precision();
727  std::streamsize width = stream.width();
728  std::ios_base::fmtflags flags = stream.flags();
729 
730  stream.precision(stream_precision_);
731  stream.width(stream_width_);
732  if (stream_scientific_) {
733  stream.setf(std::ios::scientific);
734  } else {
735  stream.unsetf(std::ios::scientific);
736  }
737  stream << e;
738  stream << std::flush;
739 
740  stream.precision(precision);
741  stream.width(width);
742  stream.flags(flags);
743  }

◆ print_sparse() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_sparse ( std::ostream &  stream,
bool  truncate = true 
) const

Definition at line 691 of file matrix_impl.hpp.

691  {
692  print_sparse(stream, sparsity(), ptr(), truncate);
693  }

Referenced by casadi::CsparseInterface::nfact().

◆ print_sparse() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_sparse ( std::ostream &  stream,
const Sparsity sp,
const Scalar *  nonzeros,
bool  truncate = true 
)
static

Definition at line 771 of file matrix_impl.hpp.

772  {
773  // Access data structures
774  casadi_int size1 = sp.size1();
775  casadi_int size2 = sp.size2();
776  const casadi_int* colind = sp.colind();
777  const casadi_int* row = sp.row();
778  casadi_int nnz = sp.nnz();
779 
780  // Quick return if all zero sparse
781  if (nnz==0) {
782  stream << "all zero sparse: " << size1 << "-by-" << size2 << std::flush;
783  return;
784  }
785 
786  // Print header
787  stream << "sparse: " << size1 << "-by-" << size2 << ", " << nnz << " nnz";
788 
789  // Get components
790  std::vector<std::string> nz, inter;
791  print_split(nnz, nonzeros, nz, inter);
792 
793  // Print intermediate expressions
794  for (casadi_int i=0; i<inter.size(); ++i)
795  stream << std::endl << " @" << (i+1) << "=" << inter[i] << ",";
796  inter.clear();
797 
798  // No need to truncate if less than 1000 nonzeros
799  const casadi_int max_nnz = 1000;
800  if (truncate && nnz<=max_nnz) truncate=false;
801 
802  // Print nonzeros
803  for (casadi_int cc=0; cc<size2; ++cc) {
804  for (casadi_int el=colind[cc]; el<colind[cc+1]; ++el) {
805  if (truncate && el>=3 && el<nnz-3) {
806  if (el==3) stream << std::endl << " ...";
807  } else {
808  stream << std::endl << " (" << row[el] << ", " << cc << ") -> " << nz.at(el);
810  }
811  }
812  }
813  stream << std::flush;
814  }
const Matrix< Scalar > nz(const K &k) const
Get vector nonzero or slice of nonzeros.
static void check()
Raises an error if an interrupt was captured.
void print_split(std::vector< std::string > &nz, std::vector< std::string > &inter) const
Get strings corresponding to the nonzeros and the interdependencies.

References casadi::InterruptHandler::check(), casadi::Sparsity::colind(), casadi::Sparsity::nnz(), casadi::Sparsity::row(), casadi::Sparsity::size1(), and casadi::Sparsity::size2().

◆ print_split() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_split ( casadi_int  nnz,
const Scalar *  nonzeros,
std::vector< std::string > &  nz,
std::vector< std::string > &  inter 
)
static

Definition at line 746 of file matrix_impl.hpp.

748  {
749  nz.resize(nnz);
750  inter.resize(0);
751 
752  // Temporary
753  std::stringstream ss;
754  ss.precision(stream_precision_);
755  ss.width(stream_width_);
756  if (stream_scientific_) {
757  ss.setf(std::ios::scientific);
758  } else {
759  ss.unsetf(std::ios::scientific);
760  }
761 
762  // Print nonzeros
763  for (casadi_int i=0; i<nz.size(); ++i) {
764  ss.str(std::string());
765  ss << nonzeros[i];
766  nz[i] = ss.str();
767  }
768  }

◆ print_split() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_split ( std::vector< std::string > &  nz,
std::vector< std::string > &  inter 
) const

Definition at line 696 of file matrix_impl.hpp.

697  {
698 
699  print_split(nnz(), ptr(), nz, inter);
700  }

◆ print_vector() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_vector ( std::ostream &  stream,
bool  truncate = true 
) const

Definition at line 636 of file matrix_impl.hpp.

636  {
637  print_vector(stream, sparsity(), ptr(), truncate);
638  }

◆ print_vector() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::print_vector ( std::ostream &  stream,
const Sparsity sp,
const Scalar *  nonzeros,
bool  truncate = true 
)
static

Definition at line 641 of file matrix_impl.hpp.

642  {
643  casadi_assert(sp.is_column(), "Not a vector");
644 
645  // Get components
646  std::vector<std::string> nz, inter;
647  print_split(sp.nnz(), nonzeros, nz, inter);
648 
649  // Print intermediate expressions
650  for (casadi_int i=0; i<inter.size(); ++i)
651  stream << "@" << (i+1) << "=" << inter[i] << ", ";
652  inter.clear();
653 
654  // Access data structures
655  const casadi_int* row = sp.row();
656  casadi_int nnz = sp.nnz();
657  casadi_int size1 = sp.size1();
658 
659  // No need to truncate if less than 1000 entries
660  const casadi_int max_numel = 1000;
661  if (truncate && size1<=max_numel) truncate=false;
662 
663  // Nonzero
664  casadi_int el=0;
665 
666  // Loop over rows
667  stream << "[";
668  for (casadi_int rr=0; rr<size1; ++rr) {
669  // String representation
670  std::string s = el<nnz && rr==row[el] ? nz.at(el++) : "00";
671 
672  // Truncate?
673  if (truncate && rr>=3 && rr<size1-3) {
674  // Do not print
675  if (rr==3) stream << ", ...";
676  } else {
677  // Print
678  if (rr!=0) stream << ", ";
679  stream << s;
680  }
681  }
682  stream << "]" << std::flush;
683  }

References casadi::Sparsity::is_column(), casadi::Sparsity::nnz(), casadi::Sparsity::row(), and casadi::Sparsity::size1().

◆ printme()

template<typename Scalar >
Matrix<Scalar> casadi::Matrix< Scalar >::printme ( const Matrix< Scalar > &  y) const

◆ project()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::project ( const Matrix< Scalar > &  x,
const Sparsity sp,
bool  intersect = false 
)
static

Functions called by friend functions defined for GenericMatrix

◆ ptr() [1/2]

template<typename Scalar >
Scalar* casadi::Matrix< Scalar >::ptr ( )

◆ ptr() [2/2]

template<typename Scalar >
const Scalar* casadi::Matrix< Scalar >::ptr ( ) const

Get a pointer to the data

◆ pw_const()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::pw_const ( const Matrix< Scalar > &  t,
const Matrix< Scalar > &  tval,
const Matrix< Scalar > &  val 
)
static

Functions called by friend functions defined here

◆ pw_lin()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::pw_lin ( const Matrix< Scalar > &  t,
const Matrix< Scalar > &  tval,
const Matrix< Scalar > &  val 
)
static

Functions called by friend functions defined here

◆ qr()

template<typename Scalar >
static void casadi::Matrix< Scalar >::qr ( const Matrix< Scalar > &  A,
Matrix< Scalar > &  Q,
Matrix< Scalar > &  R 
)
static

Functions called by friend functions defined here

◆ qr_solve()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::qr_solve ( const Matrix< Scalar > &  b,
const Matrix< Scalar > &  v,
const Matrix< Scalar > &  r,
const Matrix< Scalar > &  beta,
const std::vector< casadi_int > &  prinv,
const std::vector< casadi_int > &  pc,
bool  tr = false 
)
static

Functions called by friend functions defined here

◆ qr_sparse()

template<typename Scalar >
static void casadi::Matrix< Scalar >::qr_sparse ( const Matrix< Scalar > &  A,
Matrix< Scalar > &  V,
Matrix< Scalar > &  R,
Matrix< Scalar > &  beta,
std::vector< casadi_int > &  prinv,
std::vector< casadi_int > &  pc,
bool  amd = true 
)
static

Functions called by friend functions defined here

◆ quadratic_coeff()

void casadi::GenericMatrix< Matrix< Scalar > >::quadratic_coeff ( const Matrix< Scalar > &  expr,
const Matrix< Scalar > &  var,
Matrix< Scalar > &  A,
Matrix< Scalar > &  b,
Matrix< Scalar > &  c,
bool  check 
)
staticinherited

Definition at line 237 of file generic_matrix.hpp.

1754  {
1755  casadi_assert(expr.is_scalar(), "'quadratic_coeff' only defined for scalar expressions.");
1756  A = hessian(expr, var);
1757  b = substitute(jacobian(expr, var), var, 0).T();
1758  if (check)
1759  casadi_assert(!depends_on(A, var), "'quadratic_coeff' called on non-quadratic expression.");
1760  c = substitute(expr, var, 0);
1761  }
friend bool depends_on(const Matrix< Scalar > &f, const Matrix< Scalar > &arg)
Check if expression depends on the argument.
friend Matrix< Scalar > hessian(const Matrix< Scalar > &ex, const Matrix< Scalar > &arg, const Dict &opts=Dict())
Hessian and (optionally) gradient.

◆ ramp()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::ramp ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined here

◆ rand() [1/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::rand ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
static

◆ rand() [2/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::rand ( const Sparsity sp)
static

◆ rand() [3/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::rand ( const std::pair< casadi_int, casadi_int > &  rc)
static

◆ rank1()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::rank1 ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  alpha,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
staticinherited

Calculates A + 1/2 * alpha * x*y'

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

◆ rectangle()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::rectangle ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined here

◆ remove()

template<typename Scalar >
void casadi::Matrix< Scalar >::remove ( const std::vector< casadi_int > &  rr,
const std::vector< casadi_int > &  cc 
)

Remove/delete rows and/or columns of a matrix

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

◆ repsum()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::repsum ( const Matrix< Scalar > &  x,
casadi_int  n,
casadi_int  m = 1 
)
staticinherited

Definition at line 232 of file generic_matrix.hpp.

1529  {
1530  casadi_assert_dev(x.size1() % n==0);
1531  casadi_assert_dev(x.size2() % m==0);
1532  std::vector< std::vector< MatType> > s =
1533  blocksplit(x, x.size1()/n, x.size2()/m);
1534  MatType sum = 0;
1535  for (casadi_int i=0;i<s.size();++i) {
1536  for (casadi_int j=0;j<s[i].size();++j) {
1537  sum = sum + s[i][j];
1538  }
1539  }
1540  return sum;
1541  }
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)
Returns summation of all elements.

◆ reserve() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::reserve ( casadi_int  nnz)

◆ reserve() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::reserve ( casadi_int  nnz,
casadi_int  ncol 
)

◆ reset_input()

void CASADI_EXPORT casadi::SX::reset_input

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

Definition at line 211 of file sx_instantiator.cpp.

211  {
212  for (auto&& i : nonzeros_) {
213  i.set_temp(0);
214  }
215  }

◆ reshape() [1/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::reshape ( const Matrix< Scalar > &  x,
casadi_int  nrow,
casadi_int  ncol 
)
static

Functions called by friend functions defined for SparsityInterface

◆ reshape() [2/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::reshape ( const Matrix< Scalar > &  x,
const Sparsity sp 
)
static

Functions called by friend functions defined for SparsityInterface

◆ resize()

template<typename Scalar >
void casadi::Matrix< Scalar >::resize ( casadi_int  nrow,
casadi_int  ncol 
)

◆ reverse()

template<typename Scalar >
static std::vector<std::vector<Matrix<Scalar> > > casadi::Matrix< Scalar >::reverse ( const std::vector< Matrix< Scalar > > &  ex,
const std::vector< Matrix< Scalar > > &  arg,
const std::vector< std::vector< Matrix< Scalar > > > &  v,
const Dict opts = Dict() 
)
static

Functions called by friend functions defined here

◆ rng()

template<typename Scalar >
void casadi::Matrix< Scalar >::rng ( casadi_int  seed)
static

Definition at line 60 of file matrix_impl.hpp.

60  {
61  rng_.seed(seed);
62  }

◆ row() [1/2]

const casadi_int* casadi::GenericMatrix< Matrix< Scalar > >::row ( ) const
inlineinherited

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

Definition at line 197 of file generic_matrix.hpp.

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

◆ row() [2/2]

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::row ( casadi_int  el) const
inlineinherited

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

Definition at line 200 of file generic_matrix.hpp.

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

◆ rows()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::rows ( ) const
inlineinherited

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

Definition at line 114 of file generic_matrix.hpp.

114 {return size1();}

◆ scalar()

template<typename Scalar >
const Scalar casadi::Matrix< Scalar >::scalar ( ) const

◆ scalar_matrix()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::scalar_matrix ( casadi_int  op,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
static

◆ separate_linear()

template<typename Scalar >
static void casadi::Matrix< Scalar >::separate_linear ( const Matrix< Scalar > &  expr,
const Matrix< Scalar > &  sym_lin,
const Matrix< Scalar > &  sym_const,
Matrix< Scalar > &  expr_const,
Matrix< Scalar > &  expr_lin,
Matrix< Scalar > &  expr_nonlin 
)
static

Functions called by friend functions defined for SparsityInterface

◆ serialize() [1/3]

template<typename Scalar >
std::string casadi::Matrix< Scalar >::serialize ( ) const

◆ serialize() [2/3]

template<typename Scalar >
void casadi::Matrix< Scalar >::serialize ( SerializingStream s) const

◆ serialize() [3/3]

template<typename Scalar >
void casadi::Matrix< Scalar >::serialize ( std::ostream &  stream) const

◆ set() [1/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::set ( const Matrix< Scalar > &  m,
bool  ind1,
const Matrix< casadi_int > &  rr 
)

Set a submatrix, single argument

Definition at line 304 of file matrix_impl.hpp.

304  {
305  // Scalar
306  if (rr.is_scalar(true) && m.is_dense()) {
307  return set(m, ind1, to_slice(rr, ind1));
308  }
309 
310  // Assert dimensions of assigning matrix
311  if (rr.sparsity() != m.sparsity()) {
312  if (rr.size() == m.size()) {
313  // Remove submatrix to be replaced
314  erase(rr.nonzeros(), ind1);
315 
316  // Find the intersection between rr's and m's sparsity patterns
317  Sparsity sp = rr.sparsity() * m.sparsity();
318 
319  // Project both matrices to this sparsity
320  return set(project(m, sp), ind1, Matrix<casadi_int>::project(rr, sp));
321  } else if (m.is_scalar()) {
322  // m scalar means "set all"
323  if (m.is_dense()) {
324  return set(Matrix<Scalar>(rr.sparsity(), m), ind1, rr);
325  } else {
326  return set(Matrix<Scalar>(rr.size()), ind1, rr);
327  }
328  } else if (rr.size1() == m.size2() && rr.size2() == m.size1()
329  && std::min(m.size1(), m.size2()) == 1) {
330  // m is transposed if necessary
331  return set(m.T(), ind1, rr);
332  } else {
333  // Error otherwise
334  casadi_error("Dimension mismatch. lhs is " + str(rr.size())
335  + ", while rhs is " + str(m.size()));
336  }
337  }
338 
339  // Dimensions of this
340  casadi_int sz1 = size1(), sz2 = size2(), sz = nnz(), nel = numel(), rrsz = rr.nnz();
341 
342  // Quick return if nothing to set
343  if (rrsz==0) return;
344 
345  // Check bounds
346  casadi_assert_in_range(rr.nonzeros(), -nel+ind1, nel+ind1);
347 
348  // Dense mode
349  if (is_dense() && m.is_dense()) {
350  return set_nz(m, ind1, rr);
351  }
352 
353  // Construct new sparsity pattern
354  std::vector<casadi_int> new_row =
355  sparsity().get_row(), new_col=sparsity().get_col(), nz(rr.nonzeros());
356  new_row.reserve(sz+rrsz);
357  new_col.reserve(sz+rrsz);
358  nz.reserve(rrsz);
359  for (std::vector<casadi_int>::iterator i=nz.begin(); i!=nz.end(); ++i) {
360  if (ind1) (*i)--;
361  if (*i<0) *i += nel;
362  new_row.push_back(*i % sz1);
363  new_col.push_back(*i / sz1);
364  }
365  Sparsity sp = Sparsity::triplet(sz1, sz2, new_row, new_col);
366 
367  // If needed, update pattern
368  if (sp != sparsity()) *this = project(*this, sp);
369 
370  // Find the nonzeros corresponding to rr
371  sparsity().get_nz(nz);
372 
373  // Carry out the assignments
374  for (casadi_int i=0; i<nz.size(); ++i) {
375  nonzeros().at(nz[i]) = m->at(i);
376  }
377  }
void set(const Matrix< Scalar > &m, bool ind1, const Slice &rr)
void erase(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
Erase a submatrix (leaving structural zeros in its place)
void set_nz(const Matrix< Scalar > &m, bool ind1, const Slice &k)
std::vector< casadi_int > get_col() const
Get the column for each non-zero entry.
Definition: sparsity.cpp:368
static Sparsity triplet(casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, std::vector< casadi_int > &mapping, bool invert_mapping)
Create a sparsity pattern given the nonzeros in sparse triplet form *.
Definition: sparsity.cpp:1127

References casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::GenericMatrix< MatType >::nnz(), casadi::Matrix< Scalar >::nonzeros(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), casadi::Matrix< Scalar >::sparsity(), casadi::str(), casadi::Matrix< Scalar >::T(), casadi::to_slice(), and casadi::Sparsity::triplet().

◆ set() [2/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::set ( const Matrix< Scalar > &  m,
bool  ind1,
const Matrix< casadi_int > &  rr,
const Matrix< casadi_int > &  cc 
)

Set a submatrix, two arguments

Definition at line 218 of file matrix_impl.hpp.

219  {
220  // Scalar
221  if (rr.is_scalar(true) && cc.is_scalar(true) && m.is_dense()) {
222  return set(m, ind1, to_slice(rr, ind1), to_slice(cc, ind1));
223  }
224 
225  // Row vector rr (e.g. in MATLAB) is transposed to column vector
226  if (rr.size1()==1 && rr.size2()>1) {
227  return set(m, ind1, rr.T(), cc);
228  }
229 
230  // Row vector cc (e.g. in MATLAB) is transposed to column vector
231  if (cc.size1()==1 && cc.size2()>1) {
232  return set(m, ind1, rr, cc.T());
233  }
234 
235  // Make sure rr and cc are dense vectors
236  casadi_assert(rr.is_dense() && rr.is_column(),
237  "Matrix::set: First index not dense vector");
238  casadi_assert(cc.is_dense() && cc.is_column(),
239  "Matrix::set: Second index not dense vector");
240 
241  // Assert dimensions of assigning matrix
242  if (rr.size1() != m.size1() || cc.size1() != m.size2()) {
243  if (m.is_scalar()) {
244  // m scalar means "set all"
245  return set(repmat(m, rr.size1(), cc.size1()), ind1, rr, cc);
246  } else if (rr.size1() == m.size2() && cc.size1() == m.size1()
247  && std::min(m.size1(), m.size2()) == 1) {
248  // m is transposed if necessary
249  return set(m.T(), ind1, rr, cc);
250  } else {
251  // Error otherwise
252  casadi_error("Dimension mismatch. lhs is " + str(rr.size1()) + "-by-"
253  + str(cc.size1()) + ", while rhs is " + str(m.size()));
254  }
255  }
256 
257  // Dimensions
258  casadi_int sz1 = size1(), sz2 = size2();
259 
260  // Report out-of-bounds
261  casadi_assert_in_range(rr.nonzeros(), -sz1+ind1, sz1+ind1);
262  casadi_assert_in_range(cc.nonzeros(), -sz2+ind1, sz2+ind1);
263 
264  // If we are assigning with something sparse, first remove existing entries
265  if (!m.is_dense()) {
266  erase(rr.nonzeros(), cc.nonzeros(), ind1);
267  }
268 
269  // Collect all assignments
270  IM el = IM::zeros(m.sparsity());
271  for (casadi_int j=0; j<el.size2(); ++j) { // Loop over columns of m
272  casadi_int this_j = cc->at(j) - ind1; // Corresponding column in this
273  if (this_j<0) this_j += sz2;
274  for (casadi_int k=el.colind(j); k<el.colind(j+1); ++k) { // Loop over rows of m
275  casadi_int i = m.row(k);
276  casadi_int this_i = rr->at(i) - ind1; // Corresponding row in this
277  if (this_i<0) this_i += sz1;
278  el->at(k) = this_i + this_j*sz1;
279  }
280  }
281  return set(m, false, el);
282  }
Matrix< Scalar > T() const
Transpose the matrix.
static MatType repmat(const MatType &x, casadi_int n, casadi_int m=1)
Matrix< casadi_int > IM
Definition: im_fwd.hpp:31

References casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), and casadi::to_slice().

◆ set() [3/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::set ( const Matrix< Scalar > &  m,
bool  ind1,
const Matrix< casadi_int > &  rr,
const Slice cc 
)

Set a submatrix, two arguments

Definition at line 211 of file matrix_impl.hpp.

212  {
213  // Fall back on (IM, IM)
214  set(m, ind1, rr, cc.all(size2(), ind1));
215  }

References casadi::Slice::all().

◆ set() [4/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::set ( const Matrix< Scalar > &  m,
bool  ind1,
const Slice rr 
)

Set a submatrix, single argument

Definition at line 285 of file matrix_impl.hpp.

285  {
286  // Scalar
287  if (rr.is_scalar(numel()) && m.is_dense()) {
288  casadi_int r = rr.scalar(numel());
289  casadi_int oldsize = sparsity_.nnz();
290  casadi_int ind = sparsity_.add_nz(r % size1(), r / size1());
291  if (oldsize == sparsity_.nnz()) {
292  nonzeros_.at(ind) = m.scalar();
293  } else {
294  nonzeros_.insert(nonzeros_.begin()+ind, m.scalar());
295  }
296  return;
297  }
298 
299  // Fall back on IM
300  set(m, ind1, rr.all(numel(), ind1));
301  }
casadi_int add_nz(casadi_int rr, casadi_int cc)
Get the index of a non-zero element.
Definition: sparsity.cpp:194

References casadi::Slice::all(), casadi::GenericMatrix< MatType >::is_dense(), casadi::Slice::is_scalar(), casadi::Matrix< Scalar >::scalar(), and casadi::Slice::scalar().

Referenced by casadi::override_num().

◆ set() [5/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::set ( const Matrix< Scalar > &  m,
bool  ind1,
const Slice rr,
const Matrix< casadi_int > &  cc 
)

Set a submatrix, two arguments

Definition at line 204 of file matrix_impl.hpp.

205  {
206  // Fall back on (IM, IM)
207  set(m, ind1, rr.all(size1(), ind1), cc);
208  }

References casadi::Slice::all().

◆ set() [6/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::set ( const Matrix< Scalar > &  m,
bool  ind1,
const Slice rr,
const Slice cc 
)

Set a submatrix, two arguments

Definition at line 185 of file matrix_impl.hpp.

186  {
187  // Both are scalar
188  if (rr.is_scalar(size1()) && cc.is_scalar(size2()) && m.is_dense()) {
189  casadi_int oldsize = sparsity_.nnz();
190  casadi_int ind = sparsity_.add_nz(rr.scalar(size1()), cc.scalar(size2()));
191  if (oldsize == sparsity_.nnz()) {
192  nonzeros_.at(ind) = m.scalar();
193  } else {
194  nonzeros_.insert(nonzeros_.begin()+ind, m.scalar());
195  }
196  return;
197  }
198 
199  // Fall back on (IM, IM)
200  set(m, ind1, rr.all(size1(), ind1), cc.all(size2(), ind1));
201  }

References casadi::Slice::all(), casadi::GenericMatrix< MatType >::is_dense(), casadi::Slice::is_scalar(), casadi::Matrix< Scalar >::scalar(), and casadi::Slice::scalar().

◆ set() [7/7]

template<typename Scalar >
void casadi::Matrix< Scalar >::set ( const Matrix< Scalar > &  m,
bool  ind1,
const Sparsity sp 
)

Set a submatrix, single argument

Definition at line 380 of file matrix_impl.hpp.

380  {
381  casadi_assert(size()==sp.size(),
382  "set(Sparsity sp): shape mismatch. This matrix has shape "
383  + str(size()) + ", but supplied sparsity index has shape "
384  + str(sp.size()) + ".");
385  std::vector<casadi_int> ii = sp.find();
386  if (m.is_scalar()) {
387  (*this)(ii) = densify(m);
388  } else {
389  (*this)(ii) = densify(m(ii));
390  }
391  }

References casadi::Sparsity::find(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::Sparsity::size(), and casadi::str().

◆ set_max_depth()

void CASADI_EXPORT casadi::SX::set_max_depth ( casadi_int  eq_depth = 1)
static

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

Definition at line 42 of file sx_instantiator.cpp.

42  {
43  SXNode::eq_depth_ = eq_depth;
44  }

References casadi::SXNode::eq_depth_.

◆ set_nz() [1/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::set_nz ( const Matrix< Scalar > &  m,
bool  ind1,
const Matrix< casadi_int > &  k 
)

Set a set of nonzeros

Definition at line 447 of file matrix_impl.hpp.

447  {
448  // Scalar
449  if (kk.is_scalar(true)) {
450  return set_nz(m, ind1, to_slice(kk, ind1));
451  }
452 
453  // Assert dimensions of assigning matrix
454  if (kk.sparsity() != m.sparsity()) {
455  if (m.is_scalar()) {
456  // m scalar means "set all"
457  if (!m.is_dense()) return; // Nothing to set
458  return set_nz(Matrix<Scalar>(kk.sparsity(), m), ind1, kk);
459  } else if (kk.size() == m.size()) {
460  // Project sparsity if needed
461  return set_nz(project(m, kk.sparsity()), ind1, kk);
462  } else if (kk.size1() == m.size2() && kk.size2() == m.size1()
463  && std::min(m.size1(), m.size2()) == 1) {
464  // m is transposed if necessary
465  return set_nz(m.T(), ind1, kk);
466  } else {
467  // Error otherwise
468  casadi_error("Dimension mismatch. lhs is " + str(kk.size())
469  + ", while rhs is " + str(m.size()));
470  }
471  }
472 
473  // Get nonzeros
474  const std::vector<casadi_int>& k = kk.nonzeros();
475  casadi_int sz = nnz();
476 
477  // Check bounds
478  casadi_assert_in_range(k, -sz+ind1, sz+ind1);
479 
480  // Set nonzeros, ignoring negative indices
481  for (casadi_int el=0; el<k.size(); ++el) {
482  casadi_assert(!(ind1 && k[el]<=0),
483  "Matlab is 1-based, but requested index " + str(k[el])
484  + ". Note that negative slices are disabled in the Matlab interface. "
485  "Possibly you may want to use 'end'.");
486  casadi_int k_el = k[el]-ind1;
487  nonzeros().at(k_el>=0 ? k_el : k_el+sz) = m->at(el);
488  }
489  }

References casadi::GenericMatrix< MatType >::is_dense(), casadi::GenericMatrix< MatType >::is_scalar(), casadi::Matrix< Scalar >::nonzeros(), casadi::GenericMatrix< MatType >::size(), casadi::GenericMatrix< MatType >::size1(), casadi::GenericMatrix< MatType >::size2(), casadi::Matrix< Scalar >::sparsity(), casadi::str(), casadi::Matrix< Scalar >::T(), and casadi::to_slice().

◆ set_nz() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::set_nz ( const Matrix< Scalar > &  m,
bool  ind1,
const Slice k 
)

Set a set of nonzeros

Definition at line 435 of file matrix_impl.hpp.

435  {
436  // Scalar
437  if (kk.is_scalar(nnz())) {
438  nonzeros().at(kk.scalar(nnz())) = m.scalar();
439  return;
440  }
441 
442  // Fallback on IM
443  set_nz(m, ind1, kk.all(nnz(), ind1));
444  }

References casadi::Slice::all(), casadi::Slice::is_scalar(), casadi::Matrix< Scalar >::scalar(), and casadi::Slice::scalar().

◆ set_precision()

template<typename Scalar >
void casadi::Matrix< Scalar >::set_precision ( casadi_int  precision)
static

Definition at line 39 of file matrix_impl.hpp.

39 { stream_precision_ = precision; }

◆ set_scientific()

template<typename Scalar >
void casadi::Matrix< Scalar >::set_scientific ( bool  scientific)
static

Definition at line 45 of file matrix_impl.hpp.

45 { stream_scientific_ = scientific; }

◆ set_width()

template<typename Scalar >
void casadi::Matrix< Scalar >::set_width ( casadi_int  width)
static

Definition at line 42 of file matrix_impl.hpp.

42 { stream_width_ = width; }

◆ shared()

template<typename Scalar >
static void casadi::Matrix< Scalar >::shared ( std::vector< Matrix< Scalar > > &  ex,
std::vector< Matrix< Scalar > > &  v,
std::vector< Matrix< Scalar > > &  vdef,
const std::string &  v_prefix,
const std::string &  v_suffix 
)
static

Functions called by friend functions defined for GenericMatrix

◆ simplify()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::simplify ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ size() [1/2]

std::pair< casadi_int, casadi_int > casadi::GenericMatrix< Matrix< Scalar > >::size
inherited

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

Definition at line 136 of file generic_matrix.hpp.

1333  {
1334  return sparsity().size();
1335  }
std::pair< casadi_int, casadi_int > size() const
Get the shape.
Definition: sparsity.cpp:152

◆ size() [2/2]

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::size ( casadi_int  axis) const
inherited

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

Definition at line 141 of file generic_matrix.hpp.

1338  {
1339  return sparsity().size(axis);
1340  }

◆ size1()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::size1
inherited

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

Definition at line 109 of file generic_matrix.hpp.

1323  {
1324  return sparsity().size1();
1325  }
casadi_int size1() const
Get the number of rows.
Definition: sparsity.cpp:124

◆ size2()

casadi_int casadi::GenericMatrix< Matrix< Scalar > >::size2
inherited

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

Definition at line 119 of file generic_matrix.hpp.

1328  {
1329  return sparsity().size2();
1330  }
casadi_int size2() const
Get the number of columns.
Definition: sparsity.cpp:128

◆ skew()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::skew ( const Matrix< Scalar > &  a)
staticinherited

Definition at line 228 of file generic_matrix.hpp.

1500  {
1501  casadi_assert(a.is_vector() && (a.size1()==3 || a.size2()==3),
1502  "skew(a): Expecting 3-vector, got " + a.dim() + ".");
1503 
1504  MatType x = a(0);
1505  MatType y = a(1);
1506  MatType z = a(2);
1507  return blockcat(std::vector< std::vector<MatType> >({{0, -z, y}, {z, 0, -x}, {-y, x, 0}}));
1508  }
friend MatType blockcat(const std::vector< std::vector< MatType > > &v)
Construct a matrix from a list of list of blocks.

◆ soc()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::soc ( const Matrix< Scalar > &  x,
const Matrix< Scalar > &  y 
)
staticinherited

Functions called by friend functions defined here

◆ solve() [1/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::solve ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  b 
)
static

Functions called by friend functions defined for GenericMatrix

Referenced by casadi::SymbolicQr::init().

◆ solve() [2/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::solve ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  b,
const std::string &  lsolver,
const Dict opts 
)
static

Functions called by friend functions defined for GenericMatrix

◆ sparsify()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::sparsify ( const Matrix< Scalar > &  x,
double  tol = 0 
)
static

Functions called by friend functions defined here

◆ sparsity()

template<typename Scalar >
const Sparsity& casadi::Matrix< Scalar >::sparsity ( ) const

◆ sparsity_cast()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::sparsity_cast ( const Matrix< Scalar > &  x,
const Sparsity sp 
)
static

Functions called by friend functions defined for SparsityInterface

◆ sprank()

static casadi_int casadi::GenericMatrix< Matrix< Scalar > >::sprank ( const Matrix< Scalar > &  x)
inlinestaticinherited

Definition at line 215 of file generic_matrix.hpp.

215 { return Sparsity::sprank(x.sparsity());}

◆ substitute() [1/2]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::substitute ( const Matrix< Scalar > &  ex,
const Matrix< Scalar > &  v,
const Matrix< Scalar > &  vdef 
)
static

Functions called by friend functions defined for GenericMatrix

◆ substitute() [2/2]

template<typename Scalar >
static std::vector<Matrix<Scalar> > casadi::Matrix< Scalar >::substitute ( const std::vector< Matrix< Scalar > > &  ex,
const std::vector< Matrix< Scalar > > &  v,
const std::vector< Matrix< Scalar > > &  vdef 
)
static

Functions called by friend functions defined for GenericMatrix

◆ substitute_inplace()

template<typename Scalar >
static void casadi::Matrix< Scalar >::substitute_inplace ( const std::vector< Matrix< Scalar > > &  v,
std::vector< Matrix< Scalar > > &  vdef,
std::vector< Matrix< Scalar > > &  ex,
bool  revers 
)
static

Functions called by friend functions defined for GenericMatrix

◆ sum1()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::sum1 ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ sum2()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::sum2 ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ sumsqr()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::sumsqr ( const Matrix< Scalar > &  x)
inlinestaticinherited

Definition at line 225 of file generic_matrix.hpp.

225 { return dot(x, x);}
friend Matrix< Scalar > dot(const Matrix< Scalar > &x, const Matrix< Scalar > &y)
Inner product of two matrices.

◆ sym() [1/7]

static std::vector<Matrix< Scalar > > casadi::GenericMatrix< Matrix< Scalar > >::sym ( const std::string &  name,
casadi_int  nrow,
casadi_int  ncol,
casadi_int  p 
)
inlinestaticinherited

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

Definition at line 1234 of file generic_matrix.hpp.

1235  {
1236  return sym(name, Sparsity::dense(nrow, ncol), p);
1237  }
static Matrix< Scalar > sym(const std::string &name, casadi_int nrow=1, casadi_int ncol=1)
Create an nrow-by-ncol symbolic primitive.

◆ sym() [2/7]

static std::vector<std::vector<Matrix< Scalar > > > casadi::GenericMatrix< Matrix< Scalar > >::sym ( const std::string &  name,
casadi_int  nrow,
casadi_int  ncol,
casadi_int  p,
casadi_int  r 
)
inlinestaticinherited

with nrow-by-ncol symbolic primitives

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

Definition at line 1253 of file generic_matrix.hpp.

1253  {
1254  return sym(name, Sparsity::dense(nrow, ncol), p, r);
1255  }

◆ sym() [3/7]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::sym ( const std::string &  name,
casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestaticinherited

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

Examples
SX/SXaddition.cc, and SX/ssym.py.

Definition at line 1206 of file generic_matrix.hpp.

1206  {
1207  return sym(name, Sparsity::dense(nrow, ncol));
1208  }

◆ sym() [4/7]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::sym ( const std::string &  name,
const Sparsity sp 
)
inlinestaticinherited

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

Definition at line 1220 of file generic_matrix.hpp.

1220  {
1221  return MatType::_sym(name, sp);
1222  }

◆ sym() [5/7]

std::vector< Matrix< Scalar > > casadi::GenericMatrix< Matrix< Scalar > >::sym ( const std::string &  name,
const Sparsity sp,
casadi_int  p 
)
staticinherited

with symbolic primitives of given sparsity

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

Definition at line 1229 of file generic_matrix.hpp.

1356  {
1357  std::vector<MatType> ret(p);
1358  std::stringstream ss;
1359  for (casadi_int k=0; k<p; ++k) {
1360  ss.str("");
1361  ss << name << k;
1362  ret[k] = sym(ss.str(), sp);
1363  }
1364  return ret;
1365  }

◆ sym() [6/7]

std::vector< std::vector< Matrix< Scalar > > > casadi::GenericMatrix< Matrix< Scalar > >::sym ( const std::string &  name,
const Sparsity sp,
casadi_int  p,
casadi_int  r 
)
staticinherited

symbolic primitives with given sparsity

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

Definition at line 1245 of file generic_matrix.hpp.

1370  {
1371  std::vector<std::vector<MatType> > ret(r);
1372  for (casadi_int k=0; k<r; ++k) {
1373  std::stringstream ss;
1374  ss << name << "_" << k;
1375  ret[k] = sym(ss.str(), sp, p);
1376  }
1377  return ret;
1378  }

◆ sym() [7/7]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::sym ( const std::string &  name,
const std::pair< casadi_int, casadi_int > &  rc 
)
inlinestaticinherited

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

Definition at line 1213 of file generic_matrix.hpp.

1213  {
1214  return sym(name, rc.first, rc.second);
1215  }

◆ symvar()

template<typename Scalar >
static std::vector<Matrix<Scalar> > casadi::Matrix< Scalar >::symvar ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ T()

template<typename Scalar >
Matrix<Scalar> casadi::Matrix< Scalar >::T ( ) const

◆ tangent()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::tangent ( const Matrix< Scalar > &  ex,
const Matrix< Scalar > &  arg,
const Dict opts = Dict() 
)
staticinherited

Functions called by friend functions defined here

◆ taylor()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::taylor ( const Matrix< Scalar > &  ex,
const Matrix< Scalar > &  x,
const Matrix< Scalar > &  a,
casadi_int  order 
)
static

Functions called by friend functions defined here

◆ to_file() [1/2]

template<typename Scalar >
static void casadi::Matrix< Scalar >::to_file ( const std::string &  filename,
const Sparsity sp,
const Scalar *  nonzeros,
const std::string &  format = "" 
)
static

◆ to_file() [2/2]

template<typename Scalar >
void casadi::Matrix< Scalar >::to_file ( const std::string &  filename,
const std::string &  format = "" 
) const

Export numerical matrix to file

Supported formats:

*   - .mtx   Matrix Market (sparse)
*   - .txt   Ascii full precision representation (sparse)
*            Whitespace separated, aligned.
*            Comments with # % or /
*            Uses C locale
*            Structural zeros represented by 00
*            Does not scale well for large sparse matrices
* 

◆ trace()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::trace ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined for GenericMatrix

◆ triangle()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::triangle ( const Matrix< Scalar > &  x)
static

Functions called by friend functions defined here

◆ tril()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::tril ( const Matrix< Scalar > &  x,
bool  includeDiagonal = true 
)
inlinestaticinherited

Definition at line 219 of file generic_matrix.hpp.

219  {
220  return project(x, Sparsity::tril(x.sparsity(), includeDiagonal));
221  }
friend Matrix< Scalar > project(const Matrix< Scalar > &A, const Sparsity &sp, bool intersect=false)
Create a new matrix with a given sparsity pattern but with the.

◆ tril2symm()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::tril2symm ( const Matrix< Scalar > &  x)
staticinherited

Definition at line 230 of file generic_matrix.hpp.

1520  {
1521  casadi_assert(x.is_square(),
1522  "Shape error in tril2symm. Expecting square shape but got " + x.dim());
1523  casadi_assert(x.nnz_upper()-x.nnz_diag()==0,
1524  "Sparsity error in tril2symm. Found above-diagonal entries in argument: " + x.dim());
1525  return x + x.T() - diag(diag(x));
1526  }
friend Matrix< Scalar > diag(const Matrix< Scalar > &A)
Get the diagonal of a matrix or construct a diagonal.

◆ triplet() [1/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::triplet ( const std::vector< casadi_int > &  row,
const std::vector< casadi_int > &  col,
const Matrix< Scalar > &  d 
)
static

Default matrix size is max(col) x max(row)

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

◆ triplet() [2/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::triplet ( const std::vector< casadi_int > &  row,
const std::vector< casadi_int > &  col,
const Matrix< Scalar > &  d,
casadi_int  nrow,
casadi_int  ncol 
)
static

Default matrix size is max(col) x max(row)

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

◆ triplet() [3/3]

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::triplet ( const std::vector< casadi_int > &  row,
const std::vector< casadi_int > &  col,
const Matrix< Scalar > &  d,
const std::pair< casadi_int, casadi_int > &  rc 
)
static

Default matrix size is max(col) x max(row)

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

◆ triu()

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::triu ( const Matrix< Scalar > &  x,
bool  includeDiagonal = true 
)
inlinestaticinherited

Definition at line 222 of file generic_matrix.hpp.

222  {
223  return project(x, Sparsity::triu(x.sparsity(), includeDiagonal));
224  }

◆ triu2symm()

Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::triu2symm ( const Matrix< Scalar > &  x)
staticinherited

Definition at line 231 of file generic_matrix.hpp.

1544  {
1545  casadi_assert(x.is_square(),
1546  "Shape error in triu2symm. Expecting square shape but got " + x.dim());
1547  casadi_assert(x.nnz_lower()-x.nnz_diag()==0,
1548  "Sparsity error in triu2symm. Found below-diagonal entries in argument: " + x.dim());
1549  return x + x.T() - diag(diag(x));
1550  }

◆ type_name()

template<typename Scalar >
std::string casadi::Matrix< Scalar >::type_name
static

Definition at line 606 of file matrix_impl.hpp.

606 { return matrixName<Scalar>(); }

◆ unary()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::unary ( casadi_int  op,
const Matrix< Scalar > &  x 
)
static

◆ unite()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::unite ( const Matrix< Scalar > &  A,
const Matrix< Scalar > &  B 
)
static

Functions called by friend functions defined for GenericMatrix

◆ vertcat()

template<typename Scalar >
static Matrix<Scalar> casadi::Matrix< Scalar >::vertcat ( const std::vector< Matrix< Scalar > > &  v)
static

Functions called by friend functions defined for SparsityInterface

◆ vertsplit()

template<typename Scalar >
static std::vector< Matrix<Scalar> > casadi::Matrix< Scalar >::vertsplit ( const Matrix< Scalar > &  x,
const std::vector< casadi_int > &  offset 
)
static

Functions called by friend functions defined for SparsityInterface

◆ which_depends()

template<typename Scalar >
static std::vector<bool> casadi::Matrix< Scalar >::which_depends ( const Matrix< Scalar > &  expr,
const Matrix< Scalar > &  var,
casadi_int  order = 1,
bool  tr = false 
)
static

Functions called by friend functions defined here

◆ which_function()

Function CASADI_EXPORT casadi::SX::which_function

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

Definition at line 170 of file sx_instantiator.cpp.

170  {
171  return scalar().which_function();
172  }

References casadi::Matrix< Scalar >::scalar().

◆ which_output()

casadi_int CASADI_EXPORT casadi::SX::which_output

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

Definition at line 175 of file sx_instantiator.cpp.

175  {
176  return scalar().which_output();
177  }

References casadi::Matrix< Scalar >::scalar().

◆ zeros() [1/3]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::zeros ( casadi_int  nrow = 1,
casadi_int  ncol = 1 
)
inlinestaticinherited

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

Definition at line 1262 of file generic_matrix.hpp.

1262  {
1263  return zeros(Sparsity::dense(nrow, ncol));
1264  }

◆ zeros() [2/3]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::zeros ( const Sparsity sp)
inlinestaticinherited

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

Definition at line 1265 of file generic_matrix.hpp.

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

◆ zeros() [3/3]

static Matrix< Scalar > casadi::GenericMatrix< Matrix< Scalar > >::zeros ( const std::pair< casadi_int, casadi_int > &  rc)
inlinestaticinherited

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

Definition at line 1266 of file generic_matrix.hpp.

1266  {
1267  return zeros(rc.first, rc.second);
1268  }

Friends And Related Function Documentation

◆ get_ptr [1/2]

template<typename Scalar >
const Scalar* get_ptr ( const Matrix< Scalar > &  v)
friend

Get a pointer to the data

Definition at line 1001 of file matrix_decl.hpp.

1001 { return v.ptr(); }

◆ get_ptr [2/2]

template<typename Scalar >
Scalar* get_ptr ( Matrix< Scalar > &  v)
friend

Get a pointer to the data

Definition at line 1000 of file matrix_decl.hpp.

1000 { return v.ptr(); }

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