10 #ifndef EIGEN_MATRIX_FUNCTION_H
11 #define EIGEN_MATRIX_FUNCTION_H
31 template <
typename MatrixType>
52 template <
typename MatrixType>
58 N.template triangularView<Upper>().solveInPlace(
e);
59 return e.cwiseAbs().maxCoeff();
62 template <
typename MatrixType>
74 Fincr = m_f(avgEival,
static_cast<int>(
s)) *
P;
79 const RealScalar F_norm =
F.cwiseAbs().rowwise().sum().maxCoeff();
80 const RealScalar Fincr_norm = Fincr.cwiseAbs().rowwise().sum().maxCoeff();
91 const RealScalar P_norm =
P.cwiseAbs().rowwise().sum().maxCoeff();
104 template <
typename Index,
typename ListOfClusters>
106 typename std::list<Index>::iterator
j;
107 for (
typename ListOfClusters::iterator
i = clusters.begin();
i != clusters.end(); ++
i) {
108 j = std::find(
i->begin(),
i->end(), key);
109 if (
j !=
i->end())
return i;
111 return clusters.end();
125 template <
typename EivalsType,
typename Cluster>
131 if (qi == clusters.end()) {
134 clusters.push_back(l);
142 std::find(qi->begin(), qi->end(),
j) == qi->end()) {
144 if (qj == clusters.end()) {
147 qi->insert(qi->end(), qj->begin(), qj->end());
156 template <
typename ListOfClusters,
typename Index>
158 const Index numClusters =
static_cast<Index>(clusters.size());
159 clusterSize.
setZero(numClusters);
160 Index clusterIndex = 0;
161 for (
typename ListOfClusters::const_iterator cluster = clusters.begin(); cluster != clusters.end(); ++cluster) {
162 clusterSize[clusterIndex] = cluster->size();
168 template <
typename VectorType>
170 blockStart.resize(clusterSize.rows());
172 for (
Index i = 1;
i < clusterSize.rows();
i++) {
173 blockStart(
i) = blockStart(
i - 1) + clusterSize(
i - 1);
178 template <
typename EivalsType,
typename ListOfClusters,
typename VectorType>
180 eivalToCluster.resize(
eivals.rows());
181 Index clusterIndex = 0;
182 for (
typename ListOfClusters::const_iterator cluster = clusters.begin(); cluster != clusters.end(); ++cluster) {
184 if (std::find(cluster->begin(), cluster->end(),
i) != cluster->end()) {
185 eivalToCluster[
i] = clusterIndex;
193 template <
typename DynVectorType,
typename VectorType>
196 DynVectorType indexNextEntry = blockStart;
197 permutation.resize(eivalToCluster.rows());
198 for (
Index i = 0;
i < eivalToCluster.rows();
i++) {
199 Index cluster = eivalToCluster[
i];
200 permutation[
i] = indexNextEntry[cluster];
201 ++indexNextEntry[cluster];
206 template <
typename VectorType,
typename MatrixType>
208 for (
Index i = 0;
i < permutation.rows() - 1;
i++) {
210 for (
j =
i;
j < permutation.rows();
j++) {
211 if (permutation(
j) ==
i)
break;
217 T.applyOnTheLeft(
k,
k + 1, rotation.
adjoint());
218 T.applyOnTheRight(
k,
k + 1, rotation);
219 U.applyOnTheRight(
k,
k + 1, rotation);
220 std::swap(permutation.coeffRef(
k), permutation.coeffRef(
k + 1));
231 template <
typename MatrixType,
typename AtomicType,
typename VectorType>
234 fT.setZero(
T.rows(),
T.cols());
235 for (
Index i = 0;
i < clusterSize.rows(); ++
i) {
236 fT.block(blockStart(
i), blockStart(
i), clusterSize(
i), clusterSize(
i)) =
237 atomic.compute(
T.block(blockStart(
i), blockStart(
i), clusterSize(
i), clusterSize(
i)));
263 template <
typename MatrixType>
310 template <
typename MatrixType,
typename VectorType>
315 static const int Options = MatrixType::Options;
318 for (
Index k = 1;
k < clusterSize.rows();
k++) {
319 for (
Index i = 0;
i < clusterSize.rows() -
k;
i++) {
321 DynMatrixType
A =
T.block(blockStart(
i), blockStart(
i), clusterSize(
i), clusterSize(
i));
322 DynMatrixType
B = -
T.block(blockStart(
i +
k), blockStart(
i +
k), clusterSize(
i +
k), clusterSize(
i +
k));
323 DynMatrixType
C = fT.block(blockStart(
i), blockStart(
i), clusterSize(
i), clusterSize(
i)) *
324 T.block(blockStart(
i), blockStart(
i +
k), clusterSize(
i), clusterSize(
i +
k));
325 C -=
T.block(blockStart(
i), blockStart(
i +
k), clusterSize(
i), clusterSize(
i +
k)) *
326 fT.block(blockStart(
i +
k), blockStart(
i +
k), clusterSize(
i +
k), clusterSize(
i +
k));
328 C += fT.block(blockStart(
i), blockStart(
m), clusterSize(
i), clusterSize(
m)) *
329 T.block(blockStart(
m), blockStart(
i +
k), clusterSize(
m), clusterSize(
i +
k));
330 C -=
T.block(blockStart(
i), blockStart(
m), clusterSize(
i), clusterSize(
m)) *
331 fT.block(blockStart(
m), blockStart(
i +
k), clusterSize(
m), clusterSize(
i +
k));
333 fT.block(blockStart(
i), blockStart(
i +
k), clusterSize(
i), clusterSize(
i +
k)) =
366 template <
typename AtomicType,
typename ResultType>
376 template <
typename MatrixType>
378 template <
typename MatA,
typename AtomicType,
typename ResultType>
379 static void run(
const MatA&
A, AtomicType& atomic, ResultType& result) {
382 static const int Rows = Traits::RowsAtCompileTime, Cols = Traits::ColsAtCompileTime;
383 static const int MaxRows = Traits::MaxRowsAtCompileTime, MaxCols = Traits::MaxColsAtCompileTime;
385 typedef std::complex<Scalar> ComplexScalar;
388 ComplexMatrix CA =
A.template cast<ComplexScalar>();
389 ComplexMatrix Cresult;
391 result = Cresult.real();
398 template <
typename MatrixType>
400 template <
typename MatA,
typename AtomicType,
typename ResultType>
401 static void run(
const MatA&
A, AtomicType& atomic, ResultType& result) {
411 std::list<std::list<Index> > clusters;
437 result =
U * (fT.template triangularView<Upper>() *
U.adjoint());
453 template <
typename Derived>
474 template <
typename ResultType>
475 inline void evalTo(ResultType& result)
const {
484 AtomicType atomic(
m_f);
498 template <
typename Derived>
506 template <
typename Derived>
513 template <
typename Derived>
520 template <
typename Derived>
524 return MatrixFunctionReturnValue<Derived>(derived(), internal::stem_function_cos<ComplexScalar>);
527 template <
typename Derived>
531 return MatrixFunctionReturnValue<Derived>(derived(), internal::stem_function_sinh<ComplexScalar>);
534 template <
typename Derived>
538 return MatrixFunctionReturnValue<Derived>(derived(), internal::stem_function_cosh<ComplexScalar>);
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
AnnoyingScalar cos(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:136
AnnoyingScalar sin(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:137
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
cout<< "Here is a random 4x4 matrix, A:"<< endl<< A<< endl<< endl;ComplexSchur< MatrixXcf > schurOfA(A, false)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
#define eigen_assert(x)
Definition: Macros.h:910
VectorXcd eivals
Definition: MatrixBase_eigenvalues.cpp:2
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Matrix< Scalar, Dynamic, Dynamic > C
Definition: bench_gemm.cpp:49
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
Matrix< SCALARB, Dynamic, Dynamic, opt_B > B
Definition: bench_gemm.cpp:48
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
boost::multiprecision::number< boost::multiprecision::cpp_dec_float< 100 >, boost::multiprecision::et_on > Real
Definition: boostmultiprec.cpp:77
Rotation given by a cosine-sine pair.
Definition: Jacobi.h:38
EIGEN_DEVICE_FUNC void makeGivens(const Scalar &p, const Scalar &q, Scalar *r=0)
Definition: Jacobi.h:152
EIGEN_DEVICE_FUNC JacobiRotation adjoint() const
Definition: Jacobi.h:67
const MatrixFunctionReturnValue< Derived > matrixFunction(StemFunction f) const
Helper function for the unsupported MatrixFunctions module.
Definition: MatrixFunction.h:507
Proxy for the matrix function of some matrix (expression).
Definition: MatrixFunction.h:454
internal::ref_selector< Derived >::type DerivedNested
Definition: MatrixFunction.h:460
Index rows() const
Definition: MatrixFunction.h:489
internal::stem_function< Scalar >::type StemFunction
Definition: MatrixFunction.h:457
void evalTo(ResultType &result) const
Compute the matrix function.
Definition: MatrixFunction.h:475
StemFunction * m_f
Definition: MatrixFunction.h:494
Index cols() const
Definition: MatrixFunction.h:490
Derived::Scalar Scalar
Definition: MatrixFunction.h:456
MatrixFunctionReturnValue(const Derived &A, StemFunction f)
Constructor.
Definition: MatrixFunction.h:468
const DerivedNested m_A
Definition: MatrixFunction.h:493
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index cols() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:192
EIGEN_DEVICE_FUNC Derived & setZero(Index size)
Definition: CwiseNullaryOp.h:569
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE EIGEN_CONSTEXPR Index rows() const EIGEN_NOEXCEPT
Definition: PlainObjectBase.h:191
Definition: ReturnByValue.h:50
Helper class for computing matrix functions of atomic matrices.
Definition: MatrixFunction.h:32
MatrixFunctionAtomic(StemFunction f)
Constructor.
Definition: MatrixFunction.h:40
MatrixType::Scalar Scalar
Definition: MatrixFunction.h:34
MatrixType compute(const MatrixType &A)
Compute matrix function of atomic matrix.
Definition: MatrixFunction.h:63
StemFunction * m_f
Definition: MatrixFunction.h:49
stem_function< Scalar >::type StemFunction
Definition: MatrixFunction.h:35
Definition: matrices.h:74
@ IsComplex
Definition: common.h:73
@ N
Definition: constructor.cpp:22
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
Definition: cxx11_tensor_map.cpp:237
#define max(a, b)
Definition: datatypes.h:23
@ Success
Definition: Constants.h:440
#define X
Definition: icosphere.cpp:20
RealScalar s
Definition: level1_cplx_impl.h:130
EIGEN_BLAS_FUNC() swap(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Definition: level1_impl.h:117
int * m
Definition: level2_cplx_impl.h:294
char char char int int * k
Definition: level2_impl.h:374
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 cosh(const bfloat16 &a)
Definition: BFloat16.h:638
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 sinh(const bfloat16 &a)
Definition: BFloat16.h:637
void matrix_function_compute_permutation(const DynVectorType &blockStart, const DynVectorType &eivalToCluster, VectorType &permutation)
Compute permutation which groups ei'vals in same cluster together.
Definition: MatrixFunction.h:194
void matrix_function_compute_cluster_size(const ListOfClusters &clusters, Matrix< Index, Dynamic, 1 > &clusterSize)
Compute size of each cluster given a partitioning.
Definition: MatrixFunction.h:157
void matrix_function_compute_block_start(const VectorType &clusterSize, VectorType &blockStart)
Compute start of each block using clusterSize.
Definition: MatrixFunction.h:169
void matrix_function_compute_block_atomic(const MatrixType &T, AtomicType &atomic, const VectorType &blockStart, const VectorType &clusterSize, MatrixType &fT)
Compute block diagonal part of matrix function.
Definition: MatrixFunction.h:232
void matrix_function_permute_schur(VectorType &permutation, MatrixType &U, MatrixType &T)
Permute Schur decomposition in U and T according to permutation.
Definition: MatrixFunction.h:207
static const float matrix_function_separation
Maximum distance allowed between eigenvalues to be considered "close".
Definition: MatrixFunction.h:23
void matrix_function_compute_above_diagonal(const MatrixType &T, const VectorType &blockStart, const VectorType &clusterSize, MatrixType &fT)
Compute part of matrix function above block diagonal.
Definition: MatrixFunction.h:311
void matrix_function_partition_eigenvalues(const EivalsType &eivals, std::list< Cluster > &clusters)
Partition eigenvalues in clusters of ei'vals close to each other.
Definition: MatrixFunction.h:126
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
NumTraits< typename MatrixType::Scalar >::Real matrix_function_compute_mu(const MatrixType &A)
Definition: MatrixFunction.h:53
MatrixType matrix_function_solve_triangular_sylvester(const MatrixType &A, const MatrixType &B, const MatrixType &C)
Solve a triangular Sylvester equation AX + XB = C.
Definition: MatrixFunction.h:264
void matrix_function_compute_map(const EivalsType &eivals, const ListOfClusters &clusters, VectorType &eivalToCluster)
Compute mapping of eigenvalue indices to cluster indices.
Definition: MatrixFunction.h:179
ListOfClusters::iterator matrix_function_find_cluster(Index key, ListOfClusters &clusters)
Find cluster in clusters containing some value.
Definition: MatrixFunction.h:105
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
std::complex< double > mu
Definition: time_harmonic_fourier_decomposed_linear_elasticity/cylinder/cylinder.cc:52
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
int delta
Definition: MultiOpt.py:96
double U
Swimming speed.
Definition: two_d_variable_diff_adapt.cc:53
type
Definition: compute_granudrum_aor.py:141
Definition: Eigen_Colamd.h:49
@ F
Definition: octree.h:74
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
static void run(const MatA &A, AtomicType &atomic, ResultType &result)
Definition: MatrixFunction.h:379
static void run(const MatA &A, AtomicType &atomic, ResultType &result)
Definition: MatrixFunction.h:401
Class for computing matrix functions.
Definition: MatrixFunction.h:355
static void run(const MatrixType &A, AtomicType &atomic, ResultType &result)
Compute the matrix function.
std::conditional_t< Evaluate, PlainObject, typename ref_selector< T >::type > type
Definition: XprHelper.h:549
std::conditional_t< is_same< typename traits< ExpressionType >::XprKind, MatrixXpr >::value, MatrixColType, ArrayColType > type
Definition: XprHelper.h:782
std::conditional_t< bool(traits< T >::Flags &NestByRefBit), T const &, const T > type
Definition: XprHelper.h:507
Definition: ForwardDeclarations.h:499
std::complex< typename NumTraits< Scalar >::Real > ComplexScalar
Definition: ForwardDeclarations.h:500
Derived::PlainObject ReturnType
Definition: MatrixFunction.h:500
Definition: fft_test_shared.h:66
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2