13 #include <Eigen/Geometry> 18 using namespace Eigen;
30 double is_unitary =
false;
32 while (!is_unitary && max_tries > 0)
35 Q = MatrixType::Random(size, size);
41 for (
int prevCol = 0; prevCol <
col; ++prevCol)
44 colVec -= colVec.dot(prevColVec)*prevColVec;
46 Q.col(col) = colVec.normalized();
54 for (
int prevRow = 0; prevRow <
row; ++prevRow)
57 rowVec -= rowVec.dot(prevRowVec)*prevRowVec;
59 Q.row(row) = rowVec.normalized();
63 is_unitary = Q.isUnitary();
68 eigen_assert(
false &&
"randMatrixUnitary: Could not construct unitary matrix!");
82 MatrixType
Q = randMatrixUnitary<Scalar>(
size);
90 template <
typename MatrixType>
100 const Scalar
c =
abs(internal::random<Scalar>());
102 MatrixX
R = randMatrixSpecialUnitary<Scalar>(
dim);
103 VectorX
t =
Scalar(50)*VectorX::Random(dim,1);
105 MatrixX cR_t = MatrixX::Identity(dim+1,dim+1);
106 cR_t.block(0,0,dim,dim) = c*
R;
107 cR_t.block(0,dim,dim,1) =
t;
109 MatrixX src = MatrixX::Random(dim+1, num_elements);
112 MatrixX dst = cR_t*src;
114 MatrixX cR_t_umeyama =
umeyama(src.block(0,0,dim,num_elements), dst.block(0,0,dim,num_elements));
116 const Scalar
error = ( cR_t_umeyama*src - dst ).norm() / dst.norm();
120 template<
typename Scalar,
int Dimension>
129 const int dim = Dimension;
134 const Scalar c = internal::random<Scalar>(0.5, 2.0);
136 FixedMatrix
R = randMatrixSpecialUnitary<Scalar>(
dim);
137 FixedVector
t =
Scalar(32)*FixedVector::Random(dim,1);
139 HomMatrix cR_t = HomMatrix::Identity(dim+1,dim+1);
140 cR_t.block(0,0,dim,dim) = c*
R;
141 cR_t.block(0,dim,dim,1) =
t;
143 MatrixX src = MatrixX::Random(dim+1, num_elements);
146 MatrixX dst = cR_t*src;
151 HomMatrix cR_t_umeyama =
umeyama(src_block, dst_block);
153 const Scalar error = ( cR_t_umeyama*src - dst ).squaredNorm();
162 const int num_elements = internal::random<int>(40,500);
167 CALL_SUBTEST_1(run_test<MatrixXd>(
dim, num_elements));
168 CALL_SUBTEST_2(run_test<MatrixXf>(
dim, num_elements));
171 CALL_SUBTEST_3((run_fixed_size_test<float, 2>(num_elements)));
172 CALL_SUBTEST_4((run_fixed_size_test<float, 3>(num_elements)));
173 CALL_SUBTEST_5((run_fixed_size_test<float, 4>(num_elements)));
175 CALL_SUBTEST_6((run_fixed_size_test<double, 2>(num_elements)));
176 CALL_SUBTEST_7((run_fixed_size_test<double, 3>(num_elements)));
177 CALL_SUBTEST_8((run_fixed_size_test<double, 4>(num_elements)));
Block< Derived, 1, internal::traits< Derived >::ColsAtCompileTime, IsRowMajor > RowXpr
Matrix< Scalar, Dynamic, 1 > VectorX
void run_test(int dim, int num_elements)
Rot2 R(Rot2::fromAngle(0.1))
Namespace containing all symbols from the Eigen library.
Block< Derived, internal::traits< Derived >::RowsAtCompileTime, 1,!IsRowMajor > ColXpr
void run_fixed_size_test(int num_elements)
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > randMatrixSpecialUnitary(int size)
internal::umeyama_transform_matrix_type< Derived, OtherDerived >::type umeyama(const MatrixBase< Derived > &src, const MatrixBase< OtherDerived > &dst, bool with_scaling=true)
Returns the transformation between two point sets.
const mpreal dim(const mpreal &a, const mpreal &b, mp_rnd_t r=mpreal::get_default_rnd())
Expression of a fixed-size or dynamic-size block.
The quaternion class used to represent 3D orientations and rotations.
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > randMatrixUnitary(int size)
The matrix class, also used for vectors and row-vectors.
ScalarWithExceptions conj(const ScalarWithExceptions &x)