make Umeyama, and its unit-test, work for me on gcc 4.3

This commit is contained in:
Benoit Jacob 2009-05-27 23:10:24 +02:00
parent 86be59124d
commit ee92009fd8
3 changed files with 39 additions and 62 deletions

View File

@ -64,6 +64,7 @@
YOU_CALLED_A_FIXED_SIZE_METHOD_ON_A_DYNAMIC_SIZE_MATRIX_OR_VECTOR,
UNALIGNED_LOAD_AND_STORE_OPERATIONS_UNIMPLEMENTED_ON_ALTIVEC,
NUMERIC_TYPE_MUST_BE_FLOATING_POINT,
NUMERIC_TYPE_MUST_BE_REAL,
COEFFICIENT_WRITE_ACCESS_TO_SELFADJOINT_NOT_SUPPORTED,
WRITING_TO_TRIANGULAR_PART_WITH_UNIT_DIAGONAL_IS_NOT_SUPPORTED,
THIS_METHOD_IS_ONLY_FOR_FIXED_SIZE,

View File

@ -110,7 +110,7 @@ umeyama(const MatrixBase<Derived>& src, const MatrixBase<OtherDerived>& dst, boo
typedef typename ei_traits<TransformationMatrixType>::Scalar Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_FLOATING_POINT)
EIGEN_STATIC_ASSERT(!NumTraits<Scalar>::IsComplex, NUMERIC_TYPE_MUST_BE_REAL)
EIGEN_STATIC_ASSERT((ei_is_same_type<Scalar, typename ei_traits<OtherDerived>::Scalar>::ret),
YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY)
@ -141,7 +141,7 @@ umeyama(const MatrixBase<Derived>& src, const MatrixBase<OtherDerived>& dst, boo
// Eq. (36)-(37)
const Scalar src_var = src_demean.rowwise().squaredNorm().sum() * one_over_n;
const Scalar dst_var = dst_demean.rowwise().squaredNorm().sum() * one_over_n;
// const Scalar dst_var = dst_demean.rowwise().squaredNorm().sum() * one_over_n;
// Eq. (38)
const MatrixType sigma = (dst_demean*src_demean.transpose()).lazy() * one_over_n;
@ -182,22 +182,4 @@ umeyama(const MatrixBase<Derived>& src, const MatrixBase<OtherDerived>& dst, boo
return Rt;
}
#ifndef EIGEN_PARSED_BY_DOXYGEN
/**
* This is simply here to prevent the creation of dozens compile time errors for
* std::complex types...
*/
template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols,
typename _OtherScalar, int _OtherRows, int _OtherCols, int _OtherOptions, int _OtherMaxRows, int _OtherMaxCols>
typename ei_umeyama_transform_matrix_type<Matrix<std::complex<_Scalar>,_Rows,_Cols,_Options,_MaxRows,_MaxCols>,
Matrix<std::complex<_OtherScalar>,_OtherRows,_OtherCols,_OtherOptions,_OtherMaxRows,_OtherMaxCols> >::type
umeyama(const MatrixBase<Matrix<std::complex<_Scalar>,_Rows,_Cols,_Options,_MaxRows,_MaxCols> >& src,
const MatrixBase<Matrix<std::complex<_OtherScalar>,_OtherRows,_OtherCols,_OtherOptions,_OtherMaxRows,_OtherMaxCols> >& dst, bool with_scaling = true)
{
EIGEN_STATIC_ASSERT(false, NUMERIC_TYPE_MUST_BE_FLOATING_POINT)
}
#endif
#endif // EIGEN_UMEYAMA_H

View File

@ -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 <typename T>
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> randMatrixUnitary(int size)
{
typedef typename T Scalar;
typedef T Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> MatrixType;
@ -55,58 +49,58 @@ Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> 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();
}
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
// 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 <typename T>
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> randMatrixSpecialUnitary(int size)
{
typedef typename T Scalar;
typedef T Scalar;
typedef typename NumTraits<Scalar>::Real RealScalar;
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic> MatrixType;
// initialize unitary matrix
MatrixType Q = randMatrixUnitary<Scalar>(size);
// initialize unitary matrix
MatrixType Q = randMatrixUnitary<Scalar>(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<MatrixXf>(dim, num_elements));
}
VAR_CALL_SUBTEST(run_fixed_size_test<float, 2>(num_elements));
VAR_CALL_SUBTEST(run_fixed_size_test<float, 3>(num_elements));
VAR_CALL_SUBTEST(run_fixed_size_test<float, 4>(num_elements));
CALL_SUBTEST((run_fixed_size_test<float, 2>(num_elements)));
CALL_SUBTEST((run_fixed_size_test<float, 3>(num_elements)));
CALL_SUBTEST((run_fixed_size_test<float, 4>(num_elements)));
VAR_CALL_SUBTEST(run_fixed_size_test<double, 2>(num_elements));
VAR_CALL_SUBTEST(run_fixed_size_test<double, 3>(num_elements));
VAR_CALL_SUBTEST(run_fixed_size_test<double, 4>(num_elements));
CALL_SUBTEST((run_fixed_size_test<double, 2>(num_elements)));
CALL_SUBTEST((run_fixed_size_test<double, 3>(num_elements)));
CALL_SUBTEST((run_fixed_size_test<double, 4>(num_elements)));
}
// Those two calls don't compile and result in meaningful error messages!