PSR2 Fixes

This commit is contained in:
Progi1984 2015-05-17 14:16:53 +02:00
parent 4d65197b03
commit 1d842ed218
20 changed files with 1197 additions and 1183 deletions

View File

@ -58,7 +58,6 @@ class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements P
*/ */
protected $_charSet = 'UTF-8'; protected $_charSet = 'UTF-8';
/** /**
* Create a new PHPExcel_Reader_Excel2003XML * Create a new PHPExcel_Reader_Excel2003XML
*/ */

View File

@ -992,11 +992,8 @@ class PHPExcel_Reader_Excel2007 extends PHPExcel_Reader_Abstract implements PHPE
$column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER); $column->setFilterType(PHPExcel_Worksheet_AutoFilter_Column::AUTOFILTER_FILTERTYPE_FILTER);
$filters = $filterColumn->filters; $filters = $filterColumn->filters;
if ((isset($filters["blank"])) && ($filters["blank"] == 1)) { if ((isset($filters["blank"])) && ($filters["blank"] == 1)) {
$column->createRule()->setRule( // Operator is undefined, but always treated as EQUAL
null,// Operator is undefined, but always treated as EQUAL $column->createRule()->setRule(null, '')->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_FILTER);
''
)
->setRuleType(PHPExcel_Worksheet_AutoFilter_Column_Rule::AUTOFILTER_RULETYPE_FILTER);
} }
// Standard filters are always an OR join, so no join rule needs to be set // Standard filters are always an OR join, so no join rule needs to be set
// Entries can be either filter elements // Entries can be either filter elements

View File

