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 
94  template<typename Scalar>
95  class CASADI_EXPORT Matrix :
96  public MatrixCommon,
97  public SWIG_IF_ELSE(GenericExpressionCommon, GenericExpression<Matrix<Scalar> >),
98  public GenericMatrix<Matrix<Scalar> >,
99  public SWIG_IF_ELSE(PrintableCommon, Printable<Matrix<Scalar> >) {
100  public:
101 
106  Matrix();
107 
109  Matrix(const Matrix<Scalar>& m);
110 
111 #ifndef SWIG
113  Matrix<Scalar>& operator=(const Matrix<Scalar>& m);
114 #endif // SWIG
115 
119  Matrix(casadi_int nrow, casadi_int ncol);
120 
121 #ifndef SWIG
125  explicit Matrix(const std::pair<casadi_int, casadi_int>& rc);
126 
130  std::vector<Scalar>* operator->();
131 
135  const std::vector<Scalar>* operator->() const;
136 #endif // SWIG
137 
143  explicit Matrix(const Sparsity& sp);
144 
148  Matrix(const Sparsity& sp, const Matrix<Scalar>& d);
149 
151  Matrix(double val);
152 
153 #if !(defined(SWIG) && defined(SWIGMATLAB))
155  explicit Matrix(const std::vector< std::vector<double> >& m);
156 
160  template<typename A>
161  Matrix(const std::vector<A>& x) : 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  }
166 #endif
167 
173  template<typename A>
174  Matrix(const Matrix<A>& x) : 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  }
178 
179 #ifndef SWIG
181  Matrix(const std::vector<Scalar>& x);
182 
184  Matrix(std::initializer_list<Scalar> x) : Matrix<Scalar>(std::vector<Scalar>(x)) {}
185 
187  const Scalar scalar() const;
188 
190  typedef Scalar ScalarType;
191 
193  typedef GenericMatrix<Matrix<Scalar> > B;
194 
196  using B::nnz;
197  using B::nnz_lower;
198  using B::nnz_upper;
199  using B::numel;
200  using B::size1;
201  using B::size2;
202  using B::size;
203  using B::is_empty;
204  using B::is_scalar;
205  using B::is_dense;
206  using B::is_vector;
207  using B::is_row;
208  using B::is_column;
209  using B::is_tril;
210  using B::is_triu;
211  using B::colind;
212  using B::row;
213  using B::dim;
214  using B::sym;
215  using B::zeros;
216  using B::ones;
217  using B::nz;
218  using B::operator();
219  using B::horzsplit;
220  using B::vertsplit;
221  using B::diagsplit;
222  using B::mtimes;
223 #endif // SWIG
224 
226  bool has_nz(casadi_int rr, casadi_int cc) const;
227 
229  bool __nonzero__() const;
230 
233  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Slice& rr) const;
234  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& rr) const;
235  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Sparsity& sp) const;
237 
240  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1,
241  const Slice& rr, const Slice& cc) const;
242  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1,
243  const Slice& rr, const Matrix<casadi_int>& cc) const;
244  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1,
245  const Matrix<casadi_int>& rr, const Slice& cc) const;
246  void get(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1,
247  const Matrix<casadi_int>& rr, const Matrix<casadi_int>& cc) const;
249 
252  void set(const Matrix<Scalar>& m, bool ind1, const Slice& rr);
253  void set(const Matrix<Scalar>& m, bool ind1, const Matrix<casadi_int>& rr);
254  void set(const Matrix<Scalar>& m, bool ind1, const Sparsity& sp);
256 
259  void set(const Matrix<Scalar>& m, bool ind1, const Slice& rr, const Slice& cc);
260  void set(const Matrix<Scalar>& m, bool ind1, const Slice& rr, const Matrix<casadi_int>& cc);
261  void set(const Matrix<Scalar>& m, bool ind1, const Matrix<casadi_int>& rr, const Slice& cc);
262  void set(const Matrix<Scalar>& m, bool ind1, const Matrix<casadi_int>& rr,
263  const Matrix<casadi_int>& cc);
265 
268  void get_nz(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Slice& k) const;
269  void get_nz(Matrix<Scalar>& SWIG_OUTPUT(m), bool ind1, const Matrix<casadi_int>& k) const;
271 
274  void set_nz(const Matrix<Scalar>& m, bool ind1, const Slice& k);
275  void set_nz(const Matrix<Scalar>& m, bool ind1, const Matrix<casadi_int>& k);
277 
280 
283 
286  static Matrix<Scalar> binary(casadi_int op, const Matrix<Scalar> &x, const Matrix<Scalar> &y);
287  static Matrix<Scalar> unary(casadi_int op, const Matrix<Scalar> &x);
288  static Matrix<Scalar> scalar_matrix(casadi_int op,
289  const Matrix<Scalar> &x, const Matrix<Scalar> &y);
290  static Matrix<Scalar> matrix_scalar(casadi_int op,
291  const Matrix<Scalar> &x, const Matrix<Scalar> &y);
292  static Matrix<Scalar> matrix_matrix(casadi_int op,
293  const Matrix<Scalar> &x, const Matrix<Scalar> &y);
294  static std::vector< Matrix<Scalar> > call(const Function& f,
295  const std::vector< Matrix<Scalar> > &x);
296  static std::vector< Scalar > call(const Function& f, const std::vector< Scalar > &x);
299 
300 #ifndef SWIG
304  static bool is_equal(const Matrix<Scalar> &x, const Matrix<Scalar> &y, casadi_int depth=0);
305  static Matrix<Scalar> mmin(const Matrix<Scalar> &x);
306  static Matrix<Scalar> mmax(const Matrix<Scalar> &x);
308 
311  static Matrix<Scalar> simplify(const Matrix<Scalar> &x);
312  static Matrix<Scalar> transform(const Matrix<Scalar> &x, const Dict& opts = Dict());
313  static Matrix<Scalar> transform(const Matrix<Scalar> &x,
314  const std::vector<std::vector<GenericType> >& passes, const Dict& opts = Dict());
315  static std::vector<Matrix<Scalar> > transform(const std::vector<Matrix<Scalar> >& x,
316  const Dict& opts = Dict());
317  static std::vector<Matrix<Scalar> > transform(const std::vector<Matrix<Scalar> >& x,
318  const std::vector<std::vector<GenericType> >& passes, const Dict& opts = Dict());
319  static Matrix<Scalar> jacobian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
320  const Dict& opts = Dict());
321  static Sparsity jacobian_sparsity(const Matrix<Scalar> &f, const Matrix<Scalar> &x);
322  static Matrix<Scalar> hessian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
323  const Dict& opts = Dict());
324  static Matrix<Scalar> hessian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
325  Matrix<Scalar>& g, const Dict& opts = Dict());
326  static Matrix<Scalar>
327  substitute(const Matrix<Scalar>& ex,
328  const Matrix<Scalar>& v,
329  const Matrix<Scalar>& vdef);
330  static std::vector<Matrix<Scalar> >
331  substitute(const std::vector<Matrix<Scalar> >& ex,
332  const std::vector<Matrix<Scalar> >& v,
333  const std::vector<Matrix<Scalar> >& vdef);
334  static void substitute_inplace(const std::vector<Matrix<Scalar> >& v,
335  std::vector<Matrix<Scalar> >& vdef,
336  std::vector<Matrix<Scalar> >& ex,
337  bool revers);
338  static Matrix<Scalar> pinv(const Matrix<Scalar> &x);
339  static Matrix<Scalar> pinv(const Matrix<Scalar> &A,
340  const std::string& lsolver, const Dict& opts);
341  static Matrix<Scalar> expm_const(const Matrix<Scalar> &A, const Matrix<Scalar> &t);
342  static Matrix<Scalar> expm(const Matrix<Scalar> &A);
343  static Matrix<Scalar> solve(const Matrix<Scalar> &A, const Matrix<Scalar>& b);
344  static Matrix<Scalar> solve(const Matrix<Scalar> &A, const Matrix<Scalar>& b,
345  const std::string& lsolver, const Dict& opts);
346  static Matrix<Scalar> inv(const Matrix<Scalar> &A);
347  static Matrix<Scalar> inv(const Matrix<Scalar> &A,
348  const std::string& lsolver, const Dict& opts);
349 
350  static casadi_int n_nodes(const Matrix<Scalar> &x);
351  static std::string print_operator(const Matrix<Scalar> &x,
352  const std::vector<std::string>& args);
353  static void extract(std::vector<Matrix<Scalar>>& ex, std::vector<Matrix<Scalar>>& v,
354  std::vector<Matrix<Scalar>>& vdef, const Dict& opts = Dict());
355  static void shared(std::vector<Matrix<Scalar> >& ex,
356  std::vector<Matrix<Scalar> >& v,
357  std::vector<Matrix<Scalar> >& vdef,
358  const std::string& v_prefix,
359  const std::string& v_suffix);
360  static Matrix<Scalar> _bilin(const Matrix<Scalar>& A,
361  const Matrix<Scalar>& x,
362  const Matrix<Scalar>& y);
363  static Matrix<Scalar> _rank1(const Matrix<Scalar>& A,
364  const Matrix<Scalar>& alpha,
365  const Matrix<Scalar>& x,
366  const Matrix<Scalar>& y);
367  static Matrix<Scalar> if_else(const Matrix<Scalar> &x,
368  const Matrix<Scalar> &if_true,
369  const Matrix<Scalar> &if_false,
370  bool short_circuit=false);
371  static Matrix<Scalar> conditional(const Matrix<Scalar> &ind,
372  const std::vector<Matrix<Scalar> > &x,
373  const Matrix<Scalar> &x_default,
374  bool short_circuit=false);
375  static bool depends_on(const Matrix<Scalar> &x, const Matrix<Scalar> &arg);
376  static bool contains(const std::vector<Matrix<Scalar> >& v, const Matrix<Scalar> &n);
377  static bool contains_all(const std::vector<Matrix<Scalar> >& v,
378  const std::vector<Matrix<Scalar> > &n);
379  static bool contains_any(const std::vector<Matrix<Scalar> >& v,
380  const std::vector<Matrix<Scalar> > &n);
381 
382  static Matrix<Scalar> mrdivide(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
383  static Matrix<Scalar> mldivide(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
384  static std::vector<Matrix<Scalar> > symvar(const Matrix<Scalar> &x);
385  static Matrix<Scalar> det(const Matrix<Scalar> &x);
386  static Matrix<Scalar> det(const Matrix<Scalar> &x, const std::string& lsolver,
387  const Dict& dict=Dict());
388  static Matrix<Scalar> inv_minor(const Matrix<Scalar> &x);
389  static Matrix<Scalar> trace(const Matrix<Scalar> &x);
390  static Matrix<Scalar> norm_1(const Matrix<Scalar> &x);
391  static Matrix<Scalar> norm_2(const Matrix<Scalar> &x);
392  static Matrix<Scalar> norm_fro(const Matrix<Scalar> &x);
393  static Matrix<Scalar> norm_inf(const Matrix<Scalar> &x);
394  static Matrix<Scalar> sum2(const Matrix<Scalar> &x);
395  static Matrix<Scalar> sum1(const Matrix<Scalar> &x);
396  static Matrix<Scalar> dot(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
397  static Matrix<Scalar> nullspace(const Matrix<Scalar> &x);
398  static Matrix<Scalar> diag(const Matrix<Scalar> &x);
399  static Matrix<Scalar> unite(const Matrix<Scalar> &A, const Matrix<Scalar>& B);
400  static Matrix<Scalar> project(const Matrix<Scalar> &x,
401  const Sparsity& sp, bool intersect=false);
402  static Matrix<Scalar> polyval(const Matrix<Scalar> &p, const Matrix<Scalar>& x);
403  static Matrix<Scalar> densify(const Matrix<Scalar> &x, const Matrix<Scalar>& val);
404  static Matrix<Scalar> densify(const Matrix<Scalar> &x);
405  static Matrix<Scalar> einstein(const Matrix<Scalar>& A, const Matrix<Scalar>& B,
406  const Matrix<Scalar>& C,
407  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
408  const std::vector<casadi_int>& dim_c,
409  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
410  const std::vector<casadi_int>& c);
411 
412  static Matrix<Scalar> einstein(const Matrix<Scalar>& A, const Matrix<Scalar>& B,
413  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
414  const std::vector<casadi_int>& dim_c,
415  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
416  const std::vector<casadi_int>& c);
417  static Matrix<Scalar> cumsum(const Matrix<Scalar> &x, casadi_int axis=-1);
418  static Matrix<Scalar> _logsumexp(const Matrix<Scalar>& x);
419  static std::vector< Matrix<Scalar> > cse(const std::vector< Matrix<Scalar> >& e);
421 
424  static Matrix<Scalar> blockcat(const std::vector< std::vector<Matrix<Scalar> > > &v);
425  static Matrix<Scalar> horzcat(const std::vector<Matrix<Scalar> > &v);
426  static std::vector<Matrix<Scalar> >
427  horzsplit(const Matrix<Scalar>& x,
428  const std::vector<casadi_int>& offset);
429  static Matrix<Scalar> vertcat(const std::vector<Matrix<Scalar> > &v);
430  static std::vector< Matrix<Scalar> >
431  vertsplit(const Matrix<Scalar>& x,
432  const std::vector<casadi_int>& offset);
433  static std::vector< Matrix<Scalar> >
434  diagsplit(const Matrix<Scalar>& x,
435  const std::vector<casadi_int>& offset1,
436  const std::vector<casadi_int>& offset2);
437  static Matrix<Scalar> reshape(const Matrix<Scalar> &x, casadi_int nrow, casadi_int ncol);
438  static Matrix<Scalar> reshape(const Matrix<Scalar> &x, const Sparsity& sp);
439  static Matrix<Scalar> sparsity_cast(const Matrix<Scalar> &x, const Sparsity& sp);
440  static Matrix<Scalar> kron(const Matrix<Scalar> &x, const Matrix<Scalar>& y);
441  static Matrix<Scalar> mtimes(const Matrix<Scalar> &x, const Matrix<Scalar> &y,
442  const std::string& blas = "reference");
443  static Matrix<Scalar> mac(const Matrix<Scalar> &x,
444  const Matrix<Scalar> &y,
445  const Matrix<Scalar> &z,
446  const std::string& blas = "reference");
447  static void extract_parametric(const Matrix<Scalar> &expr,
448  const Matrix<Scalar>& par,
449  Matrix<Scalar>& expr_ret,
450  std::vector<Matrix<Scalar> >& symbols,
451  std::vector<Matrix<Scalar>>& parametric,
452  const Dict& opts);
453  static void separate_linear(const Matrix<Scalar> &expr,
454  const Matrix<Scalar> &sym_lin, const Matrix<Scalar> &sym_const,
455  Matrix<Scalar>& expr_const, Matrix<Scalar>& expr_lin, Matrix<Scalar>& expr_nonlin);
457 
460  static Matrix<Scalar> sparsify(const Matrix<Scalar> &x, double tol=0);
461  static void expand(const Matrix<Scalar>& x,
462  Matrix<Scalar>& weights,
463  Matrix<Scalar>& terms);
464  static Matrix<Scalar> pw_const(const Matrix<Scalar> &t,
465  const Matrix<Scalar> &tval, const Matrix<Scalar> &val);
466  static Matrix<Scalar> pw_lin(const Matrix<Scalar> &t,
467  const Matrix<Scalar> &tval, const Matrix<Scalar> &val);
468  static Matrix<Scalar> heaviside(const Matrix<Scalar> &x);
469  static Matrix<Scalar> rectangle(const Matrix<Scalar> &x);
470  static Matrix<Scalar> triangle(const Matrix<Scalar> &x);
471  static Matrix<Scalar> ramp(const Matrix<Scalar> &x);
472  static Matrix<Scalar> gauss_quadrature(const Matrix<Scalar> &f,
473  const Matrix<Scalar> &x, const Matrix<Scalar> &a,
474  const Matrix<Scalar> &b, casadi_int order=5);
475  static Matrix<Scalar> gauss_quadrature(const Matrix<Scalar> &f,
476  const Matrix<Scalar> &x, const Matrix<Scalar> &a,
477  const Matrix<Scalar> &b, casadi_int order,
478  const Matrix<Scalar>& w);
479  static std::vector<std::vector<Matrix<Scalar> > >
480  forward(const std::vector<Matrix<Scalar> > &ex,
481  const std::vector<Matrix<Scalar> > &arg,
482  const std::vector<std::vector<Matrix<Scalar> > > &v,
483  const Dict& opts = Dict());
484  static std::vector<std::vector<Matrix<Scalar> > >
485  reverse(const std::vector<Matrix<Scalar> > &ex,
486  const std::vector<Matrix<Scalar> > &arg,
487  const std::vector<std::vector<Matrix<Scalar> > > &v,
488  const Dict& opts = Dict());
489  static std::vector<bool> which_depends(const Matrix<Scalar> &expr, const Matrix<Scalar> &var,
490  casadi_int order=1, bool tr=false);
491  static Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
492  const Matrix<Scalar>& a, casadi_int order);
493  static Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
494  const Matrix<Scalar>& a, casadi_int order);
495  static Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex,
496  const Matrix<Scalar>& x, const Matrix<Scalar>& a,
497  casadi_int order,
498  const std::vector<casadi_int>& order_contributions);
499  static Matrix<Scalar> poly_coeff(const Matrix<Scalar>& ex, const Matrix<Scalar>&x);
500  static Matrix<Scalar> poly_roots(const Matrix<Scalar>& p);
501  static Matrix<Scalar> eig_symbolic(const Matrix<Scalar>& m);
502  static Matrix<double> evalf(const Matrix<Scalar>& m);
503  static void qr_sparse(const Matrix<Scalar>& A, Matrix<Scalar>& V, Matrix<Scalar>& R,
504  Matrix<Scalar>& beta, std::vector<casadi_int>& prinv,
505  std::vector<casadi_int>& pc, bool amd=true);
506  static Matrix<Scalar> qr_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& v,
507  const Matrix<Scalar>& r, const Matrix<Scalar>& beta,
508  const std::vector<casadi_int>& prinv,
509  const std::vector<casadi_int>& pc, bool tr=false);
510  static void qr(const Matrix<Scalar>& A, Matrix<Scalar>& Q, Matrix<Scalar>& R);
511  static void ldl(const Matrix<Scalar>& A, Matrix<Scalar>& D, Matrix<Scalar>& LT,
512  std::vector<casadi_int>& p, bool amd=true);
513  static Matrix<Scalar> ldl_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& D,
514  const Matrix<Scalar>& LT, const std::vector<casadi_int>& p);
515  static Matrix<Scalar> all(const Matrix<Scalar>& x);
516  static Matrix<Scalar> any(const Matrix<Scalar>& x);
517  static Matrix<Scalar> adj(const Matrix<Scalar>& x);
518  static Matrix<Scalar> minor(const Matrix<Scalar>& x, casadi_int i, casadi_int j);
519  static Matrix<Scalar> cofactor(const Matrix<Scalar>& A, casadi_int i, casadi_int j);
520  static Matrix<Scalar> chol(const Matrix<Scalar>& A);
521  static Matrix<Scalar> norm_inf_mul(const Matrix<Scalar>& x, const Matrix<Scalar> &y);
522  static Matrix<Scalar> diagcat(const std::vector< Matrix<Scalar> > &A);
524 
525  // Simplification with reference counting awareness
526  static bool simplify_ref_count(std::vector< Matrix<Scalar> >& arg,
527  std::vector< Matrix<Scalar> >& res,
528  const Dict& opts = Dict());
529 
530  // Simplification with constant folding
531  static bool simplify_const_folding(std::vector< Matrix<Scalar> >& arg,
532  std::vector< Matrix<Scalar> >& res,
533  const Dict& opts = Dict());
534 
535  // Simplification by combining like terms in linear combinations
536  static bool simplify_combine_terms(std::vector< Matrix<Scalar> >& arg,
537  std::vector< Matrix<Scalar> >& res,
538  const Dict& opts = Dict());
539 
541 #endif // SWIG
542 
544 
546  Matrix<Scalar> T() const;
547 
548 #if !defined(SWIG) || defined(DOXYGEN)
556  friend inline Matrix<Scalar> adj(const Matrix<Scalar>& A) {
557  return Matrix<Scalar>::adj(A);
558  }
559 
563  friend inline Matrix<Scalar> minor(const Matrix<Scalar> &x, casadi_int i, casadi_int j) {
564  return Matrix<Scalar>::minor(x, i, j);
565  }
566 
570  friend inline Matrix<Scalar> cofactor(const Matrix<Scalar> &x, casadi_int i, casadi_int j) {
571  return Matrix<Scalar>::cofactor(x, i, j);
572  }
573 
582  friend inline void qr(const Matrix<Scalar>& A, Matrix<Scalar>& Q, Matrix<Scalar>& R) {
583  return Matrix<Scalar>::qr(A, Q, R);
584  }
585 
591  friend inline void qr_sparse(const Matrix<Scalar>& A, Matrix<Scalar>& V, Matrix<Scalar>& R,
592  Matrix<Scalar>& beta, std::vector<casadi_int>& prinv,
593  std::vector<casadi_int>& pc, bool amd=true) {
594  return Matrix<Scalar>::qr_sparse(A, V, R, beta, prinv, pc, amd);
595  }
596 
600  friend inline Matrix<Scalar>
602  const Matrix<Scalar>& r, const Matrix<Scalar>& beta,
603  const std::vector<casadi_int>& prinv,
604  const std::vector<casadi_int>& pc, bool tr=false) {
605  return Matrix<Scalar>::qr_solve(b, v, r, beta, prinv, pc, tr);
606  }
607 
614  friend inline Matrix<Scalar> chol(const Matrix<Scalar>& A) {
615  return Matrix<Scalar>::chol(A);
616  }
617 
625  friend inline void ldl(const Matrix<Scalar>& A, Matrix<Scalar>& D, Matrix<Scalar>& LT,
626  std::vector<casadi_int>& p, bool amd=true) {
627  return Matrix<Scalar>::ldl(A, D, LT, p, amd);
628  }
629 
633  friend inline Matrix<Scalar>
634  ldl_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& D, const Matrix<Scalar>& LT,
635  const std::vector<casadi_int>& p) {
636  return Matrix<Scalar>::ldl_solve(b, D, LT, p);
637  }
638 
642  friend inline Matrix<Scalar> any(const Matrix<Scalar> &x) {
643  return Matrix<Scalar>::any(x);
644  }
645 
649  friend inline Matrix<Scalar> all(const Matrix<Scalar> &x) {
650  return Matrix<Scalar>::all(x);
651  }
652 
656  friend inline Matrix<Scalar>
658  return Matrix<Scalar>::norm_inf_mul(x, y);
659  }
660 
664  friend inline Matrix<Scalar>
665  sparsify(const Matrix<Scalar>& A, double tol=0) {
666  return Matrix<Scalar>::sparsify(A, tol);
667  }
668 
672  friend inline void expand(const Matrix<Scalar>& ex, Matrix<Scalar> &weights,
673  Matrix<Scalar>& terms) {
674  Matrix<Scalar>::expand(ex, weights, terms);
675  }
676 
687  friend inline Matrix<Scalar> pw_const(const Matrix<Scalar> &t,
688  const Matrix<Scalar> &tval,
689  const Matrix<Scalar> &val) {
690  return Matrix<Scalar>::pw_const(t, tval, val);
691  }
692 
703  friend inline Matrix<Scalar>
704  pw_lin(const Matrix<Scalar> &t, const Matrix<Scalar> &tval,
705  const Matrix<Scalar> &val) {
706  return Matrix<Scalar>::pw_lin(t, tval, val);
707  }
708 
720  friend inline Matrix<Scalar> heaviside(const Matrix<Scalar> &x) {
721  return Matrix<Scalar>::heaviside(x);
722  }
723 
737  friend inline Matrix<Scalar> rectangle(const Matrix<Scalar> &x) {
738  return Matrix<Scalar>::rectangle(x);
739  }
740 
752  friend inline Matrix<Scalar> triangle(const Matrix<Scalar> &x) {
753  return Matrix<Scalar>::triangle(x);
754  }
755 
769  friend inline Matrix<Scalar> ramp(const Matrix<Scalar> &x) {
770  return Matrix<Scalar>::ramp(x);
771  }
772 
774 
777  friend inline Matrix<Scalar>
779  const Matrix<Scalar> &a, const Matrix<Scalar> &b,
780  casadi_int order=5) {
781  return Matrix<Scalar>::gauss_quadrature(f, x, a, b, order);
782  }
783  friend inline Matrix<Scalar>
785  const Matrix<Scalar> &a, const Matrix<Scalar> &b,
786  casadi_int order, const Matrix<Scalar>& w) {
787  return Matrix<Scalar>::gauss_quadrature(f, x, a, b, order, w);
788  }
790 
792 
812  friend inline Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
813  const Matrix<Scalar>& a, casadi_int order=1) {
814  return Matrix<Scalar>::taylor(ex, x, a, order);
815  }
816  friend inline Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x) {
817  return Matrix<Scalar>::taylor(ex, x, 0, 1);
818  }
820 
829  friend inline Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
830  const Matrix<Scalar>& a, casadi_int order=1) {
831  return Matrix<Scalar>::mtaylor(ex, x, a, order);
832  }
833 
861  friend inline Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
862  const Matrix<Scalar>& a, casadi_int order,
863  const std::vector<casadi_int>& order_contributions) {
864  return Matrix<Scalar>::mtaylor(ex, x, a, order, order_contributions);
865  }
866 
873  friend inline Matrix<Scalar> poly_coeff(const Matrix<Scalar>& f,
874  const Matrix<Scalar>& x) {
875  return Matrix<Scalar>::poly_coeff(f, x);
876  }
877 
884  friend inline Matrix<Scalar> poly_roots(const Matrix<Scalar>& p) {
885  return Matrix<Scalar>::poly_roots(p);
886  }
887 
893  friend inline Matrix<Scalar> eig_symbolic(const Matrix<Scalar>& m) {
895  }
896 
897 
903  inline friend Matrix<double> evalf(const Matrix<Scalar>& expr) {
904  return Matrix<Scalar>::evalf(expr);
905  }
907 #endif
908 
912  static void set_max_depth(casadi_int eq_depth=1);
913 
917  static casadi_int get_max_depth();
918 
922  static std::vector<Matrix<Scalar> > get_input(const Function& f);
923 
927  static std::vector<Matrix<Scalar> > get_free(const Function& f);
928 
930  static std::string type_name();
931 
933  void print_split(std::vector<std::string>& SWIG_OUTPUT(nz),
934  std::vector<std::string>& SWIG_OUTPUT(inter)) const;
935 
937  void disp(std::ostream& stream, bool more=false) const;
938 
940  std::string get_str(bool more=false) const;
941 
943  void print_scalar(std::ostream &stream) const;
944 
946  void print_vector(std::ostream &stream, bool truncate=true) const;
947 
949  void print_dense(std::ostream &stream, bool truncate=true) const;
950 
952  void print_sparse(std::ostream &stream, bool truncate=true) const;
953 
954 #ifndef SWIG
956  static void print_default(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
957  bool truncate=true);
958 
960  static void print_scalar(std::ostream &stream, const Scalar& e);
961 
963  static void print_vector(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
964  bool truncate=true);
965 
967  static void print_canonical(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
968  bool truncate=true);
969 
971  static void print_sparse(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
972  bool truncate=true);
973 
975  static void print_split(casadi_int nnz, const Scalar* nonzeros, std::vector<std::string>& nz,
976  std::vector<std::string>& inter);
977 
979  static void print_dense(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
980  bool truncate=true);
981 #endif
982 
983  void clear();
984  void resize(casadi_int nrow, casadi_int ncol);
985  void reserve(casadi_int nnz);
986  void reserve(casadi_int nnz, casadi_int ncol);
987 
993  void erase(const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
994  bool ind1=false);
995 
1001  void erase(const std::vector<casadi_int>& rr, bool ind1=false);
1002 
1008  void remove(const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc);
1009 
1016  void enlarge(casadi_int nrow, casadi_int ncol,
1017  const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
1018  bool ind1=false);
1019 
1020 #ifndef SWIG
1023  std::vector<Scalar>& nonzeros();
1024  const std::vector<Scalar>& nonzeros() const;
1026 
1029  Scalar* ptr();
1030  const Scalar* ptr() const;
1031  friend inline Scalar* get_ptr(Matrix<Scalar>& v) { return v.ptr(); }
1032  friend inline const Scalar* get_ptr(const Matrix<Scalar>& v) { return v.ptr(); }
1034 
1036  const Sparsity& sparsity() const;
1037 
1038 #endif // SWIG
1039 
1044 
1048  Matrix<Scalar> get_output(casadi_int oind) const;
1049 
1056  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
1057  const std::vector<casadi_int>& col,
1058  const Matrix<Scalar>& d);
1059  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
1060  const std::vector<casadi_int>& col,
1061  const Matrix<Scalar>& d, casadi_int nrow, casadi_int ncol);
1062  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
1063  const std::vector<casadi_int>& col,
1064  const Matrix<Scalar>& d,
1065  const std::pair<casadi_int, casadi_int>& rc);
1067 
1069 
1072  static Matrix<Scalar> inf(const Sparsity& sp);
1073  static Matrix<Scalar> inf(casadi_int nrow=1, casadi_int ncol=1);
1074  static Matrix<Scalar> inf(const std::pair<casadi_int, casadi_int>& rc);
1076 
1078 
1081  static Matrix<Scalar> nan(const Sparsity& sp);
1082  static Matrix<Scalar> nan(casadi_int nrow=1, casadi_int ncol=1);
1083  static Matrix<Scalar> nan(const std::pair<casadi_int, casadi_int>& rc);
1085 
1089  static Matrix<Scalar> eye(casadi_int n);
1090 
1096  casadi_int element_hash() const;
1097 
1099  bool is_regular() const;
1100 
1104  bool is_smooth() const;
1105 
1111  bool is_leaf() const;
1112 
1118  bool is_commutative() const;
1119 
1134  bool is_symbolic() const;
1135 
1147  bool is_valid_input() const;
1148 
1150 
1158  bool has_duplicates() const;
1159 
1163  void reset_input() const;
1165 
1169  bool is_constant() const;
1170 
1174  bool is_call() const;
1175 
1179  bool is_output() const;
1180 
1184  bool has_output() const;
1185 
1189  casadi_int which_output() const;
1190 
1195 
1201  bool is_integer() const;
1202 
1206  bool is_zero() const;
1207 
1211  bool is_one() const;
1212 
1216  bool is_minus_one() const;
1217 
1221  bool is_half() const;
1222 
1226  bool is_value(double val) const;
1227 
1231  bool is_inf() const;
1232 
1236  bool is_minus_inf() const;
1237 
1243  bool is_nonnegative() const;
1244 
1250  bool is_eye() const;
1251 
1253  casadi_int op() const;
1254 
1256  bool is_op(casadi_int op) const;
1257 
1261  bool has_zeros() const;
1262 
1266  std::vector<Scalar> get_nonzeros() const;
1267 
1271  std::vector<Scalar> get_elements() const;
1272 
1273 #ifndef SWIG
1277  template<typename A>
1278  std::vector<A> get_nonzeros() const;
1279 #endif // SWIG
1280 
1284  explicit operator double() const;
1285 
1289  explicit operator casadi_int() const;
1290 
1291 #ifndef SWIG
1295  template<typename A>
1296  explicit operator std::vector<A>() const;
1297 #endif // SWIG
1298 
1302  std::string name() const;
1303 
1310  Matrix<Scalar> dep(casadi_int ch=0) const;
1311 
1317  casadi_int n_dep() const;
1318 
1319  // @{
1321  static void set_precision(casadi_int precision);
1322  static void set_width(casadi_int width);
1323  static void set_scientific(bool scientific);
1324  // @}
1325 
1326  // @{
1328  static casadi_int get_precision();
1329  static casadi_int get_width();
1330  static bool get_scientific();
1331  // @}
1332 
1334  static void rng(casadi_int seed);
1335 
1337 
1340  static Matrix<Scalar> rand( // NOLINT(runtime/threadsafe_fn)
1341  casadi_int nrow=1,
1342  casadi_int ncol=1);
1343  static Matrix<Scalar> rand(const Sparsity& sp); // NOLINT(runtime/threadsafe_fn)
1344  static Matrix<Scalar> rand( // NOLINT(runtime/threadsafe_fn)
1345  const std::pair<casadi_int, casadi_int>& rc);
1347 
1362  void export_code(const std::string& lang,
1363  std::ostream &stream=casadi::uout(), const Dict& options=Dict()) const;
1364 
1366  Dict info() const;
1367  #ifndef SWIG
1371  void serialize(std::ostream &stream) const;
1372  #endif
1373 
1377  std::string serialize() const;
1378 
1382  static Matrix<Scalar> deserialize(std::istream& stream);
1383 
1387  static Matrix<Scalar> deserialize(const std::string& s);
1388 
1393 
1395 
1396  // @{
1412  void to_file(const std::string& filename, const std::string& format="") const;
1413 #ifndef SWIG
1414  static void to_file(const std::string& filename, const Sparsity& sp,
1415  const Scalar* nonzeros, const std::string& format="");
1416 #endif
1417 
1418  static Matrix<double> from_file(const std::string& filename, const std::string& format_hint="");
1420 
1421 #ifndef SWIG
1423  Matrix(const Sparsity& sp, const Scalar& val, bool dummy);
1424 
1426  Matrix(const Sparsity& sp, const std::vector<Scalar>& d, bool dummy);
1427 
1429  static Matrix<Scalar> _sym(const std::string& name, const Sparsity& sp);
1431 
1432 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
1433  static std::mutex& get_mutex_temp();
1434 #endif //CASADI_WITH_THREADSAFE_SYMBOLICS
1435 
1436  private:
1438  Sparsity sparsity_;
1439 
1441  std::vector<Scalar> nonzeros_;
1442 
1444  static casadi_int stream_precision_;
1445  static casadi_int stream_width_;
1446  static bool stream_scientific_;
1447 
1449  static std::default_random_engine rng_;
1450 
1451 #endif // SWIG
1452  };
1453 
1455  template<typename Scalar>
1456  template<typename A>
1457  std::vector<A> Matrix<Scalar>::get_nonzeros() const {
1458  std::vector<A> ret(nnz());
1459  auto r = ret.begin();
1460  for (auto&& e : nonzeros()) *r++ = static_cast<A>(e);
1461  return ret;
1462  }
1463 
1465  template<typename Scalar>
1466  template<typename A>
1467  Matrix<Scalar>::operator std::vector<A>() const {
1468  // Get sparsity pattern
1469  casadi_int size1 = this->size1(), size2 = this->size2();
1470  const casadi_int *colind = this->colind(), *row = this->row();
1471  // Copy the nonzeros
1472  auto it = nonzeros().begin();
1473  std::vector<A> ret(numel(), 0);
1474  for (casadi_int cc=0; cc<size2; ++cc) {
1475  for (casadi_int el=colind[cc]; el<colind[cc+1]; ++el) {
1476  ret[row[el] + cc*size1] = static_cast<A>(*it++);
1477  }
1478  }
1479  return ret;
1480  }
1481 
1482 } // namespace casadi
1483 
1484 #endif // CASADI_MATRIX_DECL_HPP
Helper class for Serialization.
Function object.
Definition: function.hpp:60
Matrix base class.
Sparse matrix class. SX and DM are specializations.
Definition: matrix_decl.hpp:99
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 all nan
bool has_zeros() const
Check if the matrix has any zero entries which are not structural zeros.
static Matrix< Scalar > deserialize(const std::string &s)
Build Sparsity from serialization.
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)
Remove columns and rows.
bool is_regular() const
Checks if expression does not contain NaN or Inf.
Matrix(double val)
This constructor enables implicit type conversion from a numeric type.
Matrix< Scalar > T() const
Transpose the matrix.
static void set_max_depth(casadi_int eq_depth=1)
Set or reset the depth to which equalities are being checked for simplifications.
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.
void resize(casadi_int nrow, casadi_int ncol)
Sparsity get_sparsity() const
Get an owning reference to the sparsity pattern.
static Matrix< Scalar > deserialize(std::istream &stream)
Build Sparsity from serialization.
casadi_int element_hash() const
Returns a number that is unique for a given symbolic scalar.
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 a submatrix (leaving structural zeros in its 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
bool is_symbolic() const
Check if symbolic (Dense)
Matrix(const Sparsity &sp)
Create a sparse matrix from a sparsity pattern.
static std::vector< Matrix< Scalar > > get_free(const Function &f)
Get free.
Matrix(casadi_int nrow, casadi_int ncol)
Create a sparse matrix with all structural zeros.
static casadi_int get_max_depth()
Get the depth to which equalities are being checked for simplifications.
bool is_call() const
Check if function call.
Matrix< Scalar > operator+() const
bool is_smooth() const
Check if smooth.
static Matrix< Scalar > nan(const Sparsity &sp)
create a matrix with all 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.
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
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.
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.
static Matrix< Scalar > rand(casadi_int nrow=1, casadi_int ncol=1)
Create a matrix with uniformly distributed random numbers.
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 a submatrix (leaving structural zeros in its place)
static Matrix< Scalar > inf(casadi_int nrow=1, casadi_int ncol=1)
create a matrix with all inf
bool is_output() const
Check if evaluation output.
std::vector< Scalar > get_elements() const
Get all 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.
Matrix(const std::vector< std::vector< double > > &m)
Dense matrix constructor with data given as vector of vectors.
static std::vector< Matrix< Scalar > > get_input(const Function &f)
Get function input.
Matrix< Scalar > dep(casadi_int ch=0) const
Get expressions of the children of the 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 all inf
static Matrix< double > from_file(const std::string &filename, const std::string &format_hint="")
std::string serialize() const
Serialize.
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.
static Matrix< Scalar > deserialize(DeserializingStream &s)
bool is_constant() const
Check if the matrix is constant (note that false negative answers are possible)
bool is_nonnegative() const
check if the matrix is not negative
Matrix(const std::vector< A > &x)
Create an expression from a vector.
bool has_output() const
Check if a multiple output node.
void reserve(casadi_int nnz)
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)
Construct matrix with a given sparsity and nonzeros.
static Matrix< Scalar > rand(const std::pair< casadi_int, casadi_int > &rc)
Create a matrix with uniformly distributed random numbers.
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
Get the number of dependencies of a binary SXElem.
static Matrix< Scalar > nan(casadi_int nrow=1, casadi_int ncol=1)
create a matrix with all nan
static Matrix< Scalar > inf(const std::pair< casadi_int, casadi_int > &rc)
create a matrix with all inf
std::string get_str(bool more=false) const
Get string representation.
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
Get name (only if symbolic scalar)
std::vector< Scalar > get_nonzeros() const
Get all nonzeros.
Helper class for Serialization.
General sparsity class.
Definition: sparsity.hpp:106
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)
Get the (i,j) cofactor matrix.
friend Matrix< Scalar > any(const Matrix< Scalar > &x)
Returns true only if any element in the matrix is true.
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.
friend Matrix< Scalar > norm_inf_mul(const Matrix< Scalar > &x, const Matrix< Scalar > &y)
Inf-norm of a Matrix-Matrix product.
friend Matrix< Scalar > eig_symbolic(const Matrix< Scalar > &m)
Attempts to find the eigenvalues of a symbolic matrix.
friend Matrix< double > evalf(const Matrix< Scalar > &expr)
Evaluates the expression numerically.
friend Matrix< Scalar > chol(const Matrix< Scalar > &A)
Obtain a Cholesky factorisation of a matrix.
friend Matrix< Scalar > pw_lin(const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
t a scalar variable (e.g. time)
friend 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.
friend void expand(const Matrix< Scalar > &ex, Matrix< Scalar > &weights, Matrix< Scalar > &terms)
Expand the expression as a weighted sum (with constant weights)
friend Matrix< Scalar > poly_coeff(const Matrix< Scalar > &f, const Matrix< Scalar > &x)
extracts polynomial coefficients from an expression
friend Matrix< Scalar > pw_const(const Matrix< Scalar > &t, const Matrix< Scalar > &tval, const Matrix< Scalar > &val)
Create a piecewise constant function.
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.
friend Matrix< Scalar > taylor(const Matrix< Scalar > &ex, const Matrix< Scalar > &x)
univariate Taylor series expansion
friend Matrix< Scalar > all(const Matrix< Scalar > &x)
Returns true only if every element in the matrix is true.
friend Matrix< Scalar > poly_roots(const Matrix< Scalar > &p)
Attempts to find the roots of a polynomial.
friend void qr(const Matrix< Scalar > &A, Matrix< Scalar > &Q, Matrix< Scalar > &R)
QR factorization using the modified Gram-Schmidt algorithm.
friend Matrix< Scalar > heaviside(const Matrix< Scalar > &x)
Heaviside function.
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 f from a to b using Gaussian quadrature with n points.
friend Matrix< Scalar > rectangle(const Matrix< Scalar > &x)
rectangle function
friend Matrix< Scalar > triangle(const Matrix< Scalar > &x)
triangle function
friend Matrix< Scalar > sparsify(const Matrix< Scalar > &A, double tol=0)
Make a matrix sparse by removing numerical zeros.
friend Matrix< Scalar > ramp(const Matrix< Scalar > &x)
ramp function
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 f from a to b using Gaussian quadrature with n points.
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 using a sparse QR factorization.
friend Matrix< Scalar > adj(const Matrix< Scalar > &A)
Matrix adjoint.
friend Matrix< Scalar > minor(const Matrix< Scalar > &x, casadi_int i, casadi_int j)
Get the (i,j) minor matrix.
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
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.