mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 09:48:40 +00:00
fix bugs
This commit is contained in:
parent
e579f1ab30
commit
0d200da299
|
|
@ -68,7 +68,7 @@ final class DBSCAN
|
|||
*
|
||||
* Array of points assigned to a cluster
|
||||
*
|
||||
* @var array<int, array{x:float, y:float}>
|
||||
* @var array<int, array>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $clusters = [];
|
||||
|
|
@ -232,6 +232,7 @@ final class DBSCAN
|
|||
$points[] = $p->coordinates;
|
||||
}
|
||||
|
||||
// @todo: this is only good for 2D. Fix this for ND.
|
||||
$this->convexHulls[$c] = MonotoneChain::createConvexHull($points);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,9 @@ final class JWT
|
|||
return [];
|
||||
}
|
||||
|
||||
return \json_decode(Base64Url::decode($explode[0]), true);
|
||||
$json = \json_decode(Base64Url::decode($explode[0]), true);
|
||||
|
||||
return \is_array($json) ? $json : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,7 +128,9 @@ final class JWT
|
|||
return [];
|
||||
}
|
||||
|
||||
return \json_decode(Base64Url::decode($explode[1]), true);
|
||||
$json = \json_decode(Base64Url::decode($explode[1]), true);
|
||||
|
||||
return \is_array($json) ? $json : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -150,6 +154,11 @@ final class JWT
|
|||
try {
|
||||
$header = \json_decode(Base64Url::decode($explode[0]), true);
|
||||
$payload = \json_decode(Base64Url::decode($explode[1]), true);
|
||||
|
||||
if (!\is_array($header) || !\is_array($payload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$signature = self::createSignature($secret, $header, $payload);
|
||||
|
||||
return \hash_equals($signature, $explode[2]);
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ class LanguageResult implements \ArrayAccess, \IteratorAggregate, \JsonSerializa
|
|||
*/
|
||||
public function offsetSet($offset, $value) : void
|
||||
{
|
||||
/** @var float|int $value */
|
||||
if ($offset === null) {
|
||||
$this->result[] = $value;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ abstract class NgramParser
|
|||
}
|
||||
}
|
||||
|
||||
/** @var array $tokens */
|
||||
foreach ($tokens as $i => $token) {
|
||||
$sum = \array_sum($token);
|
||||
|
||||
|
|
|
|||
|
|
@ -697,11 +697,11 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
*
|
||||
* @param self $B Matrix
|
||||
*
|
||||
* @return self
|
||||
* @return int|float|self
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function dot(self $B) : self
|
||||
public function dot(self $B) : int|float|self
|
||||
{
|
||||
$value1 = $this->matrix;
|
||||
$value2 = $B->getMatrix();
|
||||
|
|
@ -731,6 +731,8 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
$result[$i][$c] = $temp;
|
||||
}
|
||||
}
|
||||
|
||||
return self::fromArray($result);
|
||||
} elseif (!$isMatrix1 && !$isMatrix2) {
|
||||
if ($m1 !== $m2) {
|
||||
throw new InvalidDimensionException($m1 . 'x' . $m2);
|
||||
|
|
@ -742,6 +744,8 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
/** @var array $value2 */
|
||||
$result += $value1[$i] * $value2[$i];
|
||||
}
|
||||
|
||||
return $result;
|
||||
} elseif ($isMatrix1 && !$isMatrix2) {
|
||||
$result = [];
|
||||
for ($i = 0; $i < $m1; ++$i) { // Row of 1
|
||||
|
|
@ -754,11 +758,11 @@ class Matrix implements \ArrayAccess, \Iterator
|
|||
|
||||
$result[$i] = $temp;
|
||||
}
|
||||
} else {
|
||||
throw new \InvalidArgumentException();
|
||||
|
||||
return self::fromArray($result);
|
||||
}
|
||||
|
||||
return self::fromArray($result);
|
||||
throw new \InvalidArgumentException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ final class Vector extends Matrix
|
|||
{
|
||||
$dotProduct = 0.0;
|
||||
for ($i = 0; $i < $this->m; ++$i) {
|
||||
$dotProduct += $this->matrix[$i][0] * $v[$i];
|
||||
$dotProduct += $this->matrix[$i][0] * $v[$i][0];
|
||||
}
|
||||
|
||||
$sumOfSquares = 0;
|
||||
|
|
@ -116,7 +116,7 @@ final class Vector extends Matrix
|
|||
}
|
||||
$magnitude2 = \sqrt($sumOfSquares);
|
||||
|
||||
if ($magnitude1 === 0 || $magnitude2 === 0) {
|
||||
if ($magnitude1 === 0.0 || $magnitude2 === 0.0) {
|
||||
return \PHP_FLOAT_MAX;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -583,7 +583,7 @@ class Graph
|
|||
|
||||
while (!empty($stack)) {
|
||||
$cNode = \array_pop($stack);
|
||||
if (isset($visited[$cNode->getId()]) && $visited[$cNode->getId()]) {
|
||||
if (isset($visited[$cNode->getId()])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -592,7 +592,7 @@ class Graph
|
|||
|
||||
$neighbors = $cNode->getNeighbors();
|
||||
foreach ($neighbors as $neighbor) {
|
||||
if (!isset($visited[$neighbor->getId()]) || !$visited[$neighbor->getId()]) {
|
||||
if (!isset($visited[$neighbor->getId()])) {
|
||||
$stack[] = $neighbor;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -311,17 +311,21 @@ final class ArrayUtils
|
|||
*/
|
||||
public static function getArg(string $id, array $args) : mixed
|
||||
{
|
||||
$key = 0;
|
||||
if (\is_numeric($id)) {
|
||||
return $args[(int) $id] ?? null;
|
||||
$key = ((int) $id) - 1;
|
||||
} else {
|
||||
if (($key = \array_search($id, $args)) === false || $key === \count($args) - 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$key = (int) $key;
|
||||
$args = \array_values($args);
|
||||
}
|
||||
|
||||
if (($key = \array_search($id, $args)) === false || $key === \count($args) - 1) {
|
||||
return null;
|
||||
}
|
||||
$value = $args[$key + 1] ?? null;
|
||||
|
||||
$value = $args[(int) $key + 1];
|
||||
|
||||
return \is_string($value) ? \trim($value, '" ') : $value;
|
||||
return \is_string($value) ? \trim($value, '\'" ') : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -336,7 +340,6 @@ final class ArrayUtils
|
|||
*/
|
||||
public static function hasArg(string $id, array $args) : int
|
||||
{
|
||||
$t = \array_search($id, $args);
|
||||
return ($key = \array_search($id, $args)) === false
|
||||
? -1
|
||||
: (int) $key;
|
||||
|
|
|
|||
|
|
@ -613,7 +613,8 @@ class Datamatrix extends TwoDAbstract
|
|||
|
||||
if ($this->isCharMode($tmpchr, self::ENC_X12)) {
|
||||
return self::ENC_X12;
|
||||
} elseif (!$this->isCharMode($tmpchr, self::ENC_X12) && !$this->isCharMode($tmpchr, self::ENC_C40)
|
||||
} elseif (!$this->isCharMode($tmpchr, self::ENC_X12)
|
||||
&& !$this->isCharMode($tmpchr, self::ENC_C40)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,8 @@ final class KmeansTest extends \PHPUnit\Framework\TestCase
|
|||
new Point([3.5, 4.5], '7'),
|
||||
];
|
||||
|
||||
$kmeans = new Kmeans($points, 2);
|
||||
$kmeans = new Kmeans();
|
||||
$kmeans->generateClusters($points, 2);
|
||||
|
||||
if ($kmeans->cluster($points[0])->group === 0
|
||||
&& $kmeans->cluster($points[1])->group === 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user