Very Minor Simplification to Matrix Functions (#2222)

The external Matrix library has introduced some changes which permit the matrix functions to be slightly simplified.
This commit is contained in:
oleibman 2021-07-22 11:01:25 -07:00 committed by GitHub
parent 11bf051c94
commit 3c5750bddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use Matrix\Builder;
use Matrix\Div0Exception as MatrixDiv0Exception;
use Matrix\Exception as MatrixException;
use Matrix\Matrix;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
@ -84,8 +85,10 @@ class MatrixFunctions
$matrix = self::getMatrix($matrixValues);
return $matrix->inverse()->toArray();
} catch (MatrixDiv0Exception $e) {
return Functions::NAN();
} catch (MatrixException $e) {
return (strpos($e->getMessage(), 'determinant') === false) ? Functions::VALUE() : Functions::NAN();
return Functions::VALUE();
} catch (Exception $e) {
return $e->getMessage();
}
@ -125,10 +128,7 @@ class MatrixFunctions
try {
$dimension = (int) Helpers::validateNumericNullBool($dimension);
Helpers::validatePositive($dimension, Functions::VALUE());
$matrix = Builder::createFilledMatrix(0, $dimension)->toArray();
for ($x = 0; $x < $dimension; ++$x) {
$matrix[$x][$x] = 1;
}
$matrix = Builder::createIdentityMatrix($dimension, 0)->toArray();
return $matrix;
} catch (Exception $e) {