matrix_decl.hpp
1 /*
2  * This file is part of CasADi.
3  *
4  * CasADi -- A symbolic framework for dynamic optimization.
5  * Copyright (C) 2010-2023 Joel Andersson, Joris Gillis, Moritz Diehl,
6  * KU Leuven. All rights reserved.
7  * Copyright (C) 2011-2014 Greg Horn
8  *
9  * CasADi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 3 of the License, or (at your option) any later version.
13  *
14  * CasADi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with CasADi; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 
26 #ifndef CASADI_MATRIX_DECL_HPP
27 #define CASADI_MATRIX_DECL_HPP
28 
29 #include "matrix_fwd.hpp"
30 #include "exception.hpp"
31 #include "casadi_limits.hpp"
32 #include "runtime/casadi_runtime.hpp"
33 #include "generic_matrix.hpp"
34 #include "generic_expression.hpp"
35 #include "printable.hpp"
36 
37 #include <random>
38 #include <typeinfo>
39 #include <vector>
40 #include <initializer_list>
41 #ifdef CASADI_WITH_THREAD
42 #ifdef CASADI_WITH_THREAD_MINGW
43 #include <mingw.mutex.h>
44 #else // CASADI_WITH_THREAD_MINGW
45 #include <mutex>
46 #endif // CASADI_WITH_THREAD_MINGW
47 #endif //CASADI_WITH_THREAD
48 
49 namespace casadi {
50 
56  struct CASADI_EXPORT MatrixCommon {};
57 
60 
63  template <typename Scalar> inline std::string matrixName()
64  { return std::string("Matrix<") + typeid(Scalar).name() + std::string(">");}
65  template<> inline std::string matrixName<double>() { return "DM"; }
66  template<> inline std::string matrixName<casadi_int>() { return "IM"; }
69 
142  template<typename Scalar>
143  class CASADI_EXPORT Matrix :
144  public MatrixCommon,
145  public SWIG_IF_ELSE(GenericExpressionCommon, GenericExpression<Matrix<Scalar> >),
146  public GenericMatrix<Matrix<Scalar> >,
147  public SWIG_IF_ELSE(PrintableCommon, Printable<Matrix<Scalar> >) {
148  public:
149 
174  Matrix();
175 
177  Matrix(const Matrix<Scalar>& m);
178 
179 #ifndef SWIG
181  Matrix<Scalar>& operator=(const Matrix<Scalar>& m);
182 #endif // SWIG
183 
233  Matrix(casadi_int nrow, casadi_int ncol);
234 
235 #ifndef SWIG
239  explicit Matrix(const std::pair<casadi_int, casadi_int>& rc);
240 
244  std::vector<Scalar>* operator->();
245 
249  const std::vector<Scalar>* operator->() const;
250 #endif // SWIG
251 
283  explicit Matrix(const Sparsity& sp);
284 
348  Matrix(const Sparsity& sp, const Matrix<Scalar>& d);
349 
351  Matrix(double val);
352 
353 #if !(defined(SWIG) && defined(SWIGMATLAB))
387  explicit Matrix(const std::vector< std::vector<double> >& m);
388 
408  template<typename A>
409  Matrix(const std::vector<A>& x) : sparsity_(Sparsity::dense(x.size(), 1)),
410  nonzeros_(std::vector<Scalar>(x.size())) {
411  auto x_it = x.begin();
412  for (auto&& d : nonzeros_) d = static_cast<Scalar>(*x_it++);
413  }
414 #endif
415 
458  template<typename A>
459  Matrix(const Matrix<A>& x) : sparsity_(x.sparsity()), nonzeros_(std::vector<Scalar>(x.nnz())) {
460  auto x_it = x->begin();
461  for (auto&& d : nonzeros_) d = static_cast<Scalar>(*x_it++);
462  }
463 
464 #ifndef SWIG
466  Matrix(const std::vector<Scalar>& x);
467 
469  Matrix(std::initializer_list<Scalar> x) : Matrix<Scalar>(std::vector<Scalar>(x)) {}
470 
472  const Scalar scalar() const;
473 
475  typedef Scalar ScalarType;
476 
478  typedef GenericMatrix<Matrix<Scalar> > B;
479 
481  using B::nnz;
482  using B::nnz_lower;
483  using B::nnz_upper;
484  using B::numel;
485  using B::size1;
486  using B::size2;
487  using B::size;
488  using B::is_empty;
489  using B::is_scalar;
490  using B::is_dense;
491  using B::is_vector;
492  using B::is_row;
493  using B::is_column;
494  using B::is_tril;
495  using B::is_triu;
496  using B::colind;
497  using B::row;
498  using B::dim;
499  using B::sym;
500  using B::zeros;
501  using B::ones;
502  using B::nz;
503  using B::operator();
504  using B::horzsplit;
505  using B::vertsplit;
506  using B::diagsplit;
507  using B::mtimes;
508 #endif // SWIG
509 
542  bool has_nz(casadi_int rr, casadi_int cc) const;
543 
576  bool __nonzero__() const;
577 
579 
663  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Slice& rr) const;
664  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& rr) const;
665  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Sparsity& sp) const;
667 
669 
755  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1,
756  const Slice& rr, const Slice& cc) const;
757  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1,
758  const Slice& rr, const Matrix<casadi_int>& cc) const;
759  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1,
760  const Matrix<casadi_int>& rr, const Slice& cc) const;
761  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1,
762  const Matrix<casadi_int>& rr, const Matrix<casadi_int>& cc) const;
764 
766 
848  void set(const Matrix<Scalar>& m, bool ind1, const Slice& rr);
849  void set(const Matrix<Scalar>& m, bool ind1, const Matrix<casadi_int>& rr);
850  void set(const Matrix<Scalar>& m, bool ind1, const Sparsity& sp);
852 
854 
944  void set(const Matrix<Scalar>& m, bool ind1, const Slice& rr, const Slice& cc);
945  void set(const Matrix<Scalar>& m, bool ind1, const Slice& rr, const Matrix<casadi_int>& cc);
946  void set(const Matrix<Scalar>& m, bool ind1, const Matrix<casadi_int>& rr, const Slice& cc);
947  void set(const Matrix<Scalar>& m, bool ind1, const Matrix<casadi_int>& rr,
948  const Matrix<casadi_int>& cc);
950 
952 
1020  void get_nz(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Slice& k) const;
1021  void get_nz(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& k) const;
1023 
1025 
1087  void set_nz(const Matrix<Scalar>& m, bool ind1, const Slice& k);
1088  void set_nz(const Matrix<Scalar>& m, bool ind1, const Matrix<casadi_int>& k);
1090 
1093 
1096 
1099  static Matrix<Scalar> binary(casadi_int op, const Matrix<Scalar> &x, const Matrix<Scalar> &y);
1100  static Matrix<Scalar> unary(casadi_int op, const Matrix<Scalar> &x);
1101  static Matrix<Scalar> scalar_matrix(casadi_int op,
1102  const Matrix<Scalar> &x, const Matrix<Scalar> &y);
1103  static Matrix<Scalar> matrix_scalar(casadi_int op,
1104  const Matrix<Scalar> &x, const Matrix<Scalar> &y);
1105  static Matrix<Scalar> matrix_matrix(casadi_int op,
1106  const Matrix<Scalar> &x, const Matrix<Scalar> &y);
1107  static std::vector< Matrix<Scalar> > call(const Function& f,
1108  const std::vector< Matrix<Scalar> > &x);
1109  static std::vector< Scalar > call(const Function& f, const std::vector< Scalar > &x);
1112 
1113 #ifndef SWIG
1117  static bool is_equal(const Matrix<Scalar> &x, const Matrix<Scalar> &y, casadi_int depth=0);
1118  static Matrix<Scalar> mmin(const Matrix<Scalar> &x);
1119  static Matrix<Scalar> mmax(const Matrix<Scalar> &x);
1121 
1124  static Matrix<Scalar> simplify(const Matrix<Scalar> &x);
1125  static Matrix<Scalar> transform(const Matrix<Scalar> &x, const Dict& opts = Dict());
1126  static Matrix<Scalar> transform(const Matrix<Scalar> &x,
1127  const std::vector<std::vector<GenericType> >& passes, const Dict& opts = Dict());
1128  static std::vector<Matrix<Scalar> > transform(const std::vector<Matrix<Scalar> >& x,
1129  const Dict& opts = Dict());
1130  static std::vector<Matrix<Scalar> > transform(const std::vector<Matrix<Scalar> >& x,
1131  const std::vector<std::vector<GenericType> >& passes, const Dict& opts = Dict());
1132  static Matrix<Scalar> jacobian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
1133  const Dict& opts = Dict());
1134  static Sparsity jacobian_sparsity(const Matrix<Scalar> &f, const Matrix<Scalar> &x);
1135  static Matrix<Scalar> hessian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
1136  const Dict& opts = Dict());
1137  static Matrix<Scalar> hessian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
1138  Matrix<Scalar>& g, const Dict& opts = Dict());
1139  static Matrix<Scalar>
1140  substitute(const Matrix<Scalar>& ex,
1141  const Matrix<Scalar>& v,
1142  const Matrix<Scalar>& vdef);
1143  static std::vector<Matrix<Scalar> >
1144  substitute(const std::vector<Matrix<Scalar> >& ex,
1145  const std::vector<Matrix<Scalar> >& v,
1146  const std::vector<Matrix<Scalar> >& vdef);
1147  static void substitute_inplace(const std::vector<Matrix<Scalar> >& v,
1148  std::vector<Matrix<Scalar> >& vdef,
1149  std::vector<Matrix<Scalar> >& ex,
1150  bool revers);
1151  static Matrix<Scalar> pinv(const Matrix<Scalar> &x);
1152  static Matrix<Scalar> pinv(const Matrix<Scalar> &A,
1153  const std::string& lsolver, const Dict& opts);
1154  static Matrix<Scalar> expm_const(const Matrix<Scalar> &A, const Matrix<Scalar> &t);
1155  static Matrix<Scalar> expm(const Matrix<Scalar> &A);
1156  static Matrix<Scalar> solve(const Matrix<Scalar> &A, const Matrix<Scalar>& b);
1157  static Matrix<Scalar> solve(const Matrix<Scalar> &A, const Matrix<Scalar>& b,
1158  const std::string& lsolver, const Dict& opts);
1159  static Matrix<Scalar> inv(const Matrix<Scalar> &A);
1160  static Matrix<Scalar> inv(const Matrix<Scalar> &A,
1161  const std::string& lsolver, const Dict& opts);
1162 
1163  static casadi_int n_nodes(const Matrix<Scalar> &x);
1164  static std::string print_operator(const Matrix<Scalar> &x,
1165  const std::vector<std::string>& args);
1166  static void extract(std::vector<Matrix<Scalar>>& ex, std::vector<Matrix<Scalar>>& v,
1167  std::vector<Matrix<Scalar>>& vdef, const Dict& opts = Dict());
1168  static void shared(std::vector<Matrix<Scalar> >& ex,
1169  std::vector<Matrix<Scalar> >& v,
1170  std::vector<Matrix<Scalar> >& vdef,
1171  const std::string& v_prefix,
1172  const std::string& v_suffix);
1173  static Matrix<Scalar> _bilin(const Matrix<Scalar>& A,
1174  const Matrix<Scalar>& x,
1175  const Matrix<Scalar>& y);
1176  static Matrix<Scalar> _rank1(const Matrix<Scalar>& A,
1177  const Matrix<Scalar>& alpha,
1178  const Matrix<Scalar>& x,
1179  const Matrix<Scalar>& y);
1180  static Matrix<Scalar> if_else(const Matrix<Scalar> &x,
1181  const Matrix<Scalar> &if_true,
1182  const Matrix<Scalar> &if_false,
1183  bool short_circuit=false);
1184  static Matrix<Scalar> conditional(const Matrix<Scalar> &ind,
1185  const std::vector<Matrix<Scalar> > &x,
1186  const Matrix<Scalar> &x_default,
1187  bool short_circuit=false);
1188  static bool depends_on(const Matrix<Scalar> &x, const Matrix<Scalar> &arg);
1189  static bool contains(const std::vector<Matrix<Scalar> >& v, const Matrix<Scalar> &n);
1190  static bool contains_all(const std::vector<Matrix<Scalar> >& v,
1191  const std::vector<Matrix<Scalar> > &n);
1192  static bool contains_any(const std::vector<Matrix<Scalar> >& v,
1193  const std::vector<Matrix<Scalar> > &n);
1194 
1195  static Matrix<Scalar> mrdivide(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
1196  static Matrix<Scalar> mldivide(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
1197  static std::vector<Matrix<Scalar> > symvar(const Matrix<Scalar> &x);
1198  static Matrix<Scalar> det(const Matrix<Scalar> &x);
1199  static Matrix<Scalar> det(const Matrix<Scalar> &x, const std::string& lsolver,
1200  const Dict& dict=Dict());
1201  static Matrix<Scalar> inv_minor(const Matrix<Scalar> &x);
1202  static Matrix<Scalar> trace(const Matrix<Scalar> &x);
1203  static Matrix<Scalar> norm_1(const Matrix<Scalar> &x);
1204  static Matrix<Scalar> norm_2(const Matrix<Scalar> &x);
1205  static Matrix<Scalar> norm_fro(const Matrix<Scalar> &x);
1206  static Matrix<Scalar> norm_inf(const Matrix<Scalar> &x);
1207  static Matrix<Scalar> sum2(const Matrix<Scalar> &x);
1208  static Matrix<Scalar> sum1(const Matrix<Scalar> &x);
1209  static Matrix<Scalar> dot(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
1210  static Matrix<Scalar> nullspace(const Matrix<Scalar> &x);
1211  static Matrix<Scalar> diag(const Matrix<Scalar> &x);
1212  static Matrix<Scalar> unite(const Matrix<Scalar> &A, const Matrix<Scalar>& B);
1213  static Matrix<Scalar> project(const Matrix<Scalar> &x,
1214  const Sparsity& sp, bool intersect=false);
1215  static Matrix<Scalar> polyval(const Matrix<Scalar> &p, const Matrix<Scalar>& x);
1216  static Matrix<Scalar> densify(const Matrix<Scalar> &x, const Matrix<Scalar>& val);
1217  static Matrix<Scalar> densify(const Matrix<Scalar> &x);
1218  static Matrix<Scalar> einstein(const Matrix<Scalar>& A, const Matrix<Scalar>& B,
1219  const Matrix<Scalar>& C,
1220  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
1221  const std::vector<casadi_int>& dim_c,
1222  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
1223  const std::vector<casadi_int>& c);
1224 
1225  static Matrix<Scalar> einstein(const Matrix<Scalar>& A, const Matrix<Scalar>& B,
1226  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
1227  const std::vector<casadi_int>& dim_c,
1228  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
1229  const std::vector<casadi_int>& c);
1230  static Matrix<Scalar> cumsum(const Matrix<Scalar> &x, casadi_int axis=-1);
1231  static Matrix<Scalar> _logsumexp(const Matrix<Scalar>& x);
1232  static std::vector< Matrix<Scalar> > cse(const std::vector< Matrix<Scalar> >& e);
1234 
1237  static Matrix<Scalar> blockcat(const std::vector< std::vector<Matrix<Scalar> > > &v);
1238  static Matrix<Scalar> horzcat(const std::vector<Matrix<Scalar> > &v);
1239  static std::vector<Matrix<Scalar> >
1240  horzsplit(const Matrix<Scalar>& x,
1241  const std::vector<casadi_int>& offset);
1242  static Matrix<Scalar> vertcat(const std::vector<Matrix<Scalar> > &v);
1243  static std::vector< Matrix<Scalar> >
1244  vertsplit(const Matrix<Scalar>& x,
1245  const std::vector<casadi_int>& offset);
1246  static std::vector< Matrix<Scalar> >
1247  diagsplit(const Matrix<Scalar>& x,
1248  const std::vector<casadi_int>& offset1,
1249  const std::vector<casadi_int>& offset2);
1250  static Matrix<Scalar> reshape(const Matrix<Scalar> &x, casadi_int nrow, casadi_int ncol);
1251  static Matrix<Scalar> reshape(const Matrix<Scalar> &x, const Sparsity& sp);
1252  static Matrix<Scalar> sparsity_cast(const Matrix<Scalar> &x, const Sparsity& sp);
1253  static Matrix<Scalar> kron(const Matrix<Scalar> &x, const Matrix<Scalar>& y);
1254  static Matrix<Scalar> mtimes(const Matrix<Scalar> &x, const Matrix<Scalar> &y,
1255  const std::string& blas = "reference");
1256  static Matrix<Scalar> mac(const Matrix<Scalar> &x,
1257  const Matrix<Scalar> &y,
1258  const Matrix<Scalar> &z,
1259  const std::string& blas = "reference");
1260  static void extract_parametric(const Matrix<Scalar> &expr,
1261  const Matrix<Scalar>& par,
1262  Matrix<Scalar>& expr_ret,
1263  std::vector<Matrix<Scalar> >& symbols,
1264  std::vector<Matrix<Scalar>>& parametric,
1265  const Dict& opts);
1266  static void separate_linear(const Matrix<Scalar> &expr,
1267  const Matrix<Scalar> &sym_lin, const Matrix<Scalar> &sym_const,
1268  Matrix<Scalar>& expr_const, Matrix<Scalar>& expr_lin, Matrix<Scalar>& expr_nonlin);
1270 
1273  static Matrix<Scalar> sparsify(const Matrix<Scalar> &x, double tol=0);
1274  static void expand(const Matrix<Scalar>& x,
1275  Matrix<Scalar>& weights,
1276  Matrix<Scalar>& terms);
1277  static Matrix<Scalar> pw_const(const Matrix<Scalar> &t,
1278  const Matrix<Scalar> &tval, const Matrix<Scalar> &val);
1279  static Matrix<Scalar> pw_lin(const Matrix<Scalar> &t,
1280  const Matrix<Scalar> &tval, const Matrix<Scalar> &val);
1281  static Matrix<Scalar> heaviside(const Matrix<Scalar> &x);
1282  static Matrix<Scalar> rectangle(const Matrix<Scalar> &x);
1283  static Matrix<Scalar> triangle(const Matrix<Scalar> &x);
1284  static Matrix<Scalar> ramp(const Matrix<Scalar> &x);
1285  static Matrix<Scalar> gauss_quadrature(const Matrix<Scalar> &f,
1286  const Matrix<Scalar> &x, const Matrix<Scalar> &a,
1287  const Matrix<Scalar> &b, casadi_int order=5);
1288  static Matrix<Scalar> gauss_quadrature(const Matrix<Scalar> &f,
1289  const Matrix<Scalar> &x, const Matrix<Scalar> &a,
1290  const Matrix<Scalar> &b, casadi_int order,
1291  const Matrix<Scalar>& w);
1292  static std::vector<std::vector<Matrix<Scalar> > >
1293  forward(const std::vector<Matrix<Scalar> > &ex,
1294  const std::vector<Matrix<Scalar> > &arg,
1295  const std::vector<std::vector<Matrix<Scalar> > > &v,
1296  const Dict& opts = Dict());
1297  static std::vector<std::vector<Matrix<Scalar> > >
1298  reverse(const std::vector<Matrix<Scalar> > &ex,
1299  const std::vector<Matrix<Scalar> > &arg,
1300  const std::vector<std::vector<Matrix<Scalar> > > &v,
1301  const Dict& opts = Dict());
1302  static std::vector<bool> which_depends(const Matrix<Scalar> &expr, const Matrix<Scalar> &var,
1303  casadi_int order=1, bool tr=false);
1304  static Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
1305  const Matrix<Scalar>& a, casadi_int order);
1306  static Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
1307  const Matrix<Scalar>& a, casadi_int order);
1308  static Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex,
1309  const Matrix<Scalar>& x, const Matrix<Scalar>& a,
1310  casadi_int order,
1311  const std::vector<casadi_int>& order_contributions);
1312  static Matrix<Scalar> poly_coeff(const Matrix<Scalar>& ex, const Matrix<Scalar>&x);
1313  static Matrix<Scalar> poly_roots(const Matrix<Scalar>& p);
1314  static Matrix<Scalar> eig_symbolic(const Matrix<Scalar>& m);
1315  static Matrix<double> evalf(const Matrix<Scalar>& m);
1316  static void qr_sparse(const Matrix<Scalar>& A, Matrix<Scalar>& V, Matrix<Scalar>& R,
1317  Matrix<Scalar>& beta, std::vector<casadi_int>& prinv,
1318  std::vector<casadi_int>& pc, bool amd=true);
1319  static Matrix<Scalar> qr_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& v,
1320  const Matrix<Scalar>& r, const Matrix<Scalar>& beta,
1321  const std::vector<casadi_int>& prinv,
1322  const std::vector<casadi_int>& pc, bool tr=false);
1323  static void qr(const Matrix<Scalar>& A, Matrix<Scalar>& Q, Matrix<Scalar>& R);
1324  static void ldl(const Matrix<Scalar>& A, Matrix<Scalar>& D, Matrix<Scalar>& LT,
1325  std::vector<casadi_int>& p, bool amd=true);
1326  static Matrix<Scalar> ldl_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& D,
1327  const Matrix<Scalar>& LT, const std::vector<casadi_int>& p);
1328  static Matrix<Scalar> all(const Matrix<Scalar>& x);
1329  static Matrix<Scalar> any(const Matrix<Scalar>& x);
1330  static Matrix<Scalar> adj(const Matrix<Scalar>& x);
1331  static Matrix<Scalar> minor(const Matrix<Scalar>& x, casadi_int i, casadi_int j);
1332  static Matrix<Scalar> cofactor(const Matrix<Scalar>& A, casadi_int i, casadi_int j);
1333  static Matrix<Scalar> chol(const Matrix<Scalar>& A);
1334  static Matrix<Scalar> norm_inf_mul(const Matrix<Scalar>& x, const Matrix<Scalar> &y);
1335  static Matrix<Scalar> diagcat(const std::vector< Matrix<Scalar> > &A);
1337 
1338  // Simplification with reference counting awareness
1339  static bool simplify_ref_count(std::vector< Matrix<Scalar> >& arg,
1340  std::vector< Matrix<Scalar> >& res,
1341  const Dict& opts = Dict());
1342 
1343  // Simplification with constant folding
1344  static bool simplify_const_folding(std::vector< Matrix<Scalar> >& arg,
1345  std::vector< Matrix<Scalar> >& res,
1346  const Dict& opts = Dict());
1347 
1348  // Simplification by combining like terms in linear combinations
1349  static bool simplify_combine_terms(std::vector< Matrix<Scalar> >& arg,
1350  std::vector< Matrix<Scalar> >& res,
1351  const Dict& opts = Dict());
1352 
1354 #endif // SWIG
1355 
1357 
1360 
1361 #if !defined(SWIG) || defined(DOXYGEN)
1423  friend inline Matrix<Scalar> adj(const Matrix<Scalar>& A) {
1424  return Matrix<Scalar>::adj(A);
1425  }
1426 
1472  friend inline Matrix<Scalar> minor(const Matrix<Scalar> &x, casadi_int i, casadi_int j) {
1473  return Matrix<Scalar>::minor(x, i, j);
1474  }
1475 
1508  friend inline Matrix<Scalar> cofactor(const Matrix<Scalar> &x, casadi_int i, casadi_int j) {
1509  return Matrix<Scalar>::cofactor(x, i, j);
1510  }
1511 
1582  friend inline void qr(const Matrix<Scalar>& A, Matrix<Scalar>& Q, Matrix<Scalar>& R) {
1583  return Matrix<Scalar>::qr(A, Q, R);
1584  }
1585 
1638  friend inline void qr_sparse(const Matrix<Scalar>& A, Matrix<Scalar>& V, Matrix<Scalar>& R,
1639  Matrix<Scalar>& beta, std::vector<casadi_int>& prinv,
1640  std::vector<casadi_int>& pc, bool amd=true) {
1641  return Matrix<Scalar>::qr_sparse(A, V, R, beta, prinv, pc, amd);
1642  }
1643 
1687  friend inline Matrix<Scalar>
1689  const Matrix<Scalar>& r, const Matrix<Scalar>& beta,
1690  const std::vector<casadi_int>& prinv,
1691  const std::vector<casadi_int>& pc, bool tr=false) {
1692  return Matrix<Scalar>::qr_solve(b, v, r, beta, prinv, pc, tr);
1693  }
1694 
1750  friend inline Matrix<Scalar> chol(const Matrix<Scalar>& A) {
1751  return Matrix<Scalar>::chol(A);
1752  }
1753 
1823  friend inline void ldl(const Matrix<Scalar>& A, Matrix<Scalar>& D, Matrix<Scalar>& LT,
1824  std::vector<casadi_int>& p, bool amd=true) {
1825  return Matrix<Scalar>::ldl(A, D, LT, p, amd);
1826  }
1827 
1870  friend inline Matrix<Scalar>
1872  const std::vector<casadi_int>& p) {
1873  return Matrix<Scalar>::ldl_solve(b, D, LT, p);
1874  }
1875 
1894  friend inline Matrix<Scalar> any(const Matrix<Scalar> &x) {
1895  return Matrix<Scalar>::any(x);
1896  }
1897 
1916  friend inline Matrix<Scalar> all(const Matrix<Scalar> &x) {
1917  return Matrix<Scalar>::all(x);
1918  }
1919 
1953  friend inline Matrix<Scalar>
1955  return Matrix<Scalar>::norm_inf_mul(x, y);
1956  }
1957 
2015  friend inline Matrix<Scalar>
2016  sparsify(const Matrix<Scalar>& A, double tol=0) {
2017  return Matrix<Scalar>::sparsify(A, tol);
2018  }
2019 
2071  friend inline void expand(const Matrix<Scalar>& ex, Matrix<Scalar> &weights,
2072  Matrix<Scalar>& terms) {
2073  Matrix<Scalar>::expand(ex, weights, terms);
2074  }
2075 
2133  friend inline Matrix<Scalar> pw_const(const Matrix<Scalar> &t,
2134  const Matrix<Scalar> &tval,
2135  const Matrix<Scalar> &val) {
2136  return Matrix<Scalar>::pw_const(t, tval, val);
2137  }
2138 
2193  friend inline Matrix<Scalar>
2194  pw_lin(const Matrix<Scalar> &t, const Matrix<Scalar> &tval,
2195  const Matrix<Scalar> &val) {
2196  return Matrix<Scalar>::pw_lin(t, tval, val);
2197  }
2198 
2234  friend inline Matrix<Scalar> heaviside(const Matrix<Scalar> &x) {
2235  return Matrix<Scalar>::heaviside(x);
2236  }
2237 
2267  friend inline Matrix<Scalar> rectangle(const Matrix<Scalar> &x) {
2268  return Matrix<Scalar>::rectangle(x);
2269  }
2270 
2299  friend inline Matrix<Scalar> triangle(const Matrix<Scalar> &x) {
2300  return Matrix<Scalar>::triangle(x);
2301  }
2302 
2338  friend inline Matrix<Scalar> ramp(const Matrix<Scalar> &x) {
2339  return Matrix<Scalar>::ramp(x);
2340  }
2341 
2343 
2383  friend inline Matrix<Scalar>
2385  const Matrix<Scalar> &a, const Matrix<Scalar> &b,
2386  casadi_int order=5) {
2387  return Matrix<Scalar>::gauss_quadrature(f, x, a, b, order);
2388  }
2389  friend inline Matrix<Scalar>
2391  const Matrix<Scalar> &a, const Matrix<Scalar> &b,
2392  casadi_int order, const Matrix<Scalar>& w) {
2393  return Matrix<Scalar>::gauss_quadrature(f, x, a, b, order, w);
2394  }
2396 
2398 
2457  friend inline Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
2458  const Matrix<Scalar>& a, casadi_int order=1) {
2459  return Matrix<Scalar>::taylor(ex, x, a, order);
2460  }
2461  friend inline Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x) {
2462  return Matrix<Scalar>::taylor(ex, x, 0, 1);
2463  }
2465 
2511  friend inline Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
2512  const Matrix<Scalar>& a, casadi_int order=1) {
2513  return Matrix<Scalar>::mtaylor(ex, x, a, order);
2514  }
2515 
2549  friend inline Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
2550  const Matrix<Scalar>& a, casadi_int order,
2551  const std::vector<casadi_int>& order_contributions) {
2552  return Matrix<Scalar>::mtaylor(ex, x, a, order, order_contributions);
2553  }
2554 
2605  friend inline Matrix<Scalar> poly_coeff(const Matrix<Scalar>& f,
2606  const Matrix<Scalar>& x) {
2607  return Matrix<Scalar>::poly_coeff(f, x);
2608  }
2609 
2664  friend inline Matrix<Scalar> poly_roots(const Matrix<Scalar>& p) {
2665  return Matrix<Scalar>::poly_roots(p);
2666  }
2667 
2720  friend inline Matrix<Scalar> eig_symbolic(const Matrix<Scalar>& m) {
2721  return Matrix<Scalar>::eig_symbolic(m);
2722  }
2723 
2724 
2773  inline friend Matrix<double> evalf(const Matrix<Scalar>& expr) {
2774  return Matrix<Scalar>::evalf(expr);
2775  }
2777 #endif
2778 
2834  static void set_max_depth(casadi_int eq_depth=1);
2835 
2841  static casadi_int get_max_depth();
2842 
2877  static std::vector<Matrix<Scalar> > get_input(const Function& f);
2878 
2912  static std::vector<Matrix<Scalar> > get_free(const Function& f);
2913 
2938  static std::string type_name();
2939 
2984  void print_split(std::vector<std::string>& SWIG_OUTPUT(nz),
2985  std::vector<std::string>& SWIG_OUTPUT(inter)) const;
2986 
2994  void disp(std::ostream& stream, bool more=false) const;
2995 
2997  std::string get_str(bool more=false) const;
2998 
3022  void print_scalar(std::ostream &stream) const;
3023 
3045  void print_vector(std::ostream &stream, bool truncate=true) const;
3046 
3073  void print_dense(std::ostream &stream, bool truncate=true) const;
3074 
3104  void print_sparse(std::ostream &stream, bool truncate=true) const;
3105 
3106 #ifndef SWIG
3108  static void print_default(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
3109  bool truncate=true);
3110 
3112  static void print_scalar(std::ostream &stream, const Scalar& e);
3113 
3115  static void print_vector(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
3116  bool truncate=true);
3117 
3119  static void print_canonical(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
3120  bool truncate=true);
3121 
3123  static void print_sparse(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
3124  bool truncate=true);
3125 
3127  static void print_split(casadi_int nnz, const Scalar* nonzeros, std::vector<std::string>& nz,
3128  std::vector<std::string>& inter);
3129 
3131  static void print_dense(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
3132  bool truncate=true);
3133 #endif
3134 
3136  void clear();
3137 
3189  void resize(casadi_int nrow, casadi_int ncol);
3190 
3192  void reserve(casadi_int nnz);
3193  void reserve(casadi_int nnz, casadi_int ncol);
3194 
3246  void erase(const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
3247  bool ind1=false);
3248 
3286  void erase(const std::vector<casadi_int>& rr, bool ind1=false);
3287 
3322  void remove(const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc);
3323 
3381  void enlarge(casadi_int nrow, casadi_int ncol,
3382  const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
3383  bool ind1=false);
3384 
3385 #ifndef SWIG
3388  std::vector<Scalar>& nonzeros();
3389  const std::vector<Scalar>& nonzeros() const;
3391 
3394  Scalar* ptr();
3395  const Scalar* ptr() const;
3396  friend inline Scalar* get_ptr(Matrix<Scalar>& v) { return v.ptr(); }
3397  friend inline const Scalar* get_ptr(const Matrix<Scalar>& v) { return v.ptr(); }
3399 
3401  const Sparsity& sparsity() const;
3402 
3403 #endif // SWIG
3404 
3434 
3438  Matrix<Scalar> get_output(casadi_int oind) const;
3439 
3514  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
3515  const std::vector<casadi_int>& col,
3516  const Matrix<Scalar>& d);
3517  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
3518  const std::vector<casadi_int>& col,
3519  const Matrix<Scalar>& d, casadi_int nrow, casadi_int ncol);
3520  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
3521  const std::vector<casadi_int>& col,
3522  const Matrix<Scalar>& d,
3523  const std::pair<casadi_int, casadi_int>& rc);
3525 
3527 
3567  static Matrix<Scalar> inf(const Sparsity& sp);
3568  static Matrix<Scalar> inf(casadi_int nrow=1, casadi_int ncol=1);
3569  static Matrix<Scalar> inf(const std::pair<casadi_int, casadi_int>& rc);
3571 
3573 
3609  static Matrix<Scalar> nan(const Sparsity& sp);
3610  static Matrix<Scalar> nan(casadi_int nrow=1, casadi_int ncol=1);
3611  static Matrix<Scalar> nan(const std::pair<casadi_int, casadi_int>& rc);
3613 
3653  static Matrix<Scalar> eye(casadi_int n);
3654 
3686  casadi_int element_hash() const;
3687 
3735  bool is_regular() const;
3736 
3774  bool is_smooth() const;
3775 
3781  bool is_leaf() const;
3782 
3788  bool is_commutative() const;
3789 
3804  bool is_symbolic() const;
3805 
3817  bool is_valid_input() const;
3818 
3820 
3867  bool has_duplicates() const;
3868 
3872  void reset_input() const;
3874 
3914  bool is_constant() const;
3915 
3919  bool is_call() const;
3920 
3924  bool is_output() const;
3925 
3929  bool has_output() const;
3930 
3934  casadi_int which_output() const;
3935 
3940 
3946  bool is_integer() const;
3947 
3951  bool is_zero() const;
3952 
3956  bool is_one() const;
3957 
3961  bool is_minus_one() const;
3962 
3966  bool is_half() const;
3967 
3971  bool is_value(double val) const;
3972 
3976  bool is_inf() const;
3977 
3981  bool is_minus_inf() const;
3982 
3988  bool is_nonnegative() const;
3989 
3995  bool is_eye() const;
3996 
3998  casadi_int op() const;
3999 
4001  bool is_op(casadi_int op) const;
4002 
4042  bool has_zeros() const;
4043 
4089  std::vector<Scalar> get_nonzeros() const;
4090 
4123  std::vector<Scalar> get_elements() const;
4124 
4125 #ifndef SWIG
4129  template<typename A>
4130  std::vector<A> get_nonzeros() const;
4131 #endif // SWIG
4132 
4166  explicit operator double() const;
4167 
4192  explicit operator casadi_int() const;
4193 
4194 #ifndef SWIG
4198  template<typename A>
4199  explicit operator std::vector<A>() const;
4200 #endif // SWIG
4201 
4231  std::string name() const;
4232 
4272  Matrix<Scalar> dep(casadi_int ch=0) const;
4273 
4279  casadi_int n_dep() const;
4280 
4281  // @{
4323  static void set_precision(casadi_int precision);
4324  static void set_width(casadi_int width);
4325  static void set_scientific(bool scientific);
4326  // @}
4327 
4328  // @{
4330  static casadi_int get_precision();
4331  static casadi_int get_width();
4332  static bool get_scientific();
4333  // @}
4334 
4370  static void rng(casadi_int seed);
4371 
4373 
4413  static Matrix<Scalar> rand( // NOLINT(runtime/threadsafe_fn)
4414  casadi_int nrow=1,
4415  casadi_int ncol=1);
4416  static Matrix<Scalar> rand(const Sparsity& sp); // NOLINT(runtime/threadsafe_fn)
4417  static Matrix<Scalar> rand( // NOLINT(runtime/threadsafe_fn)
4418  const std::pair<casadi_int, casadi_int>& rc);
4420 
4435  void export_code(const std::string& lang,
4436  std::ostream &stream=casadi::uout(), const Dict& options=Dict()) const;
4437 
4465  Dict info() const;
4466  #ifndef SWIG
4470  void serialize(std::ostream &stream) const;
4471  #endif
4472 
4519  std::string serialize() const;
4520 
4524  static Matrix<Scalar> deserialize(std::istream& stream);
4525 
4533  static Matrix<Scalar> deserialize(const std::string& s);
4534 
4539 
4541 
4542  // @{
4597  void to_file(const std::string& filename, const std::string& format="") const;
4598 #ifndef SWIG
4599  static void to_file(const std::string& filename, const Sparsity& sp,
4600  const Scalar* nonzeros, const std::string& format="");
4601 #endif
4602 
4660  static Matrix<double> from_file(const std::string& filename, const std::string& format_hint="");
4662 
4663 #ifndef SWIG
4665  Matrix(const Sparsity& sp, const Scalar& val, bool dummy);
4666 
4668  Matrix(const Sparsity& sp, const std::vector<Scalar>& d, bool dummy);
4669 
4671  static Matrix<Scalar> _sym(const std::string& name, const Sparsity& sp);
4673 
4674 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
4675  static std::mutex& get_mutex_temp();
4676 #endif //CASADI_WITH_THREADSAFE_SYMBOLICS
4677 
4678  private:
4680  Sparsity sparsity_;
4681 
4683  std::vector<Scalar> nonzeros_;
4684 
4686  static casadi_int stream_precision_;
4687  static casadi_int stream_width_;
4688  static bool stream_scientific_;
4689 
4691  static std::default_random_engine rng_;
4692 
4693 #endif // SWIG
4694  };
4695 
4697  template<typename Scalar>
4698  template<typename A>
4699  std::vector<A> Matrix<Scalar>::get_nonzeros() const {
4700  std::vector<A> ret(nnz());
4701  auto r = ret.begin();
4702  for (auto&& e : nonzeros()) *r++ = static_cast<A>(e);
4703  return ret;
4704  }
4705 
4707  template<typename Scalar>
4708  template<typename A>
4709  Matrix<Scalar>::operator std::vector<A>() const {
4710  // Get sparsity pattern
4711  casadi_int size1 = this->size1(), size2 = this->size2();
4712  const casadi_int *colind = this->colind(), *row = this->row();
4713  // Copy the nonzeros
4714  auto it = nonzeros().begin();
4715  std::vector<A> ret(numel(), 0);
4716  for (casadi_int cc=0; cc<size2; ++cc) {
4717  for (casadi_int el=colind[cc]; el<colind[cc+1]; ++el) {
4718  ret[row[el] + cc*size1] = static_cast<A>(*it++);
4719  }
4720  }
4721  return ret;
4722  }
4723 
4724 } // namespace casadi
4725 
4726 #endif // CASADI_MATRIX_DECL_HPP
Helper class for Serialization.
Function object.
Definition: function.hpp:126
Matrix base class.
Sparse matrix class. SX and DM are specializations.
Matrix(const Matrix< A > &x)
Create a matrix from another matrix with a different entry type.
bool is_inf() const
check if the matrix is inf (note that false negative answers are possible)
static Matrix< Scalar > nan(const std::pair< casadi_int, casadi_int > &rc)
Create a matrix with every nonzero equal to nan.
bool has_zeros() const
Check if any structural nonzero is known to be numerically zero.
static Matrix< Scalar > deserialize(const std::string &s)
Build a matrix from a string produced by serialize.
bool is_one() const
check if the matrix is 1 (note that false negative answers are possible)
void remove(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc)
Delete rows and columns, shrinking the matrix in place.
bool is_regular() const
Check that no entry is nan, inf or -inf.
Matrix(double val)
Dense 1-by-1 matrix holding a number; enables implicit conversion from a numeric type.
Matrix< Scalar > T() const
Transpose the matrix.
static void set_max_depth(casadi_int eq_depth=1)
Set the depth to which SX subexpressions are compared during simplification.
Function which_function() const
Get function - only valid when is_call() is true.
static Matrix< Scalar > rand(const Sparsity &sp)
Create a matrix with uniformly distributed random numbers in [0, 1)
void resize(casadi_int nrow, casadi_int ncol)
Change the shape in place, keeping nonzeros that remain inside the new bounds.
Sparsity get_sparsity() const
Get the sparsity pattern (Python: sparsity())
static Matrix< Scalar > deserialize(std::istream &stream)
Build a matrix from a serialization stream.
casadi_int element_hash() const
Hash of the node of a 1-by-1 SX expression.
casadi_int which_output() const
Get the index of evaluation output - only valid when is_output() is true.
void erase(const std::vector< casadi_int > &rr, bool ind1=false)
Erase the elements at the given linear indices, leaving structural zeros.
void clear()
Reset to an empty 0-by-0 matrix, in place.
bool is_value(double val) const
check if the matrix is value
void export_code(const std::string &lang, std::ostream &stream=casadi::uout(), const Dict &options=Dict()) const
Export matrix in specific language.
void serialize(SerializingStream &s) const
Serialize an object.
bool is_commutative() const
Check whether a binary SX is commutative.
Dict info() const
Dictionary with the sparsity pattern and the nonzeros (DM only)
bool is_symbolic() const
Check if symbolic (Dense)
Matrix(const Sparsity &sp)
Create a matrix with the given sparsity pattern and all nonzeros equal to one.
static std::vector< Matrix< Scalar > > get_free(const Function &f)
Get the free symbols of an SX Function.
Matrix(casadi_int nrow, casadi_int ncol)
Create a matrix of the given shape with all structural zeros (no nonzeros)
static casadi_int get_max_depth()
Get the depth to which SX subexpressions are compared during simplification.
bool is_call() const
Check if function call.
Matrix< Scalar > operator+() const
bool is_smooth() const
Check whether an SX expression contains only smooth operations.
static Matrix< Scalar > nan(const Sparsity &sp)
Create a matrix with every nonzero equal to nan.
static Matrix< Scalar > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d, casadi_int nrow, casadi_int ncol)
Construct a sparse matrix from triplet form (row indices, column indices, values)
bool is_minus_one() const
check if the matrix is -1 (note that false negative answers are possible)
void to_file(const std::string &filename, const std::string &format="") const
Write a numerical matrix to a text file (DM only)
static Matrix< Scalar > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d)
Construct a sparse matrix from triplet form (row indices, column indices, values)
bool is_half() const
check if the matrix is 0.5 (note that false negative answers are possible)
void disp(std::ostream &stream, bool more=false) const
Print a representation of the object to a stream.
static Matrix< Scalar > rand(casadi_int nrow=1, casadi_int ncol=1)
Create a matrix with uniformly distributed random numbers in [0, 1)
bool is_eye() const
check if the matrix is an identity matrix (note that false negative answers
bool is_op(casadi_int op) const
Is it a certain operation.
bool is_minus_inf() const
check if the matrix is -inf (note that false negative answers are possible)
void erase(const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
Erase the block at the given rows and columns, leaving structural zeros.
static Matrix< Scalar > inf(casadi_int nrow=1, casadi_int ncol=1)
Create a matrix with every nonzero equal to +inf.
bool is_output() const
Check if evaluation output.
std::vector< Scalar > get_elements() const
Get all elements as a flat list in column-major order (Python: elements())
static Matrix< Scalar > triplet(const std::vector< casadi_int > &row, const std::vector< casadi_int > &col, const Matrix< Scalar > &d, const std::pair< casadi_int, casadi_int > &rc)
Construct a sparse matrix from triplet form (row indices, column indices, values)
Matrix(const std::vector< std::vector< double > > &m)
Dense matrix from a list of rows.
static std::vector< Matrix< Scalar > > get_input(const Function &f)
Get the symbolic input expressions of an SX Function.
Matrix< Scalar > dep(casadi_int ch=0) const
Get operand ch of a 1-by-1 SX expression.
bool is_zero() const
check if the matrix is 0 (note that false negative answers are possible)
static Matrix< Scalar > inf(const Sparsity &sp)
Create a matrix with every nonzero equal to +inf.
static Matrix< double > from_file(const std::string &filename, const std::string &format_hint="")
Read a numerical matrix from a text file written by to_file (DM only)
std::string serialize() const
Serialize to a string.
void enlarge(casadi_int nrow, casadi_int ncol, const std::vector< casadi_int > &rr, const std::vector< casadi_int > &cc, bool ind1=false)
Enlarge the matrix in place, moving the existing rows and columns to new positions.
static Matrix< Scalar > deserialize(DeserializingStream &s)
bool is_constant() const
Check if every entry is a numerical constant (no symbols)
bool is_nonnegative() const
check if the matrix is not negative
Matrix(const std::vector< A > &x)
Dense column vector from a flat list of numbers.
bool has_output() const
Check if a multiple output node.
void reserve(casadi_int nnz)
Reserve storage for the given number of nonzeros (performance hint, no visible effect)
casadi_int op() const
Get operation type.
void reserve(casadi_int nnz, casadi_int ncol)
static Matrix< Scalar > eye(casadi_int n)
Create an n-by-n identity matrix.
bool is_valid_input() const
Check if matrix can be used to define function inputs.
Matrix(const Sparsity &sp, const Matrix< Scalar > &d)
Create a matrix with a given sparsity pattern and given nonzeros.
static Matrix< Scalar > rand(const std::pair< casadi_int, casadi_int > &rc)
Create a matrix with uniformly distributed random numbers in [0, 1)
Matrix< Scalar > get_output(casadi_int oind) const
Get an output.
bool is_integer() const
Check if the matrix is integer-valued.
Matrix< Scalar > operator-() const
casadi_int n_dep() const
Number of operands of a 1-by-1 SX expression (0 for symbols and constants)
static Matrix< Scalar > nan(casadi_int nrow=1, casadi_int ncol=1)
Create a matrix with every nonzero equal to nan.
static Matrix< Scalar > inf(const std::pair< casadi_int, casadi_int > &rc)
Create a matrix with every nonzero equal to +inf.
std::string get_str(bool more=false) const
Get the string representation that disp prints.
Matrix< Scalar > printme(const Matrix< Scalar > &y) const
bool is_leaf() const
Check if SX is a leaf of the SX graph.
std::string name() const
Name of a 1-by-1 symbolic SX primitive.
std::vector< Scalar > get_nonzeros() const
Get all structural nonzeros as a flat list in column-major order (Python: nonzeros())
Helper class for Serialization.
General sparsity class.
Definition: sparsity.hpp:200
friend Matrix< Scalar > mtaylor(const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order=1)
Multivariate Taylor series expansion.
friend Matrix< Scalar > cofactor(const Matrix< Scalar > &x, casadi_int i, casadi_int j)
Cofactor of a square matrix: (-1)^(i+j) times minor(x, i, j)
friend Matrix< Scalar > any(const Matrix< Scalar > &x)
True if any entry equals one.
friend void ldl(const Matrix< Scalar > &A, Matrix< Scalar > &D, Matrix< Scalar > &LT, std::vector< casadi_int > &p, bool amd=true)
Sparse LDL^T factorization of a symmetric matrix.
friend Matrix< Scalar > norm_inf_mul(const Matrix< Scalar > &x, const Matrix< Scalar > &y)
Infinity norm of a matrix product, without forming the product.
friend Matrix< Scalar > eig_symbolic(const Matrix< Scalar > &m)
Eigenvalues of a square SX matrix in closed form.
friend Matrix< double > evalf(const Matrix< Scalar > &expr)
Evaluate a constant expression numerically, returning a DM.
friend Matrix< Scalar > chol(const Matrix< Scalar > &A)
Cholesky factorization of a symmetric positive definite matrix.
friend Matrix< Scalar > pw_lin(const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
Piecewise linear function of a scalar symbolic variable.
friend Matrix< Scalar > ldl_solve(const Matrix< Scalar > &b, const Matrix< Scalar > &D, const Matrix< Scalar > &LT, const std::vector< casadi_int > &p)
Solve A*x = b with the factors returned by ldl.
friend void expand(const Matrix< Scalar > &ex, Matrix< Scalar > &weights, Matrix< Scalar > &terms)
Expand a scalar SX expression as a weighted sum of terms with constant weights.
friend Matrix< Scalar > poly_coeff(const Matrix< Scalar > &f, const Matrix< Scalar > &x)
Extract the polynomial coefficients of a scalar expression in one symbol.
friend Matrix< Scalar > pw_const(const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
Piecewise constant function of a scalar symbolic variable.
friend Matrix< Scalar > taylor(const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order=1)
Univariate Taylor series expansion.
friend void qr_sparse(const Matrix< Scalar > &A, Matrix< Scalar > &V, Matrix< Scalar > &R, Matrix< Scalar > &beta, std::vector< casadi_int > &prinv, std::vector< casadi_int > &pc, bool amd=true)
Sparse direct QR factorization with Householder reflections.
friend Matrix< Scalar > taylor(const Matrix< Scalar > &ex, const Matrix< Scalar > &x)
Univariate Taylor series expansion.
friend Matrix< Scalar > all(const Matrix< Scalar > &x)
True if every entry equals one.
friend Matrix< Scalar > poly_roots(const Matrix< Scalar > &p)
Roots of a polynomial given by its coefficients, in closed form.
friend void qr(const Matrix< Scalar > &A, Matrix< Scalar > &Q, Matrix< Scalar > &R)
Dense QR factorization using the modified Gram-Schmidt algorithm.
friend Matrix< Scalar > heaviside(const Matrix< Scalar > &x)
Heaviside step function, elementwise.
friend Matrix< Scalar > gauss_quadrature(const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order, const Matrix< Scalar > &w)
Integrate a scalar SX expression over [a, b] with 5-point Gauss-Legendre quadrature.
friend Matrix< Scalar > rectangle(const Matrix< Scalar > &x)
Rectangle (gate, pulse, window) function, elementwise.
friend Matrix< Scalar > triangle(const Matrix< Scalar > &x)
Triangle (hat) function, elementwise.
friend Matrix< Scalar > sparsify(const Matrix< Scalar > &A, double tol=0)
Make a matrix sparse by turning numerical zeros into structural zeros.
friend Matrix< Scalar > ramp(const Matrix< Scalar > &x)
Ramp function, elementwise.
friend Matrix< Scalar > gauss_quadrature(const Matrix< Scalar > &f, const Matrix< Scalar > &x, const Matrix< Scalar > &a, const Matrix< Scalar > &b, casadi_int order=5)
Integrate a scalar SX expression over [a, b] with 5-point Gauss-Legendre quadrature.
friend Matrix< Scalar > qr_solve(const Matrix< Scalar > &b, const Matrix< Scalar > &v, const Matrix< Scalar > &r, const Matrix< Scalar > &beta, const std::vector< casadi_int > &prinv, const std::vector< casadi_int > &pc, bool tr=false)
Solve A*x = b (or A^T*x = b) with the factors returned by qr_sparse.
friend Matrix< Scalar > adj(const Matrix< Scalar > &A)
Adjugate (classical adjoint) of a square matrix.
friend Matrix< Scalar > minor(const Matrix< Scalar > &x, casadi_int i, casadi_int j)
Minor of a square matrix: determinant with one column and one row removed.
friend Matrix< Scalar > mtaylor(const Matrix< Scalar > &ex, const Matrix< Scalar > &x, const Matrix< Scalar > &a, casadi_int order, const std::vector< casadi_int > &order_contributions)
Multivariate Taylor series expansion with weighted degrees.
The casadi namespace.
Definition: archiver.hpp:32
CASADI_EXPORT std::ostream & uout()
GenericType::Dict Dict
C++ equivalent of Python's dict or MATLAB's struct.