@ -34,7 +34,8 @@
*/ */
class PHPExcel_Reader_Excel2007_Chart class PHPExcel_Reader_Excel2007_Chart
{ {
private static function _getAttribute($component, $name, $format) { private static function _getAttribute($component, $name, $format)
{
$attributes = $component->attributes(); $attributes = $component->attributes();
if (isset($attributes[$name])) { if (isset($attributes[$name])) {
if ($format == 'string') { if ($format == 'string') {
@ -51,7 +52,8 @@ class PHPExcel_Reader_Excel2007_Chart
} // function _getAttribute() } // function _getAttribute()
private static function _readColor($color, $background=false) { private static function _readColor($color, $background = false)
{
if (isset($color["rgb"])) { if (isset($color["rgb"])) {
return (string)$color["rgb"]; return (string)$color["rgb"];
} else if (isset($color["indexed"])) { } else if (isset($color["indexed"])) {
@ -59,13 +61,13 @@ class PHPExcel_Reader_Excel2007_Chart
} }
} }
public static function readChart($chartElements, $chartName)
public static function readChart($chartElements, $chartName) { {
$namespacesChartMeta = $chartElements->getNamespaces(true); $namespacesChartMeta = $chartElements->getNamespaces(true);
$chartElementsC = $chartElements->children($namespacesChartMeta['c']); $chartElementsC = $chartElements->children($namespacesChartMeta['c']);
$XaxisLabel = $YaxisLabel = $legend = $title = NULL; $XaxisLabel = $YaxisLabel = $legend = $title = null;
$dispBlanksAs = $plotVisOnly = NULL; $dispBlanksAs = $plotVisOnly = null;
foreach ($chartElementsC as $chartElementKey => $chartElement) { foreach ($chartElementsC as $chartElementKey => $chartElement) {
switch ($chartElementKey) { switch ($chartElementKey) {
@ -158,7 +160,7 @@ class PHPExcel_Reader_Excel2007_Chart
break; break;
} }
} }
if ($plotAreaLayout == NULL) { if ($plotAreaLayout == null) {
$plotAreaLayout = new PHPExcel_Chart_Layout(); $plotAreaLayout = new PHPExcel_Chart_Layout();
} }
$plotArea = new PHPExcel_Chart_PlotArea($plotAreaLayout, $plotSeries); $plotArea = new PHPExcel_Chart_PlotArea($plotAreaLayout, $plotSeries);
@ -201,8 +203,8 @@ class PHPExcel_Reader_Excel2007_Chart
return $chart; return $chart;
} // function readChart() } // function readChart()
private static function _chartTitle($titleDetails, $namespacesChartMeta, $type)
private static function _chartTitle($titleDetails, $namespacesChartMeta, $type) { {
$caption = array(); $caption = array();
$titleLayout = null; $titleLayout = null;
foreach ($titleDetails as $titleDetailKey => $chartDetail) { foreach ($titleDetails as $titleDetailKey => $chartDetail) {
@ -226,8 +228,8 @@ class PHPExcel_Reader_Excel2007_Chart
return new PHPExcel_Chart_Title($caption, $titleLayout); return new PHPExcel_Chart_Title($caption, $titleLayout);
} // function _chartTitle() } // function _chartTitle()
private static function _chartLayoutDetails($chartDetail, $namespacesChartMeta)
private static function _chartLayoutDetails($chartDetail, $namespacesChartMeta) { {
if (!isset($chartDetail->manualLayout)) { if (!isset($chartDetail->manualLayout)) {
return null; return null;
} }
@ -243,9 +245,9 @@ class PHPExcel_Reader_Excel2007_Chart
return new PHPExcel_Chart_Layout($layout); return new PHPExcel_Chart_Layout($layout);
} // function _chartLayoutDetails() } // function _chartLayoutDetails()
private static function _chartDataSeries($chartDetail, $namespacesChartMeta, $plotType)
private static function _chartDataSeries($chartDetail, $namespacesChartMeta, $plotType) { {
$multiSeriesType = NULL; $multiSeriesType = null;
$smoothLine = false; $smoothLine = false;
$seriesLabel = $seriesCategory = $seriesValues = $plotOrder = array(); $seriesLabel = $seriesCategory = $seriesValues = $plotOrder = array();
@ -256,7 +258,7 @@ class PHPExcel_Reader_Excel2007_Chart
$multiSeriesType = self::_getAttribute($chartDetail->grouping, 'val', 'string'); $multiSeriesType = self::_getAttribute($chartDetail->grouping, 'val', 'string');
break; break;
case "ser": case "ser":
$marker = NULL; $marker = null;
foreach ($seriesDetails as $seriesKey => $seriesDetail) { foreach ($seriesDetails as $seriesKey => $seriesDetail) {
switch ($seriesKey) { switch ($seriesKey) {
case "idx": case "idx":
@ -294,8 +296,8 @@ class PHPExcel_Reader_Excel2007_Chart
return new PHPExcel_Chart_DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine); return new PHPExcel_Chart_DataSeries($plotType, $multiSeriesType, $plotOrder, $seriesLabel, $seriesCategory, $seriesValues, $smoothLine);
} // function _chartDataSeries() } // function _chartDataSeries()
private static function _chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null, $smoothLine = false)
private static function _chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null, $smoothLine = false) { {
if (isset($seriesDetail->strRef)) { if (isset($seriesDetail->strRef)) {
$seriesSource = (string) $seriesDetail->strRef->f; $seriesSource = (string) $seriesDetail->strRef->f;
$seriesData = self::_chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']),'s'); $seriesData = self::_chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']),'s');
@ -322,8 +324,8 @@ class PHPExcel_Reader_Excel2007_Chart
return null; return null;
} // function _chartDataSeriesValueSet() } // function _chartDataSeriesValueSet()
private static function _chartDataSeriesValues($seriesValueSet, $dataType = 'n')
private static function _chartDataSeriesValues($seriesValueSet, $dataType='n') { {
$seriesVal = array(); $seriesVal = array();
$formatCode = ''; $formatCode = '';
$pointCount = 0; $pointCount = 0;
@ -348,17 +350,18 @@ class PHPExcel_Reader_Excel2007_Chart
} }
if (empty($seriesVal)) { if (empty($seriesVal)) {
$seriesVal = NULL; $seriesVal = null;
} }
return array( 'formatCode' => $formatCode, return array(
'formatCode' => $formatCode,
'pointCount' => $pointCount, 'pointCount' => $pointCount,
'dataValues' => $seriesVal 'dataValues' => $seriesVal
); );
} // function _chartDataSeriesValues() } // function _chartDataSeriesValues()
private static function _chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType = 'n')
private static function _chartDataSeriesValuesMultiLevel($seriesValueSet, $dataType='n') { {
$seriesVal = array(); $seriesVal = array();
$formatCode = ''; $formatCode = '';
$pointCount = 0; $pointCount = 0;
@ -384,13 +387,15 @@ class PHPExcel_Reader_Excel2007_Chart
} }
} }
return array( 'formatCode' => $formatCode, return array(
'formatCode' => $formatCode,
'pointCount' => $pointCount, 'pointCount' => $pointCount,
'dataValues' => $seriesVal 'dataValues' => $seriesVal
); );
} // function _chartDataSeriesValuesMultiLevel() } // function _chartDataSeriesValuesMultiLevel()
private static function _parseRichText($titleDetailPart = null) { private static function _parseRichText($titleDetailPart = null)
{
$value = new PHPExcel_RichText(); $value = new PHPExcel_RichText();
foreach ($titleDetailPart as $titleDetailElementKey => $titleDetailElement) { foreach ($titleDetailPart as $titleDetailElementKey => $titleDetailElement) {
@ -456,7 +461,8 @@ class PHPExcel_Reader_Excel2007_Chart
return $value; return $value;
} }
private static function _readChartAttributes($chartDetail) { private static function _readChartAttributes($chartDetail)
{
$plotAttributes = array(); $plotAttributes = array();
if (isset($chartDetail->dLbls)) { if (isset($chartDetail->dLbls)) {
if (isset($chartDetail->dLbls->howLegendKey)) { if (isset($chartDetail->dLbls->howLegendKey)) {
@ -513,5 +519,4 @@ class PHPExcel_Reader_Excel2007_Chart
} }
} }
} }
} }

View File

@ -92,7 +92,8 @@ class PHPExcel_Reader_Excel2007_Theme
* *
* @return string * @return string
*/ */
public function getColourSchemeName() { public function getColourSchemeName()
{
return $this->_colourSchemeName; return $this->_colourSchemeName;
} }
@ -101,7 +102,8 @@ class PHPExcel_Reader_Excel2007_Theme
* *
* @return string * @return string
*/ */
public function getColourByIndex($index=0) { public function getColourByIndex($index = 0)
{
if (isset($this->_colourMap[$index])) { if (isset($this->_colourMap[$index])) {
return $this->_colourMap[$index]; return $this->_colourMap[$index];
} }
@ -111,7 +113,8 @@ class PHPExcel_Reader_Excel2007_Theme
/** /**
* Implement PHP __clone to create a deep clone, not just a shallow copy. * Implement PHP __clone to create a deep clone, not just a shallow copy.
*/ */
public function __clone() { public function __clone()
{
$vars = get_object_vars($this); $vars = get_object_vars($this);
foreach ($vars as $key => $value) { foreach ($vars as $key => $value) {
if ((is_object($value)) && ($key != '_parent')) { if ((is_object($value)) && ($key != '_parent')) {

View File

@ -1113,7 +1113,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
if ($this->_version == self::XLS_BIFF8) { if ($this->_version == self::XLS_BIFF8) {
foreach ($this->_sharedFormulaParts as $cell => $baseCell) { foreach ($this->_sharedFormulaParts as $cell => $baseCell) {
list($column, $row) = PHPExcel_Cell::coordinateFromString($cell); list($column, $row) = PHPExcel_Cell::coordinateFromString($cell);
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($column, $row, $this->_phpSheet->getTitle()) ) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($column, $row, $this->_phpSheet->getTitle())) {
$formula = $this->_getFormulaFromStructure($this->_sharedFormulas[$baseCell], $cell); $formula = $this->_getFormulaFromStructure($this->_sharedFormulas[$baseCell], $cell);
$this->_phpSheet->getCell($cell)->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA); $this->_phpSheet->getCell($cell)->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
} }
@ -1156,7 +1156,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
$explodes = explode('!', $range); // FIXME: what if sheetname contains exclamation mark? $explodes = explode('!', $range); // FIXME: what if sheetname contains exclamation mark?
$sheetName = trim($explodes[0], "'"); $sheetName = trim($explodes[0], "'");
if (count($explodes) == 2) { if (count($explodes) == 2) {
if (strpos($explodes[1], ':') === FALSE) { if (strpos($explodes[1], ':') === false) {
$explodes[1] = $explodes[1] . ':' . $explodes[1]; $explodes[1] = $explodes[1] . ':' . $explodes[1];
} }
$extractedRanges[] = str_replace('$', '', $explodes[1]); // C7:J66 $extractedRanges[] = str_replace('$', '', $explodes[1]); // C7:J66
@ -4125,7 +4125,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
$columnString = PHPExcel_Cell::stringFromColumnIndex($fc + $i); $columnString = PHPExcel_Cell::stringFromColumnIndex($fc + $i);
// Read cell? // Read cell?
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle())) {
$xfIndex = self::_GetInt2d($recordData, 4 + 2 * $i); $xfIndex = self::_GetInt2d($recordData, 4 + 2 * $i);
$this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]); $this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]);
} }
@ -4162,7 +4162,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
$columnString = PHPExcel_Cell::stringFromColumnIndex($column); $columnString = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell? // Read cell?
if (($this->getReadFilter() !== NULL) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle()) ) { if (($this->getReadFilter() !== null) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle())) {
// offset: 4; size: 2; XF index // offset: 4; size: 2; XF index
$xfIndex = self::_GetInt2d($recordData, 4); $xfIndex = self::_GetInt2d($recordData, 4);
@ -4528,7 +4528,7 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) { if ($this->_version == self::XLS_BIFF8 && !$this->_readDataOnly) {
$cellRangeAddressList = $this->_readBIFF8CellRangeAddressList($recordData); $cellRangeAddressList = $this->_readBIFF8CellRangeAddressList($recordData);
foreach ($cellRangeAddressList['cellRangeAddresses'] as $cellRangeAddress) { foreach ($cellRangeAddressList['cellRangeAddresses'] as $cellRangeAddress) {
if ((strpos($cellRangeAddress,':') !== FALSE) && if ((strpos($cellRangeAddress,':') !== false) &&
($this->_includeCellRangeFiltered($cellRangeAddress))) { ($this->_includeCellRangeFiltered($cellRangeAddress))) {
$this->_phpSheet->mergeCells($cellRangeAddress); $this->_phpSheet->mergeCells($cellRangeAddress);
} }
@ -8043,8 +8043,8 @@ class PHPExcel_Reader_Excel5 extends PHPExcel_Reader_Abstract implements PHPExce
} }
} }
private function _parseRichText($is = '')
private function _parseRichText($is = '') { {
$value = new PHPExcel_RichText(); $value = new PHPExcel_RichText();
$value->createText($is); $value->createText($is);

View File

@ -107,7 +107,6 @@ class PHPExcel_Reader_Excel5_Escher
// Parse Escher stream // Parse Escher stream
while ($this->_pos < $this->_dataSize) { while ($this->_pos < $this->_dataSize) {
// offset: 2; size: 2: Record Type // offset: 2; size: 2: Record Type
$fbt = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos + 2); $fbt = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos + 2);

View File

@ -60,16 +60,15 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
private $_referenceHelper = null; private $_referenceHelper = null;
/** /**
* Create a new PHPExcel_Reader_Gnumeric * Create a new PHPExcel_Reader_Gnumeric
*/ */
public function __construct() { public function __construct()
{
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
$this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance(); $this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance();
} }
/** /**
* Can the current PHPExcel_Reader_IReader read the file? * Can the current PHPExcel_Reader_IReader read the file?
* *
@ -101,7 +100,6 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
return true; return true;
} }
/** /**
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
* *
@ -116,9 +114,7 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
} }
$xml = new XMLReader(); $xml = new XMLReader();
$xml->xml( $xml->xml($this->securityScanFile('compress.zlib://'.realpath($pFilename)), null, PHPExcel_Settings::getLibXmlLoaderOptions());
$this->securityScanFile('compress.zlib://'.realpath($pFilename)), null, PHPExcel_Settings::getLibXmlLoaderOptions()
);
$xml->setParserProperty(2,true); $xml->setParserProperty(2,true);
$worksheetNames = array(); $worksheetNames = array();
@ -135,7 +131,6 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
return $worksheetNames; return $worksheetNames;
} }
/** /**
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
* *
@ -150,9 +145,7 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
} }
$xml = new XMLReader(); $xml = new XMLReader();
$xml->xml( $xml->xml($this->securityScanFile('compress.zlib://'.realpath($pFilename)), null, PHPExcel_Settings::getLibXmlLoaderOptions());
$this->securityScanFile('compress.zlib://'.realpath($pFilename)), null, PHPExcel_Settings::getLibXmlLoaderOptions()
);
$xml->setParserProperty(2, true); $xml->setParserProperty(2, true);
$worksheetInfo = array(); $worksheetInfo = array();
@ -188,8 +181,8 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
return $worksheetInfo; return $worksheetInfo;
} }
private function _gzfileGetContents($filename)
private function _gzfileGetContents($filename) { {
$file = @gzopen($filename, 'rb'); $file = @gzopen($filename, 'rb');
if ($file !== false) { if ($file !== false) {
$data = ''; $data = '';
@ -201,7 +194,6 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
return $data; return $data;
} }
/** /**
* Loads PHPExcel from file * Loads PHPExcel from file
* *
@ -218,7 +210,6 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
return $this->loadIntoExisting($pFilename, $objPHPExcel); return $this->loadIntoExisting($pFilename, $objPHPExcel);
} }
/** /**
* Loads PHPExcel from file into PHPExcel instance * Loads PHPExcel from file into PHPExcel instance
* *
@ -258,7 +249,6 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
$officeDocMetaXML = $officeDocXML->meta; $officeDocMetaXML = $officeDocXML->meta;
foreach ($officeDocMetaXML as $officePropertyData) { foreach ($officeDocMetaXML as $officePropertyData) {
$officePropertyDC = array(); $officePropertyDC = array();
if (isset($namespacesMeta['dc'])) { if (isset($namespacesMeta['dc'])) {
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']); $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
@ -374,7 +364,7 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
if ((!$this->_readDataOnly) && (isset($sheet->PrintInformation))) { if ((!$this->_readDataOnly) && (isset($sheet->PrintInformation))) {
if (isset($sheet->PrintInformation->Margins)) { if (isset($sheet->PrintInformation->Margins)) {
foreach ($sheet->PrintInformation->Margins->children('gnm',TRUE) as $key => $margin) { foreach ($sheet->PrintInformation->Margins->children('gnm', true) as $key => $margin) {
$marginAttributes = $margin->attributes(); $marginAttributes = $margin->attributes();
$marginSize = 72 / 100; // Default $marginSize = 72 / 100; // Default
switch ($marginAttributes['PrefUnit']) { switch ($marginAttributes['PrefUnit']) {
@ -411,13 +401,17 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
$row = (int) $cellAttributes->Row + 1; $row = (int) $cellAttributes->Row + 1;
$column = (int) $cellAttributes->Col; $column = (int) $cellAttributes->Col;
if ($row > $maxRow) $maxRow = $row; if ($row > $maxRow) {
if ($column > $maxCol) $maxCol = $column; $maxRow = $row;
}
if ($column > $maxCol) {
$maxCol = $column;
}
$column = PHPExcel_Cell::stringFromColumnIndex($column); $column = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell? // Read cell?
if ($this->getReadFilter() !== NULL) { if ($this->getReadFilter() !== null) {
if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) { if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) {
continue; continue;
} }
@ -431,8 +425,8 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
$type = PHPExcel_Cell_DataType::TYPE_FORMULA; $type = PHPExcel_Cell_DataType::TYPE_FORMULA;
if ($ExprID > '') { if ($ExprID > '') {
if (((string) $cell) > '') { if (((string) $cell) > '') {
$this->_expressions[$ExprID] = array(
$this->_expressions[$ExprID] = array( 'column' => $cellAttributes->Col, 'column' => $cellAttributes->Col,
'row' => $cellAttributes->Row, 'row' => $cellAttributes->Row,
'formula' => (string) $cell 'formula' => (string) $cell
); );
@ -440,12 +434,7 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
} else { } else {
$expression = $this->_expressions[$ExprID]; $expression = $this->_expressions[$ExprID];
$cell = $this->_referenceHelper->updateFormulaReferences( $expression['formula'], $cell = $this->_referenceHelper->updateFormulaReferences($expression['formula'], 'A1', $cellAttributes->Col - $expression['column'], $cellAttributes->Row - $expression['row'], $worksheetName);
'A1',
$cellAttributes->Col - $expression['column'],
$cellAttributes->Row - $expression['row'],
$worksheetName
);
// echo 'SHARED EXPRESSION ', $ExprID,'<br />'; // echo 'SHARED EXPRESSION ', $ExprID,'<br />';
// echo 'New Value is ', $cell,'<br />'; // echo 'New Value is ', $cell,'<br />';
} }
@ -457,7 +446,7 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
break; break;
case '20': // Boolean case '20': // Boolean
$type = PHPExcel_Cell_DataType::TYPE_BOOL; $type = PHPExcel_Cell_DataType::TYPE_BOOL;
$cell = ($cell == 'TRUE') ? True : False; $cell = ($cell == 'TRUE') ? true: false;
break; break;
case '30': // Integer case '30': // Integer
$cell = intval($cell); $cell = intval($cell);
@ -482,9 +471,7 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
$commentAttributes = $comment->attributes(); $commentAttributes = $comment->attributes();
// Only comment objects are handled at the moment // Only comment objects are handled at the moment
if ($commentAttributes->Text) { if ($commentAttributes->Text) {
$objPHPExcel->getActiveSheet()->getComment( (string)$commentAttributes->ObjectBound ) $objPHPExcel->getActiveSheet()->getComment((string)$commentAttributes->ObjectBound)->setAuthor((string)$commentAttributes->Author)->setText($this->_parseRichText((string)$commentAttributes->Text));
->setAuthor( (string)$commentAttributes->Author )
->setText($this->_parseRichText((string)$commentAttributes->Text) );
} }
} }
} }
@ -553,8 +540,8 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
break; break;
} }
$styleArray['alignment']['wrap'] = ($styleAttributes['WrapText'] == '1') ? True : False; $styleArray['alignment']['wrap'] = ($styleAttributes['WrapText'] == '1') ? true : false;
$styleArray['alignment']['shrinkToFit'] = ($styleAttributes['ShrinkToFit'] == '1') ? True : False; $styleArray['alignment']['shrinkToFit'] = ($styleAttributes['ShrinkToFit'] == '1') ? true : false;
$styleArray['alignment']['indent'] = (intval($styleAttributes["Indent"]) > 0) ? $styleAttributes["indent"] : 0; $styleArray['alignment']['indent'] = (intval($styleAttributes["Indent"]) > 0) ? $styleAttributes["indent"] : 0;
$RGB = self::_parseGnumericColour($styleAttributes["Fore"]); $RGB = self::_parseGnumericColour($styleAttributes["Fore"]);
@ -634,9 +621,9 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
// echo '<br />'; // echo '<br />';
$styleArray['font']['name'] = (string) $styleRegion->Style->Font; $styleArray['font']['name'] = (string) $styleRegion->Style->Font;
$styleArray['font']['size'] = intval($fontAttributes['Unit']); $styleArray['font']['size'] = intval($fontAttributes['Unit']);
$styleArray['font']['bold'] = ($fontAttributes['Bold'] == '1') ? True : False; $styleArray['font']['bold'] = ($fontAttributes['Bold'] == '1') ? true : false;
$styleArray['font']['italic'] = ($fontAttributes['Italic'] == '1') ? True : False; $styleArray['font']['italic'] = ($fontAttributes['Italic'] == '1') ? true : false;
$styleArray['font']['strike'] = ($fontAttributes['StrikeThrough'] == '1') ? True : False; $styleArray['font']['strike'] = ($fontAttributes['StrikeThrough'] == '1') ? true : false;
switch ($fontAttributes['Underline']) { switch ($fontAttributes['Underline']) {
case '1': case '1':
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_SINGLE; $styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_SINGLE;
@ -656,10 +643,10 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
} }
switch ($fontAttributes['Script']) { switch ($fontAttributes['Script']) {
case '1': case '1':
$styleArray['font']['superScript'] = True; $styleArray['font']['superScript'] = true;
break; break;
case '-1': case '-1':
$styleArray['font']['subScript'] = True; $styleArray['font']['subScript'] = true;
break; break;
} }
@ -761,7 +748,7 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
// Handle Merged Cells in this worksheet // Handle Merged Cells in this worksheet
if (isset($sheet->MergedRegions)) { if (isset($sheet->MergedRegions)) {
foreach ($sheet->MergedRegions->Merge as $mergeCells) { foreach ($sheet->MergedRegions->Merge as $mergeCells) {
if (strpos($mergeCells,':') !== FALSE) { if (strpos($mergeCells,':') !== false) {
$objPHPExcel->getActiveSheet()->mergeCells($mergeCells); $objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
} }
} }
@ -788,12 +775,10 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
} }
} }
// Return // Return
return $objPHPExcel; return $objPHPExcel;
} }
private static function _parseBorderAttributes($borderAttributes) private static function _parseBorderAttributes($borderAttributes)
{ {
$styleArray = array(); $styleArray = array();
@ -850,8 +835,8 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
return $styleArray; return $styleArray;
} }
private function _parseRichText($is = '')
private function _parseRichText($is = '') { {
$value = new PHPExcel_RichText(); $value = new PHPExcel_RichText();
$value->createText($is); $value->createText($is);
@ -859,7 +844,6 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
return $value; return $value;
} }
private static function _parseGnumericColour($gnmColour) { private static function _parseGnumericColour($gnmColour) {
list($gnmR, $gnmG, $gnmB) = explode(':', $gnmColour); list($gnmR, $gnmG, $gnmB) = explode(':', $gnmColour);
$gnmR = substr(str_pad($gnmR, 4, '0', STR_PAD_RIGHT), 0, 2); $gnmR = substr(str_pad($gnmR, 4, '0', STR_PAD_RIGHT), 0, 2);
@ -869,5 +853,4 @@ class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPEx
// echo 'Excel Colour: ', $RGB,'<br />'; // echo 'Excel Colour: ', $RGB,'<br />';
return $RGB; return $RGB;
} }
} }

View File

@ -51,7 +51,6 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
*/ */
private $_styles = array(); private $_styles = array();
/** /**
* Create a new PHPExcel_Reader_OOCalc * Create a new PHPExcel_Reader_OOCalc
*/ */
@ -59,7 +58,6 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
} }
/** /**
* Can the current PHPExcel_Reader_IReader read the file? * Can the current PHPExcel_Reader_IReader read the file?
* *
@ -77,7 +75,7 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
$zipClass = PHPExcel_Settings::getZipClass(); $zipClass = PHPExcel_Settings::getZipClass();
// Check if zip class exists // Check if zip class exists
// if (!class_exists($zipClass, FALSE)) { // if (!class_exists($zipClass, false)) {
// throw new PHPExcel_Reader_Exception($zipClass . " library is not enabled"); // throw new PHPExcel_Reader_Exception($zipClass . " library is not enabled");
// } // }
@ -109,7 +107,7 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet'); return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet');
} }
return FALSE; return false;
} }
@ -144,11 +142,12 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
while ($xml->read()) { while ($xml->read()) {
// Quickly jump through to the office:body node // Quickly jump through to the office:body node
while ($xml->name !== 'office:body') { while ($xml->name !== 'office:body') {
if ($xml->isEmptyElement) if ($xml->isEmptyElement) {
$xml->read(); $xml->read();
else } else {
$xml->next(); $xml->next();
} }
}
// Now read each node until we find our first table:table node // Now read each node until we find our first table:table node
while ($xml->read()) { while ($xml->read()) {
if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) { if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
@ -164,7 +163,6 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
return $worksheetNames; return $worksheetNames;
} }
/** /**
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns) * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
* *
@ -196,11 +194,12 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
while ($xml->read()) { while ($xml->read()) {
// Quickly jump through to the office:body node // Quickly jump through to the office:body node
while ($xml->name !== 'office:body') { while ($xml->name !== 'office:body') {
if ($xml->isEmptyElement) if ($xml->isEmptyElement) {
$xml->read(); $xml->read();
else } else {
$xml->next(); $xml->next();
} }
}
// Now read each node until we find our first table:table node // Now read each node until we find our first table:table node
while ($xml->read()) { while ($xml->read()) {
if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) { if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
@ -289,7 +288,6 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
return $worksheetInfo; return $worksheetInfo;
} }
/** /**
* Loads PHPExcel from file * Loads PHPExcel from file
* *
@ -306,8 +304,8 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
return $this->loadIntoExisting($pFilename, $objPHPExcel); return $this->loadIntoExisting($pFilename, $objPHPExcel);
} }
private static function identifyFixedStyleValue($styleList,&$styleAttributeValue)
private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) { {
$styleAttributeValue = strtolower($styleAttributeValue); $styleAttributeValue = strtolower($styleAttributeValue);
foreach ($styleList as $style) { foreach ($styleList as $style) {
if ($styleAttributeValue == strtolower($style)) { if ($styleAttributeValue == strtolower($style)) {
@ -318,7 +316,6 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
return false; return false;
} }
/** /**
* Loads PHPExcel from file into PHPExcel instance * Loads PHPExcel from file into PHPExcel instance
* *
@ -480,7 +477,7 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
$rowDataTableAttributes['number-rows-repeated'] : 1; $rowDataTableAttributes['number-rows-repeated'] : 1;
$columnID = 'A'; $columnID = 'A';
foreach ($rowData as $key => $cellData) { foreach ($rowData as $key => $cellData) {
if ($this->getReadFilter() !== NULL) { if ($this->getReadFilter() !== null) {
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) { if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
continue; continue;
} }
@ -564,7 +561,7 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
break; break;
case 'boolean' : case 'boolean' :
$type = PHPExcel_Cell_DataType::TYPE_BOOL; $type = PHPExcel_Cell_DataType::TYPE_BOOL;
$dataValue = ($allCellDataText == 'TRUE') ? True : False; $dataValue = ($allCellDataText == 'TRUE') ? true : false;
break; break;
case 'percentage' : case 'percentage' :
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC; $type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
@ -611,12 +608,12 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
break; break;
} }
// echo 'Data value is '.$dataValue.'<br />'; // echo 'Data value is '.$dataValue.'<br />';
// if ($hyperlink !== NULL) { // if ($hyperlink !== null) {
// echo 'Hyperlink is '.$hyperlink.'<br />'; // echo 'Hyperlink is '.$hyperlink.'<br />';
// } // }
} else { } else {
$type = PHPExcel_Cell_DataType::TYPE_NULL; $type = PHPExcel_Cell_DataType::TYPE_NULL;
$dataValue = NULL; $dataValue = null;
} }
if ($hasCalculatedValue) { if ($hasCalculatedValue) {
@ -641,9 +638,8 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
// echo 'Adjusted Formula: ', $cellDataFormula, PHP_EOL; // echo 'Adjusted Formula: ', $cellDataFormula, PHP_EOL;
} }
$colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ? $colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ? $cellDataTableAttributes['number-columns-repeated'] : 1;
$cellDataTableAttributes['number-columns-repeated'] : 1; if ($type !== null) {
if ($type !== NULL) {
for ($i = 0; $i < $colRepeats; ++$i) { for ($i = 0; $i < $colRepeats; ++$i) {
if ($i > 0) { if ($i > 0) {
++$columnID; ++$columnID;
@ -656,12 +652,12 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
// echo 'Forumla result is '.$dataValue.'<br />'; // echo 'Forumla result is '.$dataValue.'<br />';
$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue); $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue);
} }
if ($formatting !== NULL) { if ($formatting !== null) {
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting); $objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting);
} else { } else {
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL); $objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL);
} }
if ($hyperlink !== NULL) { if ($hyperlink !== null) {
$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink); $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink);
} }
} }
@ -699,13 +695,12 @@ class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExce
return $objPHPExcel; return $objPHPExcel;
} }
private function _parseRichText($is = '')
private function _parseRichText($is = '') { {
$value = new PHPExcel_RichText(); $value = new PHPExcel_RichText();
$value->createText($is); $value->createText($is);
return $value; return $value;
} }
} }

View File

@ -75,7 +75,8 @@ class PHPExcel_Reader_SYLK extends PHPExcel_Reader_Abstract implements PHPExcel_
/** /**
* Create a new PHPExcel_Reader_SYLK * Create a new PHPExcel_Reader_SYLK
*/ */
public function __construct() { public function __construct()
{
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter(); $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
} }
@ -244,7 +245,6 @@ class PHPExcel_Reader_SYLK extends PHPExcel_Reader_Abstract implements PHPExcel_
// loop through one row (line) at a time in the file // loop through one row (line) at a time in the file
while (($rowData = fgets($fileHandle)) !== false) { while (($rowData = fgets($fileHandle)) !== false) {
// convert SYLK encoded $rowData to UTF-8 // convert SYLK encoded $rowData to UTF-8
$rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData); $rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData);

View File

@ -15,8 +15,8 @@
* @author Michael Bommarito * @author Michael Bommarito
* @version 1.2 * @version 1.2
*/ */
class CholeskyDecomposition { class CholeskyDecomposition
{
/** /**
* Decomposition storage * Decomposition storage
* @var array * @var array
@ -38,14 +38,14 @@ class CholeskyDecomposition {
*/ */
private $isspd = true; private $isspd = true;
/** /**
* CholeskyDecomposition * CholeskyDecomposition
* *
* Class constructor - decomposes symmetric positive definite matrix * Class constructor - decomposes symmetric positive definite matrix
* @param mixed Matrix square symmetric positive definite matrix * @param mixed Matrix square symmetric positive definite matrix
*/ */
public function __construct($A = null) { public function __construct($A = null)
{
if ($A instanceof Matrix) { if ($A instanceof Matrix) {
$this->L = $A->getArray(); $this->L = $A->getArray();
$this->m = $A->getRowDimension(); $this->m = $A->getRowDimension();
@ -77,35 +77,35 @@ class CholeskyDecomposition {
} }
} // function __construct() } // function __construct()
/** /**
* Is the matrix symmetric and positive definite? * Is the matrix symmetric and positive definite?
* *
* @return boolean * @return boolean
*/ */
public function isSPD() { public function isSPD()
{
return $this->isspd; return $this->isspd;
} // function isSPD() } // function isSPD()
/** /**
* getL * getL
* *
* Return triangular factor. * Return triangular factor.
* @return Matrix Lower triangular matrix * @return Matrix Lower triangular matrix
*/ */
public function getL() { public function getL()
{
return new Matrix($this->L); return new Matrix($this->L);
} // function getL() } // function getL()
/** /**
* Solve A*X = B * Solve A*X = B
* *
* @param $B Row-equal matrix * @param $B Row-equal matrix
* @return Matrix L * L' * X = B * @return Matrix L * L' * X = B
*/ */
public function solve($B = null) { public function solve($B = null)
{
if ($B instanceof Matrix) { if ($B instanceof Matrix) {
if ($B->getRowDimension() == $this->m) { if ($B->getRowDimension() == $this->m) {
if ($this->isspd) { if ($this->isspd) {
@ -145,5 +145,4 @@ class CholeskyDecomposition {
throw new PHPExcel_Calculation_Exception(JAMAError(ArgumentTypeException)); throw new PHPExcel_Calculation_Exception(JAMAError(ArgumentTypeException));
} }
} // function solve() } // function solve()
}
} // class CholeskyDecomposition

View File

@ -21,8 +21,8 @@
* @license PHP v3.0 * @license PHP v3.0
* @version 1.1 * @version 1.1
*/ */
class EigenvalueDecomposition { class EigenvalueDecomposition
{
/** /**
* Row and column dimension (square matrix). * Row and column dimension (square matrix).
* @var int * @var int
@ -67,13 +67,13 @@ class EigenvalueDecomposition {
private $cdivr; private $cdivr;
private $cdivi; private $cdivi;
/** /**
* Symmetric Householder reduction to tridiagonal form. * Symmetric Householder reduction to tridiagonal form.
* *
* @access private * @access private
*/ */
private function tred2 () { private function tred2 ()
{
// This is derived from the Algol procedures tred2 by // This is derived from the Algol procedures tred2 by
// Bowdler, Martin, Reinsch, and Wilkinson, Handbook for // Bowdler, Martin, Reinsch, and Wilkinson, Handbook for
// Auto. Comp., Vol.ii-Linear Algebra, and the corresponding // Auto. Comp., Vol.ii-Linear Algebra, and the corresponding
@ -171,7 +171,6 @@ class EigenvalueDecomposition {
$this->e[0] = 0.0; $this->e[0] = 0.0;
} }
/** /**
* Symmetric tridiagonal QL algorithm. * Symmetric tridiagonal QL algorithm.
* *
@ -182,7 +181,8 @@ class EigenvalueDecomposition {
* *
* @access private * @access private
*/ */
private function tql2() { private function tql2()
{
for ($i = 1; $i < $this->n; ++$i) { for ($i = 1; $i < $this->n; ++$i) {
$this->e[$i-1] = $this->e[$i]; $this->e[$i-1] = $this->e[$i];
} }
@ -196,8 +196,9 @@ class EigenvalueDecomposition {
$tst1 = max($tst1, abs($this->d[$l]) + abs($this->e[$l])); $tst1 = max($tst1, abs($this->d[$l]) + abs($this->e[$l]));
$m = $l; $m = $l;
while ($m < $this->n) { while ($m < $this->n) {
if (abs($this->e[$m]) <= $eps * $tst1) if (abs($this->e[$m]) <= $eps * $tst1) {
break; break;
}
++$m; ++$m;
} }
// If m == l, $this->d[l] is an eigenvalue, // If m == l, $this->d[l] is an eigenvalue,
@ -211,14 +212,16 @@ class EigenvalueDecomposition {
$g = $this->d[$l]; $g = $this->d[$l];
$p = ($this->d[$l+1] - $g) / (2.0 * $this->e[$l]); $p = ($this->d[$l+1] - $g) / (2.0 * $this->e[$l]);
$r = hypo($p, 1.0); $r = hypo($p, 1.0);
if ($p < 0) if ($p < 0) {
$r *= -1; $r *= -1;
}
$this->d[$l] = $this->e[$l] / ($p + $r); $this->d[$l] = $this->e[$l] / ($p + $r);
$this->d[$l+1] = $this->e[$l] * ($p + $r); $this->d[$l+1] = $this->e[$l] * ($p + $r);
$dl1 = $this->d[$l+1]; $dl1 = $this->d[$l+1];
$h = $g - $this->d[$l]; $h = $g - $this->d[$l];
for ($i = $l + 2; $i < $this->n; ++$i) for ($i = $l + 2; $i < $this->n; ++$i) {
$this->d[$i] -= $h; $this->d[$i] -= $h;
}
$f += $h; $f += $h;
// Implicit QL transformation. // Implicit QL transformation.
$p = $this->d[$m]; $p = $this->d[$m];
@ -277,7 +280,6 @@ class EigenvalueDecomposition {
} }
} }
/** /**
* Nonsymmetric reduction to Hessenberg form. * Nonsymmetric reduction to Hessenberg form.
* *
@ -288,7 +290,8 @@ class EigenvalueDecomposition {
* *
* @access private * @access private
*/ */
private function orthes () { private function orthes()
{
$low = 0; $low = 0;
$high = $this->n-1; $high = $this->n-1;
@ -364,13 +367,13 @@ class EigenvalueDecomposition {
} }
} }
/** /**
* Performs complex division. * Performs complex division.
* *
* @access private * @access private
*/ */
private function cdiv($xr, $xi, $yr, $yi) { private function cdiv($xr, $xi, $yr, $yi)
{
if (abs($yr) > abs($yi)) { if (abs($yr) > abs($yi)) {
$r = $yi / $yr; $r = $yi / $yr;
$d = $yr + $r * $yi; $d = $yr + $r * $yi;
@ -384,7 +387,6 @@ class EigenvalueDecomposition {
} }
} }
/** /**
* Nonsymmetric reduction from Hessenberg to real Schur form. * Nonsymmetric reduction from Hessenberg to real Schur form.
* *
@ -395,7 +397,8 @@ class EigenvalueDecomposition {
* *
* @access private * @access private
*/ */
private function hqr2 () { private function hqr2()
{
// Initialize // Initialize
$nn = $this->n; $nn = $this->n;
$n = $nn - 1; $n = $nn - 1;
@ -408,7 +411,7 @@ class EigenvalueDecomposition {
$norm = 0.0; $norm = 0.0;
for ($i = 0; $i < $nn; ++$i) { for ($i = 0; $i < $nn; ++$i) {
if (($i < $low) OR ($i > $high)) { if (($i < $low) or ($i > $high)) {
$this->d[$i] = $this->H[$i][$i]; $this->d[$i] = $this->H[$i][$i];
$this->e[$i] = 0.0; $this->e[$i] = 0.0;
} }
@ -477,7 +480,7 @@ class EigenvalueDecomposition {
$this->H[$n][$j] = $q * $this->H[$n][$j] - $p * $z; $this->H[$n][$j] = $q * $this->H[$n][$j] - $p * $z;
} }
// Column modification // Column modification
for ($i = 0; $i <= n; ++$i) { for ($i = 0; $i <= $n; ++$i) {
$z = $this->H[$i][$n-1]; $z = $this->H[$i][$n-1];
$this->H[$i][$n-1] = $q * $z + $p * $this->H[$i][$n]; $this->H[$i][$n-1] = $q * $z + $p * $this->H[$i][$n];
$this->H[$i][$n] = $q * $this->H[$i][$n] - $p * $z; $this->H[$i][$n] = $q * $this->H[$i][$n] - $p * $z;
@ -771,7 +774,6 @@ class EigenvalueDecomposition {
} }
} // end hqr2 } // end hqr2
/** /**
* Constructor: Check for symmetry, then construct the eigenvalue decomposition * Constructor: Check for symmetry, then construct the eigenvalue decomposition
* *
@ -779,7 +781,8 @@ class EigenvalueDecomposition {
* @param A Square matrix * @param A Square matrix
* @return Structure to access D and V. * @return Structure to access D and V.
*/ */
public function __construct($Arg) { public function __construct($Arg)
{
$this->A = $Arg->getArray(); $this->A = $Arg->getArray();
$this->n = $Arg->getColumnDimension(); $this->n = $Arg->getColumnDimension();
@ -806,47 +809,47 @@ class EigenvalueDecomposition {
} }
} }
/** /**
* Return the eigenvector matrix * Return the eigenvector matrix
* *
* @access public * @access public
* @return V * @return V
*/ */
public function getV() { public function getV()
{
return new Matrix($this->V, $this->n, $this->n); return new Matrix($this->V, $this->n, $this->n);
} }
/** /**
* Return the real parts of the eigenvalues * Return the real parts of the eigenvalues
* *
* @access public * @access public
* @return real(diag(D)) * @return real(diag(D))
*/ */
public function getRealEigenvalues() { public function getRealEigenvalues()
{
return $this->d; return $this->d;
} }
/** /**
* Return the imaginary parts of the eigenvalues * Return the imaginary parts of the eigenvalues
* *
* @access public * @access public
* @return imag(diag(D)) * @return imag(diag(D))
*/ */
public function getImagEigenvalues() { public function getImagEigenvalues()
{
return $this->e; return $this->e;
} }
/** /**
* Return the block diagonal eigenvalue matrix * Return the block diagonal eigenvalue matrix
* *
* @access public * @access public
* @return D * @return D
*/ */
public function getD() { public function getD()
{
for ($i = 0; $i < $this->n; ++$i) { for ($i = 0; $i < $this->n; ++$i) {
$D[$i] = array_fill(0, $this->n, 0.0); $D[$i] = array_fill(0, $this->n, 0.0);
$D[$i][$i] = $this->d[$i]; $D[$i][$i] = $this->d[$i];
@ -858,5 +861,4 @@ class EigenvalueDecomposition {
} }
return new Matrix($D); return new Matrix($D);
} }
}
} // class EigenvalueDecomposition

View File

@ -18,8 +18,8 @@
* @version 1.1 * @version 1.1
* @license PHP v3.0 * @license PHP v3.0
*/ */
class PHPExcel_Shared_JAMA_LUDecomposition { class PHPExcel_Shared_JAMA_LUDecomposition
{
const MatrixSingularException = "Can only perform operation on singular matrix."; const MatrixSingularException = "Can only perform operation on singular matrix.";
const MatrixSquareException = "Mismatched Row dimension"; const MatrixSquareException = "Mismatched Row dimension";
@ -53,14 +53,14 @@ class PHPExcel_Shared_JAMA_LUDecomposition {
*/ */
private $piv = array(); private $piv = array();
/** /**
* LU Decomposition constructor. * LU Decomposition constructor.
* *
* @param $A Rectangular matrix * @param $A Rectangular matrix
* @return Structure to access L, U and piv. * @return Structure to access L, U and piv.
*/ */
public function __construct($A) { public function __construct($A)
{
if ($A instanceof PHPExcel_Shared_JAMA_Matrix) { if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Use a "left-looking", dot-product, Crout/Doolittle algorithm. // Use a "left-looking", dot-product, Crout/Doolittle algorithm.
$this->LU = $A->getArray(); $this->LU = $A->getArray();
@ -119,13 +119,13 @@ class PHPExcel_Shared_JAMA_LUDecomposition {
} }
} // function __construct() } // function __construct()
/** /**
* Get lower triangular factor. * Get lower triangular factor.
* *
* @return array Lower triangular factor * @return array Lower triangular factor
*/ */
public function getL() { public function getL()
{
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($i > $j) { if ($i > $j) {
@ -140,13 +140,13 @@ class PHPExcel_Shared_JAMA_LUDecomposition {
return new PHPExcel_Shared_JAMA_Matrix($L); return new PHPExcel_Shared_JAMA_Matrix($L);
} // function getL() } // function getL()
/** /**
* Get upper triangular factor. * Get upper triangular factor.
* *
* @return array Upper triangular factor * @return array Upper triangular factor
*/ */
public function getU() { public function getU()
{
for ($i = 0; $i < $this->n; ++$i) { for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($i <= $j) { if ($i <= $j) {
@ -159,33 +159,33 @@ class PHPExcel_Shared_JAMA_LUDecomposition {
return new PHPExcel_Shared_JAMA_Matrix($U); return new PHPExcel_Shared_JAMA_Matrix($U);
} // function getU() } // function getU()
/** /**
* Return pivot permutation vector. * Return pivot permutation vector.
* *
* @return array Pivot vector * @return array Pivot vector
*/ */
public function getPivot() { public function getPivot()
{
return $this->piv; return $this->piv;
} // function getPivot() } // function getPivot()
/** /**
* Alias for getPivot * Alias for getPivot
* *
* @see getPivot * @see getPivot
*/ */
public function getDoublePivot() { public function getDoublePivot()
{
return $this->getPivot(); return $this->getPivot();
} // function getDoublePivot() } // function getDoublePivot()
/** /**
* Is the matrix nonsingular? * Is the matrix nonsingular?
* *
* @return true if U, and hence A, is nonsingular. * @return true if U, and hence A, is nonsingular.
*/ */
public function isNonsingular() { public function isNonsingular()
{
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($this->LU[$j][$j] == 0) { if ($this->LU[$j][$j] == 0) {
return false; return false;
@ -194,13 +194,13 @@ class PHPExcel_Shared_JAMA_LUDecomposition {
return true; return true;
} // function isNonsingular() } // function isNonsingular()
/** /**
* Count determinants * Count determinants
* *
* @return array d matrix deterninat * @return array d matrix deterninat
*/ */
public function det() { public function det()
{
if ($this->m == $this->n) { if ($this->m == $this->n) {
$d = $this->pivsign; $d = $this->pivsign;
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
@ -212,7 +212,6 @@ class PHPExcel_Shared_JAMA_LUDecomposition {
} }
} // function det() } // function det()
/** /**
* Solve A*X = B * Solve A*X = B
* *
@ -221,7 +220,8 @@ class PHPExcel_Shared_JAMA_LUDecomposition {
* @PHPExcel_Calculation_Exception IllegalArgumentException Matrix row dimensions must agree. * @PHPExcel_Calculation_Exception IllegalArgumentException Matrix row dimensions must agree.
* @PHPExcel_Calculation_Exception RuntimeException Matrix is singular. * @PHPExcel_Calculation_Exception RuntimeException Matrix is singular.
*/ */
public function solve($B) { public function solve($B)
{
if ($B->getRowDimension() == $this->m) { if ($B->getRowDimension() == $this->m) {
if ($this->isNonsingular()) { if ($this->isNonsingular()) {
// Copy right hand side with pivoting // Copy right hand side with pivoting
@ -254,5 +254,4 @@ class PHPExcel_Shared_JAMA_LUDecomposition {
throw new PHPExcel_Calculation_Exception(self::MatrixSquareException); throw new PHPExcel_Calculation_Exception(self::MatrixSquareException);
} }
} // function solve() } // function solve()
}
} // class PHPExcel_Shared_JAMA_LUDecomposition

View File

@ -24,9 +24,8 @@ if (!defined('PHPEXCEL_ROOT')) {
* @license PHP v3.0 * @license PHP v3.0
* @see http://math.nist.gov/javanumerics/jama/ * @see http://math.nist.gov/javanumerics/jama/
*/ */
class PHPExcel_Shared_JAMA_Matrix { class PHPExcel_Shared_JAMA_Matrix
{
const PolymorphicArgumentException = "Invalid argument pattern for polymorphic function."; const PolymorphicArgumentException = "Invalid argument pattern for polymorphic function.";
const ArgumentTypeException = "Invalid argument type."; const ArgumentTypeException = "Invalid argument type.";
const ArgumentBoundsException = "Invalid argument range."; const ArgumentBoundsException = "Invalid argument range.";
@ -57,13 +56,13 @@ class PHPExcel_Shared_JAMA_Matrix {
*/ */
private $n; private $n;
/** /**
* Polymorphic constructor * Polymorphic constructor
* *
* As PHP has no support for polymorphic constructors, we hack our own sort of polymorphism using func_num_args, func_get_arg, and gettype. In essence, we're just implementing a simple RTTI filter and calling the appropriate constructor. * As PHP has no support for polymorphic constructors, we hack our own sort of polymorphism using func_num_args, func_get_arg, and gettype. In essence, we're just implementing a simple RTTI filter and calling the appropriate constructor.
*/ */
public function __construct() { public function __construct()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
@ -114,37 +113,36 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function __construct() } // function __construct()
/** /**
* getArray * getArray
* *
* @return array Matrix array * @return array Matrix array
*/ */
public function getArray() { public function getArray()
{
return $this->A; return $this->A;
} // function getArray() } // function getArray()
/** /**
* getRowDimension * getRowDimension
* *
* @return int Row dimension * @return int Row dimension
*/ */
public function getRowDimension() { public function getRowDimension()
{
return $this->m; return $this->m;
} // function getRowDimension() } // function getRowDimension()
/** /**
* getColumnDimension * getColumnDimension
* *
* @return int Column dimension * @return int Column dimension
*/ */
public function getColumnDimension() { public function getColumnDimension()
{
return $this->n; return $this->n;
} // function getColumnDimension() } // function getColumnDimension()
/** /**
* get * get
* *
@ -153,11 +151,11 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param int $j Column position * @param int $j Column position
* @return mixed Element (int/float/double) * @return mixed Element (int/float/double)
*/ */
public function get($i = null, $j = null) { public function get($i = null, $j = null)
{
return $this->A[$i][$j]; return $this->A[$i][$j];
} // function get() } // function get()
/** /**
* getMatrix * getMatrix
* *
@ -168,7 +166,8 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param int $jF Final column index * @param int $jF Final column index
* @return Matrix Submatrix * @return Matrix Submatrix
*/ */
public function getMatrix() { public function getMatrix()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
@ -261,7 +260,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function getMatrix() } // function getMatrix()
/** /**
* checkMatrixDimensions * checkMatrixDimensions
* *
@ -269,7 +267,8 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param Matrix $B Matrix B * @param Matrix $B Matrix B
* @return boolean * @return boolean
*/ */
public function checkMatrixDimensions($B = null) { public function checkMatrixDimensions($B = null)
{
if ($B instanceof PHPExcel_Shared_JAMA_Matrix) { if ($B instanceof PHPExcel_Shared_JAMA_Matrix) {
if (($this->m == $B->getRowDimension()) && ($this->n == $B->getColumnDimension())) { if (($this->m == $B->getRowDimension()) && ($this->n == $B->getColumnDimension())) {
return true; return true;
@ -281,8 +280,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function checkMatrixDimensions() } // function checkMatrixDimensions()
/** /**
* set * set
* *
@ -292,12 +289,12 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $c Int/float/double value * @param mixed $c Int/float/double value
* @return mixed Element (int/float/double) * @return mixed Element (int/float/double)
*/ */
public function set($i = null, $j = null, $c = null) { public function set($i = null, $j = null, $c = null)
{
// Optimized set version just has this // Optimized set version just has this
$this->A[$i][$j] = $c; $this->A[$i][$j] = $c;
} // function set() } // function set()
/** /**
* identity * identity
* *
@ -306,11 +303,11 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param int $n Column dimension * @param int $n Column dimension
* @return Matrix Identity matrix * @return Matrix Identity matrix
*/ */
public function identity($m = null, $n = null) { public function identity($m = null, $n = null)
{
return $this->diagonal($m, $n, 1); return $this->diagonal($m, $n, 1);
} // function identity() } // function identity()
/** /**
* diagonal * diagonal
* *
@ -320,7 +317,8 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $c Diagonal value * @param mixed $c Diagonal value
* @return Matrix Diagonal matrix * @return Matrix Diagonal matrix
*/ */
public function diagonal($m = null, $n = null, $c = 1) { public function diagonal($m = null, $n = null, $c = 1)
{
$R = new PHPExcel_Shared_JAMA_Matrix($m, $n); $R = new PHPExcel_Shared_JAMA_Matrix($m, $n);
for($i = 0; $i < $m; ++$i) { for($i = 0; $i < $m; ++$i) {
$R->set($i, $i, $c); $R->set($i, $i, $c);
@ -328,7 +326,6 @@ class PHPExcel_Shared_JAMA_Matrix {
return $R; return $R;
} // function diagonal() } // function diagonal()
/** /**
* getMatrixByRow * getMatrixByRow
* *
@ -337,7 +334,8 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param int $iF Final row index * @param int $iF Final row index
* @return Matrix Submatrix * @return Matrix Submatrix
*/ */
public function getMatrixByRow($i0 = null, $iF = null) { public function getMatrixByRow($i0 = null, $iF = null)
{
if (is_int($i0)) { if (is_int($i0)) {
if (is_int($iF)) { if (is_int($iF)) {
return $this->getMatrix($i0, 0, $iF + 1, $this->n); return $this->getMatrix($i0, 0, $iF + 1, $this->n);
@ -349,7 +347,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function getMatrixByRow() } // function getMatrixByRow()
/** /**
* getMatrixByCol * getMatrixByCol
* *
@ -358,7 +355,8 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param int $iF Final column index * @param int $iF Final column index
* @return Matrix Submatrix * @return Matrix Submatrix
*/ */
public function getMatrixByCol($j0 = null, $jF = null) { public function getMatrixByCol($j0 = null, $jF = null)
{
if (is_int($j0)) { if (is_int($j0)) {
if (is_int($jF)) { if (is_int($jF)) {
return $this->getMatrix(0, $j0, $this->m, $jF + 1); return $this->getMatrix(0, $j0, $this->m, $jF + 1);
@ -370,14 +368,14 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function getMatrixByCol() } // function getMatrixByCol()
/** /**
* transpose * transpose
* *
* Tranpose matrix * Tranpose matrix
* @return Matrix Transposed matrix * @return Matrix Transposed matrix
*/ */
public function transpose() { public function transpose()
{
$R = new PHPExcel_Shared_JAMA_Matrix($this->n, $this->m); $R = new PHPExcel_Shared_JAMA_Matrix($this->n, $this->m);
for($i = 0; $i < $this->m; ++$i) { for($i = 0; $i < $this->m; ++$i) {
for($j = 0; $j < $this->n; ++$j) { for($j = 0; $j < $this->n; ++$j) {
@ -387,14 +385,14 @@ class PHPExcel_Shared_JAMA_Matrix {
return $R; return $R;
} // function transpose() } // function transpose()
/** /**
* trace * trace
* *
* Sum of diagonal elements * Sum of diagonal elements
* @return float Sum of diagonal elements * @return float Sum of diagonal elements
*/ */
public function trace() { public function trace()
{
$s = 0; $s = 0;
$n = min($this->m, $this->n); $n = min($this->m, $this->n);
for($i = 0; $i < $n; ++$i) { for($i = 0; $i < $n; ++$i) {
@ -403,17 +401,16 @@ class PHPExcel_Shared_JAMA_Matrix {
return $s; return $s;
} // function trace() } // function trace()
/** /**
* uminus * uminus
* *
* Unary minus matrix -A * Unary minus matrix -A
* @return Matrix Unary minus matrix * @return Matrix Unary minus matrix
*/ */
public function uminus() { public function uminus()
{
} // function uminus() } // function uminus()
/** /**
* plus * plus
* *
@ -421,14 +418,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Sum * @return Matrix Sum
*/ */
public function plus() { public function plus()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -449,7 +451,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function plus() } // function plus()
/** /**
* plusEquals * plusEquals
* *
@ -457,14 +458,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Sum * @return Matrix Sum
*/ */
public function plusEquals() { public function plusEquals()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -476,7 +482,7 @@ class PHPExcel_Shared_JAMA_Matrix {
$this->checkMatrixDimensions($M); $this->checkMatrixDimensions($M);
for($i = 0; $i < $this->m; ++$i) { for($i = 0; $i < $this->m; ++$i) {
for($j = 0; $j < $this->n; ++$j) { for($j = 0; $j < $this->n; ++$j) {
$validValues = True; $validValues = true;
$value = $M->get($i, $j); $value = $M->get($i, $j);
if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
$this->A[$i][$j] = trim($this->A[$i][$j],'"'); $this->A[$i][$j] = trim($this->A[$i][$j],'"');
@ -499,7 +505,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function plusEquals() } // function plusEquals()
/** /**
* minus * minus
* *
@ -507,14 +512,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Sum * @return Matrix Sum
*/ */
public function minus() { public function minus()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -535,7 +545,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function minus() } // function minus()
/** /**
* minusEquals * minusEquals
* *
@ -543,14 +552,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Sum * @return Matrix Sum
*/ */
public function minusEquals() { public function minusEquals()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -562,7 +576,7 @@ class PHPExcel_Shared_JAMA_Matrix {
$this->checkMatrixDimensions($M); $this->checkMatrixDimensions($M);
for($i = 0; $i < $this->m; ++$i) { for($i = 0; $i < $this->m; ++$i) {
for($j = 0; $j < $this->n; ++$j) { for($j = 0; $j < $this->n; ++$j) {
$validValues = True; $validValues = true;
$value = $M->get($i, $j); $value = $M->get($i, $j);
if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
$this->A[$i][$j] = trim($this->A[$i][$j],'"'); $this->A[$i][$j] = trim($this->A[$i][$j],'"');
@ -585,7 +599,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function minusEquals() } // function minusEquals()
/** /**
* arrayTimes * arrayTimes
* *
@ -594,14 +607,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Matrix Cij * @return Matrix Matrix Cij
*/ */
public function arrayTimes() { public function arrayTimes()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -622,7 +640,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function arrayTimes() } // function arrayTimes()
/** /**
* arrayTimesEquals * arrayTimesEquals
* *
@ -631,14 +648,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Matrix Aij * @return Matrix Matrix Aij
*/ */
public function arrayTimesEquals() { public function arrayTimesEquals()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -650,7 +672,7 @@ class PHPExcel_Shared_JAMA_Matrix {
$this->checkMatrixDimensions($M); $this->checkMatrixDimensions($M);
for($i = 0; $i < $this->m; ++$i) { for($i = 0; $i < $this->m; ++$i) {
for($j = 0; $j < $this->n; ++$j) { for($j = 0; $j < $this->n; ++$j) {
$validValues = True; $validValues = true;
$value = $M->get($i, $j); $value = $M->get($i, $j);
if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
$this->A[$i][$j] = trim($this->A[$i][$j],'"'); $this->A[$i][$j] = trim($this->A[$i][$j],'"');
@ -673,7 +695,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function arrayTimesEquals() } // function arrayTimesEquals()
/** /**
* arrayRightDivide * arrayRightDivide
* *
@ -682,14 +703,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param Matrix $B Matrix B * @param Matrix $B Matrix B
* @return Matrix Division result * @return Matrix Division result
*/ */
public function arrayRightDivide() { public function arrayRightDivide()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -701,7 +727,7 @@ class PHPExcel_Shared_JAMA_Matrix {
$this->checkMatrixDimensions($M); $this->checkMatrixDimensions($M);
for($i = 0; $i < $this->m; ++$i) { for($i = 0; $i < $this->m; ++$i) {
for($j = 0; $j < $this->n; ++$j) { for($j = 0; $j < $this->n; ++$j) {
$validValues = True; $validValues = true;
$value = $M->get($i, $j); $value = $M->get($i, $j);
if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
$this->A[$i][$j] = trim($this->A[$i][$j],'"'); $this->A[$i][$j] = trim($this->A[$i][$j],'"');
@ -738,14 +764,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Matrix Aij * @return Matrix Matrix Aij
*/ */
public function arrayRightDivideEquals() { public function arrayRightDivideEquals()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -775,14 +806,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param Matrix $B Matrix B * @param Matrix $B Matrix B
* @return Matrix Division result * @return Matrix Division result
*/ */
public function arrayLeftDivide() { public function arrayLeftDivide()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -812,14 +848,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Matrix Aij * @return Matrix Matrix Aij
*/ */
public function arrayLeftDivideEquals() { public function arrayLeftDivideEquals()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -848,14 +889,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $n Matrix/Array/Scalar * @param mixed $n Matrix/Array/Scalar
* @return Matrix Product * @return Matrix Product
*/ */
public function times() { public function times()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $B = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$B = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
if ($this->n == $B->m) { if ($this->n == $B->m) {
$C = new PHPExcel_Shared_JAMA_Matrix($this->m, $B->n); $C = new PHPExcel_Shared_JAMA_Matrix($this->m, $B->n);
for($j = 0; $j < $B->n; ++$j) { for($j = 0; $j < $B->n; ++$j) {
@ -931,7 +977,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function times() } // function times()
/** /**
* power * power
* *
@ -939,14 +984,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Sum * @return Matrix Sum
*/ */
public function power() { public function power()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
break; break;
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
@ -958,7 +1008,7 @@ class PHPExcel_Shared_JAMA_Matrix {
$this->checkMatrixDimensions($M); $this->checkMatrixDimensions($M);
for($i = 0; $i < $this->m; ++$i) { for($i = 0; $i < $this->m; ++$i) {
for($j = 0; $j < $this->n; ++$j) { for($j = 0; $j < $this->n; ++$j) {
$validValues = True; $validValues = true;
$value = $M->get($i, $j); $value = $M->get($i, $j);
if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) { if ((is_string($this->A[$i][$j])) && (strlen($this->A[$i][$j]) > 0) && (!is_numeric($this->A[$i][$j]))) {
$this->A[$i][$j] = trim($this->A[$i][$j],'"'); $this->A[$i][$j] = trim($this->A[$i][$j],'"');
@ -981,7 +1031,6 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function power() } // function power()
/** /**
* concat * concat
* *
@ -989,14 +1038,19 @@ class PHPExcel_Shared_JAMA_Matrix {
* @param mixed $B Matrix/Array * @param mixed $B Matrix/Array
* @return Matrix Sum * @return Matrix Sum
*/ */
public function concat() { public function concat()
{
if (func_num_args() > 0) { if (func_num_args() > 0) {
$args = func_get_args(); $args = func_get_args();
$match = implode(",", array_map('gettype', $args)); $match = implode(",", array_map('gettype', $args));
switch ($match) { switch ($match) {
case 'object': case 'object':
if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) { $M = $args[0]; } else { throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException); } if ($args[0] instanceof PHPExcel_Shared_JAMA_Matrix) {
$M = $args[0];
} else {
throw new PHPExcel_Calculation_Exception(self::ArgumentTypeException);
}
case 'array': case 'array':
$M = new PHPExcel_Shared_JAMA_Matrix($args[0]); $M = new PHPExcel_Shared_JAMA_Matrix($args[0]);
break; break;
@ -1016,14 +1070,14 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function concat() } // function concat()
/** /**
* Solve A*X = B. * Solve A*X = B.
* *
* @param Matrix $B Right hand side * @param Matrix $B Right hand side
* @return Matrix ... Solution if A is square, least squares solution otherwise * @return Matrix ... Solution if A is square, least squares solution otherwise
*/ */
public function solve($B) { public function solve($B)
{
if ($this->m == $this->n) { if ($this->m == $this->n) {
$LU = new PHPExcel_Shared_JAMA_LUDecomposition($this); $LU = new PHPExcel_Shared_JAMA_LUDecomposition($this);
return $LU->solve($B); return $LU->solve($B);
@ -1033,24 +1087,24 @@ class PHPExcel_Shared_JAMA_Matrix {
} }
} // function solve() } // function solve()
/** /**
* Matrix inverse or pseudoinverse. * Matrix inverse or pseudoinverse.
* *
* @return Matrix ... Inverse(A) if A is square, pseudoinverse otherwise. * @return Matrix ... Inverse(A) if A is square, pseudoinverse otherwise.
*/ */
public function inverse() { public function inverse()
{
return $this->solve($this->identity($this->m, $this->m)); return $this->solve($this->identity($this->m, $this->m));
} // function inverse() } // function inverse()
/** /**
* det * det
* *
* Calculate determinant * Calculate determinant
* @return float Determinant * @return float Determinant
*/ */
public function det() { public function det()
{
$L = new PHPExcel_Shared_JAMA_LUDecomposition($this); $L = new PHPExcel_Shared_JAMA_LUDecomposition($this);
return $L->det(); return $L->det();
} // function det() } // function det()

View File

@ -16,8 +16,8 @@
* @license PHP v3.0 * @license PHP v3.0
* @version 1.1 * @version 1.1
*/ */
class PHPExcel_Shared_JAMA_QRDecomposition { class PHPExcel_Shared_JAMA_QRDecomposition
{
const MatrixRankException = "Can only perform operation on full-rank matrix."; const MatrixRankException = "Can only perform operation on full-rank matrix.";
/** /**
@ -51,7 +51,8 @@ class PHPExcel_Shared_JAMA_QRDecomposition {
* @param matrix $A Rectangular matrix * @param matrix $A Rectangular matrix
* @return Structure to access R and the Householder vectors and compute Q. * @return Structure to access R and the Householder vectors and compute Q.
*/ */
public function __construct($A) { public function __construct($A)
{
if ($A instanceof PHPExcel_Shared_JAMA_Matrix) { if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {
// Initialize. // Initialize.
$this->QR = $A->getArrayCopy(); $this->QR = $A->getArrayCopy();
@ -98,7 +99,8 @@ class PHPExcel_Shared_JAMA_QRDecomposition {
* *
* @return boolean true if R, and hence A, has full rank, else false. * @return boolean true if R, and hence A, has full rank, else false.
*/ */
public function isFullRank() { public function isFullRank()
{
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($this->Rdiag[$j] == 0) { if ($this->Rdiag[$j] == 0) {
return false; return false;
@ -107,13 +109,13 @@ class PHPExcel_Shared_JAMA_QRDecomposition {
return true; return true;
} // function isFullRank() } // function isFullRank()
/** /**
* Return the Householder vectors * Return the Householder vectors
* *
* @return Matrix Lower trapezoidal matrix whose columns define the reflections * @return Matrix Lower trapezoidal matrix whose columns define the reflections
*/ */
public function getH() { public function getH()
{
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($i >= $j) { if ($i >= $j) {
@ -126,13 +128,13 @@ class PHPExcel_Shared_JAMA_QRDecomposition {
return new PHPExcel_Shared_JAMA_Matrix($H); return new PHPExcel_Shared_JAMA_Matrix($H);
} // function getH() } // function getH()
/** /**
* Return the upper triangular factor * Return the upper triangular factor
* *
* @return Matrix upper triangular factor * @return Matrix upper triangular factor
*/ */
public function getR() { public function getR()
{
for ($i = 0; $i < $this->n; ++$i) { for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
if ($i < $j) { if ($i < $j) {
@ -147,13 +149,13 @@ class PHPExcel_Shared_JAMA_QRDecomposition {
return new PHPExcel_Shared_JAMA_Matrix($R); return new PHPExcel_Shared_JAMA_Matrix($R);
} // function getR() } // function getR()
/** /**
* Generate and return the (economy-sized) orthogonal factor * Generate and return the (economy-sized) orthogonal factor
* *
* @return Matrix orthogonal factor * @return Matrix orthogonal factor
*/ */
public function getQ() { public function getQ()
{
for ($k = $this->n-1; $k >= 0; --$k) { for ($k = $this->n-1; $k >= 0; --$k) {
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
$Q[$i][$k] = 0.0; $Q[$i][$k] = 0.0;
@ -184,14 +186,14 @@ class PHPExcel_Shared_JAMA_QRDecomposition {
return new PHPExcel_Shared_JAMA_Matrix($Q); return new PHPExcel_Shared_JAMA_Matrix($Q);
} // function getQ() } // function getQ()
/** /**
* Least squares solution of A*X = B * Least squares solution of A*X = B
* *
* @param Matrix $B A Matrix with as many rows as A and any number of columns. * @param Matrix $B A Matrix with as many rows as A and any number of columns.
* @return Matrix Matrix that minimizes the two norm of Q*R*X-B. * @return Matrix Matrix that minimizes the two norm of Q*R*X-B.
*/ */
public function solve($B) { public function solve($B)
{
if ($B->getRowDimension() == $this->m) { if ($B->getRowDimension() == $this->m) {
if ($this->isFullRank()) { if ($this->isFullRank()) {
// Copy right hand side // Copy right hand side
@ -230,5 +232,5 @@ class PHPExcel_Shared_JAMA_QRDecomposition {
throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException); throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::MatrixDimensionException);
} }
} // function solve() } // function solve()
}
} // PHPExcel_Shared_JAMA_class QRDecomposition

View File

@ -17,8 +17,8 @@
* @license PHP v3.0 * @license PHP v3.0
* @version 1.1 * @version 1.1
*/ */
class SingularValueDecomposition { class SingularValueDecomposition
{
/** /**
* Internal storage of U. * Internal storage of U.
* @var array * @var array
@ -49,7 +49,6 @@ class SingularValueDecomposition {
*/ */
private $n; private $n;
/** /**
* Construct the singular value decomposition * Construct the singular value decomposition
* *
@ -58,8 +57,8 @@ class SingularValueDecomposition {
* @param $A Rectangular matrix * @param $A Rectangular matrix
* @return Structure to access U, S and V. * @return Structure to access U, S and V.
*/ */
public function __construct($Arg) { public function __construct($Arg)
{
// Initialize. // Initialize.
$A = $Arg->getArrayCopy(); $A = $Arg->getArrayCopy();
$this->m = $Arg->getRowDimension(); $this->m = $Arg->getRowDimension();
@ -75,7 +74,6 @@ class SingularValueDecomposition {
// Reduce A to bidiagonal form, storing the diagonal elements // Reduce A to bidiagonal form, storing the diagonal elements
// in s and the super-diagonal elements in e. // in s and the super-diagonal elements in e.
for ($k = 0; $k < max($nct, $nrt); ++$k) { for ($k = 0; $k < max($nct, $nrt); ++$k) {
if ($k < $nct) { if ($k < $nct) {
// Compute the transformation for the k-th column and // Compute the transformation for the k-th column and
// place the k-th diagonal in s[$k]. // place the k-th diagonal in s[$k].
@ -113,7 +111,7 @@ class SingularValueDecomposition {
} }
} }
if ($wantu AND ($k < $nct)) { if ($wantu and ($k < $nct)) {
// Place the transformation in U for subsequent back // Place the transformation in U for subsequent back
// multiplication. // multiplication.
for ($i = $k; $i < $this->m; ++$i) { for ($i = $k; $i < $this->m; ++$i) {
@ -139,7 +137,7 @@ class SingularValueDecomposition {
$e[$k+1] += 1.0; $e[$k+1] += 1.0;
} }
$e[$k] = -$e[$k]; $e[$k] = -$e[$k];
if (($k+1 < $this->m) AND ($e[$k] != 0.0)) { if (($k+1 < $this->m) and ($e[$k] != 0.0)) {
// Apply the transformation. // Apply the transformation.
for ($i = $k+1; $i < $this->m; ++$i) { for ($i = $k+1; $i < $this->m; ++$i) {
$work[$i] = 0.0; $work[$i] = 0.0;
@ -217,7 +215,7 @@ class SingularValueDecomposition {
// If required, generate V. // If required, generate V.
if ($wantv) { if ($wantv) {
for ($k = $this->n - 1; $k >= 0; --$k) { for ($k = $this->n - 1; $k >= 0; --$k) {
if (($k < $nrt) AND ($e[$k] != 0.0)) { if (($k < $nrt) and ($e[$k] != 0.0)) {
for ($j = $k + 1; $j < $nu; ++$j) { for ($j = $k + 1; $j < $nu; ++$j) {
$t = 0; $t = 0;
for ($i = $k + 1; $i < $this->n; ++$i) { for ($i = $k + 1; $i < $this->n; ++$i) {
@ -331,9 +329,7 @@ class SingularValueDecomposition {
// Perform one qr step. // Perform one qr step.
case 3: case 3:
// Calculate the shift. // Calculate the shift.
$scale = max(max(max(max( $scale = max(max(max(max(abs($this->s[$p-1]), abs($this->s[$p-2])), abs($e[$p-2])), abs($this->s[$k])), abs($e[$k]));
abs($this->s[$p-1]),abs($this->s[$p-2])),abs($e[$p-2])),
abs($this->s[$k])), abs($e[$k]));
$sp = $this->s[$p-1] / $scale; $sp = $this->s[$p-1] / $scale;
$spm1 = $this->s[$p-2] / $scale; $spm1 = $this->s[$p-2] / $scale;
$epm1 = $e[$p-2] / $scale; $epm1 = $e[$p-2] / $scale;
@ -408,14 +404,14 @@ class SingularValueDecomposition {
$t = $this->s[$k]; $t = $this->s[$k];
$this->s[$k] = $this->s[$k+1]; $this->s[$k] = $this->s[$k+1];
$this->s[$k+1] = $t; $this->s[$k+1] = $t;
if ($wantv AND ($k < $this->n - 1)) { if ($wantv and ($k < $this->n - 1)) {
for ($i = 0; $i < $this->n; ++$i) { for ($i = 0; $i < $this->n; ++$i) {
$t = $this->V[$i][$k+1]; $t = $this->V[$i][$k+1];
$this->V[$i][$k+1] = $this->V[$i][$k]; $this->V[$i][$k+1] = $this->V[$i][$k];
$this->V[$i][$k] = $t; $this->V[$i][$k] = $t;
} }
} }
if ($wantu AND ($k < $this->m-1)) { if ($wantu and ($k < $this->m-1)) {
for ($i = 0; $i < $this->m; ++$i) { for ($i = 0; $i < $this->m; ++$i) {
$t = $this->U[$i][$k+1]; $t = $this->U[$i][$k+1];
$this->U[$i][$k+1] = $this->U[$i][$k]; $this->U[$i][$k+1] = $this->U[$i][$k];
@ -439,7 +435,8 @@ class SingularValueDecomposition {
* @access public * @access public
* @return U * @return U
*/ */
public function getU() { public function getU()
{
return new Matrix($this->U, $this->m, min($this->m + 1, $this->n)); return new Matrix($this->U, $this->m, min($this->m + 1, $this->n));
} }
@ -450,7 +447,8 @@ class SingularValueDecomposition {
* @access public * @access public
* @return V * @return V
*/ */
public function getV() { public function getV()
{
return new Matrix($this->V); return new Matrix($this->V);
} }
@ -461,7 +459,8 @@ class SingularValueDecomposition {
* @access public * @access public
* @return diagonal of S. * @return diagonal of S.
*/ */
public function getSingularValues() { public function getSingularValues()
{
return $this->s; return $this->s;
} }
@ -472,7 +471,8 @@ class SingularValueDecomposition {
* @access public * @access public
* @return S * @return S
*/ */
public function getS() { public function getS()
{
for ($i = 0; $i < $this->n; ++$i) { for ($i = 0; $i < $this->n; ++$i) {
for ($j = 0; $j < $this->n; ++$j) { for ($j = 0; $j < $this->n; ++$j) {
$S[$i][$j] = 0.0; $S[$i][$j] = 0.0;
@ -489,7 +489,8 @@ class SingularValueDecomposition {
* @access public * @access public
* @return max(S) * @return max(S)
*/ */
public function norm2() { public function norm2()
{
return $this->s[0]; return $this->s[0];
} }
@ -500,7 +501,8 @@ class SingularValueDecomposition {
* @access public * @access public
* @return max(S)/min(S) * @return max(S)/min(S)
*/ */
public function cond() { public function cond()
{
return $this->s[0] / $this->s[min($this->m, $this->n) - 1]; return $this->s[0] / $this->s[min($this->m, $this->n) - 1];
} }
@ -511,7 +513,8 @@ class SingularValueDecomposition {
* @access public * @access public
* @return Number of nonnegligible singular values. * @return Number of nonnegligible singular values.
*/ */
public function rank() { public function rank()
{
$eps = pow(2.0, -52.0); $eps = pow(2.0, -52.0);
$tol = max($this->m, $this->n) * $this->s[0] * $eps; $tol = max($this->m, $this->n) * $this->s[0] * $eps;
$r = 0; $r = 0;
@ -522,5 +525,4 @@ class SingularValueDecomposition {
} }
return $r; return $r;
} }
}
} // class SingularValueDecomposition

View File

@ -67,7 +67,8 @@ $error['EN'][RowLengthException] = "All rows must have the same length.";
* Custom error handler * Custom error handler
* @param int $num Error number * @param int $num Error number
*/ */
function JAMAError($errorNumber = null) { function JAMAError($errorNumber = null)
{
global $error; global $error;
if (isset($errorNumber)) { if (isset($errorNumber)) {

View File

@ -11,7 +11,8 @@
* *
* r = sqrt(a^2 + b^2) without under/overflow. * r = sqrt(a^2 + b^2) without under/overflow.
*/ */
function hypo($a, $b) { function hypo($a, $b)
{
if (abs($a) > abs($b)) { if (abs($a) > abs($b)) {
$r = $b / $a; $r = $b / $a;
$r = abs($a) * sqrt(1 + $r * $r); $r = abs($a) * sqrt(1 + $r * $r);

View File

@ -73,8 +73,9 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
if (is_resource($filename)) { if (is_resource($filename)) {
$this->_FILEH_ = $filename; $this->_FILEH_ = $filename;
} else if ($filename == '-' || $filename == '') { } else if ($filename == '-' || $filename == '') {
if ($this->_tmp_dir === null) if ($this->_tmp_dir === null) {
$this->_tmp_dir = PHPExcel_Shared_File::sys_get_temp_dir(); $this->_tmp_dir = PHPExcel_Shared_File::sys_get_temp_dir();
}
$this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root"); $this->_tmp_filename = tempnam($this->_tmp_dir, "OLE_PPS_Root");
$this->_FILEH_ = fopen($this->_tmp_filename,"w+b"); $this->_FILEH_ = fopen($this->_tmp_filename,"w+b");
if ($this->_FILEH_ == false) { if ($this->_FILEH_ == false) {
@ -199,7 +200,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
} }
// Save Header // Save Header
fwrite($FILE, fwrite(
$FILE,
"\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
. "\x00\x00\x00\x00" . "\x00\x00\x00\x00"
. "\x00\x00\x00\x00" . "\x00\x00\x00\x00"
@ -222,7 +224,8 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
); );
// Extra BDList Start, Count // Extra BDList Start, Count
if ($iBdCnt < $i1stBdL) { if ($iBdCnt < $i1stBdL) {
fwrite($FILE, fwrite(
$FILE,
pack("V", -2) // Extra BDList Start pack("V", -2) // Extra BDList Start
. pack("V", 0)// Extra BDList Count . pack("V", 0)// Extra BDList Count
); );
@ -258,9 +261,7 @@ class PHPExcel_Shared_OLE_PPS_Root extends PHPExcel_Shared_OLE_PPS
for ($i = 0; $i < $iCount; ++$i) { for ($i = 0; $i < $iCount; ++$i) {
if ($raList[$i]->Type != PHPExcel_Shared_OLE::OLE_PPS_TYPE_DIR) { if ($raList[$i]->Type != PHPExcel_Shared_OLE::OLE_PPS_TYPE_DIR) {
$raList[$i]->Size = $raList[$i]->_DataLen(); $raList[$i]->Size = $raList[$i]->_DataLen();
if (($raList[$i]->Size >= PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) || if (($raList[$i]->Size >= PHPExcel_Shared_OLE::OLE_DATA_SIZE_SMALL) || (($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data))) {
(($raList[$i]->Type == PHPExcel_Shared_OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data)))
{
// Write Data // Write Data
//if (isset($raList[$i]->_PPS_FILE)) { //if (isset($raList[$i]->_PPS_FILE)) {
// $iLen = 0; // $iLen = 0;

View File

@ -28,7 +28,8 @@
defined('IDENTIFIER_OLE') || defined('IDENTIFIER_OLE') ||
define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1)); define('IDENTIFIER_OLE', pack('CCCCCCCC', 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1));
class PHPExcel_Shared_OLERead { class PHPExcel_Shared_OLERead
{
private $data = ''; private $data = '';
// OLE identifier // OLE identifier

View File

@ -3167,7 +3167,6 @@ class PclZip
// ----- Look for PCLZIP_OPT_STOP_ON_ERROR // ----- Look for PCLZIP_OPT_STOP_ON_ERROR
if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) { if ((isset($p_options[PCLZIP_OPT_STOP_ON_ERROR])) && ($p_options[PCLZIP_OPT_STOP_ON_ERROR] === true)) {
$this->privSwapBackMagicQuotes(); $this->privSwapBackMagicQuotes();
PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, "Filename '".$v_header['stored_filename']."' is compressed by an unsupported compression method (".$v_header['compression'].") "); PclZip::privErrorLog(PCLZIP_ERR_UNSUPPORTED_COMPRESSION, "Filename '".$v_header['stored_filename']."' is compressed by an unsupported compression method (".$v_header['compression'].") ");
@ -3249,9 +3248,8 @@ class PclZip
if ($v_result1 == 2) { if ($v_result1 == 2) {
break; break;
} }
} } elseif ((isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
// ----- Look for extraction in standard output // ----- Look for extraction in standard output
elseif ((isset($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) && ($p_options[PCLZIP_OPT_EXTRACT_IN_OUTPUT])) {
// ----- Extracting the file in standard output // ----- Extracting the file in standard output
$v_result1 = $this->privExtractFileInOutput($v_header, $p_options); $v_result1 = $this->privExtractFileInOutput($v_header, $p_options);
if ($v_result1 < 1) { if ($v_result1 < 1) {
@ -3410,7 +3408,6 @@ class PclZip
if (file_exists($p_entry['filename'])) { if (file_exists($p_entry['filename'])) {
// ----- Look if file is a directory // ----- Look if file is a directory
if (is_dir($p_entry['filename'])) { if (is_dir($p_entry['filename'])) {
// ----- Change the file status // ----- Change the file status
$p_entry['status'] = "already_a_directory"; $p_entry['status'] = "already_a_directory";
@ -3454,11 +3451,9 @@ class PclZip
// ----- Check the directory availability and create it if necessary // ----- Check the directory availability and create it if necessary
if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) { if ((($p_entry['external']&0x00000010)==0x00000010) || (substr($p_entry['filename'], -1) == '/')) {
$v_dir_to_check = $p_entry['filename']; $v_dir_to_check = $p_entry['filename'];
} } else if (!strstr($p_entry['filename'], "/")) {
else if (!strstr($p_entry['filename'], "/")) {
$v_dir_to_check = ""; $v_dir_to_check = "";
} } else {
else {
$v_dir_to_check = dirname($p_entry['filename']); $v_dir_to_check = dirname($p_entry['filename']);
} }
@ -3530,7 +3525,6 @@ class PclZip
$v_file_content = @gzinflate($v_buffer); $v_file_content = @gzinflate($v_buffer);
unset($v_buffer); unset($v_buffer);
if ($v_file_content === false) { if ($v_file_content === false) {
// ----- Change the file status // ----- Change the file status
// TBC // TBC
$p_entry['status'] = "error"; $p_entry['status'] = "error";
@ -3540,7 +3534,6 @@ class PclZip
// ----- Opening destination file // ----- Opening destination file
if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) { if (($v_dest_file = @fopen($p_entry['filename'], 'wb')) == 0) {
// ----- Change the file status // ----- Change the file status
$p_entry['status'] = "write_error"; $p_entry['status'] = "write_error";
@ -3723,7 +3716,6 @@ class PclZip
if (!(($p_entry['external']&0x00000010)==0x00000010)) { if (!(($p_entry['external']&0x00000010)==0x00000010)) {
// ----- Look for not compressed file // ----- Look for not compressed file
if ($p_entry['compressed_size'] == $p_entry['size']) { if ($p_entry['compressed_size'] == $p_entry['size']) {
// ----- Read the file in a buffer (one shot) // ----- Read the file in a buffer (one shot)
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
@ -3731,7 +3723,6 @@ class PclZip
echo $v_buffer; echo $v_buffer;
unset($v_buffer); unset($v_buffer);
} else { } else {
// ----- Read the compressed file in a buffer (one shot) // ----- Read the compressed file in a buffer (one shot)
$v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']); $v_buffer = @fread($this->zip_fd, $p_entry['compressed_size']);
@ -3830,11 +3821,9 @@ class PclZip
// ----- Look for not compressed file // ----- Look for not compressed file
// if ($p_entry['compressed_size'] == $p_entry['size']) // if ($p_entry['compressed_size'] == $p_entry['size'])
if ($p_entry['compression'] == 0) { if ($p_entry['compression'] == 0) {
// ----- Reading the file // ----- Reading the file
$p_string = @fread($this->zip_fd, $p_entry['compressed_size']); $p_string = @fread($this->zip_fd, $p_entry['compressed_size']);
} else { } else {
// ----- Reading the file // ----- Reading the file
$v_data = @fread($this->zip_fd, $p_entry['compressed_size']); $v_data = @fread($this->zip_fd, $p_entry['compressed_size']);
@ -4037,8 +4026,7 @@ class PclZip
// ----- Get comment // ----- Get comment
if ($p_header['comment_len'] != 0) { if ($p_header['comment_len'] != 0) {
$p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']); $p_header['comment'] = fread($this->zip_fd, $p_header['comment_len']);
} } else {
else {
$p_header['comment'] = ''; $p_header['comment'] = '';
} }
@ -4171,8 +4159,9 @@ class PclZip
// ----- Go back to the maximum possible size of the Central Dir End Record // ----- Go back to the maximum possible size of the Central Dir End Record
if (!$v_found) { if (!$v_found) {
$v_maximum_size = 65557; // 0xFFFF + 22; $v_maximum_size = 65557; // 0xFFFF + 22;
if ($v_maximum_size > $v_size) if ($v_maximum_size > $v_size) {
$v_maximum_size = $v_size; $v_maximum_size = $v_size;
}
@fseek($this->zip_fd, $v_size-$v_maximum_size); @fseek($this->zip_fd, $v_size-$v_maximum_size);
if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) { if (@ftell($this->zip_fd) != ($v_size-$v_maximum_size)) {
// ----- Error log // ----- Error log
@ -4196,8 +4185,7 @@ class PclZip
$v_bytes = (($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte); $v_bytes = (($v_bytes & 0xFFFFFF) << 8) | Ord($v_byte);
// ----- Compare the bytes // ----- Compare the bytes
if ($v_bytes == 0x504b0506) if ($v_bytes == 0x504b0506) {
{
$v_pos++; $v_pos++;
break; break;
} }
@ -4342,27 +4330,13 @@ class PclZip
} elseif ((($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) { } elseif ((($v_header_list[$v_nb_extracted]['external']&0x00000010)==0x00000010) /* Indicates a folder */ && ($v_header_list[$v_nb_extracted]['stored_filename'].'/' == $p_options[PCLZIP_OPT_BY_NAME][$j])) {
$v_found = true; $v_found = true;
} }
} } elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
// ----- Look for a filename // ----- Look for a filename
elseif ($v_header_list[$v_nb_extracted]['stored_filename'] == $p_options[PCLZIP_OPT_BY_NAME][$j]) {
$v_found = true; $v_found = true;
} }
} }
} } else if ((isset($p_options[PCLZIP_OPT_BY_PREG])) && ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
// ----- Look for extract by ereg rule
// ereg() is deprecated with PHP 5.3
/*
else if ( (isset($p_options[PCLZIP_OPT_BY_EREG]))
&& ($p_options[PCLZIP_OPT_BY_EREG] != "")) {
if (ereg($p_options[PCLZIP_OPT_BY_EREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
$v_found = true;
}
}
*/
else if ((isset($p_options[PCLZIP_OPT_BY_PREG]))
// ----- Look for extract by preg rule // ----- Look for extract by preg rule
&& ($p_options[PCLZIP_OPT_BY_PREG] != "")) {
if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) { if (preg_match($p_options[PCLZIP_OPT_BY_PREG], $v_header_list[$v_nb_extracted]['stored_filename'])) {
$v_found = true; $v_found = true;
} }
@ -4376,7 +4350,6 @@ class PclZip
if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) { if ($i>=$p_options[PCLZIP_OPT_BY_INDEX][$j]['end']) {
$j_start = $j+1; $j_start = $j+1;
} }
if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) { if ($p_options[PCLZIP_OPT_BY_INDEX][$j]['start']>$i) {
break; break;
} }
@ -4608,7 +4581,6 @@ class PclZip
// ----- Look if the archive_to_add exists // ----- Look if the archive_to_add exists
if (!is_file($p_archive_to_add->zipname)) { if (!is_file($p_archive_to_add->zipname)) {
// ----- Nothing to merge, so merge is a success // ----- Nothing to merge, so merge is a success
$v_result = 1; $v_result = 1;
@ -4618,7 +4590,6 @@ class PclZip
// ----- Look if the archive exists // ----- Look if the archive exists
if (!is_file($this->zipname)) { if (!is_file($this->zipname)) {
// ----- Do a duplicate // ----- Do a duplicate
$v_result = $this->privDuplicate($p_archive_to_add->zipname); $v_result = $this->privDuplicate($p_archive_to_add->zipname);
@ -4781,7 +4752,6 @@ class PclZip
// ----- Look if the $p_archive_filename exists // ----- Look if the $p_archive_filename exists
if (!is_file($p_archive_filename)) { if (!is_file($p_archive_filename)) {
// ----- Nothing to duplicate, so duplicate is a success. // ----- Nothing to duplicate, so duplicate is a success.
$v_result = 1; $v_result = 1;
@ -4970,8 +4940,7 @@ function PclZipUtilPathReduction($p_dir)
// ----- Look for item to skip // ----- Look for item to skip
if ($v_skip > 0) { if ($v_skip > 0) {
$v_skip--; $v_skip--;
} } else {
else {
$v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:""); $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
} }
} }
@ -5051,8 +5020,12 @@ function PclZipUtilPathInclusion($p_dir, $p_path)
// ----- Look if everything seems to be the same // ----- Look if everything seems to be the same
if ($v_result) { if ($v_result) {
// ----- Skip all the empty items // ----- Skip all the empty items
while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) $j++; while (($j < $v_list_path_size) && ($v_list_path[$j] == '')) {
while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) $i++; $j++;
}
while (($i < $v_list_dir_size) && ($v_list_dir[$i] == '')) {
$i++;
}
if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) { if (($i >= $v_list_dir_size) && ($j >= $v_list_path_size)) {
// ----- There are exactly the same // ----- There are exactly the same
@ -5160,7 +5133,6 @@ function PclZipUtilRename($p_src, $p_dest)
// -------------------------------------------------------------------------------- // --------------------------------------------------------------------------------
function PclZipUtilOptionText($p_option) function PclZipUtilOptionText($p_option)
{ {
$v_list = get_defined_constants(); $v_list = get_defined_constants();
for (reset($v_list); $v_key = key($v_list); next($v_list)) { for (reset($v_list); $v_key = key($v_list); next($v_list)) {
$v_prefix = substr($v_key, 0, 10); $v_prefix = substr($v_key, 0, 10);
@ -5200,4 +5172,3 @@ function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter = true)
} }
return $p_path; return $p_path;
} }
// --------------------------------------------------------------------------------