sparsity_interface.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_SPARSITY_INTERFACE_HPP
27 #define CASADI_SPARSITY_INTERFACE_HPP
28 
29 #include "casadi_misc.hpp"
30 
31 namespace casadi {
37  struct CASADI_EXPORT SparsityInterfaceCommon {};
38 
39 #ifndef SWIG
50  template<typename MatType>
52  protected:
53  // Helper functions
54  inline const MatType& self() const { return static_cast<const MatType&>(*this); }
55  inline MatType& self() { return static_cast<MatType&>(*this); }
56  public:
57 
59  static std::vector< std::vector< MatType > >
60  blocksplit(const MatType& x, const std::vector<casadi_int>& vert_offset,
61  const std::vector<casadi_int>& horz_offset);
62  static std::vector< std::vector< MatType > >
63  blocksplit(const MatType& x, casadi_int vert_incr, casadi_int horz_incr);
64  static MatType veccat(const std::vector< MatType >& x);
65  static MatType vec(const MatType& x);
66  static MatType repmat(const MatType& x, casadi_int n, casadi_int m=1);
67  static std::vector<casadi_int> offset(const std::vector< MatType > &v, bool vert=true);
68  static std::vector< MatType > diagsplit(const MatType& x,
69  const std::vector<casadi_int>& output_offset);
70  static std::vector< MatType > diagsplit(const MatType& x, casadi_int incr);
71  static std::vector< MatType > diagsplit(const MatType& x, casadi_int incr1, casadi_int incr2);
72  static MatType mtimes(const std::vector<MatType> &args,
73  const std::string& blas = "reference");
74  static std::vector<MatType > horzsplit(const MatType& x, casadi_int incr);
75  static std::vector<MatType > vertsplit(const MatType& x, casadi_int incr);
76  static std::vector<MatType > horzsplit_n(const MatType& x, casadi_int n);
77  static std::vector<MatType > vertsplit_n(const MatType& x, casadi_int n);
78  static MatType repmat(const MatType &A, const std::pair<casadi_int, casadi_int>& rc) {
79  return MatType::repmat(A, rc.first, rc.second);
80  }
82 
171  inline friend MatType horzcat(const std::vector<MatType> &v) {
172  return MatType::horzcat(v);
173  }
174 
249  inline friend MatType vertcat(const std::vector<MatType> &v) {
250  return MatType::vertcat(v);
251  }
252 
327  inline friend std::vector<MatType >
328  horzsplit(const MatType &x, const std::vector<casadi_int>& offset) {
329  return MatType::horzsplit(x, offset);
330  }
331 
408  inline friend std::vector<MatType > horzsplit(const MatType& x, casadi_int incr=1) {
409  return MatType::horzsplit(x, incr);
410  }
411 
472  inline friend std::vector<MatType > horzsplit_n(const MatType& x, casadi_int n) {
473  return MatType::horzsplit_n(x, n);
474  }
475 
536  inline friend std::vector<MatType >
537  vertsplit(const MatType& x, const std::vector<casadi_int>& offset) {
538  return MatType::vertsplit(x, offset);
539  }
540 
583  inline friend std::vector<casadi_int > offset(const std::vector<MatType> &v, bool vert=true) {
584  return MatType::offset(v, vert);
585  }
586 
663  inline friend std::vector<MatType > vertsplit(const MatType &x, casadi_int incr=1) {
664  return MatType::vertsplit(x, incr);
665  }
666 
717  inline friend std::vector<MatType > vertsplit_n(const MatType& x, casadi_int n) {
718  return MatType::vertsplit_n(x, n);
719  }
720 
778  inline friend MatType blockcat(const std::vector< std::vector<MatType > > &v) {
779  return MatType::blockcat(v);
780  }
781 
813  inline friend MatType
814  blockcat(const MatType &A, const MatType &B, const MatType &C, const MatType &D) {
815  return vertcat(horzcat(A, B), horzcat(C, D));
816  }
817 
869  inline friend std::vector< std::vector< MatType > >
870  blocksplit(const MatType& x,
871  const std::vector<casadi_int>& vert_offset,
872  const std::vector<casadi_int>& horz_offset) {
873  return MatType::blocksplit(x, vert_offset, horz_offset);
874  }
875 
938  inline friend std::vector< std::vector< MatType > >
939  blocksplit(const MatType& x, casadi_int vert_incr=1, casadi_int horz_incr=1) {
940  return MatType::blocksplit(x, vert_incr, horz_incr);
941  }
942 
1005  inline friend MatType diagcat(const std::vector<MatType> &A) {
1006  return MatType::diagcat(A);
1007  }
1008 
1053  friend std::vector< MatType >
1054  diagsplit(const MatType& x,
1055  const std::vector<casadi_int>& output_offset1,
1056  const std::vector<casadi_int>& output_offset2) {
1057  return MatType::diagsplit(x, output_offset1, output_offset2);
1058  }
1059 
1116  inline friend std::vector< MatType >
1117  diagsplit(const MatType& x, const std::vector<casadi_int>& output_offset) {
1118  return MatType::diagsplit(x, output_offset);
1119  }
1120 
1200  inline friend std::vector< MatType >
1201  diagsplit(const MatType& x, casadi_int incr=1) {
1202  return MatType::diagsplit(x, incr);
1203  }
1204 
1241  inline friend std::vector< MatType >
1242  diagsplit(const MatType& x, casadi_int incr1, casadi_int incr2) {
1243  return MatType::diagsplit(x, incr1, incr2);
1244  }
1245 
1287  inline friend MatType veccat(const std::vector< MatType >& x) {
1288  return MatType::veccat(x);
1289  }
1290 
1381  inline friend MatType mtimes(const MatType &x, const MatType &y,
1382  const std::string& blas = "reference") {
1383  return MatType::mtimes(x, y, blas);
1384  }
1385 
1417  inline friend MatType mtimes(const std::vector<MatType> &args,
1418  const std::string& blas = "reference") {
1419  return MatType::mtimes(args, blas);
1420  }
1421 
1488  inline friend MatType
1489  mac(const MatType &x, const MatType &y, const MatType &z,
1490  const std::string& blas = "reference") {
1491  return MatType::mac(x, y, z, blas);
1492  }
1493 
1532  inline friend MatType transpose(const MatType& X) {
1533  return X.T();
1534  }
1535 
1588  inline friend MatType vec(const MatType& x) {
1589  return MatType::vec(x);
1590  }
1591 
1669  inline friend MatType reshape(const MatType& x, casadi_int nrow, casadi_int ncol) {
1670  return MatType::reshape(x, nrow, ncol);
1671  }
1672 
1704  inline friend MatType reshape(const MatType& x, std::pair<casadi_int, casadi_int> rc) {
1705  return MatType::reshape(x, rc.first, rc.second);
1706  }
1707 
1751  inline friend MatType reshape(const MatType& x, const Sparsity& sp) {
1752  return MatType::reshape(x, sp);
1753  }
1754 
1815  inline friend MatType sparsity_cast(const MatType& x, const Sparsity& sp) {
1816  return MatType::sparsity_cast(x, sp);
1817  }
1818 
1869  inline friend casadi_int sprank(const MatType& x) {
1870  return MatType::sprank(x);
1871  }
1872 
1921  inline friend casadi_int norm_0_mul(const MatType &x, const MatType &y) {
1922  return MatType::norm_0_mul(x, y);
1923  }
1924 
1982  inline friend MatType triu(const MatType& x, bool includeDiagonal=true) {
1983  return MatType::triu(x, includeDiagonal);
1984  }
1985 
2036  inline friend MatType tril(const MatType& x, bool includeDiagonal=true) {
2037  return MatType::tril(x, includeDiagonal);
2038  }
2039 
2096  inline friend MatType kron(const MatType& a, const MatType& b) {
2097  return MatType::kron(a, b);
2098  }
2099 
2166  inline friend MatType repmat(const MatType &A, casadi_int n, casadi_int m=1) {
2167  return MatType::repmat(A, n, m);
2168  }
2169 
2196  inline friend MatType repmat(const MatType &A, const std::pair<casadi_int, casadi_int>& rc) {
2197  return MatType::repmat(A, rc);
2198  }
2199 
2205  inline friend MatType horzcat(const MatType &x, const MatType &y) {
2206  return horzcat(std::vector<MatType>{x, y});
2207  }
2208 
2214  inline friend MatType horzcat(const MatType &x, const MatType &y, const MatType &z) {
2215  return horzcat(std::vector<MatType>{x, y, z});
2216  }
2217 
2223  inline friend MatType horzcat(const MatType &x, const MatType &y, const MatType &z,
2224  const MatType &w) {
2225  return horzcat(std::vector<MatType>{x, y, z, w});
2226  }
2227 
2233  inline friend MatType horzcat(const MatType &x, const MatType &y, const MatType &z,
2234  const MatType &w, const MatType &v) {
2235  return horzcat(std::vector<MatType>{x, y, z, w, v});
2236  }
2237 
2243  inline friend MatType horzcat(const MatType &x, const MatType &y, const MatType &z,
2244  const MatType &w, const MatType &v, const MatType &u) {
2245  return horzcat(std::vector<MatType>{x, y, z, w, v, u});
2246  }
2247 
2253  inline friend MatType vertcat(const MatType &x, const MatType &y) {
2254  return vertcat(std::vector<MatType>{x, y});
2255  }
2256 
2262  inline friend MatType vertcat(const MatType &x, const MatType &y, const MatType &z) {
2263  return vertcat(std::vector<MatType>{x, y, z});
2264  }
2265 
2271  inline friend MatType vertcat(const MatType &x, const MatType &y, const MatType &z,
2272  const MatType &w) {
2273  return vertcat(std::vector<MatType>{x, y, z, w});
2274  }
2275 
2281  inline friend MatType vertcat(const MatType &x, const MatType &y, const MatType &z,
2282  const MatType &w, const MatType &v) {
2283  return vertcat(std::vector<MatType>{x, y, z, w, v});
2284  }
2285 
2291  inline friend MatType vertcat(const MatType &x, const MatType &y, const MatType &z,
2292  const MatType &w, const MatType &v, const MatType &u) {
2293  return vertcat(std::vector<MatType>{x, y, z, w, v, u});
2294  }
2295 
2301  inline friend MatType diagcat(const MatType &x, const MatType &y) {
2302  return diagcat(std::vector<MatType>{x, y});
2303  }
2304 
2310  inline friend MatType diagcat(const MatType &x, const MatType &y, const MatType &z) {
2311  return diagcat(std::vector<MatType>{x, y, z});
2312  }
2313 
2319  inline friend MatType diagcat(const MatType &x, const MatType &y, const MatType &z,
2320  const MatType &w) {
2321  return diagcat(std::vector<MatType>{x, y, z, w});
2322  }
2323 
2329  inline friend MatType diagcat(const MatType &x, const MatType &y, const MatType &z,
2330  const MatType &w, const MatType &v) {
2331  return diagcat(std::vector<MatType>{x, y, z, w, v});
2332  }
2333 
2339  inline friend MatType diagcat(const MatType &x, const MatType &y, const MatType &z,
2340  const MatType &w, const MatType &v, const MatType &u) {
2341  return diagcat(std::vector<MatType>{x, y, z, w, v, u});
2342  }
2343 
2394  inline friend MatType sum1(const MatType &x) { return MatType::sum1(x);}
2395 
2439  inline friend MatType sum2(const MatType &x) { return MatType::sum2(x);}
2440 
2490  inline friend MatType sum(const MatType &x) {
2491  if (x.is_vector()) {
2492  if (x.is_column()) {
2493  return MatType::sum1(x);
2494  } else {
2495  return MatType::sum2(x);
2496  }
2497  }
2498  if (x.size1()>x.size2()) {
2499  return MatType::sum2(MatType::sum1(x));
2500  } else {
2501  return MatType::sum1(MatType::sum2(x));
2502  }
2503  }
2504 
2506  };
2507 #endif // SWIG
2508 
2509 #ifndef SWIG
2510  template<typename MatType>
2511  MatType SparsityInterface<MatType>::vec(const MatType& x) {
2512  if (x.size2()==1) return x;
2513  return reshape(x, x.numel(), 1);
2514  }
2515 
2516  template<typename MatType>
2517  MatType SparsityInterface<MatType>::repmat(const MatType& x, casadi_int n, casadi_int m) {
2518  casadi_assert(n>=0 && m>=0,
2519  "repmat(x,n,m): n (" + str(n) + ") and m (" + str(m) + ") must be non-negative");
2520  if (n==1 && m==1) return x;
2521  MatType allrows = vertcat(std::vector<MatType>(n, x));
2522  if (n==0) allrows = MatType(0, x.size2());
2523  MatType ret = horzcat(std::vector<MatType>(m, allrows));
2524  if (m==0) ret = MatType(allrows.size1(), 0);
2525  return ret;
2526  }
2527 
2528  template<typename MatType>
2529  std::vector< std::vector< MatType > >
2531  const std::vector<casadi_int>& vert_offset,
2532  const std::vector<casadi_int>& horz_offset) {
2533  std::vector<MatType> rows = MatType::vertsplit(x, vert_offset);
2534  std::vector< std::vector< MatType > > ret;
2535  for (auto&& r : rows) ret.push_back(MatType::horzsplit(r, horz_offset));
2536  return ret;
2537  }
2538 
2539  template<typename MatType>
2540  std::vector< std::vector< MatType > >
2542  casadi_int vert_incr, casadi_int horz_incr) {
2543  casadi_assert(vert_incr>=1, "blocksplit: vert_incr (" + str(vert_incr) + ") must be positive");
2544  casadi_assert(horz_incr>=1, "blocksplit: horz_incr (" + str(horz_incr) + ") must be positive");
2545  casadi_int sz1 = x.size1();
2546  std::vector<casadi_int> offset1 = range(0, sz1, vert_incr);
2547  offset1.push_back(sz1);
2548  casadi_int sz2 = x.size2();
2549  std::vector<casadi_int> offset2 = range(0, sz2, horz_incr);
2550  offset2.push_back(sz2);
2551  return blocksplit(x, offset1, offset2);
2552  }
2553 
2554  template<typename MatType>
2555  std::vector<casadi_int>
2556  SparsityInterface<MatType>::offset(const std::vector< MatType > &v, bool vert) {
2557  std::vector<casadi_int> ret(v.size()+1);
2558  ret[0]=0;
2559  for (casadi_int i=0; i<v.size(); ++i) {
2560  ret[i+1] = ret[i] + (vert ? v[i].size1() : v[i].size2());
2561  }
2562  return ret;
2563  }
2564 
2565  template<typename MatType>
2566  MatType SparsityInterface<MatType>::veccat(const std::vector< MatType >& x) {
2567  std::vector< MatType > x_vec = x;
2568  for (typename std::vector< MatType >::iterator it=x_vec.begin();
2569  it!=x_vec.end(); ++it) {
2570  *it = vec(*it);
2571  }
2572  if (x_vec.empty()) {
2573  return MatType(0, 1);
2574  } else {
2575  return vertcat(x_vec);
2576  }
2577  }
2578 
2579  template<typename MatType>
2580  std::vector< MatType >
2582  const std::vector<casadi_int>& output_offset) {
2583  casadi_assert(x.is_square(), "diagsplit(x,incr)::input must be square but got "
2584  + x.dim() + ".");
2585  return MatType::diagsplit(x, output_offset, output_offset);
2586  }
2587 
2588  template<typename MatType>
2589  std::vector< MatType >
2590  SparsityInterface<MatType>::diagsplit(const MatType& x, casadi_int incr) {
2591  casadi_assert(incr>=1, "diagsplit(x,incr): incr (" + str(incr) + ") must be positive");
2592  casadi_assert(x.is_square(), "diagsplit(x,incr)::input must be square but got "
2593  + x.dim() + ".");
2594  std::vector<casadi_int> offset2 = range(0, x.size2(), incr);
2595  offset2.push_back(x.size2());
2596  return MatType::diagsplit(x, offset2);
2597  }
2598 
2599  template<typename MatType>
2600  std::vector< MatType >
2601  SparsityInterface<MatType>::diagsplit(const MatType& x, casadi_int incr1, casadi_int incr2) {
2602  casadi_assert(incr1>=1, "diagsplit: incr1 (" + str(incr1) + ") must be positive");
2603  casadi_assert(incr2>=1, "diagsplit: incr2 (" + str(incr2) + ") must be positive");
2604  std::vector<casadi_int> offset1 = range(0, x.size1(), incr1);
2605  offset1.push_back(x.size1());
2606  std::vector<casadi_int> offset2 = range(0, x.size2(), incr2);
2607  offset2.push_back(x.size2());
2608  return MatType::diagsplit(x, offset1, offset2);
2609  }
2610 
2611  template<typename MatType>
2612  MatType SparsityInterface<MatType>::mtimes(const std::vector<MatType> &args,
2613  const std::string& blas) {
2614  casadi_assert(!args.empty(),
2615  "mul(std::vector<MatType> &args): "
2616  "supplied list must not be empty.");
2617  MatType ret = args[0];
2618  for (casadi_int i=1; i<args.size(); ++i) ret = MatType::mtimes(ret, args[i], blas);
2619  return ret;
2620  }
2621 
2622  template<typename MatType>
2623  std::vector<MatType > SparsityInterface<MatType>::horzsplit(const MatType& x, casadi_int incr) {
2624  casadi_assert(incr>=1, "horzsplit(x,incr): incr (" + str(incr) + ") must be positive");
2625  casadi_int sz2 = x.size2();
2626  std::vector<casadi_int> offset2 = range(0, sz2, incr);
2627  offset2.push_back(sz2);
2628  return MatType::horzsplit(x, offset2);
2629  }
2630 
2631  template<typename MatType>
2632  std::vector<MatType > SparsityInterface<MatType>::vertsplit(const MatType& x, casadi_int incr) {
2633  casadi_assert(incr>=1, "vertsplit(x,incr): incr (" + str(incr) + ") must be positive");
2634  casadi_int sz1 = x.size1();
2635  std::vector<casadi_int> offset1 = range(0, sz1, incr);
2636  offset1.push_back(sz1);
2637  return MatType::vertsplit(x, offset1);
2638  }
2639  template<typename MatType>
2640  std::vector<MatType > SparsityInterface<MatType>::horzsplit_n(const MatType& x, casadi_int n) {
2641  casadi_assert(n>=0, "horzsplit_n(x,n): n (" + str(n) + ") must be non-negative");
2642  if (x.size2()==0) return std::vector<MatType>(n, x);
2643  casadi_assert(n>0 && x.size2() % n==0, "horzsplit_n(x,n): x.size2() (" + str(x.size2()) +
2644  ") must be a multiple of n (" + str(n) + ")");
2645  return horzsplit(x, x.size2()/n);
2646  }
2647  template<typename MatType>
2648  std::vector<MatType > SparsityInterface<MatType>::vertsplit_n(const MatType& x, casadi_int n) {
2649  casadi_assert(n>=0, "vertsplit_n(x,n): n (" + str(n) + ") must be non-negative");
2650  if (x.size1()==0) return std::vector<MatType>(n, x);
2651  casadi_assert(n>0 && x.size1() % n==0, "vertsplit_n(x,n): x.size1() (" + str(x.size1()) +
2652  ") must be a multiple of n (" + str(n) + ")");
2653  return vertsplit(x, x.size1()/n);
2654  }
2655 
2656 #endif // SWIG
2657 
2658 } // namespace casadi
2659 
2660 #endif // CASADI_SPARSITY_INTERFACE_HPP
Sparsity interface class.
static std::vector< MatType > horzsplit_n(const MatType &x, casadi_int n)
static std::vector< MatType > vertsplit_n(const MatType &x, casadi_int n)
static MatType veccat(const std::vector< MatType > &x)
static std::vector< casadi_int > offset(const std::vector< MatType > &v, bool vert=true)
static MatType repmat(const MatType &x, casadi_int n, casadi_int m=1)
static std::vector< MatType > diagsplit(const MatType &x, const std::vector< casadi_int > &output_offset)
static std::vector< std::vector< MatType > > blocksplit(const MatType &x, const std::vector< casadi_int > &vert_offset, const std::vector< casadi_int > &horz_offset)
static std::vector< MatType > diagsplit(const MatType &x, casadi_int incr1, casadi_int incr2)
static std::vector< MatType > horzsplit(const MatType &x, casadi_int incr)
static MatType vec(const MatType &x)
static std::vector< std::vector< MatType > > blocksplit(const MatType &x, casadi_int vert_incr, casadi_int horz_incr)
static std::vector< MatType > vertsplit(const MatType &x, casadi_int incr)
static MatType mtimes(const std::vector< MatType > &args, const std::string &blas="reference")
static std::vector< MatType > diagsplit(const MatType &x, casadi_int incr)
static MatType repmat(const MatType &A, const std::pair< casadi_int, casadi_int > &rc)
General sparsity class.
Definition: sparsity.hpp:200
friend std::vector< MatType > vertsplit(const MatType &x, const std::vector< casadi_int > &offset)
Split a matrix vertically into groups of rows.
friend MatType sum1(const MatType &x)
Sum the elements of every column.
friend casadi_int sprank(const MatType &x)
Obtain the structural rank of a sparsity-pattern.
friend std::vector< std::vector< MatType > > blocksplit(const MatType &x, const std::vector< casadi_int > &vert_offset, const std::vector< casadi_int > &horz_offset)
Split a matrix into a grid of blocks.
friend MatType diagcat(const std::vector< MatType > &A)
Construct a block-diagonal matrix from a list of matrices.
friend std::vector< MatType > diagsplit(const MatType &x, const std::vector< casadi_int > &output_offset)
Split a square matrix into square diagonal blocks of given boundaries.
friend MatType diagcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v, const MatType &u)
Concatenate along diagonal, six matrices.
friend MatType diagcat(const MatType &x, const MatType &y)
Concatenate along diagonal, two matrices.
friend MatType horzcat(const MatType &x, const MatType &y, const MatType &z)
Concatenate horizontally, three matrices.
friend MatType kron(const MatType &a, const MatType &b)
Kronecker tensor product.
friend MatType horzcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v, const MatType &u)
Concatenate horizontally, six matrices.
friend MatType horzcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v)
Concatenate horizontally, five matrices.
friend MatType vertcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v, const MatType &u)
Concatenate vertically, six matrices.
friend std::vector< MatType > horzsplit(const MatType &x, casadi_int incr=1)
Split a matrix horizontally into fixed-size groups of columns.
friend MatType diagcat(const MatType &x, const MatType &y, const MatType &z)
Concatenate along diagonal, three matrices.
friend MatType vertcat(const MatType &x, const MatType &y, const MatType &z)
Concatenate vertically, three matrices.
friend MatType vertcat(const std::vector< MatType > &v)
Concatenate a list of matrices vertically.
friend MatType vertcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v)
Concatenate vertically, five matrices.
friend MatType vertcat(const MatType &x, const MatType &y)
Concatenate vertically, two matrices.
friend MatType horzcat(const std::vector< MatType > &v)
Concatenate a list of matrices horizontally.
friend MatType blockcat(const MatType &A, const MatType &B, const MatType &C, const MatType &D)
Construct a matrix from 4 blocks.
friend MatType repmat(const MatType &A, const std::pair< casadi_int, casadi_int > &rc)
Repeat matrix A n times vertically and m times horizontally.
friend MatType vec(const MatType &x)
Reshape a matrix into a column vector.
friend MatType transpose(const MatType &X)
Transpose.
friend std::vector< std::vector< MatType > > blocksplit(const MatType &x, casadi_int vert_incr=1, casadi_int horz_incr=1)
Split a matrix into a grid of fixed-size blocks.
friend MatType tril(const MatType &x, bool includeDiagonal=true)
Get the lower triangular part of a matrix.
friend MatType horzcat(const MatType &x, const MatType &y)
Concatenate horizontally, two matrices.
friend std::vector< MatType > vertsplit(const MatType &x, casadi_int incr=1)
Split a matrix vertically into fixed-size groups of rows.
friend MatType veccat(const std::vector< MatType > &x)
Concatenate vertically after vectorizing every argument.
friend std::vector< MatType > vertsplit_n(const MatType &x, casadi_int n)
Split a matrix vertically into a given number of equal groups of rows.
friend MatType blockcat(const std::vector< std::vector< MatType > > &v)
Construct a matrix from a list of lists of blocks.
friend MatType triu(const MatType &x, bool includeDiagonal=true)
Get the upper triangular part of a matrix.
friend MatType vertcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w)
Concatenate vertically, four matrices.
friend std::vector< MatType > horzsplit_n(const MatType &x, casadi_int n)
Split a matrix horizontally into a given number of equal groups of columns.
friend MatType repmat(const MatType &A, casadi_int n, casadi_int m=1)
Repeat matrix A n times vertically and m times horizontally.
friend MatType diagcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w, const MatType &v)
Concatenate along diagonal, five matrices.
friend MatType mtimes(const std::vector< MatType > &args, const std::string &blas="reference")
Matrix product of n matrices.
friend MatType reshape(const MatType &x, std::pair< casadi_int, casadi_int > rc)
Returns a reshaped version of the matrix, dimensions as a vector.
friend std::vector< MatType > diagsplit(const MatType &x, casadi_int incr=1)
Split a square matrix into square diagonal blocks of fixed size.
friend MatType sum2(const MatType &x)
Sum the elements of every row.
friend MatType diagcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w)
Concatenate along diagonal, four matrices.
friend MatType sum(const MatType &x)
Sum all elements.
friend casadi_int norm_0_mul(const MatType &x, const MatType &y)
0-norm (nonzero count) of a Matrix-matrix product
friend MatType reshape(const MatType &x, casadi_int nrow, casadi_int ncol)
Returns a reshaped version of the matrix.
friend std::vector< MatType > diagsplit(const MatType &x, const std::vector< casadi_int > &output_offset1, const std::vector< casadi_int > &output_offset2)
Split a matrix into diagonal blocks of given row and column boundaries.
friend MatType reshape(const MatType &x, const Sparsity &sp)
Reshape the matrix to a given sparsity pattern.
friend MatType mtimes(const MatType &x, const MatType &y, const std::string &blas="reference")
Matrix product of two matrices.
friend MatType sparsity_cast(const MatType &x, const Sparsity &sp)
Cast matrix nonzeros to different Sparsity.
friend std::vector< casadi_int > offset(const std::vector< MatType > &v, bool vert=true)
Get the block offsets of a list of matrices.
friend std::vector< MatType > horzsplit(const MatType &x, const std::vector< casadi_int > &offset)
Split a matrix horizontally into groups of columns.
friend std::vector< MatType > diagsplit(const MatType &x, casadi_int incr1, casadi_int incr2)
Split a matrix into diagonal blocks of fixed size.
friend MatType horzcat(const MatType &x, const MatType &y, const MatType &z, const MatType &w)
Concatenate horizontally, four matrices.
friend MatType mac(const MatType &x, const MatType &y, const MatType &z, const std::string &blas="reference")
Multiply-accumulate operation.
The casadi namespace.
Definition: archiver.cpp:28
std::vector< casadi_int > range(casadi_int start, casadi_int stop, casadi_int step, casadi_int len)
Range function.
std::string str(const T &v)
String representation, any type.