Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
Matrix.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // Eigen includes
21 #include <Eigen/Core>
22 
23 // autodiff includes
24 #include <autodiff/forward/real/eigen.hpp>
25 
26 // Reaktoro includes
27 #include <Reaktoro/Common/Index.hpp>
28 #include <Reaktoro/Common/Real.hpp>
29 #include <Reaktoro/Common/TraitsUtils.hpp>
30 #include <Reaktoro/Common/TypeOp.hpp>
31 
32 namespace Reaktoro {
33 
35 template<typename T>
36 using VectorX = Eigen::Matrix<T, -1, 1, 0, -1, 1>;
37 
39 template<typename T>
40 using MatrixX = Eigen::Matrix<T, -1, -1, 0, -1, -1>;
41 
43 template<typename T>
44 using ArrayX = Eigen::Array<T, -1, 1, 0, -1, 1>;
45 
47 template<typename T>
48 using ArrayXX = Eigen::Array<T, -1, -1, 0, -1, -1>;
49 
51 template<typename T>
52 using RowVectorX = Eigen::Matrix<T, 1, -1, 0, 1, -1>;
53 
54 //---------------------------------------------------------------------------------------------------------------------
55 // == VECTOR TYPE ALIASES ==
56 //---------------------------------------------------------------------------------------------------------------------
57 
58 using VectorXr = autodiff::VectorXreal;
59 using VectorXrRef = Eigen::Ref<VectorXr>;
60 using VectorXrConstRef = Eigen::Ref<const VectorXr>;
61 using VectorXrMap = Eigen::Map<VectorXr>;
62 using VectorXrConstMap = Eigen::Map<const VectorXr>;
63 using VectorXrStridedRef = Eigen::Ref<VectorXr, 0, Eigen::InnerStride<>>;
64 using VectorXrStridedConstRef = Eigen::Ref<const VectorXr, 0, Eigen::InnerStride<>>;
65 
67 using VectorXlRef = Eigen::Ref<VectorXl>;
68 using VectorXlConstRef = Eigen::Ref<const VectorXl>;
69 using VectorXlMap = Eigen::Map<VectorXl>;
70 using VectorXlConstMap = Eigen::Map<const VectorXl>;
71 using VectorXlStridedRef = Eigen::Ref<VectorXl, 0, Eigen::InnerStride<>>;
72 using VectorXlStridedConstRef = Eigen::Ref<const VectorXl, 0, Eigen::InnerStride<>>;
73 
74 using VectorXd = Eigen::VectorXd;
75 using VectorXdRef = Eigen::Ref<VectorXd>;
76 using VectorXdConstRef = Eigen::Ref<const VectorXd>;
77 using VectorXdMap = Eigen::Map<VectorXd>;
78 using VectorXdConstMap = Eigen::Map<const VectorXd>;
79 using VectorXdStridedRef = Eigen::Ref<VectorXd, 0, Eigen::InnerStride<>>;
80 using VectorXdStridedConstRef = Eigen::Ref<const VectorXd, 0, Eigen::InnerStride<>>;
81 
82 
83 //---------------------------------------------------------------------------------------------------------------------
84 // == ARRAY TYPE ALIASES ==
85 //---------------------------------------------------------------------------------------------------------------------
86 
87 using ArrayXr = autodiff::ArrayXreal;
88 using ArrayXrRef = Eigen::Ref<ArrayXr>;
89 using ArrayXrConstRef = Eigen::Ref<const ArrayXr>;
90 using ArrayXrMap = Eigen::Map<ArrayXr>;
91 using ArrayXrConstMap = Eigen::Map<const ArrayXr>;
92 using ArrayXrStridedRef = Eigen::Ref<ArrayXr, 0, Eigen::InnerStride<>>;
93 using ArrayXrStridedConstRef = Eigen::Ref<const ArrayXr, 0, Eigen::InnerStride<>>;
94 
96 using ArrayXlRef = Eigen::Ref<ArrayXl>;
97 using ArrayXlConstRef = Eigen::Ref<const ArrayXl>;
98 using ArrayXlMap = Eigen::Map<ArrayXl>;
99 using ArrayXlConstMap = Eigen::Map<const ArrayXl>;
100 using ArrayXlStridedRef = Eigen::Ref<ArrayXl, 0, Eigen::InnerStride<>>;
101 using ArrayXlStridedConstRef = Eigen::Ref<const ArrayXl, 0, Eigen::InnerStride<>>;
102 
103 using ArrayXd = Eigen::ArrayXd;
104 using ArrayXdRef = Eigen::Ref<ArrayXd>;
105 using ArrayXdConstRef = Eigen::Ref<const ArrayXd>;
106 using ArrayXdMap = Eigen::Map<ArrayXd>;
107 using ArrayXdConstMap = Eigen::Map<const ArrayXd>;
108 using ArrayXdStridedRef = Eigen::Ref<ArrayXd, 0, Eigen::InnerStride<>>;
109 using ArrayXdStridedConstRef = Eigen::Ref<const ArrayXd, 0, Eigen::InnerStride<>>;
110 
111 using ArrayXXr = autodiff::ArrayXXreal;
112 using ArrayXXrRef = Eigen::Ref<ArrayXXr>;
113 using ArrayXXrConstRef = Eigen::Ref<const ArrayXXr>;
114 using ArrayXXrMap = Eigen::Map<ArrayXXr>;
115 using ArrayXXrConstMap = Eigen::Map<const ArrayXXr>;
116 using ArrayXXrStridedRef = Eigen::Ref<ArrayXXr, 0, Eigen::InnerStride<>>;
117 using ArrayXXrStridedConstRef = Eigen::Ref<const ArrayXXr, 0, Eigen::InnerStride<>>;
118 
119 using ArrayXXd = Eigen::ArrayXXd;
120 using ArrayXXdRef = Eigen::Ref<ArrayXXd>;
121 using ArrayXXdConstRef = Eigen::Ref<const ArrayXXd>;
122 using ArrayXXdMap = Eigen::Map<ArrayXXd>;
123 using ArrayXXdConstMap = Eigen::Map<const ArrayXXd>;
124 using ArrayXXdStridedRef = Eigen::Ref<ArrayXXd, 0, Eigen::InnerStride<>>;
125 using ArrayXXdStridedConstRef = Eigen::Ref<const ArrayXXd, 0, Eigen::InnerStride<>>;
126 
127 //---------------------------------------------------------------------------------------------------------------------
128 // == MATRIX TYPE ALIASES ==
129 //---------------------------------------------------------------------------------------------------------------------
130 
131 using MatrixXr = autodiff::MatrixXreal;
132 using MatrixXrRef = Eigen::Ref<MatrixXr>;
133 using MatrixXrConstRef = Eigen::Ref<const MatrixXr>;
134 using MatrixXrMap = Eigen::Map<MatrixXr>;
135 using MatrixXrConstMap = Eigen::Map<const MatrixXr>;
136 
137 using MatrixXd = Eigen::MatrixXd;
138 using MatrixXdRef = Eigen::Ref<MatrixXd>;
139 using MatrixXdConstRef = Eigen::Ref<const MatrixXd>;
140 using MatrixXdMap = Eigen::Map<MatrixXd>;
141 using MatrixXdConstMap = Eigen::Map<const MatrixXd>;
142 
143 //---------------------------------------------------------------------------------------------------------------------
144 // == ROW VECTOR TYPE ALIASES ==
145 //---------------------------------------------------------------------------------------------------------------------
146 
147 using RowVectorXr = autodiff::RowVectorXreal;
148 using RowVectorXrRef = Eigen::Ref<RowVectorXr>;
149 using RowVectorXrConstRef = Eigen::Ref<const RowVectorXr>;
150 using RowVectorXrMap = Eigen::Map<RowVectorXr>;
151 using RowVectorXrConstMap = Eigen::Map<const RowVectorXr>;
152 
153 using RowVectorXl = RowVectorX<Eigen::Index>;
154 using RowVectorXlRef = Eigen::Ref<RowVectorXl>;
155 using RowVectorXlConstRef = Eigen::Ref<const RowVectorXl>;
156 using RowVectorXlMap = Eigen::Map<RowVectorXl>;
157 using RowVectorXlConstMap = Eigen::Map<const RowVectorXl>;
158 
159 using RowVectorXd = Eigen::RowVectorXd;
160 using RowVectorXdRef = Eigen::Ref<RowVectorXd>;
161 using RowVectorXdConstRef = Eigen::Ref<const RowVectorXd>;
162 using RowVectorXdMap = Eigen::Map<RowVectorXd>;
163 using RowVectorXdConstMap = Eigen::Map<const RowVectorXd>;
164 
165 //---------------------------------------------------------------------------------------------------------------------
166 // == OTHER TYPE ALIASES ==
167 //---------------------------------------------------------------------------------------------------------------------
168 
170 using PermutationMatrix = Eigen::PermutationMatrix<Eigen::Dynamic, Eigen::Dynamic>;
171 
172 //---------------------------------------------------------------------------------------------------------------------
173 // == FUNCTION ALIASES ==
174 //---------------------------------------------------------------------------------------------------------------------
175 
179 auto zeros(Index rows) -> decltype(VectorXd::Zero(rows));
180 
184 auto ones(Index rows) -> decltype(VectorXd::Ones(rows));
185 
189 auto random(Index rows) -> decltype(VectorXd::Random(rows));
190 
196 auto linspace(double start, double stop, Index rows) -> decltype(VectorXd::LinSpaced(rows, start, stop));
197 
202 auto unit(Index rows, Index i) -> decltype(VectorXd::Unit(rows, i));
203 
208 auto zeros(Index rows, Index cols) -> decltype(MatrixXd::Zero(rows, cols));
209 
214 auto ones(Index rows, Index cols) -> decltype(MatrixXd::Ones(rows, cols));
215 
220 auto random(Index rows, Index cols) -> decltype(MatrixXd::Random(rows, cols));
221 
226 auto identity(Index rows, Index cols) -> decltype(MatrixXd::Identity(rows, cols));
227 
232 template<typename Derived>
233 auto rows(Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleRows(start, num));
234 
239 template<typename Derived>
240 auto rows(const Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleRows(start, num));
241 
245 template<typename Derived, typename Indices>
246 auto rows(Eigen::MatrixBase<Derived>& mat, const Indices& irows) -> decltype(mat(irows, Eigen::all));
247 
251 template<typename Derived, typename Indices>
252 auto rows(const Eigen::MatrixBase<Derived>& mat, const Indices& irows) -> decltype(mat(irows, Eigen::all));
253 
258 template<typename Derived>
259 auto cols(Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleCols(start, num));
260 
265 template<typename Derived>
266 auto cols(const Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleCols(start, num));
267 
271 template<typename Derived, typename Indices>
272 auto cols(Eigen::MatrixBase<Derived>& mat, const Indices& icols) -> decltype(mat(Eigen::all, icols));
273 
277 template<typename Derived, typename Indices>
278 auto cols(const Eigen::MatrixBase<Derived>& mat, const Indices& icols) -> decltype(mat(Eigen::all, icols));
279 
284 template<typename Derived>
285 auto segment(Eigen::MatrixBase<Derived>& vec, Index irow, Index nrows) -> decltype(vec.segment(irow, nrows));
286 
291 template<typename Derived>
292 auto segment(const Eigen::MatrixBase<Derived>& vec, Index irow, Index nrows) -> decltype(vec.segment(irow, nrows));
293 
300 template<typename Derived>
301 auto block(Eigen::MatrixBase<Derived>& mat, Index irow, Index icol, Index nrows, Index ncols) -> decltype(mat.block(irow, icol, nrows, ncols));
302 
309 template<typename Derived>
310 auto block(const Eigen::MatrixBase<Derived>& mat, Index irow, Index icol, Index nrows, Index ncols) -> decltype(mat.block(irow, icol, nrows, ncols));
311 
316 template<typename Derived, typename Indices>
317 auto submatrix(Eigen::MatrixBase<Derived>& mat, const Indices& irows, const Indices& icols) -> decltype(mat(irows, icols));
318 
323 template<typename Derived, typename Indices>
324 auto submatrix(const Eigen::MatrixBase<Derived>& mat, const Indices& irows, const Indices& icols) -> decltype(mat(irows, icols));
325 
327 template<typename Derived>
328 auto tr(Eigen::MatrixBase<Derived>& mat) -> decltype(mat.transpose());
329 
331 template<typename Derived>
332 auto tr(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.transpose());
333 
335 template<typename Derived>
336 auto inv(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseInverse());
337 
339 template<typename Derived>
340 auto diag(const Eigen::MatrixBase<Derived>& vec) -> decltype(vec.asDiagonal());
341 
343 template<typename Derived>
344 auto diagonal(Eigen::MatrixBase<Derived>& mat) -> decltype(mat.diagonal());
345 
347 template<typename Derived>
348 auto diagonal(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.diagonal());
349 
351 template<int p, typename Derived>
352 auto norm(const Eigen::MatrixBase<Derived>& mat) -> double;
353 
355 template<typename Derived>
356 auto norm(const Eigen::MatrixBase<Derived>& mat) -> double;
357 
359 template<typename Derived>
360 auto norminf(const Eigen::MatrixBase<Derived>& mat) -> double;
361 
363 template<typename Derived>
364 auto sum(const Eigen::DenseBase<Derived>& mat) -> typename Derived::Scalar;
365 
367 template<typename DerivedLHS, typename DerivedRHS>
368 auto dot(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.dot(rhs));
369 
371 template<typename Derived>
372 auto min(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.minCoeff());
373 
375 template<typename DerivedLHS, typename DerivedRHS>
376 auto min(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseMin(rhs));
377 
379 template<typename Derived>
380 auto max(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.maxCoeff());
381 
383 template<typename DerivedLHS, typename DerivedRHS>
384 auto max(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseMax(rhs));
385 
387 template<typename DerivedLHS, typename DerivedRHS>
388 auto operator%(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseProduct(rhs));
389 
391 template<typename DerivedLHS, typename DerivedRHS>
392 auto operator/(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseQuotient(rhs));
393 
395 template<typename Derived>
396 auto operator/(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype(scalar*mat.cwiseInverse());
397 
399 template<typename Derived>
400 auto operator+(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype((scalar + mat.array()).matrix());
401 
403 template<typename Derived>
404 auto operator+(const Eigen::MatrixBase<Derived>& mat, const typename Derived::Scalar& scalar) -> decltype((scalar + mat.array()).matrix());
405 
407 template<typename Derived>
408 auto operator-(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype((scalar - mat.array()).matrix());
409 
411 template<typename Derived>
412 auto operator-(const Eigen::MatrixBase<Derived>& mat, const typename Derived::Scalar& scalar) -> decltype((mat.array() - scalar).matrix());
413 
415 template<typename Derived>
416 auto abs(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseAbs());
417 
419 template<typename Derived>
420 auto sqrt(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseSqrt());
421 
423 template<typename Derived>
424 auto pow(const Eigen::MatrixBase<Derived>& mat, double power) -> decltype(mat.array().pow(power));
425 
427 template<typename Derived>
428 auto exp(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().exp().matrix());
429 
431 template<typename Derived>
432 auto log(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().log().matrix());
433 
435 template<typename Derived>
436 auto log10(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().log10().matrix());
437 
438 } // namespace Reaktoro
439 
440 //=========================================================================
441 // CODE BELOW NEEDED FOR MEMOIZATION TECHNIQUE INVOLVING EIGEN TYPES
442 //=========================================================================
443 namespace Reaktoro {
444 
445 template<typename T>
446 struct MemoizationTraits;
447 
449 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
450 struct MemoizationTraits<Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
451 {
452  using Type = Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>;
453 
454  using CacheType = Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>;
455 
457  static auto equal(const CacheType& a, const Type& b)
458  {
459  return (a == b).all();
460  }
461 };
462 
464 template<typename EigenType>
465 struct MemoizationTraits<Eigen::Ref<EigenType>>
466 {
467  using Type = Eigen::Ref<EigenType>;
468 
469  using CacheType = typename MemoizationTraits<Decay<EigenType>>::CacheType;
470 
472  static auto equal(const CacheType& a, const Type& b)
473  {
475  }
476 
478  static auto assign(const CacheType& a, const Type& b)
479  {
481  }
482 };
483 
484 } // namespace Reaktoro
485 
486 //=========================================================================
487 // CODE BELOW NEEDED FOR TypeOp TRAITS INVOLVING EIGEN TYPES
488 //=========================================================================
489 namespace Reaktoro {
490 namespace detail {
491 
492 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
493 struct TypeOpRef<Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
494 {
495  using type = Eigen::Ref<Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>;
496 };
497 
498 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
499 struct TypeOpRef<Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
500 {
501  using type = Eigen::Ref<Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>;
502 };
503 
504 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
505 struct TypeOpConstRef<Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
506 {
507  using type = Eigen::Ref<const Eigen::Matrix<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>;
508 };
509 
510 template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
511 struct TypeOpConstRef<Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>
512 {
513  using type = Eigen::Ref<const Eigen::Array<Scalar, Rows, Cols, Options, MaxRows, MaxCols>>;
514 };
515 
516 } // namespace detail
517 } // namespace Reaktoro
518 
519 namespace Reaktoro {
520 
521 inline auto zeros(Index rows) -> decltype(VectorXd::Zero(rows))
522 {
523  return VectorXd::Zero(rows);
524 }
525 
526 inline auto ones(Index rows) -> decltype(VectorXd::Ones(rows))
527 {
528  return VectorXd::Ones(rows);
529 }
530 
531 inline auto constants(Index rows, double val) -> decltype(VectorXd::Constant(rows, val))
532 {
533  return VectorXd::Constant(rows, val);
534 }
535 
536 inline auto random(Index rows) -> decltype(VectorXd::Random(rows))
537 {
538  return VectorXd::Random(rows);
539 }
540 
541 inline auto linspace(double start, double stop, Index rows) -> decltype(VectorXd::LinSpaced(rows, start, stop))
542 {
543  return VectorXd::LinSpaced(rows, start, stop);
544 }
545 
546 inline auto unit(Index rows, Index i) -> decltype(VectorXd::Unit(rows, i))
547 {
548  return VectorXd::Unit(rows, i);
549 }
550 
551 inline auto unitcol(Index rows, Index i) -> decltype(unit(rows, i))
552 {
553  return unit(rows, i);
554 }
555 
556 inline auto unitrow(Index cols, Index i) -> decltype(RowVectorXd::Unit(cols, i))
557 {
558  return RowVectorXd::Unit(cols, i);
559 }
560 
561 inline auto zeros(Index rows, Index cols) -> decltype(MatrixXd::Zero(rows, cols))
562 {
563  return MatrixXd::Zero(rows, cols);
564 }
565 
566 inline auto ones(Index rows, Index cols) -> decltype(MatrixXd::Ones(rows, cols))
567 {
568  return MatrixXd::Ones(rows, cols);
569 }
570 
571 inline auto random(Index rows, Index cols) -> decltype(MatrixXd::Random(rows, cols))
572 {
573  return MatrixXd::Random(rows, cols);
574 }
575 
576 inline auto identity(Index rows, Index cols) -> decltype(MatrixXd::Identity(rows, cols))
577 {
578  return MatrixXd::Identity(rows, cols);
579 }
580 
581 template<typename Derived>
582 auto rows(Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleRows(start, num))
583 {
584  return mat.middleRows(start, num);
585 }
586 
587 template<typename Derived>
588 auto rows(const Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleRows(start, num))
589 {
590  return mat.middleRows(start, num);
591 }
592 
593 template<typename Derived, typename Indices>
594 auto rows(Eigen::MatrixBase<Derived>& mat, const Indices& irows) -> decltype(mat(irows, Eigen::all))
595 {
596  return mat(irows, Eigen::all);
597 }
598 
599 template<typename Derived, typename Indices>
600 auto rows(const Eigen::MatrixBase<Derived>& mat, const Indices& irows) -> decltype(mat(irows, Eigen::all))
601 {
602  return mat(irows, Eigen::all);
603 }
604 
605 template<typename Derived>
606 auto cols(Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleCols(start, num))
607 {
608  return mat.middleCols(start, num);
609 }
610 
611 template<typename Derived>
612 auto cols(const Eigen::MatrixBase<Derived>& mat, Index start, Index num) -> decltype(mat.middleCols(start, num))
613 {
614  return mat.middleCols(start, num);
615 }
616 
617 template<typename Derived, typename Indices>
618 auto cols(Eigen::MatrixBase<Derived>& mat, const Indices& icols) -> decltype(mat(Eigen::all, icols))
619 {
620  return mat(Eigen::all, icols);
621 }
622 
623 template<typename Derived, typename Indices>
624 auto cols(const Eigen::MatrixBase<Derived>& mat, const Indices& icols) -> decltype(mat(Eigen::all, icols))
625 {
626  return mat(Eigen::all, icols);
627 }
628 
629 template<typename Derived>
630 auto segment(Eigen::MatrixBase<Derived>& vec, Index irow, Index nrows) -> decltype(vec.segment(irow, nrows))
631 {
632  return vec.segment(irow, nrows);
633 }
634 
635 template<typename Derived>
636 auto segment(const Eigen::MatrixBase<Derived>& vec, Index irow, Index nrows) -> decltype(vec.segment(irow, nrows))
637 {
638  return vec.segment(irow, nrows);
639 }
640 
641 template<typename Derived>
642 auto block(Eigen::MatrixBase<Derived>& mat, Index irow, Index icol, Index nrows, Index ncols) -> decltype(mat.block(irow, icol, nrows, ncols))
643 {
644  return mat.block(irow, icol, nrows, ncols);
645 }
646 
647 template<typename Derived>
648 auto block(const Eigen::MatrixBase<Derived>& mat, Index irow, Index icol, Index nrows, Index ncols) -> decltype(mat.block(irow, icol, nrows, ncols))
649 {
650  return mat.block(irow, icol, nrows, ncols);
651 }
652 
653 template<typename Derived, typename Indices>
654 auto submatrix(Eigen::MatrixBase<Derived>& mat, const Indices& irows, const Indices& icols) -> decltype(mat(irows, icols))
655 {
656  return mat(irows, icols);
657 }
658 
659 template<typename Derived, typename Indices>
660 auto submatrix(const Eigen::MatrixBase<Derived>& mat, const Indices& irows, const Indices& icols) -> decltype(mat(irows, icols))
661 {
662  return mat(irows, icols);
663 }
664 
665 template<typename Derived>
666 auto tr(Eigen::MatrixBase<Derived>& mat) -> decltype(mat.transpose())
667 {
668  return mat.transpose();
669 }
670 
671 template<typename Derived>
672 auto tr(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.transpose())
673 {
674  return mat.transpose();
675 }
676 
677 template<typename Derived>
678 auto inv(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseInverse())
679 {
680  return mat.cwiseInverse();
681 }
682 
683 template<typename Derived>
684 auto diag(const Eigen::MatrixBase<Derived>& vec) -> decltype(vec.asDiagonal())
685 {
686  return vec.asDiagonal();
687 }
688 
689 template<typename Derived>
690 auto diagonal(Eigen::MatrixBase<Derived>& mat) -> decltype(mat.diagonal())
691 {
692  return mat.diagonal();
693 }
694 
695 template<typename Derived>
696 auto diagonal(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.diagonal())
697 {
698  return mat.diagonal();
699 }
700 
701 template<int p, typename Derived>
702 auto norm(const Eigen::MatrixBase<Derived>& mat) -> double
703 {
704  return mat.template lpNorm<p>();
705 }
706 
707 template<typename Derived>
708 auto norm(const Eigen::MatrixBase<Derived>& mat) -> double
709 {
710  return mat.norm();
711 }
712 
713 template<typename Derived>
714 auto norminf(const Eigen::MatrixBase<Derived>& mat) -> double
715 {
716  return mat.template lpNorm<Eigen::Infinity>();
717 }
718 
719 template<typename Derived>
720 auto sum(const Eigen::DenseBase<Derived>& mat) -> typename Derived::Scalar
721 {
722  return mat.sum();
723 }
724 
725 template<typename DerivedLHS, typename DerivedRHS>
726 auto dot(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.dot(rhs))
727 {
728  return lhs.dot(rhs);
729 }
730 
731 template<typename Derived>
732 auto min(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.minCoeff())
733 {
734  return mat.minCoeff();
735 }
736 
737 template<typename DerivedLHS, typename DerivedRHS>
738 auto min(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseMin(rhs))
739 {
740  return lhs.cwiseMin(rhs);
741 }
742 
743 template<typename Derived>
744 auto max(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.maxCoeff())
745 {
746  return mat.maxCoeff();
747 }
748 
749 template<typename DerivedLHS, typename DerivedRHS>
750 auto max(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseMax(rhs))
751 {
752  return lhs.cwiseMax(rhs);
753 }
754 
755 template<typename DerivedLHS, typename DerivedRHS>
756 auto operator%(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseProduct(rhs))
757 {
758  return lhs.cwiseProduct(rhs);
759 }
760 
761 template<typename DerivedLHS, typename DerivedRHS>
762 auto operator/(const Eigen::MatrixBase<DerivedLHS>& lhs, const Eigen::MatrixBase<DerivedRHS>& rhs) -> decltype(lhs.cwiseQuotient(rhs))
763 {
764  return lhs.cwiseQuotient(rhs);
765 }
766 
767 template<typename Derived>
768 auto operator/(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype(scalar*mat.cwiseInverse())
769 {
770  return scalar*mat.cwiseInverse();
771 }
772 
773 template<typename Derived>
774 auto operator+(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype((scalar + mat.array()).matrix())
775 {
776  return (scalar + mat.array()).matrix();
777 }
778 
779 template<typename Derived>
780 auto operator+(const Eigen::MatrixBase<Derived>& mat, const typename Derived::Scalar& scalar) -> decltype((scalar + mat.array()).matrix())
781 {
782  return (scalar + mat.array()).matrix();
783 }
784 
785 template<typename Derived>
786 auto operator-(const typename Derived::Scalar& scalar, const Eigen::MatrixBase<Derived>& mat) -> decltype((scalar - mat.array()).matrix())
787 {
788  return (scalar - mat.array()).matrix();
789 }
790 
791 template<typename Derived>
792 auto operator-(const Eigen::MatrixBase<Derived>& mat, const typename Derived::Scalar& scalar) -> decltype((mat.array() - scalar).matrix())
793 {
794  return (mat.array() - scalar).matrix();
795 }
796 
797 template<typename Derived>
798 auto abs(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseAbs())
799 {
800  return mat.cwiseAbs();
801 }
802 
803 template<typename Derived>
804 auto sqrt(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.cwiseSqrt())
805 {
806  return mat.cwiseSqrt();
807 }
808 
809 template<typename Derived>
810 auto pow(const Eigen::MatrixBase<Derived>& mat, double power) -> decltype(mat.array().pow(power).matrix())
811 {
812  return mat.array().pow(power).matrix();
813 }
814 
815 template<typename Derived>
816 auto exp(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().exp().matrix())
817 {
818  return mat.array().exp().matrix();
819 }
820 
821 template<typename Derived>
822 auto log(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().log().matrix())
823 {
824  return mat.array().log().matrix();
825 }
826 
827 template<typename Derived>
828 auto log10(const Eigen::MatrixBase<Derived>& mat) -> decltype(mat.array().log10().matrix())
829 {
830  return mat.array().log10().matrix();
831 }
832 
833 } // namespace Reaktoro
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
auto pow(const Eigen::MatrixBase< Derived > &mat, double power) -> decltype(mat.array().pow(power))
Return the component-wise exponential of a matrix.
Definition: Matrix.hpp:810
std::array< T, N > Array
Convenient alias for std::array<T, N>.
Definition: Types.hpp:62
Eigen::Ref< const VectorXd, 0, Eigen::InnerStride<> > VectorXdStridedConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:80
auto operator/(const Eigen::MatrixBase< DerivedLHS > &lhs, const Eigen::MatrixBase< DerivedRHS > &rhs) -> decltype(lhs.cwiseQuotient(rhs))
Return the component-wise division of two matrices.
Definition: Matrix.hpp:762
auto norminf(const Eigen::MatrixBase< Derived > &mat) -> double
Return the L-inf norm of a matrix.
Definition: Matrix.hpp:714
autodiff::MatrixXreal MatrixXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:131
Eigen::Map< const VectorXd > VectorXdConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:78
Eigen::Map< ArrayXXd > ArrayXXdMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:122
Eigen::Ref< const MatrixXr > MatrixXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:133
Eigen::Ref< const VectorXl > VectorXlConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:68
auto submatrix(Eigen::MatrixBase< Derived > &mat, const Indices &irows, const Indices &icols) -> decltype(mat(irows, icols))
Return a view of some rows and columns of a matrix.
Definition: Matrix.hpp:654
auto tr(Eigen::MatrixBase< Derived > &mat) -> decltype(mat.transpose())
Return the transpose of the matrix.
Definition: Matrix.hpp:666
auto abs(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.cwiseAbs())
Return the component-wise absolute entries of a matrix.
Definition: Matrix.hpp:798
Eigen::Map< VectorXr > VectorXrMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:61
Eigen::Ref< const ArrayXXr > ArrayXXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:113
auto rows(Eigen::MatrixBase< Derived > &mat, Index start, Index num) -> decltype(mat.middleRows(start, num))
Return a view of a sequence of rows of a matrix.
Definition: Matrix.hpp:582
Eigen::Map< ArrayXXr > ArrayXXrMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:114
Eigen::Map< const ArrayXd > ArrayXdConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:107
Eigen::Ref< ArrayXd, 0, Eigen::InnerStride<> > ArrayXdStridedRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:108
Eigen::RowVectorXd RowVectorXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:159
Eigen::Ref< const VectorXr > VectorXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:60
Eigen::Ref< const RowVectorXl > RowVectorXlConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:155
Eigen::Ref< const ArrayXl, 0, Eigen::InnerStride<> > ArrayXlStridedConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:101
Eigen::Ref< ArrayXd > ArrayXdRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:104
RowVectorX< Eigen::Index > RowVectorXl
Convenient alias to Eigen type.
Definition: Matrix.hpp:153
auto operator%(const Eigen::MatrixBase< DerivedLHS > &lhs, const Eigen::MatrixBase< DerivedRHS > &rhs) -> decltype(lhs.cwiseProduct(rhs))
Return the component-wise multiplication of two matrices.
Definition: Matrix.hpp:756
auto unit(Index rows, Index i) -> decltype(VectorXd::Unit(rows, i))
Return an expression of a unit vector.
Definition: Matrix.hpp:546
Eigen::Ref< ArrayXXd, 0, Eigen::InnerStride<> > ArrayXXdStridedRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:124
Eigen::Map< const ArrayXXr > ArrayXXrConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:115
Eigen::Map< ArrayXl > ArrayXlMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:98
Eigen::Map< MatrixXr > MatrixXrMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:134
Eigen::Map< ArrayXd > ArrayXdMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:106
Eigen::MatrixXd MatrixXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:137
Eigen::Ref< ArrayXl, 0, Eigen::InnerStride<> > ArrayXlStridedRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:100
auto dot(const Eigen::MatrixBase< DerivedLHS > &lhs, const Eigen::MatrixBase< DerivedRHS > &rhs) -> decltype(lhs.dot(rhs))
Return the dot product of two matrices.
Definition: Matrix.hpp:726
Eigen::Ref< const ArrayXXd, 0, Eigen::InnerStride<> > ArrayXXdStridedConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:125
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
auto operator-(const typename Derived::Scalar &scalar, const Eigen::MatrixBase< Derived > &mat) -> decltype((scalar - mat.array()).matrix())
Return the component-wise division of two matrices.
Definition: Matrix.hpp:786
Eigen::Matrix< T, -1, -1, 0, -1, -1 > MatrixX
Convenient alias to Eigen type.
Definition: Matrix.hpp:42
auto operator+(const typename Derived::Scalar &scalar, const Eigen::MatrixBase< Derived > &mat) -> decltype((scalar+mat.array()).matrix())
Return the component-wise division of two matrices.
Definition: Matrix.hpp:774
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.hpp:630
Eigen::Map< RowVectorXr > RowVectorXrMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:150
ArrayX< Eigen::Index > ArrayXl
Convenient alias to Eigen type.
Definition: Matrix.hpp:95
Eigen::Ref< const VectorXr, 0, Eigen::InnerStride<> > VectorXrStridedConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:64
Eigen::Ref< RowVectorXl > RowVectorXlRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:154
Eigen::Ref< const ArrayXl > ArrayXlConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:97
Eigen::Ref< const VectorXd > VectorXdConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:76
Eigen::Map< RowVectorXl > RowVectorXlMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:156
Eigen::VectorXd VectorXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:74
Eigen::Ref< const ArrayXXr, 0, Eigen::InnerStride<> > ArrayXXrStridedConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:117
autodiff::ArrayXXreal ArrayXXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:111
Eigen::Ref< VectorXr > VectorXrRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:59
Eigen::Ref< ArrayXr, 0, Eigen::InnerStride<> > ArrayXrStridedRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:92
Eigen::Map< const ArrayXXd > ArrayXXdConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:123
Eigen::Map< const VectorXl > VectorXlConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:70
Eigen::Map< MatrixXd > MatrixXdMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:140
Eigen::ArrayXXd ArrayXXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:119
Eigen::Ref< const ArrayXd, 0, Eigen::InnerStride<> > ArrayXdStridedConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:109
Eigen::Map< const MatrixXr > MatrixXrConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:135
autodiff::VectorXreal VectorXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:58
Eigen::Ref< const VectorXl, 0, Eigen::InnerStride<> > VectorXlStridedConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:72
Eigen::Ref< MatrixXr > MatrixXrRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:132
auto norm(const Eigen::MatrixBase< Derived > &mat) -> double
Return the Lp norm of a matrix.
Definition: Matrix.hpp:702
auto sum(std::size_t ibegin, std::size_t iend, const Function &f)
Return the sum f(ibegin) + ... + f(iend-1) for a given function f.
Definition: Algorithms.hpp:257
Eigen::Ref< const ArrayXXd > ArrayXXdConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:121
auto linspace(double start, double stop, Index rows) -> decltype(VectorXd::LinSpaced(rows, start, stop))
Return a linearly spaced vector.
Definition: Matrix.hpp:541
Eigen::Ref< ArrayXr > ArrayXrRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:88
Eigen::Ref< ArrayXl > ArrayXlRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:96
Eigen::Map< const VectorXr > VectorXrConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:62
Eigen::Map< const RowVectorXr > RowVectorXrConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:151
Eigen::Map< RowVectorXd > RowVectorXdMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:162
Eigen::Ref< ArrayXXr > ArrayXXrRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:112
Eigen::Ref< const ArrayXd > ArrayXdConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:105
auto ones(Index rows) -> decltype(VectorXd::Ones(rows))
Return an expression of a vector with entries equal to one.
Definition: Matrix.hpp:526
Eigen::Ref< const ArrayXr, 0, Eigen::InnerStride<> > ArrayXrStridedConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:93
autodiff::RowVectorXreal RowVectorXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:147
Eigen::Map< const RowVectorXl > RowVectorXlConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:157
Eigen::Ref< ArrayXXd > ArrayXXdRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:120
Eigen::Array< T, -1, 1, 0, -1, 1 > ArrayX
Convenient alias to Eigen type.
Definition: Matrix.hpp:46
Eigen::Map< VectorXl > VectorXlMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:69
Eigen::Ref< VectorXl, 0, Eigen::InnerStride<> > VectorXlStridedRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:71
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.hpp:606
Eigen::Ref< const RowVectorXr > RowVectorXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:149
Eigen::PermutationMatrix< Eigen::Dynamic, Eigen::Dynamic > PermutationMatrix
Define an alias to a permutation matrix type of the Eigen library.
Definition: Matrix.hpp:170
Eigen::Ref< const RowVectorXd > RowVectorXdConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:161
Eigen::Ref< VectorXl > VectorXlRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:67
auto sqrt(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.cwiseSqrt())
Return the component-wise square root of a matrix.
Definition: Matrix.hpp:804
Eigen::Map< const RowVectorXd > RowVectorXdConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:163
auto min(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.minCoeff())
Return the minimum component of a matrix.
Definition: Matrix.hpp:732
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.hpp:684
Eigen::Ref< RowVectorXr > RowVectorXrRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:148
Eigen::ArrayXd ArrayXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:103
Eigen::Map< const MatrixXd > MatrixXdConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:141
Eigen::Ref< const MatrixXd > MatrixXdConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:139
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.hpp:642
Eigen::Ref< const ArrayXr > ArrayXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:89
auto inv(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.cwiseInverse())
Return the component-wise inverse of the matrix.
Definition: Matrix.hpp:678
auto log(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.array().log().matrix())
Return the component-wise natural log of a matrix.
Definition: Matrix.hpp:822
auto identity(Index rows, Index cols) -> decltype(MatrixXd::Identity(rows, cols))
Return an expression of an identity matrix.
Definition: Matrix.hpp:576
Eigen::Matrix< T, -1, 1, 0, -1, 1 > VectorX
Convenient alias to Eigen type.
Definition: Matrix.hpp:38
Eigen::Ref< VectorXd, 0, Eigen::InnerStride<> > VectorXdStridedRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:79
Eigen::Array< T, -1, -1, 0, -1, -1 > ArrayXX
Convenient alias to Eigen type.
Definition: Matrix.hpp:50
Eigen::Ref< MatrixXd > MatrixXdRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:138
auto zeros(Index rows) -> decltype(VectorXd::Zero(rows))
Return an expression of a zero vector.
Definition: Matrix.hpp:521
Eigen::Map< const ArrayXl > ArrayXlConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:99
auto exp(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.array().exp().matrix())
Return the component-wise natural exponential of a matrix.
Definition: Matrix.hpp:816
Eigen::Ref< ArrayXXr, 0, Eigen::InnerStride<> > ArrayXXrStridedRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:116
auto random(Index rows) -> decltype(VectorXd::Random(rows))
Return an expression of a vector with random entries.
Definition: Matrix.hpp:536
autodiff::ArrayXreal ArrayXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:87
auto diagonal(Eigen::MatrixBase< Derived > &mat) -> decltype(mat.diagonal())
Return a vector representation of the diagonal of a matrix.
Definition: Matrix.hpp:690
Eigen::Ref< RowVectorXd > RowVectorXdRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:160
Eigen::Ref< VectorXd > VectorXdRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:75
Eigen::Ref< VectorXr, 0, Eigen::InnerStride<> > VectorXrStridedRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:63
auto max(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.maxCoeff())
Return the maximum component of a matrix.
Definition: Matrix.hpp:744
VectorX< Eigen::Index > VectorXl
Convenient alias to Eigen type.
Definition: Matrix.hpp:66
Eigen::Map< ArrayXr > ArrayXrMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:90
Eigen::Map< const ArrayXr > ArrayXrConstMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:91
auto log10(const Eigen::MatrixBase< Derived > &mat) -> decltype(mat.array().log10().matrix())
Return the component-wise log10 of a matrix.
Definition: Matrix.hpp:828
Eigen::Map< VectorXd > VectorXdMap
Convenient alias to Eigen type.
Definition: Matrix.hpp:77
static auto equal(const CacheType &a, const Type &b)
Return true if two arrays are equal.
Definition: Matrix.hpp:457
static auto assign(const CacheType &a, const Type &b)
Assign an Eigen ref object to an Eigen object.
Definition: Matrix.hpp:478
static auto equal(const CacheType &a, const Type &b)
Return true if the two Eigen objects are equal.
Definition: Matrix.hpp:472
Used to enable function arguments of a type T to be cached in a memoized version of the function.
Definition: Memoization.hpp:30
static auto assign(CacheType &a, const Type &b)
Assign the value of b, of type T, into a, of type CacheType.
Definition: Memoization.hpp:64
static auto equal(const CacheType &a, const Type &b)
Check if a, of type CacheType, is equal to b, of type T.
Definition: Memoization.hpp:56
Type CacheType
The type of the object constructed with a given object of type T.
Definition: Memoization.hpp:47
Definition: TypeOp.hpp:35
Definition: TypeOp.hpp:29