Skip to content

Commit

Permalink
Merge pull request #1076 from nextcloud/fix/isolate-rubix
Browse files Browse the repository at this point in the history
fix(Rubix\ML): Isolate rubix
  • Loading branch information
marcelklehr authored Jan 11, 2024
2 parents c38ee20 + a983d1e commit 3900d99
Show file tree
Hide file tree
Showing 15 changed files with 1,596 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

strategy:
matrix:
php-versions: ['8.0', '8.1', '8.2', '8.3']
php-versions: ['8.1', '8.2', '8.3']
server-versions: ['master', 'stable28']

services:
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

require_once './vendor/autoload.php';
require_once './vendor/scoper-autoload.php';

use Nextcloud\CodingStandard\Config;

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
},
"require-dev": {
"nextcloud/ocp": "dev-master",
"nextcloud/ocp": "^28.0",
"symfony/console": "^5.4",
"symfony/process": "^5.2"
},
Expand All @@ -24,10 +24,12 @@
"test:unit": "phpunit --config tests/phpunit.xml",
"post-install-cmd": [
"@composer bin all install --ansi",
"grep -r 'OCA\\\\Recognize\\\\Rubix' ./vendor/rubix/ml/ || ( vendor/bin/php-scoper add-prefix --prefix='OCA\\Recognize' --output-dir=\".\" --working-dir=\"./vendor/rubix/ml/\" -f --config=\"../../../scoper.inc.php\" && sed -i 's:Rubix\\\\\\\\ML\\\\\\\\:OCA\\\\\\\\Recognize\\\\\\\\Rubix\\\\\\\\ML\\\\\\\\:' vendor/composer/installed.json )",
"composer dump-autoload"
],
"post-update-cmd": [
"@composer bin all update --ansi",
"grep -r 'OCA\\\\Recognize\\\\Rubix' ./vendor/rubix/ml/ || ( vendor/bin/php-scoper add-prefix --prefix='OCA\\Recognize' --output-dir=\".\" --working-dir=\"./vendor/rubix/ml/\" -f --config=\"../../../scoper.inc.php\" && sed -i 's:Rubix\\\\\\\\ML\\\\\\\\:OCA\\\\\\\\Recognize\\\\\\\\Rubix\\\\\\\\ML\\\\\\\\:' vendor/composer/installed.json )",
"composer dump-autoload"
]
},
Expand Down
14 changes: 7 additions & 7 deletions lib/Clustering/DualTreeBall.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
declare(strict_types=1);
namespace OCA\Recognize\Clustering;

use \Rubix\ML\Datasets\Labeled;
use \Rubix\ML\Graph\Nodes\Ball;
use \Rubix\ML\Helpers\Stats;
use \Rubix\ML\Kernels\Distance\Distance;
use function \Rubix\ML\argmax;
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
use \OCA\Recognize\Rubix\ML\Graph\Nodes\Ball;
use \OCA\Recognize\Rubix\ML\Helpers\Stats;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;
use function \OCA\Recognize\Rubix\ML\argmax;

