Skip to content

Commit 9005fc4

Browse files
committed
ruff formatter
1 parent b3a4a3e commit 9005fc4

File tree

5 files changed

+68
-56
lines changed

5 files changed

+68
-56
lines changed

docs/source/conf.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
import os
1010
import sys
1111

12-
sys.path.insert(0, os.path.abspath('../..'))
12+
sys.path.insert(0, os.path.abspath("../.."))
1313

14-
project = 'Radius Clustering'
15-
copyright = '2024, Haenn Quentin, Chardin Brice, Baron Mickaël'
16-
author = 'Haenn Quentin, Chardin Brice, Baron Mickaël'
17-
release = '1.0'
14+
project = "Radius Clustering"
15+
copyright = "2024, Haenn Quentin, Chardin Brice, Baron Mickaël"
16+
author = "Haenn Quentin, Chardin Brice, Baron Mickaël"
17+
release = "1.0"
1818

1919
# -- General configuration ---------------------------------------------------
2020
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
2121

2222
extensions = [
23-
'sphinx.ext.autodoc',
24-
'sphinx.ext.autosummary',
25-
'sphinx.ext.viewcode',
23+
"sphinx.ext.autodoc",
24+
"sphinx.ext.autosummary",
25+
"sphinx.ext.viewcode",
2626
"sphinx-prompt",
27-
'sphinx.ext.napoleon',
27+
"sphinx.ext.napoleon",
2828
"sphinx_remove_toctrees",
2929
"sphinxcontrib.email",
30-
'sphinx_gallery.gen_gallery',
31-
'sphinx_copybutton',
30+
"sphinx_gallery.gen_gallery",
31+
"sphinx_copybutton",
3232
"sphinx.ext.intersphinx",
3333
"sphinx_design",
3434
]
@@ -43,22 +43,20 @@
4343
# Conf of numpydoc
4444
numpydoc_class_members_toctree = False
4545

46-
templates_path = ['_templates']
46+
templates_path = ["_templates"]
4747
exclude_patterns = []
4848

4949
# -- Options for HTML output -------------------------------------------------
5050
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
5151

52-
html_theme = 'pydata_sphinx_theme'
53-
#html_static_path = ['_static']
52+
html_theme = "pydata_sphinx_theme"
53+
# html_static_path = ['_static']
5454

5555
html_logo = "./images/logo-lias.jpg"
5656

5757
html_short_title = "Radius Clustering"
5858

59-
html_sidebars = {
60-
"**": []
61-
}
59+
html_sidebars = {"**": []}
6260

