/** * Tests if cache will be flushed after using NumArray::abs */ public function testAbsCache() { $numArray = new NumArray(5); $numArray->setCache('key', 6); $numArray->abs(); $this->assertFalse($numArray->inCache('key')); }
/** * Tests if cache will be flushed after use of NumArray::sub */ public function testSubCache() { $numArray = new NumArray(5); $numArray->setCache('key', 7); $numArray->sub(3); $this->assertFalse($numArray->inCache('key')); }
/** * 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')); }
/** * 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); }