From ee92009fd8f178111218ac4721d225237efad0b7 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Wed, 27 May 2009 23:10:24 +0200 Subject: make Umeyama, and its unit-test, work for me on gcc 4.3 --- test/umeyama.cpp | 80 ++++++++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 43 deletions(-) (limited to 'test/umeyama.cpp') diff --git a/test/umeyama.cpp b/test/umeyama.cpp index 94198ae44..b6d394883 100644 --- a/test/umeyama.cpp +++ b/test/umeyama.cpp @@ -33,17 +33,11 @@ using namespace Eigen; -#define VAR_CALL_SUBTEST(...) do { \ - g_test_stack.push_back(EI_PP_MAKE_STRING(__VA_ARGS__)); \ - __VA_ARGS__; \ - g_test_stack.pop_back(); \ -} while (0) - // Constructs a random matrix from the unitary group U(size). template Eigen::Matrix randMatrixUnitary(int size) { - typedef typename T Scalar; + typedef T Scalar; typedef typename NumTraits::Real RealScalar; typedef Eigen::Matrix MatrixType; @@ -55,58 +49,58 @@ Eigen::Matrix randMatrixUnitary(int size) while (!is_unitary && max_tries > 0) { - // initialize random matrix + // initialize random matrix Q = MatrixType::Random(size, size); - // orthogonalize columns using the Gram-Schmidt algorithm - for (int col = 0; col < size; ++col) - { - MatrixType::ColXpr colVec = Q.col(col); - for (int prevCol = 0; prevCol < col; ++prevCol) - { - MatrixType::ColXpr prevColVec = Q.col(prevCol); + // orthogonalize columns using the Gram-Schmidt algorithm + for (int col = 0; col < size; ++col) + { + typename MatrixType::ColXpr colVec = Q.col(col); + for (int prevCol = 0; prevCol < col; ++prevCol) + { + typename MatrixType::ColXpr prevColVec = Q.col(prevCol); colVec -= colVec.dot(prevColVec)*prevColVec; - } - Q.col(col) = colVec.normalized(); - } + } + Q.col(col) = colVec.normalized(); + } - // this additional orthogonalization is not necessary in theory but should enhance + // this additional orthogonalization is not necessary in theory but should enhance // the numerical orthogonality of the matrix - for (int row = 0; row < size; ++row) - { - MatrixType::RowXpr rowVec = Q.row(row); - for (int prevRow = 0; prevRow < row; ++prevRow) - { - MatrixType::RowXpr prevRowVec = Q.row(prevRow); - rowVec -= rowVec.dot(prevRowVec)*prevRowVec; - } - Q.row(row) = rowVec.normalized(); - } - - // final check + for (int row = 0; row < size; ++row) + { + typename MatrixType::RowXpr rowVec = Q.row(row); + for (int prevRow = 0; prevRow < row; ++prevRow) + { + typename MatrixType::RowXpr prevRowVec = Q.row(prevRow); + rowVec -= rowVec.dot(prevRowVec)*prevRowVec; + } + Q.row(row) = rowVec.normalized(); + } + + // final check is_unitary = Q.isUnitary(); --max_tries; } if (max_tries == 0) - throw std::runtime_error("randMatrixUnitary: Could not construct unitary matrix!"); + ei_assert(false && "randMatrixUnitary: Could not construct unitary matrix!"); - return Q; + return Q; } // Constructs a random matrix from the special unitary group SU(size). template Eigen::Matrix randMatrixSpecialUnitary(int size) { - typedef typename T Scalar; + typedef T Scalar; typedef typename NumTraits::Real RealScalar; typedef Eigen::Matrix MatrixType; - // initialize unitary matrix - MatrixType Q = randMatrixUnitary(size); + // initialize unitary matrix + MatrixType Q = randMatrixUnitary(size); - // tweak the first column to make the determinant be 1 + // tweak the first column to make the determinant be 1 Q.col(0) *= ei_conj(Q.determinant()); return Q; @@ -191,13 +185,13 @@ void test_umeyama() CALL_SUBTEST(run_test(dim, num_elements)); } - VAR_CALL_SUBTEST(run_fixed_size_test(num_elements)); - VAR_CALL_SUBTEST(run_fixed_size_test(num_elements)); - VAR_CALL_SUBTEST(run_fixed_size_test(num_elements)); + CALL_SUBTEST((run_fixed_size_test(num_elements))); + CALL_SUBTEST((run_fixed_size_test(num_elements))); + CALL_SUBTEST((run_fixed_size_test(num_elements))); - VAR_CALL_SUBTEST(run_fixed_size_test(num_elements)); - VAR_CALL_SUBTEST(run_fixed_size_test(num_elements)); - VAR_CALL_SUBTEST(run_fixed_size_test(num_elements)); + CALL_SUBTEST((run_fixed_size_test(num_elements))); + CALL_SUBTEST((run_fixed_size_test(num_elements))); + CALL_SUBTEST((run_fixed_size_test(num_elements))); } // Those two calls don't compile and result in meaningful error messages! -- cgit v1.2.3