10 #ifndef EIGEN_MATRIX_SQUARE_ROOT
11 #define EIGEN_MATRIX_SQUARE_ROOT
22 template <
typename MatrixType,
typename ResultType>
29 sqrtT.template block<2, 2>(
i,
i) =
30 (
es.eigenvectors() *
es.eigenvalues().cwiseSqrt().asDiagonal() *
es.eigenvectors().inverse()).
real();
36 template <
typename MatrixType,
typename ResultType>
40 sqrtT.coeffRef(
i,
j) = (
T.coeff(
i,
j) -
tmp) / (sqrtT.coeff(
i,
i) + sqrtT.coeff(
j,
j));
44 template <
typename MatrixType,
typename ResultType>
48 if (
j -
i > 1) rhs -= sqrtT.block(
i,
i + 1, 1,
j -
i - 1) * sqrtT.block(
i + 1,
j,
j -
i - 1, 2);
50 A += sqrtT.template block<2, 2>(
j,
j).transpose();
51 sqrtT.template block<1, 2>(
i,
j).transpose() =
A.fullPivLu().solve(rhs.transpose());
55 template <
typename MatrixType,
typename ResultType>
59 if (
j -
i > 2) rhs -= sqrtT.block(
i,
i + 2, 2,
j -
i - 2) * sqrtT.block(
i + 2,
j,
j -
i - 2, 1);
61 A += sqrtT.template block<2, 2>(
i,
i);
62 sqrtT.template block<2, 1>(
i,
j) =
A.fullPivLu().solve(rhs);
66 template <
typename MatrixType>
75 coeffMatrix.
coeffRef(0, 1) =
B.coeff(1, 0);
77 coeffMatrix.
coeffRef(1, 0) =
B.coeff(0, 1);
80 coeffMatrix.
coeffRef(2, 3) =
B.coeff(1, 0);
82 coeffMatrix.
coeffRef(3, 2) =
B.coeff(0, 1);
91 result = coeffMatrix.fullPivLu().solve(rhs);
93 X.coeffRef(0, 0) = result.
coeff(0);
94 X.coeffRef(0, 1) = result.
coeff(1);
95 X.coeffRef(1, 0) = result.
coeff(2);
96 X.coeffRef(1, 1) = result.
coeff(3);
100 template <
typename MatrixType,
typename ResultType>
106 if (
j -
i > 2)
C -= sqrtT.block(
i,
i + 2, 2,
j -
i - 2) * sqrtT.block(
i + 2,
j,
j -
i - 2, 2);
109 sqrtT.template block<2, 2>(
i,
j) =
X;
114 template <
typename MatrixType,
typename ResultType>
119 if (
i ==
size - 1 ||
T.coeff(
i + 1,
i) == 0) {
121 sqrtT.coeffRef(
i,
i) =
sqrt(
T.coeff(
i,
i));
131 template <
typename MatrixType,
typename ResultType>
135 if (
T.coeff(
j,
j - 1) != 0)
138 if (
i > 0 &&
T.coeff(
i,
i - 1) != 0)
140 bool iBlockIs2x2 = (
i <
size - 1) && (
T.coeff(
i + 1,
i) != 0);
141 bool jBlockIs2x2 = (
j <
size - 1) && (
T.coeff(
j + 1,
j) != 0);
142 if (iBlockIs2x2 && jBlockIs2x2)
144 else if (iBlockIs2x2 && !jBlockIs2x2)
146 else if (!iBlockIs2x2 && jBlockIs2x2)
148 else if (!iBlockIs2x2 && !jBlockIs2x2)
171 template <
typename MatrixType,
typename ResultType>
174 result.resize(arg.rows(), arg.cols());
193 template <
typename MatrixType,
typename ResultType>
202 result.resize(arg.rows(), arg.cols());
203 for (
Index i = 0;
i < arg.rows();
i++) {
204 result.coeffRef(
i,
i) =
sqrt(arg.coeff(
i,
i));
206 for (
Index j = 1;
j < arg.cols();
j++) {
211 result.coeffRef(
i,
j) = (arg.coeff(
i,
j) -
tmp) / (result.coeff(
i,
i) + result.coeff(
j,
j));
234 template <
typename ResultType>
240 template <
typename MatrixType>
243 template <
typename ResultType>
257 result =
U * sqrtT *
U.adjoint();
263 template <
typename MatrixType>
266 template <
typename ResultType>
280 result =
U * (sqrtT.template triangularView<Upper>() *
U.adjoint());
298 template <
typename Derived>
316 template <
typename ResultType>
317 inline void evalTo(ResultType& result)
const {
332 template <
typename Derived>
338 template <
typename Derived>
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
int i
Definition: BiCGSTAB_step_by_step.cpp:9
cout<< "Here is a random 4x4 matrix, A:"<< endl<< A<< endl<< endl;ComplexSchur< MatrixXcf > schurOfA(A, false)
EigenSolver< MatrixXf > es
Definition: EigenSolver_compute.cpp:1
Eigen::Triplet< double > T
Definition: EigenUnitTest.cpp:11
#define eigen_assert(x)
Definition: Macros.h:910
m m block(1, 0, 2, 2)<< 4
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
Performs a complex Schur decomposition of a real or complex square matrix.
Definition: ComplexSchur.h:56
Computes eigenvalues and eigenvectors of general matrices.
Definition: EigenSolver.h:68
Proxy for the matrix square root of some matrix (expression).
Definition: MatrixSquareRoot.h:299
internal::ref_selector< Derived >::type DerivedNested
Definition: MatrixSquareRoot.h:301
Index cols() const
Definition: MatrixSquareRoot.h:325
const DerivedNested m_src
Definition: MatrixSquareRoot.h:328
void evalTo(ResultType &result) const
Compute the matrix square root.
Definition: MatrixSquareRoot.h:317
MatrixSquareRootReturnValue(const Derived &src)
Constructor.
Definition: MatrixSquareRoot.h:309
Index rows() const
Definition: MatrixSquareRoot.h:324
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE Scalar & coeffRef(Index rowId, Index colId)
Definition: PlainObjectBase.h:217
EIGEN_DEVICE_FUNC constexpr EIGEN_STRONG_INLINE const Scalar & coeff(Index rowId, Index colId) const
Definition: PlainObjectBase.h:198
Performs a real Schur decomposition of a square matrix.
Definition: RealSchur.h:58
Definition: ReturnByValue.h:50
Definition: matrices.h:74
@ IsComplex
Definition: common.h:73
#define X
Definition: icosphere.cpp:20
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
void matrix_sqrt_quasi_triangular_1x2_off_diagonal_block(const MatrixType &T, Index i, Index j, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:45
void matrix_sqrt_quasi_triangular_solve_auxiliary_equation(MatrixType &X, const MatrixType &A, const MatrixType &B, const MatrixType &C)
Definition: MatrixSquareRoot.h:67
void matrix_sqrt_quasi_triangular_diagonal(const MatrixType &T, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:115
void matrix_sqrt_quasi_triangular_2x2_diagonal_block(const MatrixType &T, Index i, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:23
typename remove_all< T >::type remove_all_t
Definition: Meta.h:142
void matrix_sqrt_quasi_triangular_off_diagonal(const MatrixType &T, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:132
void matrix_sqrt_quasi_triangular_2x2_off_diagonal_block(const MatrixType &T, Index i, Index j, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:101
void matrix_sqrt_quasi_triangular_1x1_off_diagonal_block(const MatrixType &T, Index i, Index j, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:37
void matrix_sqrt_quasi_triangular_2x1_off_diagonal_block(const MatrixType &T, Index i, Index j, ResultType &sqrtT)
Definition: MatrixSquareRoot.h:56
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:70
squared absolute value
Definition: GlobalFunctions.h:87
void matrix_sqrt_quasi_triangular(const MatrixType &arg, ResultType &result)
Compute matrix square root of quasi-triangular matrix.
Definition: MatrixSquareRoot.h:172
const AutoDiffScalar< DerType > & real(const AutoDiffScalar< DerType > &x)
Definition: AutoDiffScalar.h:486
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
void matrix_sqrt_triangular(const MatrixType &arg, ResultType &result)
Compute matrix square root of triangular matrix.
Definition: MatrixSquareRoot.h:194
double U
Swimming speed.
Definition: two_d_variable_diff_adapt.cc:53
Definition: Eigen_Colamd.h:49
double Zero
Definition: pseudosolid_node_update_elements.cc:35
MatrixType::PlainObject PlainType
Definition: MatrixSquareRoot.h:242
static void run(const MatrixType &arg, ResultType &result)
Definition: MatrixSquareRoot.h:244
static void run(const MatrixType &arg, ResultType &result)
Definition: MatrixSquareRoot.h:267
MatrixType::PlainObject PlainType
Definition: MatrixSquareRoot.h:265
Helper struct for computing matrix square roots of general matrices.
Definition: MatrixSquareRoot.h:226
static void run(const MatrixType &arg, ResultType &result)
Compute the matrix square root.
std::conditional_t< Evaluate, PlainObject, typename ref_selector< T >::type > type
Definition: XprHelper.h:549
std::conditional_t< bool(traits< T >::Flags &NestByRefBit), T const &, const T > type
Definition: XprHelper.h:507
Derived::PlainObject ReturnType
Definition: MatrixSquareRoot.h:334
Definition: ForwardDeclarations.h:21
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2