class DualTreeBall extends Ball {
protected float $longestDistanceInNode = INF;
Expand Down Expand Up @@ -97,8 +97,8 @@ public function propagateSetChanges(array &$labelToSetId) {
/**
* Factory method to build a hypersphere by splitting the dataset into left and right clusters.
*
* @param \Rubix\ML\Datasets\Labeled $dataset
* @param \Rubix\ML\Kernels\Distance\Distance $kernel
* @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset
* @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance $kernel
* @return self
*/
public static function split(Labeled $dataset, Distance $kernel): self {
Expand Down
14 changes: 7 additions & 7 deletions lib/Clustering/DualTreeClique.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
declare(strict_types=1);
namespace OCA\Recognize\Clustering;

use \Rubix\ML\Datasets\Labeled;
use \Rubix\ML\Graph\Nodes\Clique;
use \Rubix\ML\Helpers\Stats;
use \Rubix\ML\Kernels\Distance\Distance;
use function \Rubix\ML\argmax;
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
use \OCA\Recognize\Rubix\ML\Graph\Nodes\Clique;
use \OCA\Recognize\Rubix\ML\Helpers\Stats;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;
use function \OCA\Recognize\Rubix\ML\argmax;

class DualTreeClique extends Clique {
protected float $longestDistanceInNode = INF;
Expand Down Expand Up @@ -80,8 +80,8 @@ public function propagateSetChanges(array &$labelToSetId) {
/**
* Terminate a branch with a dataset.
*
* @param \Rubix\ML\Datasets\Labeled $dataset
* @param \Rubix\ML\Kernels\Distance\Distance $kernel
* @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset
* @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance $kernel
* @return self
*/
public static function terminate(Labeled $dataset, Distance $kernel): self {
Expand Down
16 changes: 8 additions & 8 deletions lib/Clustering/HDBSCAN.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
declare(strict_types=1);
namespace OCA\Recognize\Clustering;

use \Rubix\ML\Datasets\Labeled;
use \Rubix\ML\EstimatorType;
use \Rubix\ML\Helpers\Params;
use \Rubix\ML\Kernels\Distance\Distance;
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
use \OCA\Recognize\Rubix\ML\EstimatorType;
use \OCA\Recognize\Rubix\ML\Helpers\Params;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;

/**
* HDBSCAN
Expand Down Expand Up @@ -59,7 +59,7 @@ class HDBSCAN {
* The distance kernel used for computing interpoint distances.
*
*/
protected \Rubix\ML\Datasets\Labeled $dataset;
protected \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset;



Expand All @@ -70,7 +70,7 @@ class HDBSCAN {
* @param array $oldCoreDistances
* @param Distance $kernel
* @param bool $useTrueMst // (Build true or approximate minimum spanning tree)
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
*/
public function __construct(Labeled $dataset, int $minClusterSize = 5, int $sampleSize = 5, array $oldCoreDistances = [], ?Distance $kernel = null, bool $useTrueMst = true) {
if ($minClusterSize < 2) {
Expand All @@ -96,7 +96,7 @@ public function getCoreNeighborDistances(): array {
/**
* Return the estimator type.
*
* @return \Rubix\ML\EstimatorType
* @return \OCA\Recognize\Rubix\ML\EstimatorType
*/
public function type(): EstimatorType {
return EstimatorType::clusterer();
Expand All @@ -105,7 +105,7 @@ public function type(): EstimatorType {
/**
* Return the data types that the estimator is compatible with.
*
* @return list<\Rubix\ML\DataType>
* @return list<\OCA\Recognize\Rubix\ML\DataType>
*/
public function compatibility(): array {
return $this->mstSolver->kernel()->compatibility();
Expand Down
24 changes: 12 additions & 12 deletions lib/Clustering/MrdBallTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
declare(strict_types=1);
namespace OCA\Recognize\Clustering;

use \Rubix\ML\Datasets\Labeled;
use \Rubix\ML\Graph\Nodes\Ball;
use \Rubix\ML\Graph\Nodes\Hypersphere;
use \Rubix\ML\Graph\Trees\BallTree;
use \Rubix\ML\Kernels\Distance\Distance;
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
use \OCA\Recognize\Rubix\ML\Graph\Nodes\Ball;
use \OCA\Recognize\Rubix\ML\Graph\Nodes\Hypersphere;
use \OCA\Recognize\Rubix\ML\Graph\Trees\BallTree;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;

class MrdBallTree extends BallTree {
private ?Labeled $dataset = null;
Expand All @@ -25,8 +25,8 @@ class MrdBallTree extends BallTree {
/**
* @param int $maxLeafSize
* @param int $coreDistSampleSize
* @param \Rubix\ML\Kernels\Distance\Distance|null $kernel
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
* @param \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance|null $kernel
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
*/
public function __construct(int $maxLeafSize = 30, int $sampleSize = 5, ?Distance $kernel = null) {
if ($maxLeafSize < 1) {
Expand Down Expand Up @@ -462,7 +462,7 @@ public function cachedComputeNative($a, array $a_vector, $b, array $b_vector, bo
*
* @param int|string $sampleLabel
* @param bool $useCachedValues
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
* @return array{list<mixed>,list<float>}
*/
public function getCoreNeighbors($sampleLabel, bool $useCachedValues = true): array {
Expand Down Expand Up @@ -546,8 +546,8 @@ public function getCoreNeighbors($sampleLabel, bool $useCachedValues = true): ar
*
* @param int $sampleLabel
* @param float $radius
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
* @throws \Rubix\ML\Exceptions\RuntimeException
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
* @throws \OCA\Recognize\Rubix\ML\Exceptions\RuntimeException
* @return array{list<mixed>,list<float>}
*/
public function cachedRange($sampleLabel, float $radius): array {
Expand Down Expand Up @@ -624,8 +624,8 @@ public function cachedRange($sampleLabel, float $radius): array {
*
* @internal
*
* @param \Rubix\ML\Datasets\Labeled $dataset
* @throws \Rubix\ML\Exceptions\InvalidArgumentException
* @param \OCA\Recognize\Rubix\ML\Datasets\Labeled $dataset
* @throws \OCA\Recognize\Rubix\ML\Exceptions\InvalidArgumentException
*/
public function grow(Labeled $dataset): void {
$this->dataset = $dataset;
Expand Down
4 changes: 2 additions & 2 deletions lib/Clustering/MstSolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
declare(strict_types=1);
namespace OCA\Recognize\Clustering;

use \Rubix\ML\Datasets\Labeled;
use \Rubix\ML\Kernels\Distance\Distance;
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;

class MstSolver {
private MrdBallTree $tree;
Expand Down
6 changes: 3 additions & 3 deletions lib/Clustering/SquaredDistance.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
declare(strict_types=1);
namespace OCA\Recognize\Clustering;

use \Rubix\ML\DataType;
use \Rubix\ML\Kernels\Distance\Distance;
use \OCA\Recognize\Rubix\ML\DataType;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Distance;

/**
* Squared distance
Expand All @@ -24,7 +24,7 @@ class SquaredDistance implements Distance {
*
* @internal
*
* @return list<\Rubix\ML\DataType>
* @return list<\OCA\Recognize\Rubix\ML\DataType>
*/
public function compatibility(): array {
return [
Expand Down
2 changes: 1 addition & 1 deletion lib/Dav/Faces/FacePhoto.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
declare(strict_types=1);
namespace OCA\Recognize\Dav\Faces;

use \Rubix\ML\Kernels\Distance\Euclidean;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Euclidean;
use OCA\Recognize\Db\FaceDetection;
use OCA\Recognize\Db\FaceDetectionMapper;
use OCA\Recognize\Service\FaceClusterAnalyzer;
Expand Down
4 changes: 2 additions & 2 deletions lib/Service/FaceClusterAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
declare(strict_types=1);
namespace OCA\Recognize\Service;

use \Rubix\ML\Datasets\Labeled;
use \Rubix\ML\Kernels\Distance\Euclidean;
use \OCA\Recognize\Rubix\ML\Datasets\Labeled;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Euclidean;
use OCA\Recognize\Clustering\HDBSCAN;
use OCA\Recognize\Db\FaceCluster;
use OCA\Recognize\Db\FaceClusterMapper;
Expand Down
24 changes: 24 additions & 0 deletions scoper.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

// scoper.inc.php

return [
'patchers' => [
static function (string $filePath, string $prefix, string $content): string {
//
// PHP-Parser patch conditions for file targets
//
if (str_contains($filePath, '/rubix/')) {
return preg_replace(
'%([ |<{:,])\\\\Rubix\\\\ML%',
'$1\\\\OCA\\\\Recognize\\\\Rubix\\\\ML',
$content
);
}

return $content;
},
],
];
2 changes: 1 addition & 1 deletion tests/ClusterTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use \Rubix\ML\Kernels\Distance\Euclidean;
use \OCA\Recognize\Rubix\ML\Kernels\Distance\Euclidean;
use OCA\Recognize\Db\FaceClusterMapper;
use OCA\Recognize\Db\FaceDetection;
use OCA\Recognize\Db\FaceDetectionMapper;
Expand Down
5 changes: 5 additions & 0 deletions vendor-bin/php-scoper/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"humbug/php-scoper": "^0.18.7"
}
}
Loading

0 comments on commit 3900d99

Please sign in to comment.