6361
html_theme_options = {
6462
"icon_links_label": "Icon Links",
@@ -87,16 +85,15 @@
8785
sg_examples_dir = "../../examples"
8886
sg_gallery_dir = "auto_examples"
8987
sphinx_gallery_conf = {
90-
"doc_module" : "radius_clustering",
91-
"backreferences_dir" : os.path.join("modules", "generated"),
92-
"show_memory" : False,
93-
"examples_dirs" : [sg_examples_dir],
94-
"gallery_dirs" : [sg_gallery_dir],
95-
88+
"doc_module": "radius_clustering",
89+
"backreferences_dir": os.path.join("modules", "generated"),
90+
"show_memory": False,
91+
"examples_dirs": [sg_examples_dir],
92+
"gallery_dirs": [sg_gallery_dir],
9693
# avoid generating too many cross links
9794
"inspect_global_variables": False,
98-
"remove_config_comments" : True,
99-
"plot_gallery" : "True",
100-
"recommender" : {"enable": True, "n_examples": 4, "min_df": 12},
101-
"reset_modules" : ("matplotlib", "seaborn"),
95+
"remove_config_comments": True,
96+
"plot_gallery": "True",
97+
"recommender": {"enable": True, "n_examples": 4, "min_df": 12},
98+
"reset_modules": ("matplotlib", "seaborn"),
10299
}

examples/plot_iris_example.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# SPDX-License-Identifier: MIT
2020

2121

22-
#%%
22+
# %%
2323
# Load the Iris dataset
2424
# ---------------------
2525
#
@@ -34,11 +34,11 @@
3434

3535
# Load the Iris dataset
3636
iris = datasets.load_iris()
37-
X = iris['data']
37+
X = iris["data"]
3838
y = iris.target
3939

4040

41-
#%%
41+
# %%
4242
# Visualize the Iris dataset
4343
# --------------------------
4444
#
@@ -52,13 +52,13 @@
5252
pca = PCA(n_components=3)
5353
iris_reduced = pca.fit_transform(X)
5454
fig = plt.figure(figsize=(8, 6))
55-
ax = fig.add_subplot(111, projection='3d', elev=48, azim=134)
55+
ax = fig.add_subplot(111, projection="3d", elev=48, azim=134)
5656
ax.scatter(
5757
iris_reduced[:, 0],
5858
iris_reduced[:, 1],
5959
iris_reduced[:, 2],
6060
c=y,
61-
cmap='Dark2',
61+
cmap="Dark2",
6262
s=40,
6363
)
6464
# Set plot labels
@@ -74,7 +74,7 @@
7474

7575
plt.show()
7676

77-
#%%
77+
# %%
7878
# Compute Clustering with Radius Clustering
7979
# -----------------------------------------
8080
#
@@ -87,7 +87,7 @@
8787
rad.fit(X)
8888
t_rad = time.time() - t0
8989

90-
#%%
90+
# %%
9191
# Compute KMeans Clustering for Comparison
9292
# ----------------------------------------
9393
#
@@ -100,14 +100,15 @@
100100
k_means.fit(X)
101101
t_kmeans = time.time() - t0
102102

103-
#%% Establishing parity between clusters
103+
# %% Establishing parity between clusters
104104
# --------------------------------------
105105
#
106106
# We want to have the same color for the same cluster in both plots.
107107
# We can achieve this by matching the cluster labels of the Radius clustering and the KMeans clustering.
108108
# First we define a function to retrieve the cluster centers from the Radius clustering and KMeans clustering and
109109
# match them pairwise.
110110

111+
111112
def get_order_labels(kmeans, rad, data):
112113
centers1_cpy = kmeans.cluster_centers_.copy()
113114
centers2_cpy = data[rad.centers_].copy()
@@ -133,6 +134,7 @@ def get_order_labels(kmeans, rad, data):
133134
order.append(int(match_label[0]))
134135
return order
135136

137+
136138
from sklearn.metrics.pairwise import pairwise_distances_argmin
137139

138140
rad_centers_index = np.array(rad.centers_)
@@ -146,7 +148,7 @@ def get_order_labels(kmeans, rad, data):
146148
kmeans_labels = pairwise_distances_argmin(X, kmeans_centers)
147149
rad_labels = pairwise_distances_argmin(X, rad_centers_coordinates)
148150

149-
#%%
151+
# %%
150152
# Plotting the results and the difference
151153
# ---------------------------------------
152154

@@ -162,7 +164,7 @@ def get_order_labels(kmeans, rad, data):
162164
iris_reduced[:, 1],
163165
iris_reduced[:, 2],
164166
c=kmeans_labels,
165-
cmap='Dark2',
167+
cmap="Dark2",
166168
s=40,
167169
)
168170
# adapting center coordinates to the 3D plot
@@ -214,7 +216,9 @@ def get_order_labels(kmeans, rad, data):
214216
different += (kmeans_labels == k) != (rad_labels == k)
215217

216218
identical = np.logical_not(different)
217-
ax.scatter(iris_reduced[identical, 0], iris_reduced[identical, 1], color="#bbbbbb", marker=".")
219+
ax.scatter(
220+
iris_reduced[identical, 0], iris_reduced[identical, 1], color="#bbbbbb", marker="."
221+
)
218222
ax.scatter(iris_reduced[different, 0], iris_reduced[different, 1], color="m")
219223
ax.set_title("Difference")
220224
ax.set_xticks(())
@@ -223,7 +227,7 @@ def get_order_labels(kmeans, rad, data):
223227

224228
plt.show()
225229

226-
#%%
230+
# %%
227231
# Another difference plot
228232
# -----------------------
229233
#
@@ -250,7 +254,7 @@ def get_order_labels(kmeans, rad, data):
250254
k_means.fit(X)
251255
t_kmeans = time.time() - t0
252256

253-
#%%
257+
# %%
254258
# Reapllying the same process as before
255259
# --------------------------------------
256260

@@ -265,7 +269,7 @@ def get_order_labels(kmeans, rad, data):
265269
kmeans_labels = pairwise_distances_argmin(X, kmeans_centers)
266270
rad_labels = pairwise_distances_argmin(X, rad_centers_coordinates)
267271

268-
#%%
272+
# %%
269273
# Plotting the results and the difference
270274
# ---------------------------------------
271275

@@ -281,7 +285,7 @@ def get_order_labels(kmeans, rad, data):
281285
wine_reduced[:, 1],
282286
wine_reduced[:, 2],
283287
c=kmeans_labels,
284-
cmap='Dark2',
288+
cmap="Dark2",
285289
s=40,
286290
)
287291
# adapting center coordinates to the 3D plot
@@ -298,7 +302,9 @@ def get_order_labels(kmeans, rad, data):
298302
ax.set_yticks(())
299303
ax.set_zticks(())
300304

