[poincare] Check for nan values when inverting matrix

Change-Id: Idb542682003348da151975e635958cf909010d16
This commit is contained in:
Hugo Saint-Vignes
2020-09-30 16:15:21 +02:00
committed by Émilie Feral
parent ab864d10d8
commit 3f43504398

View File

@@ -172,7 +172,12 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) {
T operands[2*k_maxNumberOfCoefficients];
for (int i = 0; i < dim; i++) {
for (int j = 0; j < dim; j++) {
operands[i*2*dim+j] = array[i*numberOfColumns+j];
T cell = array[i*numberOfColumns+j];
// Using abs function to be compatible with both double and std::complex
if (!std::isfinite(std::abs(cell))) {
return -2;
}
operands[i*2*dim+j] = cell;
}
for (int j = dim; j < 2*dim; j++) {
operands[i*2*dim+j] = j-dim == i ? 1.0 : 0.0;
@@ -181,7 +186,8 @@ int Matrix::ArrayInverse(T * array, int numberOfRows, int numberOfColumns) {
ArrayRowCanonize(operands, dim, 2*dim);
// Check inversibility
for (int i = 0; i < dim; i++) {
if (std::abs(operands[i*2*dim+i] - (T)1.0) > Expression::Epsilon<float>()) {
T cell = operands[i*2*dim+i];
if (!std::isfinite(std::abs(cell)) || std::abs(cell - (T)1.0) > Expression::Epsilon<float>()) {
return -2;
}
}