Skip to content
Permalink
Browse files

Matrix (#790)

* Refactor Excel Matrix functions to use external Matrix library rather than JAMA
  • Loading branch information...
MarkBaker committed Nov 29, 2018
1 parent b6a73ae commit a5eb64c77f6c1a53159e50d80dbed935d00bd8e6
@@ -1,10 +1,11 @@
<?php
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude(['vendor', 'tests/data/Calculation'])
->in('samples')
->in('src')
->in('tests');
->in('tests/PhpSpreadsheetTests')
;
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

### Added

- Refactored Matrix Functions to use external Matrix library


## [1.5.2] - 2018-11-25

### Security
@@ -53,11 +53,13 @@
"ext-zip": "*",
"ext-zlib": "*",
"psr/simple-cache": "^1.0",
"markbaker/complex": "^1.4.1"
"markbaker/complex": "^1.4",
"markbaker/matrix": "^1.1"
},
"require-dev": {
"tecnickcom/tcpdf": "^6.2",
"phpunit/phpunit": "^5.7",
"doctrine/instantiator": "^1.0.0",
"dompdf/dompdf": "^0.8.0",
"mpdf/mpdf": "^7.0.0",
"jpgraph/jpgraph": "^4.0",

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -37,6 +37,7 @@ DATE | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DATE
DATEDIF | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DATEDIF
DATEVALUE | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DATEVALUE
DAY | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DAYOFMONTH
DAYS | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DAYS
DAYS360 | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DAYS360
EDATE | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::EDATE
EOMONTH | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::EOMONTH
@@ -45,6 +46,7 @@ ISOWEEKNUM | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::ISOWEEKNUM
MINUTE | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::MINUTE
MONTH | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::MONTHOFYEAR
NETWORKDAYS | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::NETWORKDAYS
NETWORKDAYS.INTL | **Not yet Implemented**
NOW | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DATETIMENOW
SECOND | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::SECOND
TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::TIME
@@ -53,6 +55,7 @@ TODAY | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DATENOW
WEEKDAY | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::WEEKDAY
WEEKNUM | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::WEEKNUM
WORKDAY | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::WORKDAY
WORKDAY.INTL | **Not yet Implemented**
YEAR | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::YEAR
YEARFRAC | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::YEARFRAC

@@ -66,7 +69,12 @@ BESSELK | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BESSELK
BESSELY | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BESSELY
BIN2DEC | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BINTODEC
BIN2HEX | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BINTOHEX
BIN2OCT | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BINTOOCT
BIN2OCT | \PhpOffice\PhpSpreadsheet\Calculation\Engineeri
BITAND | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITAND
BITLSHIFT | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITLSHIFT
BITOR | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITOR
BITRSHIFT | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITRSHIFT
BITXOR | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITXOR
COMPLEX | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::COMPLEX
CONVERT | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::CONVERTUOM
DEC2BIN | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::DECTOBIN
@@ -43,6 +43,11 @@ BIN2DEC | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet
BIN2HEX | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BINTOHEX
BIN2OCT | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BINTOOCT
BINOMDIST | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::BINOMDIST
BITAND | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITAND
BITLSHIFT | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITLSHIFT
BITOR | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITOR
BITRSHIFT | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITRSHIFT
BITXOR | CATEGORY_ENGINEERING | \PhpOffice\PhpSpreadsheet\Calculation\Engineering::BITXOR

## C

@@ -104,6 +109,7 @@ DATEDIF | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet
DATEVALUE | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DATEVALUE
DAVERAGE | CATEGORY_DATABASE | \PhpOffice\PhpSpreadsheet\Calculation\Database::DAVERAGE
DAY | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DAYOFMONTH
DAYS | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DAYS
DAYS360 | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::DAYS360
DB | CATEGORY_FINANCIAL | \PhpOffice\PhpSpreadsheet\Calculation\Financial::DB
DCOUNT | CATEGORY_DATABASE | \PhpOffice\PhpSpreadsheet\Calculation\Database::DCOUNT
@@ -317,6 +323,7 @@ N | CATEGORY_INFORMATION | \PhpOffice\PhpSpreadsheet
NA | CATEGORY_INFORMATION | \PhpOffice\PhpSpreadsheet\Calculation\Functions::NA
NEGBINOMDIST | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::NEGBINOMDIST
NETWORKDAYS | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::NETWORKDAYS
NETWORKDAYS.INTL | CATEGORY_DATE_AND_TIME | **Not yet Implemented**
NOMINAL | CATEGORY_FINANCIAL | \PhpOffice\PhpSpreadsheet\Calculation\Financial::NOMINAL
NORMDIST | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::NORMDIST
NORMINV | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::NORMINV
@@ -494,6 +501,7 @@ WEEKDAY | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet
WEEKNUM | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::WEEKNUM
WEIBULL | CATEGORY_STATISTICAL | \PhpOffice\PhpSpreadsheet\Calculation\Statistical::WEIBULL
WORKDAY | CATEGORY_DATE_AND_TIME | \PhpOffice\PhpSpreadsheet\Calculation\DateTime::WORKDAY
WORKDAY.INTL | CATEGORY_DATE_AND_TIME | **Not yet Implemented**

## X

@@ -2,8 +2,8 @@
namespace PhpOffice\PhpSpreadsheet\Calculation;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Shared\JAMA\Matrix;
use Matrix\Exception as MatrixException;
use Matrix\Matrix;
class MathTrig
{
@@ -498,23 +498,23 @@ public static function MDETERM($matrixValues)
if ((is_string($matrixCell)) || ($matrixCell === null)) {
return Functions::VALUE();
}
$matrixData[$column][$row] = $matrixCell;
$matrixData[$row][$column] = $matrixCell;
++$column;
}
if ($column > $maxColumn) {
$maxColumn = $column;
}
++$row;
}
if ($row != $maxColumn) {
$matrix = new Matrix($matrixData);
if (!$matrix->isSquare()) {
return Functions::VALUE();
}
try {
$matrix = new Matrix($matrixData);
return $matrix->det();
} catch (PhpSpreadsheetException $ex) {
return $matrix->determinant();
} catch (MatrixException $ex) {
return Functions::VALUE();
}
}
@@ -550,25 +550,27 @@ public static function MINVERSE($matrixValues)
if ((is_string($matrixCell)) || ($matrixCell === null)) {
return Functions::VALUE();
}
$matrixData[$column][$row] = $matrixCell;
$matrixData[$row][$column] = $matrixCell;
++$column;
}
if ($column > $maxColumn) {
$maxColumn = $column;
}
++$row;
}
foreach ($matrixValues as $matrixRow) {
if (count($matrixRow) != $maxColumn) {
return Functions::VALUE();
}
$matrix = new Matrix($matrixData);
if (!$matrix->isSquare()) {
return Functions::VALUE();
}
try {
$matrix = new Matrix($matrixData);
if ($matrix->determinant() == 0.0) {
return Functions::NAN();
}
return $matrix->inverse()->getArray();
} catch (PhpSpreadsheetException $ex) {
try {
return $matrix->inverse()->toArray();
} catch (MatrixException $ex) {
return Functions::VALUE();
}
}
@@ -629,8 +631,8 @@ public static function MMULT($matrixData1, $matrixData2)
return Functions::VALUE();
}
return $matrixA->times($matrixB)->getArray();
} catch (PhpSpreadsheetException $ex) {
return $matrixA->multiply($matrixB)->toArray();
} catch (MatrixException $ex) {
return Functions::VALUE();
}
}
@@ -281,10 +281,8 @@ public function providerMDETERM()
*/
public function testMINVERSE($expectedResult, ...$args)
{
$this->markTestIncomplete('TODO: This test should be fixed');
$result = MathTrig::MINVERSE(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerMINVERSE()
@@ -299,10 +297,8 @@ public function providerMINVERSE()
*/
public function testMMULT($expectedResult, ...$args)
{
$this->markTestIncomplete('TODO: This test should be fixed');
$result = MathTrig::MMULT(...$args);
self::assertEquals($expectedResult, $result, null, 1E-12);
self::assertEquals($expectedResult, $result, null, 1E-8);
}
public function providerMMULT()
Oops, something went wrong.

0 comments on commit a5eb64c

Please sign in to comment.
You can’t perform that action at this time.