Example #1
0
 /**
  * @return Matrix
  */
 private function getTargetsMatrix()
 {
     if (is_array($this->targets[0])) {
         return new Matrix($this->targets);
     }
     return Matrix::fromFlatArray($this->targets);
 }
Example #2
0
 /**
  * @param Matrix $matrix
  *
  * @return Matrix
  *
  * @throws InvalidArgumentException
  */
 public function multiply(Matrix $matrix)
 {
     if ($this->columns != $matrix->getRows()) {
         throw InvalidArgumentException::inconsistentMatrixSupplied();
     }
     $product = [];
     $multiplier = $matrix->toArray();
     for ($i = 0; $i < $this->rows; ++$i) {
         $columns = $matrix->getColumns();
         for ($j = 0; $j < $columns; ++$j) {
             $product[$i][$j] = 0;
             for ($k = 0; $k < $this->columns; ++$k) {
                 $product[$i][$j] += $this->matrix[$i][$k] * $multiplier[$k][$j];
             }
         }
     }
     return new self($product, false);
 }
Example #3
0
 public function testCrossOutMatrix()
 {
     $matrix = new Matrix([[3, 4, 2], [4, 5, 5], [1, 1, 1]]);
     $crossOuted = [[3, 2], [1, 1]];
     $this->assertEquals($crossOuted, $matrix->crossOut(1, 1)->toArray());
 }