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