301-
ax.text3D(60.0, 80.0, 0.0, "train time: %.2fs\ninertia: %f" % (t_kmeans, k_means.inertia_))
305+
ax.text3D(
306+
60.0, 80.0, 0.0, "train time: %.2fs\ninertia: %f" % (t_kmeans, k_means.inertia_)
307+
)
302308

303309
# MDS
304310
ax = fig.add_subplot(1, 3, 2, projection="3d", elev=48, azim=134, roll=0)
@@ -333,7 +339,9 @@ def get_order_labels(kmeans, rad, data):
333339
different += (kmeans_labels == k) != (rad_labels == k)
334340

335341
identical = np.logical_not(different)
336-
ax.scatter(wine_reduced[identical, 0], wine_reduced[identical, 1], color="#bbbbbb", marker=".")
342+
ax.scatter(
343+
wine_reduced[identical, 0], wine_reduced[identical, 1], color="#bbbbbb", marker="."
344+
)
337345
ax.scatter(wine_reduced[different, 0], wine_reduced[different, 1], color="m")
338346
ax.set_title("Difference")
339347
ax.set_xticks(())
@@ -342,7 +350,7 @@ def get_order_labels(kmeans, rad, data):
342350

343351
plt.show()
344352

345-
#%%
353+
# %%
346354
# Conclusion
347355
# ----------
348356
#

radius_clustering/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Import the main clustering class
22
from .radius_clustering import RadiusClustering
33

4-
__all__ = ['RadiusClustering']
4+
__all__ = ["RadiusClustering"]
55

66
# Optionally, you can set a version number for your package
7-
__version__ = '1.0.0'
7+
__version__ = "1.0.0"

setup.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@
77
"radius_clustering.utils._emos",
88
["radius_clustering/utils/emos.pyx", "radius_clustering/utils/main-emos.c"],
99
include_dirs=[np.get_include(), "radius_clustering/utils"],
10-
extra_compile_args = ["-std=c99", "-O3", "-march=native", "-ffast-math", "-DREP"],
10+
extra_compile_args=["-std=c99", "-O3", "-march=native", "-ffast-math", "-DREP"],
1111
),
1212
Extension(
1313
"radius_clustering.utils._mds_approx",
14-
["radius_clustering/utils/mds.pyx", "radius_clustering/utils/mds_core.cpp", "radius_clustering/utils/random_manager.cpp"],
14+
[
15+
"radius_clustering/utils/mds.pyx",
16+
"radius_clustering/utils/mds_core.cpp",
17+
"radius_clustering/utils/random_manager.cpp",
18+
],
1519
include_dirs=[np.get_include(), "radius_clustering/utils"],
1620
language="c++",
1721
extra_compile_args=["-std=c++11", "-O3", "-march=native", "-ffast-math"],
1822
extra_link_args=["-std=c++11", "-fopenmp"],
19-
)
23+
),
2024
]
2125

2226
setup(
23-
ext_modules = cythonize(extensions, language_level=3),
27+
ext_modules=cythonize(extensions, language_level=3),
2428
include_dirs=[np.get_include()],
2529
package_data={"radius_clustering": ["utils/*.pyx", "utils/*.h"]},
26-
)
30+
)

tests/test_rad.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,23 @@ def test_from_import():
99
def test_radius_clustering_approx():
1010
from radius_clustering import RadiusClustering
1111
from sklearn import datasets
12+
1213
# Load the Iris dataset
13-
iris = datasets.fetch_openml(name='iris', version=1, parser='auto')
14-
X = iris['data'] # Use dictionary-style access instead of attribute access
14+
iris = datasets.fetch_openml(name="iris", version=1, parser="auto")
15+
X = iris["data"] # Use dictionary-style access instead of attribute access
1516

1617
graph_mds_api_consistent = RadiusClustering(manner="approx", threshold=1.43)
1718

1819
result_api_consistent = graph_mds_api_consistent.fit_predict(X)
1920

21+
2022
def test_radius_clustering_exact():
2123
from radius_clustering import RadiusClustering
2224
from sklearn import datasets
25+
2326
# Load the Iris dataset
24-
iris = datasets.fetch_openml(name='iris', version=1, parser='auto')
25-
X = iris['data'] # Use dictionary-style access instead of attribute access
27+
iris = datasets.fetch_openml(name="iris", version=1, parser="auto")
28+
X = iris["data"] # Use dictionary-style access instead of attribute access
2629

2730
graph_mds_api_consistent = RadiusClustering(manner="exact", threshold=1.43)
2831

0 commit comments

Comments
 (0)