PHPExcel
[ class tree: PHPExcel ] [ index: PHPExcel ] [ all elements ]

Source for file tile.php

Documentation is available at tile.php

  1. <?php
  2.  
  3. include "../Matrix.php";
  4.  
  5. /**
  6. * Tiling of matrix X in [rowWise by colWise] dimension. Tiling
  7. * creates a larger matrix than the original data X. Example, if
  8. * X is to be tiled in a [3 x 4] manner, then:
  9. *
  10. *     /            \
  11. *     | X  X  X  X |
  12. * C = | X  X  X  X |
  13. *     | X  X  X  X |
  14. *     \           /
  15. *
  16. * @param X Matrix
  17. * @param rowWise int
  18. * @param colWise int
  19. * @return Matrix 
  20. */
  21.  
  22. function tile(&$X, $rowWise, $colWise){
  23.  
  24.   $xArray = $X->getArray();
  25.   print_r($xArray);
  26.  
  27.   $countRow    = 0;
  28.   $countColumn = 0;
  29.  
  30.   $m = $X->getRowDimension();
  31.   $n = $X->getColumnDimension();
  32.  
  33.   if( $rowWise<1 || $colWise<1 ){
  34.     die("tile : Array index is out-of-bound.");
  35.   }
  36.  
  37.   $newRowDim = $m*$rowWise;
  38.   $newColDim = $n*$colWise;
  39.  
  40.   $result = array();
  41.  
  42.   for($i=0 ; $i<$newRowDim; ++$i) {
  43.  
  44.     $holder = array();
  45.  
  46.     for($j=0 ; $j<$newColDim ; ++$j) {
  47.  
  48.       $holder[$j] = $xArray[$countRow][$countColumn++];
  49.  
  50.       // reset the column-index to zero to avoid reference to out-of-bound index in xArray[][]
  51.  
  52.       if($countColumn == $n) { $countColumn = 0; }
  53.  
  54.     } // end for
  55.  
  56.     ++$countRow;
  57.  
  58.     // reset the row-index to zero to avoid reference to out-of-bound index in xArray[][]
  59.  
  60.     if($countRow == $m) { $countRow = 0; }
  61.  
  62.     $result[$i] = $holder;
  63.  
  64.   } // end for
  65.  
  66.   return new Matrix($result);
  67.  
  68. }
  69.  
  70.  
  71. $X =array(1,2,3,4,5,6,7,8,9);
  72. $nRow = 3;
  73. $nCol = 3;
  74. $tiled_matrix = tile(new Matrix($X), $nRow, $nCol);
  75. echo "<pre>";
  76. print_r($tiled_matrix);
  77. echo "</pre>";
  78. ?>

Documentation generated on Sun, 27 Feb 2011 16:35:42 -0800 by phpDocumentor 1.4.3