You are here

public function PHPExcel_Shared_JAMA_LUDecomposition::__construct in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/JAMA/LUDecomposition.php \PHPExcel_Shared_JAMA_LUDecomposition::__construct()

* LU Decomposition constructor. * *

Parameters

$A Rectangular matrix: * @return Structure to access L, U and piv.

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Shared/JAMA/LUDecomposition.php, line 63

Class

PHPExcel_Shared_JAMA_LUDecomposition
@package JAMA

Code

public function __construct($A) {
  if ($A instanceof PHPExcel_Shared_JAMA_Matrix) {

    // Use a "left-looking", dot-product, Crout/Doolittle algorithm.
    $this->LU = $A
      ->getArray();
    $this->m = $A
      ->getRowDimension();
    $this->n = $A
      ->getColumnDimension();
    for ($i = 0; $i < $this->m; ++$i) {
      $this->piv[$i] = $i;
    }
    $this->pivsign = 1;
    $LUrowi = $LUcolj = array();

    // Outer loop.
    for ($j = 0; $j < $this->n; ++$j) {

      // Make a copy of the j-th column to localize references.
      for ($i = 0; $i < $this->m; ++$i) {
        $LUcolj[$i] =& $this->LU[$i][$j];
      }

      // Apply previous transformations.
      for ($i = 0; $i < $this->m; ++$i) {
        $LUrowi = $this->LU[$i];

        // Most of the time is spent in the following dot product.
        $kmax = min($i, $j);
        $s = 0.0;
        for ($k = 0; $k < $kmax; ++$k) {
          $s += $LUrowi[$k] * $LUcolj[$k];
        }
        $LUrowi[$j] = $LUcolj[$i] -= $s;
      }

      // Find pivot and exchange if necessary.
      $p = $j;
      for ($i = $j + 1; $i < $this->m; ++$i) {
        if (abs($LUcolj[$i]) > abs($LUcolj[$p])) {
          $p = $i;
        }
      }
      if ($p != $j) {
        for ($k = 0; $k < $this->n; ++$k) {
          $t = $this->LU[$p][$k];
          $this->LU[$p][$k] = $this->LU[$j][$k];
          $this->LU[$j][$k] = $t;
        }
        $k = $this->piv[$p];
        $this->piv[$p] = $this->piv[$j];
        $this->piv[$j] = $k;
        $this->pivsign = $this->pivsign * -1;
      }

      // Compute multipliers.
      if ($j < $this->m && $this->LU[$j][$j] != 0.0) {
        for ($i = $j + 1; $i < $this->m; ++$i) {
          $this->LU[$i][$j] /= $this->LU[$j][$j];
        }
      }
    }
  }
  else {
    throw new PHPExcel_Calculation_Exception(PHPExcel_Shared_JAMA_Matrix::ArgumentTypeException);
  }
}