mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-23 14:07:34 +08:00
LeastSquaresSolver: Fix nasty GCC compile optimization error
The original implementation with no wrapping on size_t is more readable but the compiler errors with: internal compiler error: in trunc_int_for_mode, at explow.c:55 I read up and it's apparently a loop optimization problem. Inspired by https://stackoverflow.com/a/27224697/6326048 I used a far less readable implementation that works fine and wrote a comment to explain it.
This commit is contained in:
committed by
Julian Kent
parent
5844b0e46e
commit
3747232724
@@ -116,20 +116,21 @@ public:
|
||||
Vector<Type, M> qtbv = qtb(b);
|
||||
Vector<Type, N> x;
|
||||
|
||||
for (size_t l = N; l > 0 ; l--) {
|
||||
size_t i = l - 1;
|
||||
// size_t is unsigned and wraps i = 0 - 1 to i > N
|
||||
for (size_t i = N - 1; i < N; i--) {
|
||||
printf("i %d\n", static_cast<int>(i));
|
||||
x(i) = qtbv(i);
|
||||
for (size_t r = i+1; r < N; r++) {
|
||||
x(i) -= _A(i,r) * x(r);
|
||||
}
|
||||
// divide by zero, return vector of zeros
|
||||
if (fabs(_A(i,i)) < Type(1e-8)) {
|
||||
if (isEqualF(_A(i,i), Type(0), Type(1e-8))) {
|
||||
for (size_t z = 0; z < N; z++) {
|
||||
x(z) = Type(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
x(i) = x(i) / _A(i,i);
|
||||
x(i) /= _A(i,i);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user