Skip to content

Commit

Permalink
Very Minor Simplification to Matrix Functions (#2222)
Browse files Browse the repository at this point in the history
The external Matrix library has introduced some changes which permit the matrix functions to be slightly simplified.
  • Loading branch information
oleibman committed Jul 22, 2021
1 parent 11bf051 commit 3c5750b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/PhpSpreadsheet/Calculation/MathTrig/MatrixFunctions.php
Expand Up @@ -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;
Expand Down Expand Up @@ -84,8 +85,10 @@ public static function inverse($matrixValues)
$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();
}
Expand Down Expand Up @@ -125,10 +128,7 @@ public static function identity($dimension)
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) {
Expand Down

0 comments on commit 3c5750b

Please sign in to comment.