Пример #1
0
 /**
  * Tests Cache::flushCache
  */
 public function testFlushCacheKey()
 {
     $numArray = new NumArray(5);
     $numArray->setCache('key1', 7);
     $numArray->setCache('key2', 8);
     $numArray->flushCache('key2');
     $this->assertSame(7, $numArray->getCache('key1'));
     $this->assertFalse($numArray->inCache('key2'));
 }
Пример #2
0
 /**
  * Calculates the inverse of a not singular square matrix
  *
  * @param mixed $squareMatrix not singular matrix
  *
  * @throws SingularMatrixException will be thrown, when `$squareMatrix` is singular
  *
  * @api
  * @since 1.0.0
  *
  * @return NumArray
  */
 public static function inv($squareMatrix)
 {
     if (!$squareMatrix instanceof NumArray) {
         $squareMatrix = new NumArray($squareMatrix);
     } elseif ($squareMatrix->inCache(self::CACHE_KEY_INVERSE)) {
         return $squareMatrix->getCache(self::CACHE_KEY_INVERSE);
     }
     if (!Helper::isNotSingularMatrix($squareMatrix)) {
         throw new SingularMatrixException("Matrix is singular");
     }
     $shape = $squareMatrix->getShape();
     $inv = self::solve($squareMatrix, NumPHP::identity($shape[0]));
     $squareMatrix->setCache(self::CACHE_KEY_INVERSE, $inv);
     return self::inv($squareMatrix);
 }