Skip to content

Commit 743994c

Browse files
committed
update pyo3 version
1 parent 309939b commit 743994c

4 files changed

Lines changed: 44 additions & 38 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ crate-type = ["cdylib"]
1515

1616
[dependencies]
1717
rustkmedoids = { version = "0.4.0", package = "kmedoids", git = "https://github.com/kno10/rust-kmedoids" }
18-
numpy = "0.16"
18+
numpy = "0.17"
1919
ndarray = "0.15"
2020
rand = "0.8"
2121
rayon = "1.5"
@@ -24,18 +24,3 @@ rayon = "1.5"
2424
version = "0.17.1"
2525
features = ["extension-module"]
2626

27-
[package.metadata.maturin]
28-
classifier = [
29-
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
30-
"Intended Audience :: Developers",
31-
"Intended Audience :: Science/Research",
32-
"Programming Language :: Python",
33-
"Programming Language :: Rust",
34-
"Operating System :: POSIX",
35-
"Operating System :: MacOS",
36-
"Operating System :: Microsoft :: Windows",
37-
"Topic :: Scientific/Engineering :: Artificial Intelligence",
38-
"Topic :: Software Development :: Libraries"
39-
]
40-
requires-dist = ["numpy"]
41-
project-url = { "ReadTheDocs" = "https://python-kmedoids.readthedocs.io/", "Rust Source Code" = "https://github.com/kno10/rust-kmedoids" }

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ an earlier (slower, and now obsolete) version was published as:
2222
This is a port of the original Java code from [ELKI](https://elki-project.github.io/) to Rust.
2323
The [Rust version](https://github.com/kno10/rust-kmedoids) is then wrapped for use with Python.
2424

25-
For further details on the implemented algorithm FasterMSC, see:
25+
For further details on medoid Silhouette clustering with FasterMSC, see:
2626

27-
> Lars Lenssen, Erich Schubert
27+
> Lars Lenssen, Erich Schubert:
2828
> **Clustering by Direct Optimization of the Medoid Silhouette**
29-
> In: 15th International Conference on Similarity Search and Applications (SISAP 2022)
29+
> In: 15th International Conference on Similarity Search and Applications (SISAP 2022)
30+
> <https://doi.org/10.1007/978-3-031-17849-8_15>
3031
3132
If you use this code in scientific work, please cite above papers. Thank you.
3233

@@ -64,6 +65,7 @@ maturin develop --release
6465
```
6566
Integration test to validate the installation.
6667
```sh
68+
pip install numpy
6769
python -m unittest discover tests
6870
```
6971

pyproject.toml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
[build-system]
2-
requires = ["maturin>=0.11,<0.12"]
2+
requires = ["maturin>=0.13,<0.14"]
33
build-backend = "maturin"
4+
5+
[project]
6+
name = "kmedoids"
7+
version = "0.4.0"
8+
description = "k-Medoids Clustering in Python with FasterPAM"
9+
requires-dist = ["numpy"]
10+
classifier = [
11+
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
12+
"Intended Audience :: Developers",
13+
"Intended Audience :: Science/Research",
14+
"Programming Language :: Python",
15+
"Programming Language :: Rust",
16+
"Operating System :: POSIX",
17+
"Operating System :: MacOS",
18+
"Operating System :: Microsoft :: Windows",
19+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
20+
"Topic :: Software Development :: Libraries"
21+
]
22+
project-url = { "ReadTheDocs" = "https://python-kmedoids.readthedocs.io/", "Rust Source Code" = "https://github.com/kno10/rust-kmedoids" }

src/lib.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
2323
assert_eq!(dist.shape()[0], dist.shape()[1]);
2424
let mut meds = meds.to_vec()?;
2525
let (loss, assi, n_iter, n_swap): ($ltype, _, _, _) = rustkmedoids::$variant(&dist.as_array(), &mut meds, max_iter);
26-
let gil = Python::acquire_gil();
27-
let py = gil.python();
28-
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
26+
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
27+
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
28+
})
2929
}
3030
}}
3131
variant_call!(fasterpam_f32, fasterpam, f32, f64);
@@ -70,9 +70,9 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
7070
let mut meds = meds.to_vec()?;
7171
let mut rnd = StdRng::seed_from_u64(seed);
7272
let (loss, assi, n_iter, n_swap): ($ltype, _, _, _) = rustkmedoids::$variant(&dist.as_array(), &mut meds, max_iter, &mut rnd);
73-
let gil = Python::acquire_gil();
74-
let py = gil.python();
75-
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
73+
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
74+
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
75+
})
7676
}
7777
}}
7878
rand_call!(rand_fasterpam_f32, rand_fasterpam, f32, f64);
@@ -107,9 +107,9 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
107107
let mut rnd = StdRng::seed_from_u64(seed);
108108
rustkmedoids::$variant(&dist, &mut meds, max_iter, &mut rnd)
109109
});
110-
let gil = Python::acquire_gil();
111-
let py = gil.python();
112-
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
110+
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
111+
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
112+
})
113113
}
114114
}}
115115
par_call!(par_fasterpam_f32, par_fasterpam, f32, f64);
@@ -132,9 +132,9 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, k: usize) -> PyResult<Py<PyAny>> {
132132
assert_eq!(dist.ndim(), 2);
133133
assert_eq!(dist.shape()[0], dist.shape()[1]);
134134
let (loss, assi, meds): ($ltype, _, _) = rustkmedoids::pam_build(&dist.as_array(), k);
135-
let gil = Python::acquire_gil();
136-
let py = gil.python();
137-
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), 1).to_object(py))
135+
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
136+
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), 1).to_object(py))
137+
})
138138
}
139139
}}
140140
pam_build_call!(pam_build_f32, f32, f64);
@@ -160,9 +160,9 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
160160
assert_eq!(dist.shape()[0], dist.shape()[1]);
161161
let mut meds = meds.to_vec()?;
162162
let (loss, assi, n_iter): ($ltype, _, _) = rustkmedoids::alternating(&dist.as_array(), &mut meds, max_iter);
163-
let gil = Python::acquire_gil();
164-
let py = gil.python();
165-
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter).to_object(py))
163+
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
164+
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter).to_object(py))
165+
})
166166
}
167167
}}
168168
alternating_call!(alternating_f32, f32, f64);
@@ -187,9 +187,9 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, assi: PyReadonlyArray1<'_, usize>, s
187187
assert_eq!(dist.ndim(), 2);
188188
assert_eq!(dist.shape()[0], dist.shape()[1]);
189189
let (sil, sils): (f64, _) = rustkmedoids::silhouette(&dist.as_array(), &assi.to_vec()?, samples);
190-
let gil = Python::acquire_gil();
191-
let py = gil.python();
192-
Ok((sil, PyArray1::from_vec(py, sils)).to_object(py))
190+
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
191+
Ok((sil, PyArray1::from_vec(py, sils)).to_object(py))
192+
})
193193
}
194194
}}
195195
silhouette_call!(silhouette_f32, f32);

0 commit comments

Comments
 (0)