Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very Minor Simplification to Matrix Functions #2222

Merged
merged 2 commits into from Jul 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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