mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -11,34 +11,34 @@
|
||||
#include <limits>
|
||||
#include <Eigen/Eigenvalues>
|
||||
|
||||
template<typename MatrixType> void verifyIsQuasiTriangular(const MatrixType& T)
|
||||
{
|
||||
template <typename MatrixType>
|
||||
void verifyIsQuasiTriangular(const MatrixType& T) {
|
||||
const Index size = T.cols();
|
||||
typedef typename MatrixType::Scalar Scalar;
|
||||
|
||||
// Check T is lower Hessenberg
|
||||
for(int row = 2; row < size; ++row) {
|
||||
for(int col = 0; col < row - 1; ++col) {
|
||||
VERIFY_IS_EQUAL(T(row,col), Scalar(0));
|
||||
for (int row = 2; row < size; ++row) {
|
||||
for (int col = 0; col < row - 1; ++col) {
|
||||
VERIFY_IS_EQUAL(T(row, col), Scalar(0));
|
||||
}
|
||||
}
|
||||
|
||||
// Check that any non-zero on the subdiagonal is followed by a zero and is
|
||||
// part of a 2x2 diagonal block with imaginary eigenvalues.
|
||||
for(int row = 1; row < size; ++row) {
|
||||
for (int row = 1; row < size; ++row) {
|
||||
if (!numext::is_exactly_zero(T(row, row - 1))) {
|
||||
VERIFY(row == size-1 || numext::is_exactly_zero(T(row + 1, row)));
|
||||
Scalar tr = T(row-1,row-1) + T(row,row);
|
||||
Scalar det = T(row-1,row-1) * T(row,row) - T(row-1,row) * T(row,row-1);
|
||||
VERIFY(row == size - 1 || numext::is_exactly_zero(T(row + 1, row)));
|
||||
Scalar tr = T(row - 1, row - 1) + T(row, row);
|
||||
Scalar det = T(row - 1, row - 1) * T(row, row) - T(row - 1, row) * T(row, row - 1);
|
||||
VERIFY(4 * det > tr * tr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTime)
|
||||
{
|
||||
template <typename MatrixType>
|
||||
void schur(int size = MatrixType::ColsAtCompileTime) {
|
||||
// Test basic functionality: T is quasi-triangular and A = U T U*
|
||||
for(int counter = 0; counter < g_repeat; ++counter) {
|
||||
for (int counter = 0; counter < g_repeat; ++counter) {
|
||||
MatrixType A = MatrixType::Random(size, size);
|
||||
RealSchur<MatrixType> schurOfA(A);
|
||||
VERIFY_IS_EQUAL(schurOfA.info(), Success);
|
||||
@@ -53,7 +53,7 @@ template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTim
|
||||
VERIFY_RAISES_ASSERT(rsUninitialized.matrixT());
|
||||
VERIFY_RAISES_ASSERT(rsUninitialized.matrixU());
|
||||
VERIFY_RAISES_ASSERT(rsUninitialized.info());
|
||||
|
||||
|
||||
// Test whether compute() and constructor returns same result
|
||||
MatrixType A = MatrixType::Random(size, size);
|
||||
RealSchur<MatrixType> rs1;
|
||||
@@ -77,10 +77,10 @@ template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTim
|
||||
}
|
||||
|
||||
MatrixType Atriangular = A;
|
||||
Atriangular.template triangularView<StrictlyLower>().setZero();
|
||||
rs3.setMaxIterations(1).compute(Atriangular); // triangular matrices do not need any iterations
|
||||
Atriangular.template triangularView<StrictlyLower>().setZero();
|
||||
rs3.setMaxIterations(1).compute(Atriangular); // triangular matrices do not need any iterations
|
||||
VERIFY_IS_EQUAL(rs3.info(), Success);
|
||||
VERIFY_IS_APPROX(rs3.matrixT(), Atriangular); // approx because of scaling...
|
||||
VERIFY_IS_APPROX(rs3.matrixT(), Atriangular); // approx because of scaling...
|
||||
VERIFY_IS_EQUAL(rs3.matrixU(), MatrixType::Identity(size, size));
|
||||
|
||||
// Test computation of only T, not U
|
||||
@@ -89,21 +89,19 @@ template<typename MatrixType> void schur(int size = MatrixType::ColsAtCompileTim
|
||||
VERIFY_IS_EQUAL(rs1.matrixT(), rsOnlyT.matrixT());
|
||||
VERIFY_RAISES_ASSERT(rsOnlyT.matrixU());
|
||||
|
||||
if (size > 2 && size < 20)
|
||||
{
|
||||
if (size > 2 && size < 20) {
|
||||
// Test matrix with NaN
|
||||
A(0,0) = std::numeric_limits<typename MatrixType::Scalar>::quiet_NaN();
|
||||
A(0, 0) = std::numeric_limits<typename MatrixType::Scalar>::quiet_NaN();
|
||||
RealSchur<MatrixType> rsNaN(A);
|
||||
VERIFY_IS_EQUAL(rsNaN.info(), NoConvergence);
|
||||
}
|
||||
}
|
||||
|
||||
EIGEN_DECLARE_TEST(schur_real)
|
||||
{
|
||||
CALL_SUBTEST_1(( schur<Matrix4f>() ));
|
||||
CALL_SUBTEST_2(( schur<MatrixXd>(internal::random<int>(1,EIGEN_TEST_MAX_SIZE/4)) ));
|
||||
CALL_SUBTEST_3(( schur<Matrix<float, 1, 1> >() ));
|
||||
CALL_SUBTEST_4(( schur<Matrix<double, 3, 3, Eigen::RowMajor> >() ));
|
||||
EIGEN_DECLARE_TEST(schur_real) {
|
||||
CALL_SUBTEST_1((schur<Matrix4f>()));
|
||||
CALL_SUBTEST_2((schur<MatrixXd>(internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 4))));
|
||||
CALL_SUBTEST_3((schur<Matrix<float, 1, 1> >()));
|
||||
CALL_SUBTEST_4((schur<Matrix<double, 3, 3, Eigen::RowMajor> >()));
|
||||
|
||||
// Test problem size constructors
|
||||
CALL_SUBTEST_5(RealSchur<MatrixXf>(10));
|
||||
|
||||
Reference in New Issue
Block a user