Reaktoro 
A unified framework for modeling chemically reactive systems
Matrix.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2015 Allan Leal
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 #define EIGEN_MATRIX_PLUGIN "Reaktoro/Math/EigenMatrixPlugin.hpp"
21 
22 // Eigen includes
23 #include <Reaktoro/Math/Eigen/Core>
24 
25 // Reaktoro includes
26 #include <Reaktoro/Common/Index.hpp>
27 
28 namespace Eigen {
29 
30 template<typename Derived, typename Indices>
31 class MatrixRowsView;
32 
33 template<typename Derived, typename Indices>
34 class MatrixRowsViewConst;
35 
36 template<typename Derived, typename Indices>
37 class MatrixColsView;
38 
39 template<typename Derived, typename Indices>
40 class MatrixColsViewConst;
41 
42 template<typename Derived, typename Indices>
43 class MatrixSubView;
44 
45 template<typename Derived, typename Indices>
46 class MatrixSubViewConst;
47 
48 namespace internal {
49 
50 template<typename Derived, typename Indices>
51 struct traits<MatrixRowsView<Derived, Indices>>
52 {
53  typedef Eigen::Dense StorageKind;
54  typedef Eigen::MatrixXpr XprKind;
55  typedef typename Derived::Scalar Scalar;
56  typedef typename Derived::Index Index;
57  enum {
58  Flags = Eigen::ColMajor | EvalBeforeNestingBit | EvalBeforeAssigningBit,
59  RowsAtCompileTime = Derived::RowsAtCompileTime,
60  ColsAtCompileTime = Derived::ColsAtCompileTime,
61  MaxRowsAtCompileTime = Derived::MaxRowsAtCompileTime,
62  MaxColsAtCompileTime = Derived::MaxColsAtCompileTime,
63  CoeffReadCost = Derived::CoeffReadCost
64  };
65 };
66 
67 template<typename Derived, typename Indices>
68 struct traits<MatrixRowsViewConst<Derived, Indices>>
69 {
70  typedef Eigen::Dense StorageKind;
71  typedef Eigen::MatrixXpr XprKind;
72  typedef typename Derived::Scalar Scalar;
73  typedef typename Derived::Index Index;
74  enum {
75  Flags = Eigen::ColMajor | EvalBeforeNestingBit | EvalBeforeAssigningBit,
76  RowsAtCompileTime = Derived::RowsAtCompileTime,
77  ColsAtCompileTime = Derived::ColsAtCompileTime,
78  MaxRowsAtCompileTime = Derived::MaxRowsAtCompileTime,
79  MaxColsAtCompileTime = Derived::MaxColsAtCompileTime,
80  CoeffReadCost = Derived::CoeffReadCost
81  };
82 };
83 
84 template<typename Derived, typename Indices>
85 struct traits<MatrixColsView<Derived, Indices>>
86 {
87  typedef Eigen::Dense StorageKind;
88  typedef Eigen::MatrixXpr XprKind;
89  typedef typename Derived::Scalar Scalar;
90  typedef typename Derived::Index Index;
91  enum {
92  Flags = Eigen::ColMajor | EvalBeforeNestingBit | EvalBeforeAssigningBit,
93  RowsAtCompileTime = Derived::RowsAtCompileTime,
94  ColsAtCompileTime = Derived::ColsAtCompileTime,
95  MaxRowsAtCompileTime = Derived::MaxRowsAtCompileTime,
96  MaxColsAtCompileTime = Derived::MaxColsAtCompileTime,
97  CoeffReadCost = Derived::CoeffReadCost
98  };
99 };
100 
101 template<typename Derived, typename Indices>
102 struct traits<MatrixColsViewConst<Derived, Indices>>
103 {
104  typedef Eigen::Dense StorageKind;
105  typedef Eigen::MatrixXpr XprKind;
106  typedef typename Derived::Scalar Scalar;
107  typedef typename Derived::Index Index;
108  enum {
109  Flags = Eigen::ColMajor | EvalBeforeNestingBit | EvalBeforeAssigningBit,
110  RowsAtCompileTime = Derived::RowsAtCompileTime,
111  ColsAtCompileTime = Derived::ColsAtCompileTime,
112  MaxRowsAtCompileTime = Derived::MaxRowsAtCompileTime,
113  MaxColsAtCompileTime = Derived::MaxColsAtCompileTime,
114  CoeffReadCost = Derived::CoeffReadCost
115  };
116 };
117 
118 template<typename Derived, typename Indices>
119 struct traits<MatrixSubView<Derived, Indices>>
120 {
121  typedef Eigen::Dense StorageKind;
122  typedef Eigen::MatrixXpr XprKind;
123  typedef typename Derived::Scalar Scalar;
124  typedef typename Derived::Index Index;
125  enum {
126  Flags = Eigen::ColMajor | EvalBeforeNestingBit | EvalBeforeAssigningBit,
127  RowsAtCompileTime = Derived::RowsAtCompileTime,
128  ColsAtCompileTime = Derived::ColsAtCompileTime,
129  MaxRowsAtCompileTime = Derived::MaxRowsAtCompileTime,
130  MaxColsAtCompileTime = Derived::MaxColsAtCompileTime,
131  CoeffReadCost = Derived::CoeffReadCost
132  };
133 };
134 
135 template<typename Derived, typename Indices>
136 struct traits<MatrixSubViewConst<Derived, Indices>>
137 {
138  typedef Eigen::Dense StorageKind;
139  typedef Eigen::MatrixXpr XprKind;
140  typedef typename Derived::Scalar Scalar;
141  typedef typename Derived::Index Index;
142  enum {
143  Flags = Eigen::ColMajor | EvalBeforeNestingBit | EvalBeforeAssigningBit,
144  RowsAtCompileTime = Derived::RowsAtCompileTime,
145  ColsAtCompileTime = Derived::ColsAtCompileTime,
146  MaxRowsAtCompileTime = Derived::MaxRowsAtCompileTime,
147  MaxColsAtCompileTime = Derived::MaxColsAtCompileTime,
148  CoeffReadCost = Derived::CoeffReadCost
149  };
150 };
151 
152 } // namespace internal
153 
154 template<typename Derived, typename Indices>
155 class MatrixRowsView : public MatrixBase<MatrixRowsView<Derived, Indices>>
156 {
157 public:
158  typedef MatrixBase<MatrixRowsView> Base;
159  typedef typename Derived::PlainObject PlainObject;
160  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixRowsView)
161 
162  MatrixRowsView(MatrixBase<Derived>& mat, const Indices& irows)
163  : m_mat(mat), m_irows(irows)
164  {}
165 
166  template<typename DerivedOther>
167  auto operator=(const MatrixBase<DerivedOther>& other) -> MatrixRowsView&
168  {
169  for(Index i = 0; i < rows(); ++i)
170  for(Index j = 0; j < cols(); ++j)
171  coeff(i, j) = other(i, j);
172  return *this;
173  }
174 
175  auto rows() const -> Index { return m_irows.size(); }
176  auto cols() const -> Index { return m_mat.cols(); }
177 
178  auto coeff(Index row, Index col) -> Scalar& { return m_mat(m_irows[row], col); }
179  auto coeff(Index row, Index col) const -> Scalar { return m_mat(m_irows[row], col); }
180  auto operator()(Index row, Index col) -> Scalar& { return coeff(row, col); }
181  auto operator()(Index row, Index col) const -> Scalar { return coeff(row, col); }
182 
183  operator PlainObject() const
184  {
185  PlainObject res(rows(), cols());
186  for(Index i = 0; i < rows(); ++i)
187  for(Index j = 0; j < cols(); ++j)
188  res(i, j) = coeff(i, j);
189  return res;
190  }
191 
192 private:
193  MatrixBase<Derived>& m_mat;
194  Indices m_irows;
195 };
196 
197 template<typename Derived, typename Indices>
198 class MatrixRowsViewConst : public MatrixBase<MatrixRowsViewConst<Derived, Indices>>
199 {
200 public:
201  typedef MatrixBase<MatrixRowsViewConst> Base;
202  typedef typename Derived::PlainObject PlainObject;
203  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixRowsViewConst)
204 
205  MatrixRowsViewConst(const MatrixBase<Derived>& mat, const Indices& irows)
206  : m_mat(mat), m_irows(irows)
207  {}
208 
209  auto rows() const -> Index { return m_irows.size(); }
210  auto cols() const -> Index { return m_mat.cols(); }
211 
212  auto coeff(Index row, Index col) const -> Scalar { return m_mat(m_irows[row], col); }
213  auto operator()(Index row, Index col) const -> Scalar { return coeff(row, col); }
214 
215  operator PlainObject() const
216  {
217  PlainObject res(rows(), cols());
218  for(Index i = 0; i < rows(); ++i)
219  for(Index j = 0; j < cols(); ++j)
220  res(i, j) = coeff(i, j);
221  return res;
222  }
223 
224 private:
225  const MatrixBase<Derived>& m_mat;
226  Indices m_irows;
227 };
228 
229 template<typename Derived, typename Indices>
230 class MatrixColsView : public MatrixBase<MatrixColsView<Derived, Indices>>
231 {
232 public:
233  typedef MatrixBase<MatrixColsView> Base;
234  typedef typename Derived::PlainObject PlainObject;
235  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixColsView)
236 
237  MatrixColsView(MatrixBase<Derived>& mat, const Indices& icols)
238  : m_mat(mat), m_icols(icols)
239  {}
240 
241  template<typename DerivedOther>
242  auto operator=(const MatrixBase<DerivedOther>& other) -> MatrixColsView&
243  {
244  for(Index i = 0; i < rows(); ++i)
245  for(Index j = 0; j < cols(); ++j)
246  coeff(i, j) = other(i, j);
247  return *this;
248  }
249 
250  auto rows() const -> Index { return m_mat.rows(); }
251  auto cols() const -> Index { return m_icols.size(); }
252 
253  auto coeff(Index row, Index col) -> Scalar& { return m_mat(row, m_icols[col]); }
254  auto coeff(Index row, Index col) const -> Scalar { return m_mat(row, m_icols[col]); }
255  auto operator()(Index row, Index col) -> Scalar& { return coeff(row, col); }
256  auto operator()(Index row, Index col) const -> Scalar { return coeff(row, col); }
257 
258  operator PlainObject() const
259  {
260  PlainObject res(rows(), cols());
261  for(Index i = 0; i < rows(); ++i)
262  for(Index j = 0; j < cols(); ++j)
263  res(i, j) = coeff(i, j);
264  return res;
265  }
266 
267 private:
268  MatrixBase<Derived>& m_mat;
269  Indices m_icols;
270 };
271 
272 template<typename Derived, typename Indices>
273 class MatrixColsViewConst : public MatrixBase<MatrixColsViewConst<Derived, Indices>>
274 {
275 public:
276  typedef MatrixBase<MatrixColsViewConst> Base;
277  typedef typename Derived::PlainObject PlainObject;
278  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixColsViewConst)
279 
280  MatrixColsViewConst(const MatrixBase<Derived>& mat, const Indices& icols)
281  : m_mat(mat), m_icols(icols)
282  {}
283 
284  auto rows() const -> Index { return m_mat.rows(); }
285  auto cols() const -> Index { return m_icols.size(); }
286 
287  auto coeff(Index row, Index col) const -> Scalar { return m_mat(row, m_icols[col]); }
288  auto operator()(Index row, Index col) const -> Scalar { return coeff(row, col); }
289 
290  operator PlainObject() const
291  {
292  PlainObject res(rows(), cols());
293  for(Index i = 0; i < rows(); ++i)
294  for(Index j = 0; j < cols(); ++j)
295  res(i, j) = coeff(i, j);
296  return res;
297  }
298 
299 private:
300  const MatrixBase<Derived>& m_mat;
301  Indices m_icols;
302 };
303 
304 template<typename Derived, typename Indices>
305 class MatrixSubView : public MatrixBase<MatrixSubView<Derived, Indices>>
306 {
307 public:
308  typedef MatrixBase<MatrixSubView> Base;
309  typedef typename Derived::PlainObject PlainObject;
310  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixSubView)
311 
312  MatrixSubView(MatrixBase<Derived>& mat, const Indices& irows, const Indices& icols)
313  : m_mat(mat), m_irows(irows), m_icols(icols)
314  {}
315 
316  template<typename DerivedOther>
317  auto operator=(const MatrixBase<DerivedOther>& other) -> MatrixSubView&
318  {
319  for(Index i = 0; i < rows(); ++i)
320  for(Index j = 0; j < cols(); ++j)
321  coeff(i, j) = other(i, j);
322  return *this;
323  }
324 
325  auto rows() const -> Index { return m_irows.size(); }
326  auto cols() const -> Index { return m_icols.size(); }
327 
328  auto coeff(Index row, Index col) -> Scalar& { return m_mat(m_irows[row], m_icols[col]); }
329  auto coeff(Index row, Index col) const -> Scalar { return m_mat(m_irows[row], m_icols[col]); }
330  auto operator()(Index row, Index col) -> Scalar& { return coeff(row, col); }
331  auto operator()(Index row, Index col) const -> Scalar { return coeff(row, col); }
332 
333  operator PlainObject() const
334  {
335  PlainObject res(rows(), cols());
336  for(Index i = 0; i < rows(); ++i)
337  for(Index j = 0; j < cols(); ++j)
338  res(i, j) = coeff(i, j);
339  return res;
340  }
341 
342 private:
343  MatrixBase<Derived>& m_mat;
344  Indices m_irows, m_icols;
345 };
346 
347 template<typename Derived, typename Indices>
348 class MatrixSubViewConst : public MatrixBase<MatrixSubViewConst<Derived, Indices>>
349 {
350 public:
351  typedef MatrixBase<MatrixSubViewConst> Base;
352  typedef typename Derived::PlainObject PlainObject;
353  EIGEN_DENSE_PUBLIC_INTERFACE(MatrixSubViewConst)
354 
355  MatrixSubViewConst(const MatrixBase<Derived>& mat, const Indices& irows, const Indices& icols)
356  : m_mat(mat), m_irows(irows), m_icols(icols)
357  {}
358 
359  auto rows() const -> Index { return m_irows.size(); }
360  auto cols() const -> Index { return m_icols.size(); }
361 
362  auto coeff(Index row, Index col) const -> Scalar { return m_mat(m_irows[row], m_icols[col]); }
363  auto operator()(Index row, Index col) const -> Scalar { return coeff(row, col); }
364 
365  operator PlainObject() const
366  {
367  PlainObject res(rows(), cols());
368  for(Index i = 0; i < rows(); ++i)
369  for(Index j = 0; j < cols(); ++j)
370  res(i, j) = coeff(i, j);
371  return res;
372  }
373 
374 private:
375  const MatrixBase<Derived>& m_mat;
376  Indices m_irows, m_icols;
377 };
378 
379 } // namespace Eigen
380 
381 namespace Reaktoro {
382 
384 using Vector = Eigen::VectorXd;
385 
387 using Matrix = Eigen::MatrixXd;
388 
390 using PermutationMatrix = Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic>;
391 
395 auto zeros(Index rows) -> decltype(Vector::Zero(rows));
396 
400 auto ones(Index rows) -> decltype(Vector::Ones(rows));
401 
405 auto random(Index rows) -> decltype(Vector::Random(rows));
406 
412 auto linspace(Index rows, double start, double stop) -> decltype(Vector::LinSpaced(rows, start, stop));
413 
418 auto unit(Index rows, Index i) -> decltype(Vector::Unit(rows, i));
419 
424 auto zeros(Index rows, Index cols) -> decltype(Matrix::Zero(rows, cols));
425 
430 auto ones(Index rows, Index cols) -> decltype(Matrix::Ones(rows, cols));
431 
436 auto random(Index rows, Index cols) -> decltype(Matrix::Random(rows, cols));
437 
442 auto identity(Index rows, Index cols) -> decltype(Matrix::Identity(rows, cols));
443 
447 template<typename Derived>
448 auto rows(Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleRows(start, num));
449 
453 template<typename Derived>
454 auto rows(const Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleRows(start, num));
455 
459 template<typename Derived, typename Indices>
460 auto rows(Eigen::MatrixBase<Derived>& mat, const Indices& irows) -> Eigen::MatrixRowsView<Derived, Indices>;
461 
465 template<typename Derived, typename Indices>
466 auto rows(const Eigen::MatrixBase<Derived>& mat, const Indices& irows) -> Eigen::MatrixRowsViewConst<Derived, Indices>;
467 
471 template<typename Derived>
472 auto cols(Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleCols(start, num));
473 
477 template<typename Derived>
478 auto cols(const Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleCols(start, num));
479 
483 template<typename Derived, typename Indices>
484 auto cols(Eigen::MatrixBase<Derived>& mat, const Indices& icols) -> Eigen::MatrixColsView<Derived, Indices>;
485 
489 template<typename Derived, typename Indices>
490 auto cols(const Eigen::MatrixBase<Derived>& mat, const Indices& icols) -> Eigen::MatrixColsViewConst<Derived, Indices>;
491 
496 template<typename Derived>
497 auto segment(Eigen::MatrixBase<Derived>& vec, Index irow, Index nrows) -> decltype(vec.segment(irow, nrows));
498 
503 template<typename Derived>
504 auto segment(const Eigen::MatrixBase<Derived>& vec, Index irow, Index nrows) -> decltype(vec.segment(irow, nrows));
505 
510 template<typename Derived>
511 auto block(Eigen::MatrixBase<Derived>& mat, Index irow, Index icol, Index nrows, Index ncols) -> decltype(mat.block(irow, icol, nrows, ncols));
512 
517 template<typename Derived>
518 auto block(const Eigen::MatrixBase<Derived>& mat, Index irow, Index icol, Index nrows, Index ncols) -> decltype(mat.block(irow, icol, nrows, ncols));
519 
524 template<typename Derived, typename Indices>
525 auto submatrix(Eigen::MatrixBase<Derived>& mat, const Indices& irows, const Indices& icols) -> Eigen::MatrixSubView<Derived, Indices>;
526 
531 template<typename Derived, typename Indices>
532 auto submatrix(const Eigen::MatrixBase<Derived>& mat, const Indices& irows, const Indices& icols) -> Eigen::MatrixSubViewConst<Derived, Indices>;
533 
535 template<typename Derived>
536 auto tr(Eigen::MatrixBase<Derived>& mat) -> decltype(mat.transpose());
537 
539 template<typename Derived>
540 auto tr(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.transpose());
541 
543 template<typename Derived>
544 auto inv(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseInverse());
545 
547 template<typename Derived>
548 auto diag(const Eigen::MatrixBase<Derived>& vec) -> decltype(vec.asDiagonal());
549 
551 template<typename Derived>
552 auto diagonal(Eigen::MatrixBase<Derived>& mat) -> decltype(mat.diagonal());
553 
555 template<typename Derived>
556 auto diagonal(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.diagonal());
557 
559 template<int p, typename Derived>
560 auto norm(const Eigen::MatrixBase<Derived>& mat) -> double;
561 
563 template<typename Derived>
564 auto norm(const Eigen::MatrixBase<Derived>& mat) -> double;
565 
567 template<typename Derived>
568 auto norminf(const Eigen::MatrixBase<Derived>& mat) -> double;
569 
571 template<typename Derived>
572 auto sum(const Eigen::DenseBase<Derived>& mat) -> typename Derived::Scalar;
573 
575 template<typename DerivedLHS, typename DerivedRHS>
576 auto dot(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.dot(rhs));
577 
579 template<typename Derived>
580 auto min(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.minCoeff());
581 
583 template<typename DerivedLHS, typename DerivedRHS>
584 auto min(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseMin(rhs));
585 
587 template<typename Derived>
588 auto max(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.maxCoeff());
589 
591 template<typename DerivedLHS, typename DerivedRHS>
592 auto max(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseMax(rhs));
593 
595 template<typename DerivedLHS, typename DerivedRHS>
596 auto operator%(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseProduct(rhs));
597 
599 template<typename DerivedLHS, typename DerivedRHS>
600 auto operator/(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseQuotient(rhs));
601 
603 template<typename Derived>
604 auto operator/(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype(scalar*mat.cwiseInverse());
605 
607 template<typename Derived>
608 auto operator+(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype((scalar + mat.array()).matrix());
609 
611 template<typename Derived>
612 auto operator+(const Eigen::MatrixBase<Derived>& mat, const typename Derived::Scalar& scalar) -> decltype((scalar + mat.array()).matrix());
613 
615 template<typename Derived>
616 auto operator-(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype((scalar - mat.array()).matrix());
617 
619 template<typename Derived>
620 auto operator-(const Eigen::MatrixBase<Derived>& mat, const typename Derived::Scalar& scalar) -> decltype((mat.array() - scalar).matrix());
621 
623 template<typename Derived>
624 auto abs(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseAbs());
625 
627 template<typename Derived>
628 auto sqrt(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseSqrt());
629 
631 template<typename Derived>
632 auto pow(const Eigen::MatrixBase<Derived>& mat, double power) -> decltype(mat.array().pow(power));
633 
635 template<typename Derived>
636 auto exp(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().exp().matrix());
637 
639 template<typename Derived>
640 auto log(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().log().matrix());
641 
643 template<typename Derived>
644 auto log10(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().log10().matrix());
645 
646 } // namespace Reaktoro
647 
648 #include "Matrix.hxx"
Eigen::MatrixXd Matrix
Define an alias to the matrix type of the Eigen library.
Definition: Matrix.hpp:387
auto norminf(const Eigen::MatrixBase< Derived > &mat) -> double
Return the L-inf norm of a matrix.
Definition: Matrix.hxx:205
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
auto diag(const Eigen::MatrixBase< Derived > &vec) -> decltype(vec.asDiagonal())
Return a diagonal matrix representation of a vector.
Definition: Matrix.hxx:175
Definition: Matrix.hpp:28
auto diagonal(Eigen::MatrixBase< Derived > &mat) -> decltype(mat.diagonal())
Return a vector representation of the diagonal of a matrix.
Definition: Matrix.hxx:181
auto rows(ChemicalVectorBase< V, T, P, N > &vec, Index irow, Index nrows) -> ChemicalVectorBase< decltype(rows(vec.val, irow, nrows)), decltype(rows(vec.ddT, irow, nrows)), decltype(rows(vec.ddP, irow, nrows)), decltype(rows(vec.ddn, irow, nrows))>
Return a reference of a sequence of rows of this ChemicalVectorBase instance.
Definition: ChemicalVector.hpp:618
auto inv(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.cwiseInverse())
Return the component-wise inverse of the matrix.
Definition: Matrix.hxx:169
Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic > PermutationMatrix
Define an alias to a permutation matrix type of the Eigen library.
Definition: Matrix.hpp:390
Eigen::VectorXd Vector
Define an alias to the vector type of the Eigen library.
Definition: Matrix.hpp:384
auto linspace(Index rows, double start, double stop) -> decltype(Vector::LinSpaced(rows, start, stop))
Return a linearly spaced vector.
Definition: Matrix.hxx:42
auto block(Eigen::MatrixBase< Derived > &mat, Index irow, Index icol, Index nrows, Index ncols) -> decltype(mat.block(irow, icol, nrows, ncols))
Return a view of some rows and columns of a matrix.
Definition: Matrix.hxx:133
auto identity(Index rows, Index cols) -> decltype(Matrix::Identity(rows, cols))
Return an expression of an identity matrix.
Definition: Matrix.hxx:67
auto unit(Index rows, Index i) -> decltype(Vector::Unit(rows, i))
Return an expression of a unit vector.
Definition: Matrix.hxx:47
auto segment(Eigen::MatrixBase< Derived > &vec, Index irow, Index nrows) -> decltype(vec.segment(irow, nrows))
Return a view of some rows and columns of a matrix.
Definition: Matrix.hxx:121
auto cols(Eigen::MatrixBase< Derived > &mat, Index start, Index num) -> decltype(mat.middleCols(start, num))
Return a view of a sequence of columns of a matrix.
Definition: Matrix.hxx:97
auto ones(Index rows) -> decltype(Vector::Ones(rows))
Return an expression of a vector with entries equal to one.
Definition: Matrix.hxx:27
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
auto tr(Eigen::MatrixBase< Derived > &mat) -> decltype(mat.transpose())
Return the transpose of the matrix.
Definition: Matrix.hxx:157
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto norm(const Eigen::MatrixBase< Derived > &mat) -> double
Return the Lp norm of a matrix.
Definition: Matrix.hxx:193
auto submatrix(Eigen::MatrixBase< Derived > &mat, const Indices &irows, const Indices &icols) -> Eigen::MatrixSubView< Derived, Indices >
Return a view of some rows and columns of a matrix.
Definition: Matrix.hxx:145
auto random(Index rows) -> decltype(Vector::Random(rows))
Return an expression of a vector with random entries.
Definition: Matrix.hxx:37
auto zeros(Index rows) -> decltype(Vector::Zero(rows))
Return an expression of a zero vector.
Definition: Matrix.hxx:22