set() public method

Replaces a value or complete parts in the NumArray. The new value is always the last argument
Since: 1.0.0
public set ( )
 /**
  * @param NumArray $matrix
  * @param NumArray $vector
  * @return array
  */
 protected static function gaussianEliminationPivoting(NumArray $matrix, NumArray $vector)
 {
     $shape = $matrix->getShape();
     for ($i = 0; $i < $shape[0]; $i++) {
         // find pivo element
         $max = abs($matrix->get($i, $i)->getData());
         $maxIndex = $i;
         for ($j = $i + 1; $j < $shape[0]; $j++) {
             $abs = abs($matrix->get($j, $i)->getData());
             if ($abs > $max) {
                 $max = $abs;
                 $maxIndex = $j;
             }
         }
         // pivoting
         if ($maxIndex !== $i) {
             // change maxIndex row with i row in $matrix
             $temp = $matrix->get($i);
             $matrix->set($i, $matrix->get($maxIndex));
             $matrix->set($maxIndex, $temp);
             // change maxIndex row with i row in $vector
             $temp = $vector->get($i);
             $vector->set($i, $vector->get($maxIndex));
             $vector->set($maxIndex, $temp);
         }
         for ($j = $i + 1; $j < $shape[0]; $j++) {
             $fac = -$matrix->get($j, $i)->getData() / $matrix->get($i, $i)->getData();
             $matrix->set($j, $matrix->get($j)->add($matrix->get($i)->dot($fac)));
             $vector->set($j, $vector->get($j)->add($vector->get($i)->dot($fac)));
         }
     }
     return ['M' => $matrix, 'b' => $vector];
 }
Esempio n. 2
0
 /**
  * Tests if cache will be flushed after NumArray::set
  */
 public function testSetCache()
 {
     $numArray = new NumArray(5);
     $numArray->setCache('key', 6);
     $numArray->set(6);
     $this->assertFalse($numArray->inCache('key'));
 }