68 const double &delta) : B(B0),
69 U(
Eigen::Matrix<long int,
Eigen::Dynamic,
Eigen::Dynamic>::Identity(B0.cols(), B0.cols()))
71 assert(delta >= 0.5 && delta <= 1.0 &&
"delta must be in [0.5 1]");
73 const int n = B0.cols();
74 assert(n <= B0.rows() &&
"B.rows() must be >= B.cols()");
77 VectorType H(VectorType::Zero(n));
78 for (
int j = 0;
j < n; ++
j)
80 H(
j) = B.col(
j).squaredNorm();
86 MatrixType
M(MatrixType::Identity(n, n));
87 for (
int j = 0;
j < n; ++
j)
89 for (
int i =
j + 1;
i < n; ++
i)
94 for (
int k = 0;
k <=
j - 1; ++
k)
100 M(
i,
j) = (B.col(
i).dot(B.col(
j)) -
temp) / H(
j);
101 H(
i) -= std::pow(
M(
i,
j), 2) * H(
j);
112 if (fabs(
M(
k,
k - 1)) > 0.5)
114 size_reduce(
M,
k,
k - 1);
117 if (H(
k) < (delta - std::pow(
M(
k,
k - 1), 2)) * H(
k - 1))
120 U.col(
k).swap(U.col(
k - 1));
121 k = std::max(1,
k - 1);
126 for (
int j =
k - 2;
j >= 0; --
j)
128 if (fabs(
M(
k,
j)) > 0.5)
130 size_reduce(
M,
k,
j);
137 const double err = (B0.lu().solve(B) - U.cast<
double>()).norm() / U.cast<
double>().norm();
138 if (err > FLT_EPSILON)
140 std::cout <<
"RLLL relative error= " << std::setprecision(15) << std::scientific << err <<
" > " << FLT_EPSILON << std::endl;
141 assert(
false &&
"Relative error too large. RLLL failed.");
144 const double absDetU(fabs(U.cast<
double>().determinant()));
145 if (fabs(absDetU - 1.0) > FLT_EPSILON)
147 std::cout <<
"|det(U)|= " << std::setprecision(15) << std::scientific << absDetU << std::endl;
148 assert(
false &&
"U is not unimodular. RLLL failed.");