Skip to content

Commit 25338b7

Browse files
committed
Adapting headers for crossplatform compile
1 parent e679797 commit 25338b7

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "radius-clustering"
7-
version = "1.0.0"
7+
version = "1.0.1"
88
description = "A Clustering under radius constraints algorithm using minimum dominating sets"
99
readme = "README.md"
1010
authors = [

radius_clustering/radius_clustering.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import os
1212
import numpy as np
13-
import scipy.spatial as sp_spatial
13+
from sklearn.metrics import pairwise_distances
1414
from sklearn.base import BaseEstimator, ClusterMixin
1515
from sklearn.utils.validation import check_array
1616

@@ -38,7 +38,7 @@ class RadiusClustering(BaseEstimator, ClusterMixin):
3838
-----------
3939
X : array-like, shape (n_samples, n_features)
4040
The input data.
41-
centers : list
41+
centers\_ : list
4242
The indices of the cluster centers.
4343
labels\_ : array-like, shape (n_samples,)
4444
The cluster labels for each point in the input data.
@@ -50,6 +50,9 @@ def __init__(self, manner="approx", threshold=0.5):
5050
self.manner = manner
5151
self.threshold = threshold
5252

53+
def _check_symmetric(self, a, tol=1e-8):
54+
return np.allclose(a, a.T, atol=tol)
55+
5356
def fit(self, X, y=None):
5457
"""
5558
Fit the MDS clustering model to the input data.
@@ -87,10 +90,19 @@ def fit(self, X, y=None):
8790
self.X = check_array(X)
8891

8992
# Create dist and adj matrices
90-
dist_mat = sp_spatial.distance_matrix(self.X, self.X)
93+
if not self._check_symmetric(self.X):
94+
dist_mat = pairwise_distances(self.X, metric="euclidean")
95+
else:
96+
dist_mat = self.X
9197
adj_mask = np.triu((dist_mat <= self.threshold), k=1)
9298
self.nb_edges = np.sum(adj_mask)
93-
self.edges = np.argwhere(adj_mask).astype(np.int32)
99+
if self.nb_edges == 0:
100+
self.centers_ = list(range(self.X.shape[0]))
101+
self.labels_ = self.centers_
102+
self.effective_radius = 0
103+
self._mds_exec_time = 0
104+
return self
105+
self.edges = np.argwhere(adj_mask).astype(np.int32) #TODO: changer en uint32
94106
self.dist_mat = dist_mat
95107

96108
self._clustering()

radius_clustering/utils/mds3-util.h

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@
1515
#include <stdlib.h>
1616
#include <string.h>
1717
#include <assert.h>
18+
#include <time.h>
19+
20+
#ifdef _WIN32
21+
#include <windows.h>
22+
#elif defined(__APPLE__) || defined(__linux__)
1823
#include <sys/time.h>
1924
#include <sys/resource.h>
25+
#else
26+
#error "Unsupported platform"
27+
#endif
2028

2129
#define WORD_LENGTH 100
2230
#define TRUE 1
@@ -200,10 +208,27 @@ struct Result {
200208
};
201209

202210
static double get_utime() {
203-
struct rusage utime;
204-
getrusage(RUSAGE_SELF, &utime);
205-
return (double) (utime.ru_utime.tv_sec
206-
+ (double) utime.ru_utime.tv_usec / 1000000);
211+
#ifdef _WIN32
212+
FILETIME createTime;
213+
FILETIME exitTime;
214+
FILETIME kernelTime;
215+
FILETIME userTime;
216+
if (GetProcessTimes(GetCurrentProcess(),
217+
&createTime, &exitTime,
218+
&kernelTime, &userTime) != 0) {
219+
ULARGE_INTEGER li = {{userTime.dwLowDateTime, userTime.dwHighDateTime}};
220+
return li.QuadPart * 1e-7;
221+
}
222+
return 0.0;
223+
#elif defined(__APPLE__) || defined(__linux__)
224+
struct rusage utime;
225+
if (getrusage(RUSAGE_SELF, &utime) == 0) {
226+
return (double)utime.ru_utime.tv_sec + (double)utime.ru_utime.tv_usec * 1e-6;
227+
}
228+
return 0.0;
229+
#else
230+
return (double)clock() / CLOCKS_PER_SEC;
231+
#endif
207232
}
208233

209234
static int cmp_branching_vertex_score(const void * a, const void *b){

0 commit comments

Comments
 (0)