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> jacobian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
313  const Dict& opts = Dict());
314  static Sparsity jacobian_sparsity(const Matrix<Scalar> &f, const Matrix<Scalar> &x);
315  static Matrix<Scalar> hessian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
316  const Dict& opts = Dict());
317  static Matrix<Scalar> hessian(const Matrix<Scalar> &f, const Matrix<Scalar> &x,
318  Matrix<Scalar>& g, const Dict& opts = Dict());
319  static Matrix<Scalar>
320  substitute(const Matrix<Scalar>& ex,
321  const Matrix<Scalar>& v,
322  const Matrix<Scalar>& vdef);
323  static std::vector<Matrix<Scalar> >
324  substitute(const std::vector<Matrix<Scalar> >& ex,
325  const std::vector<Matrix<Scalar> >& v,
326  const std::vector<Matrix<Scalar> >& vdef);
327  static void substitute_inplace(const std::vector<Matrix<Scalar> >& v,
328  std::vector<Matrix<Scalar> >& vdef,
329  std::vector<Matrix<Scalar> >& ex,
330  bool revers);
331  static Matrix<Scalar> pinv(const Matrix<Scalar> &x);
332  static Matrix<Scalar> pinv(const Matrix<Scalar> &A,
333  const std::string& lsolver, const Dict& opts);
334  static Matrix<Scalar> expm_const(const Matrix<Scalar> &A, const Matrix<Scalar> &t);
335  static Matrix<Scalar> expm(const Matrix<Scalar> &A);
336  static Matrix<Scalar> solve(const Matrix<Scalar> &A, const Matrix<Scalar>& b);
337  static Matrix<Scalar> solve(const Matrix<Scalar> &A, const Matrix<Scalar>& b,
338  const std::string& lsolver, const Dict& opts);
339  static Matrix<Scalar> inv(const Matrix<Scalar> &A);
340  static Matrix<Scalar> inv(const Matrix<Scalar> &A,
341  const std::string& lsolver, const Dict& opts);
342 
343  static casadi_int n_nodes(const Matrix<Scalar> &x);
344  static std::string print_operator(const Matrix<Scalar> &x,
345  const std::vector<std::string>& args);
346  static void extract(std::vector<Matrix<Scalar>>& ex, std::vector<Matrix<Scalar>>& v,
347  std::vector<Matrix<Scalar>>& vdef, const Dict& opts = Dict());
348  static void shared(std::vector<Matrix<Scalar> >& ex,
349  std::vector<Matrix<Scalar> >& v,
350  std::vector<Matrix<Scalar> >& vdef,
351  const std::string& v_prefix,
352  const std::string& v_suffix);
353  static Matrix<Scalar> _bilin(const Matrix<Scalar>& A,
354  const Matrix<Scalar>& x,
355  const Matrix<Scalar>& y);
356  static Matrix<Scalar> _rank1(const Matrix<Scalar>& A,
357  const Matrix<Scalar>& alpha,
358  const Matrix<Scalar>& x,
359  const Matrix<Scalar>& y);
360  static Matrix<Scalar> if_else(const Matrix<Scalar> &x,
361  const Matrix<Scalar> &if_true,
362  const Matrix<Scalar> &if_false,
363  bool short_circuit=false);
364  static Matrix<Scalar> conditional(const Matrix<Scalar> &ind,
365  const std::vector<Matrix<Scalar> > &x,
366  const Matrix<Scalar> &x_default,
367  bool short_circuit=false);
368  static bool depends_on(const Matrix<Scalar> &x, const Matrix<Scalar> &arg);
369  static bool contains(const std::vector<Matrix<Scalar> >& v, const Matrix<Scalar> &n);
370  static bool contains_all(const std::vector<Matrix<Scalar> >& v,
371  const std::vector<Matrix<Scalar> > &n);
372  static bool contains_any(const std::vector<Matrix<Scalar> >& v,
373  const std::vector<Matrix<Scalar> > &n);
374 
375  static Matrix<Scalar> mrdivide(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
376  static Matrix<Scalar> mldivide(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
377  static std::vector<Matrix<Scalar> > symvar(const Matrix<Scalar> &x);
378  static Matrix<Scalar> det(const Matrix<Scalar> &x);
379  static Matrix<Scalar> inv_minor(const Matrix<Scalar> &x);
380  static Matrix<Scalar> trace(const Matrix<Scalar> &x);
381  static Matrix<Scalar> norm_1(const Matrix<Scalar> &x);
382  static Matrix<Scalar> norm_2(const Matrix<Scalar> &x);
383  static Matrix<Scalar> norm_fro(const Matrix<Scalar> &x);
384  static Matrix<Scalar> norm_inf(const Matrix<Scalar> &x);
385  static Matrix<Scalar> sum2(const Matrix<Scalar> &x);
386  static Matrix<Scalar> sum1(const Matrix<Scalar> &x);
387  static Matrix<Scalar> dot(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
388  static Matrix<Scalar> nullspace(const Matrix<Scalar> &x);
389  static Matrix<Scalar> diag(const Matrix<Scalar> &x);
390  static Matrix<Scalar> unite(const Matrix<Scalar> &A, const Matrix<Scalar>& B);
391  static Matrix<Scalar> project(const Matrix<Scalar> &x,
392  const Sparsity& sp, bool intersect=false);
393  static Matrix<Scalar> polyval(const Matrix<Scalar> &p, const Matrix<Scalar>& x);
394  static Matrix<Scalar> densify(const Matrix<Scalar> &x, const Matrix<Scalar>& val);
395  static Matrix<Scalar> densify(const Matrix<Scalar> &x);
396  static Matrix<Scalar> einstein(const Matrix<Scalar>& A, const Matrix<Scalar>& B,
397  const Matrix<Scalar>& C,
398  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
399  const std::vector<casadi_int>& dim_c,
400  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
401  const std::vector<casadi_int>& c);
402 
403  static Matrix<Scalar> einstein(const Matrix<Scalar>& A, const Matrix<Scalar>& B,
404  const std::vector<casadi_int>& dim_a, const std::vector<casadi_int>& dim_b,
405  const std::vector<casadi_int>& dim_c,
406  const std::vector<casadi_int>& a, const std::vector<casadi_int>& b,
407  const std::vector<casadi_int>& c);
408  static Matrix<Scalar> cumsum(const Matrix<Scalar> &x, casadi_int axis=-1);
409  static Matrix<Scalar> _logsumexp(const Matrix<Scalar>& x);
410  static std::vector< Matrix<Scalar> > cse(const std::vector< Matrix<Scalar> >& e);
412 
415  static Matrix<Scalar> blockcat(const std::vector< std::vector<Matrix<Scalar> > > &v);
416  static Matrix<Scalar> horzcat(const std::vector<Matrix<Scalar> > &v);
417  static std::vector<Matrix<Scalar> >
418  horzsplit(const Matrix<Scalar>& x,
419  const std::vector<casadi_int>& offset);
420  static Matrix<Scalar> vertcat(const std::vector<Matrix<Scalar> > &v);
421  static std::vector< Matrix<Scalar> >
422  vertsplit(const Matrix<Scalar>& x,
423  const std::vector<casadi_int>& offset);
424  static std::vector< Matrix<Scalar> >
425  diagsplit(const Matrix<Scalar>& x,
426  const std::vector<casadi_int>& offset1,
427  const std::vector<casadi_int>& offset2);
428  static Matrix<Scalar> reshape(const Matrix<Scalar> &x, casadi_int nrow, casadi_int ncol);
429  static Matrix<Scalar> reshape(const Matrix<Scalar> &x, const Sparsity& sp);
430  static Matrix<Scalar> sparsity_cast(const Matrix<Scalar> &x, const Sparsity& sp);
431  static Matrix<Scalar> kron(const Matrix<Scalar> &x, const Matrix<Scalar>& y);
432  static Matrix<Scalar> mtimes(const Matrix<Scalar> &x, const Matrix<Scalar> &y);
433  static Matrix<Scalar> mac(const Matrix<Scalar> &x,
434  const Matrix<Scalar> &y,
435  const Matrix<Scalar> &z);
436  static void extract_parametric(const Matrix<Scalar> &expr,
437  const Matrix<Scalar>& par,
438  Matrix<Scalar>& expr_ret,
439  std::vector<Matrix<Scalar> >& symbols,
440  std::vector<Matrix<Scalar>>& parametric,
441  const Dict& opts);
442  static void separate_linear(const Matrix<Scalar> &expr,
443  const Matrix<Scalar> &sym_lin, const Matrix<Scalar> &sym_const,
444  Matrix<Scalar>& expr_const, Matrix<Scalar>& expr_lin, Matrix<Scalar>& expr_nonlin);
446 
449  static Matrix<Scalar> sparsify(const Matrix<Scalar> &x, double tol=0);
450  static void expand(const Matrix<Scalar>& x,
451  Matrix<Scalar>& weights,
452  Matrix<Scalar>& terms);
453  static Matrix<Scalar> pw_const(const Matrix<Scalar> &t,
454  const Matrix<Scalar> &tval, const Matrix<Scalar> &val);
455  static Matrix<Scalar> pw_lin(const Matrix<Scalar> &t,
456  const Matrix<Scalar> &tval, const Matrix<Scalar> &val);
457  static Matrix<Scalar> heaviside(const Matrix<Scalar> &x);
458  static Matrix<Scalar> rectangle(const Matrix<Scalar> &x);
459  static Matrix<Scalar> triangle(const Matrix<Scalar> &x);
460  static Matrix<Scalar> ramp(const Matrix<Scalar> &x);
461  static Matrix<Scalar> gauss_quadrature(const Matrix<Scalar> &f,
462  const Matrix<Scalar> &x, const Matrix<Scalar> &a,
463  const Matrix<Scalar> &b, casadi_int order=5);
464  static Matrix<Scalar> gauss_quadrature(const Matrix<Scalar> &f,
465  const Matrix<Scalar> &x, const Matrix<Scalar> &a,
466  const Matrix<Scalar> &b, casadi_int order,
467  const Matrix<Scalar>& w);
468  static std::vector<std::vector<Matrix<Scalar> > >
469  forward(const std::vector<Matrix<Scalar> > &ex,
470  const std::vector<Matrix<Scalar> > &arg,
471  const std::vector<std::vector<Matrix<Scalar> > > &v,
472  const Dict& opts = Dict());
473  static std::vector<std::vector<Matrix<Scalar> > >
474  reverse(const std::vector<Matrix<Scalar> > &ex,
475  const std::vector<Matrix<Scalar> > &arg,
476  const std::vector<std::vector<Matrix<Scalar> > > &v,
477  const Dict& opts = Dict());
478  static std::vector<bool> which_depends(const Matrix<Scalar> &expr, const Matrix<Scalar> &var,
479  casadi_int order=1, bool tr=false);
480  static Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
481  const Matrix<Scalar>& a, casadi_int order);
482  static Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
483  const Matrix<Scalar>& a, casadi_int order);
484  static Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex,
485  const Matrix<Scalar>& x, const Matrix<Scalar>& a,
486  casadi_int order,
487  const std::vector<casadi_int>& order_contributions);
488  static Matrix<Scalar> poly_coeff(const Matrix<Scalar>& ex, const Matrix<Scalar>&x);
489  static Matrix<Scalar> poly_roots(const Matrix<Scalar>& p);
490  static Matrix<Scalar> eig_symbolic(const Matrix<Scalar>& m);
491  static Matrix<double> evalf(const Matrix<Scalar>& m);
492  static void qr_sparse(const Matrix<Scalar>& A, Matrix<Scalar>& V, Matrix<Scalar>& R,
493  Matrix<Scalar>& beta, std::vector<casadi_int>& prinv,
494  std::vector<casadi_int>& pc, bool amd=true);
495  static Matrix<Scalar> qr_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& v,
496  const Matrix<Scalar>& r, const Matrix<Scalar>& beta,
497  const std::vector<casadi_int>& prinv,
498  const std::vector<casadi_int>& pc, bool tr=false);
499  static void qr(const Matrix<Scalar>& A, Matrix<Scalar>& Q, Matrix<Scalar>& R);
500  static void ldl(const Matrix<Scalar>& A, Matrix<Scalar>& D, Matrix<Scalar>& LT,
501  std::vector<casadi_int>& p, bool amd=true);
502  static Matrix<Scalar> ldl_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& D,
503  const Matrix<Scalar>& LT, const std::vector<casadi_int>& p);
504  static Matrix<Scalar> all(const Matrix<Scalar>& x);
505  static Matrix<Scalar> any(const Matrix<Scalar>& x);
506  static Matrix<Scalar> adj(const Matrix<Scalar>& x);
507  static Matrix<Scalar> minor(const Matrix<Scalar>& x, casadi_int i, casadi_int j);
508  static Matrix<Scalar> cofactor(const Matrix<Scalar>& A, casadi_int i, casadi_int j);
509  static Matrix<Scalar> chol(const Matrix<Scalar>& A);
510  static Matrix<Scalar> norm_inf_mul(const Matrix<Scalar>& x, const Matrix<Scalar> &y);
511  static Matrix<Scalar> diagcat(const std::vector< Matrix<Scalar> > &A);
514 #endif // SWIG
515 
517 
519  Matrix<Scalar> T() const;
520 
521 #if !defined(SWIG) || defined(DOXYGEN)
529  friend inline Matrix<Scalar> adj(const Matrix<Scalar>& A) {
530  return Matrix<Scalar>::adj(A);
531  }
532 
536  friend inline Matrix<Scalar> minor(const Matrix<Scalar> &x, casadi_int i, casadi_int j) {
537  return Matrix<Scalar>::minor(x, i, j);
538  }
539 
543  friend inline Matrix<Scalar> cofactor(const Matrix<Scalar> &x, casadi_int i, casadi_int j) {
544  return Matrix<Scalar>::cofactor(x, i, j);
545  }
546 
555  friend inline void qr(const Matrix<Scalar>& A, Matrix<Scalar>& Q, Matrix<Scalar>& R) {
556  return Matrix<Scalar>::qr(A, Q, R);
557  }
558 
564  friend inline void qr_sparse(const Matrix<Scalar>& A, Matrix<Scalar>& V, Matrix<Scalar>& R,
565  Matrix<Scalar>& beta, std::vector<casadi_int>& prinv,
566  std::vector<casadi_int>& pc, bool amd=true) {
567  return Matrix<Scalar>::qr_sparse(A, V, R, beta, prinv, pc, amd);
568  }
569 
573  friend inline Matrix<Scalar>
575  const Matrix<Scalar>& r, const Matrix<Scalar>& beta,
576  const std::vector<casadi_int>& prinv,
577  const std::vector<casadi_int>& pc, bool tr=false) {
578  return Matrix<Scalar>::qr_solve(b, v, r, beta, prinv, pc, tr);
579  }
580 
587  friend inline Matrix<Scalar> chol(const Matrix<Scalar>& A) {
588  return Matrix<Scalar>::chol(A);
589  }
590 
598  friend inline void ldl(const Matrix<Scalar>& A, Matrix<Scalar>& D, Matrix<Scalar>& LT,
599  std::vector<casadi_int>& p, bool amd=true) {
600  return Matrix<Scalar>::ldl(A, D, LT, p, amd);
601  }
602 
606  friend inline Matrix<Scalar>
607  ldl_solve(const Matrix<Scalar>& b, const Matrix<Scalar>& D, const Matrix<Scalar>& LT,
608  const std::vector<casadi_int>& p) {
609  return Matrix<Scalar>::ldl_solve(b, D, LT, p);
610  }
611 
615  friend inline Matrix<Scalar> any(const Matrix<Scalar> &x) {
616  return Matrix<Scalar>::any(x);
617  }
618 
622  friend inline Matrix<Scalar> all(const Matrix<Scalar> &x) {
623  return Matrix<Scalar>::all(x);
624  }
625 
629  friend inline Matrix<Scalar>
631  return Matrix<Scalar>::norm_inf_mul(x, y);
632  }
633 
637  friend inline Matrix<Scalar>
638  sparsify(const Matrix<Scalar>& A, double tol=0) {
639  return Matrix<Scalar>::sparsify(A, tol);
640  }
641 
645  friend inline void expand(const Matrix<Scalar>& ex, Matrix<Scalar> &weights,
646  Matrix<Scalar>& terms) {
647  Matrix<Scalar>::expand(ex, weights, terms);
648  }
649 
660  friend inline Matrix<Scalar> pw_const(const Matrix<Scalar> &t,
661  const Matrix<Scalar> &tval,
662  const Matrix<Scalar> &val) {
663  return Matrix<Scalar>::pw_const(t, tval, val);
664  }
665 
676  friend inline Matrix<Scalar>
677  pw_lin(const Matrix<Scalar> &t, const Matrix<Scalar> &tval,
678  const Matrix<Scalar> &val) {
679  return Matrix<Scalar>::pw_lin(t, tval, val);
680  }
681 
693  friend inline Matrix<Scalar> heaviside(const Matrix<Scalar> &x) {
694  return Matrix<Scalar>::heaviside(x);
695  }
696 
710  friend inline Matrix<Scalar> rectangle(const Matrix<Scalar> &x) {
711  return Matrix<Scalar>::rectangle(x);
712  }
713 
725  friend inline Matrix<Scalar> triangle(const Matrix<Scalar> &x) {
726  return Matrix<Scalar>::triangle(x);
727  }
728 
742  friend inline Matrix<Scalar> ramp(const Matrix<Scalar> &x) {
743  return Matrix<Scalar>::ramp(x);
744  }
745 
747 
750  friend inline Matrix<Scalar>
752  const Matrix<Scalar> &a, const Matrix<Scalar> &b,
753  casadi_int order=5) {
754  return Matrix<Scalar>::gauss_quadrature(f, x, a, b, order);
755  }
756  friend inline Matrix<Scalar>
758  const Matrix<Scalar> &a, const Matrix<Scalar> &b,
759  casadi_int order, const Matrix<Scalar>& w) {
760  return Matrix<Scalar>::gauss_quadrature(f, x, a, b, order, w);
761  }
763 
765 
785  friend inline Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
786  const Matrix<Scalar>& a, casadi_int order=1) {
787  return Matrix<Scalar>::taylor(ex, x, a, order);
788  }
789  friend inline Matrix<Scalar> taylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x) {
790  return Matrix<Scalar>::taylor(ex, x, 0, 1);
791  }
793 
802  friend inline Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
803  const Matrix<Scalar>& a, casadi_int order=1) {
804  return Matrix<Scalar>::mtaylor(ex, x, a, order);
805  }
806 
834  friend inline Matrix<Scalar> mtaylor(const Matrix<Scalar>& ex, const Matrix<Scalar>& x,
835  const Matrix<Scalar>& a, casadi_int order,
836  const std::vector<casadi_int>& order_contributions) {
837  return Matrix<Scalar>::mtaylor(ex, x, a, order, order_contributions);
838  }
839 
846  friend inline Matrix<Scalar> poly_coeff(const Matrix<Scalar>& f,
847  const Matrix<Scalar>& x) {
848  return Matrix<Scalar>::poly_coeff(f, x);
849  }
850 
857  friend inline Matrix<Scalar> poly_roots(const Matrix<Scalar>& p) {
858  return Matrix<Scalar>::poly_roots(p);
859  }
860 
866  friend inline Matrix<Scalar> eig_symbolic(const Matrix<Scalar>& m) {
868  }
869 
870 
876  inline friend Matrix<double> evalf(const Matrix<Scalar>& expr) {
877  return Matrix<Scalar>::evalf(expr);
878  }
880 #endif
881 
885  static void set_max_depth(casadi_int eq_depth=1);
886 
890  static casadi_int get_max_depth();
891 
895  static std::vector<Matrix<Scalar> > get_input(const Function& f);
896 
900  static std::vector<Matrix<Scalar> > get_free(const Function& f);
901 
903  static std::string type_name();
904 
906  void print_split(std::vector<std::string>& SWIG_OUTPUT(nz),
907  std::vector<std::string>& SWIG_OUTPUT(inter)) const;
908 
910  void disp(std::ostream& stream, bool more=false) const;
911 
913  std::string get_str(bool more=false) const;
914 
916  void print_scalar(std::ostream &stream) const;
917 
919  void print_vector(std::ostream &stream, bool truncate=true) const;
920 
922  void print_dense(std::ostream &stream, bool truncate=true) const;
923 
925  void print_sparse(std::ostream &stream, bool truncate=true) const;
926 
927 #ifndef SWIG
929  static void print_default(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
930  bool truncate=true);
931 
933  static void print_scalar(std::ostream &stream, const Scalar& e);
934 
936  static void print_vector(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
937  bool truncate=true);
938 
940  static void print_sparse(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
941  bool truncate=true);
942 
944  static void print_split(casadi_int nnz, const Scalar* nonzeros, std::vector<std::string>& nz,
945  std::vector<std::string>& inter);
946 
948  static void print_dense(std::ostream &stream, const Sparsity& sp, const Scalar* nonzeros,
949  bool truncate=true);
950 #endif
951 
952  void clear();
953  void resize(casadi_int nrow, casadi_int ncol);
954  void reserve(casadi_int nnz);
955  void reserve(casadi_int nnz, casadi_int ncol);
956 
962  void erase(const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
963  bool ind1=false);
964 
970  void erase(const std::vector<casadi_int>& rr, bool ind1=false);
971 
977  void remove(const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc);
978 
985  void enlarge(casadi_int nrow, casadi_int ncol,
986  const std::vector<casadi_int>& rr, const std::vector<casadi_int>& cc,
987  bool ind1=false);
988 
989 #ifndef SWIG
992  std::vector<Scalar>& nonzeros();
993  const std::vector<Scalar>& nonzeros() const;
995 
998  Scalar* ptr();
999  const Scalar* ptr() const;
1000  friend inline Scalar* get_ptr(Matrix<Scalar>& v) { return v.ptr(); }
1001  friend inline const Scalar* get_ptr(const Matrix<Scalar>& v) { return v.ptr(); }
1003 
1005  const Sparsity& sparsity() const;
1006 
1007 #endif // SWIG
1008 
1013 
1017  Matrix<Scalar> get_output(casadi_int oind) const;
1018 
1025  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
1026  const std::vector<casadi_int>& col,
1027  const Matrix<Scalar>& d);
1028  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
1029  const std::vector<casadi_int>& col,
1030  const Matrix<Scalar>& d, casadi_int nrow, casadi_int ncol);
1031  static Matrix<Scalar> triplet(const std::vector<casadi_int>& row,
1032  const std::vector<casadi_int>& col,
1033  const Matrix<Scalar>& d,
1034  const std::pair<casadi_int, casadi_int>& rc);
1036 
1038 
1041  static Matrix<Scalar> inf(const Sparsity& sp);
1042  static Matrix<Scalar> inf(casadi_int nrow=1, casadi_int ncol=1);
1043  static Matrix<Scalar> inf(const std::pair<casadi_int, casadi_int>& rc);
1045 
1047 
1050  static Matrix<Scalar> nan(const Sparsity& sp);
1051  static Matrix<Scalar> nan(casadi_int nrow=1, casadi_int ncol=1);
1052  static Matrix<Scalar> nan(const std::pair<casadi_int, casadi_int>& rc);
1054 
1058  static Matrix<Scalar> eye(casadi_int n);
1059 
1065  casadi_int element_hash() const;
1066 
1068  bool is_regular() const;
1069 
1073  bool is_smooth() const;
1074 
1080  bool is_leaf() const;
1081 
1087  bool is_commutative() const;
1088 
1103  bool is_symbolic() const;
1104 
1116  bool is_valid_input() const;
1117 
1119 
1127  bool has_duplicates() const;
1128 
1132  void reset_input() const;
1134 
1138  bool is_constant() const;
1139 
1143  bool is_call() const;
1144 
1148  bool is_output() const;
1149 
1153  bool has_output() const;
1154 
1158  casadi_int which_output() const;
1159 
1164 
1170  bool is_integer() const;
1171 
1175  bool is_zero() const;
1176 
1180  bool is_one() const;
1181 
1185  bool is_minus_one() const;
1186 
1192  bool is_eye() const;
1193 
1195  casadi_int op() const;
1196 
1198  bool is_op(casadi_int op) const;
1199 
1203  bool has_zeros() const;
1204 
1208  std::vector<Scalar> get_nonzeros() const;
1209 
1213  std::vector<Scalar> get_elements() const;
1214 
1215 #ifndef SWIG
1219  template<typename A>
1220  std::vector<A> get_nonzeros() const;
1221 #endif // SWIG
1222 
1226  explicit operator double() const;
1227 
1231  explicit operator casadi_int() const;
1232 
1233 #ifndef SWIG
1237  template<typename A>
1238  explicit operator std::vector<A>() const;
1239 #endif // SWIG
1240 
1244  std::string name() const;
1245 
1252  Matrix<Scalar> dep(casadi_int ch=0) const;
1253 
1259  casadi_int n_dep() const;
1260 
1261  // @{
1263  static void set_precision(casadi_int precision);
1264  static void set_width(casadi_int width);
1265  static void set_scientific(bool scientific);
1266  // @}
1267 
1269  static void rng(casadi_int seed);
1270 
1272 
1275  static Matrix<Scalar> rand( // NOLINT(runtime/threadsafe_fn)
1276  casadi_int nrow=1,
1277  casadi_int ncol=1);
1278  static Matrix<Scalar> rand(const Sparsity& sp); // NOLINT(runtime/threadsafe_fn)
1279  static Matrix<Scalar> rand( // NOLINT(runtime/threadsafe_fn)
1280  const std::pair<casadi_int, casadi_int>& rc);
1282 
1297  void export_code(const std::string& lang,
1298  std::ostream &stream=casadi::uout(), const Dict& options=Dict()) const;
1299 
1301  Dict info() const;
1302  #ifndef SWIG
1306  void serialize(std::ostream &stream) const;
1307  #endif
1308 
1312  std::string serialize() const;
1313 
1317  static Matrix<Scalar> deserialize(std::istream& stream);
1318 
1322  static Matrix<Scalar> deserialize(const std::string& s);
1323 
1328 
1330 
1331  // @{
1347  void to_file(const std::string& filename, const std::string& format="") const;
1348 #ifndef SWIG
1349  static void to_file(const std::string& filename, const Sparsity& sp,
1350  const Scalar* nonzeros, const std::string& format="");
1351 #endif
1352 
1353  static Matrix<double> from_file(const std::string& filename, const std::string& format_hint="");
1355 
1356 #ifndef SWIG
1358  Matrix(const Sparsity& sp, const Scalar& val, bool dummy);
1359 
1361  Matrix(const Sparsity& sp, const std::vector<Scalar>& d, bool dummy);
1362 
1364  static Matrix<Scalar> _sym(const std::string& name, const Sparsity& sp);
1366 
1367 #ifdef CASADI_WITH_THREADSAFE_SYMBOLICS
1368  static std::mutex& get_mutex_temp();
1369 #endif //CASADI_WITH_THREADSAFE_SYMBOLICS
1370 
1371  private:
1373  Sparsity sparsity_;
1374 
1376  std::vector<Scalar> nonzeros_;
1377 
1379  static casadi_int stream_precision_;
1380  static casadi_int stream_width_;
1381  static bool stream_scientific_;
1382 
1384  static std::default_random_engine rng_;
1385 
1386 #endif // SWIG
1387  };
1388 
1390  template<typename Scalar>
1391  template<typename A>
1392  std::vector<A> Matrix<Scalar>::get_nonzeros() const {
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  }
1398 
1400  template<typename Scalar>
1401  template<typename A>
1402  Matrix<Scalar>::operator std::vector<A>() const {
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  }
1416 
1417 } // namespace casadi
1418 
1419 #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.
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)
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.
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.
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)
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.