Skip to content

Commit

Permalink
Version updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kno10 committed Sep 10, 2024
1 parent 67e48ac commit ccb60aa
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 32 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ jobs:
strategy:
matrix:
container:
- "quay.io/pypa/musllinux_1_2_x86_64"
- "quay.io/pypa/manylinux2014_x86_64"
- "quay.io/pypa/manylinux_2_28_x86_64"
container: ${{ matrix.container }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build wheels
run: |
bash .github/workflows/build-wheels.sh
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: wheels
path: wheelhouse
Expand All @@ -31,17 +32,18 @@ jobs:
strategy:
matrix:
container:
- "quay.io/pypa/musllinux_1_2_aarch64"
- "quay.io/pypa/manylinux2014_aarch64"
- "quay.io/pypa/manylinux_2_28_aarch64"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install QEMU
run: |
docker run --privileged --rm tonistiigi/binfmt --install arm64
- name: Build wheels
run: |
docker run --platform linux/arm64 --workdir /src -v ${PWD}:/src ${{ matrix.container }} /bin/bash .github/workflows/build-wheels.sh
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: wheels
path: wheelhouse
Expand All @@ -51,9 +53,9 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -68,7 +70,7 @@ jobs:
maturin build --release --strip --target universal2-apple-darwin
python3 -m pip install kmedoids --no-index --find-links target/wheels
cd tests && python3 -m unittest discover && cd ..
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: wheels
path: target/wheels
Expand All @@ -78,9 +80,9 @@ jobs:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
Expand All @@ -94,7 +96,7 @@ jobs:
maturin build --release --strip
python -m pip install kmedoids --no-index --find-links target/wheels
cd tests && python -m unittest discover && cd ..
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: wheels
path: target/wheels
Expand All @@ -106,7 +108,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Collect artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: wheels
path: wheels/
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

For changes to the main Rust package, please see <https://github.com/kno10/rust-kmedoids/blob/main/CHANGELOG.md>

## kmedoids 0.5.2 (2024-09-10)

- fix clippy warnings
- update to pyo3 0.21, numpy 0.21
- update github action for python 3.13 and musllinux

## kmedoids 0.5.1 (2024-03-14)

- DynMSC: best loss reported incorrectly if best k=2
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ authors:
title: "Fast k-medoids Clustering in Rust and Python"
journal: "J. Open Source Softw."
doi: 10.21105/joss.04183
version: 0.5.1
date-released: 2024-03-14
version: 0.5.2
date-released: 2024-09-10
license: GPL-3.0
preferred-citation:
title: "Fast k-medoids Clustering in Rust and Python"
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
edition = "2021"
name = "kmedoids"
version = "0.5.1"
version = "0.5.2"
authors = ["Erich Schubert <[email protected]>", "Lars Lenssen <[email protected]>"]
description = "k-Medoids clustering with the FasterPAM algorithm"
homepage = "https://github.com/kno10/python-kmedoids"
Expand All @@ -14,13 +14,13 @@ name = "kmedoids"
crate-type = ["cdylib"]

[dependencies]
rustkmedoids = { version = "0.5.1", package = "kmedoids", git = "https://github.com/kno10/rust-kmedoids" }
numpy = "0.20"
rustkmedoids = { version = "0.5.2", package = "kmedoids", git = "https://github.com/kno10/rust-kmedoids" }
numpy = "0.21"
ndarray = "0.15"
rand = "0.8"
rayon = "1.9"
rayon = "1.10"

[dependencies.pyo3]
version = "0.20"
version = "^0.21"
features = ["extension-module"]

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "kmedoids"
version = "0.5.1"
version = "0.5.2"
description = "k-Medoids Clustering in Python with FasterPAM"
requires-dist = ["numpy"]
classifier = [
Expand Down
23 changes: 10 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
use numpy::{PyArray1, PyReadonlyArray1, PyReadonlyArray2};
use numpy::{PyArray1, PyReadonlyArray1, PyReadonlyArray2, PyArrayMethods, PyUntypedArrayMethods};
use rand::{rngs::StdRng, SeedableRng};
use rayon;
use rustkmedoids;

macro_rules! variant_call {
($name:ident, $variant:ident, $type: ty, $ltype: ty) => {
Expand All @@ -24,7 +22,7 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
let mut meds = meds.to_vec()?;
let (loss, assi, n_iter, n_swap): ($ltype, _, _, _) = rustkmedoids::$variant(&dist.as_array(), &mut meds, max_iter);
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
Ok((loss, PyArray1::from_vec_bound(py, assi), PyArray1::from_vec_bound(py, meds), n_iter, n_swap).to_object(py))
})
}
}}
Expand Down Expand Up @@ -71,7 +69,7 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
let mut rnd = StdRng::seed_from_u64(seed);
let (loss, assi, n_iter, n_swap): ($ltype, _, _, _) = rustkmedoids::$variant(&dist.as_array(), &mut meds, max_iter, &mut rnd);
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
Ok((loss, PyArray1::from_vec_bound(py, assi), PyArray1::from_vec_bound(py, meds), n_iter, n_swap).to_object(py))
})
}
}}
Expand Down Expand Up @@ -108,7 +106,7 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
rustkmedoids::$variant(&dist, &mut meds, max_iter, &mut rnd)
});
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter, n_swap).to_object(py))
Ok((loss, PyArray1::from_vec_bound(py, assi), PyArray1::from_vec_bound(py, meds), n_iter, n_swap).to_object(py))
})
}
}}
Expand All @@ -133,7 +131,7 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, k: usize) -> PyResult<Py<PyAny>> {
assert_eq!(dist.shape()[0], dist.shape()[1]);
let (loss, assi, meds): ($ltype, _, _) = rustkmedoids::pam_build(&dist.as_array(), k);
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), 1).to_object(py))
Ok((loss, PyArray1::from_vec_bound(py, assi), PyArray1::from_vec_bound(py, meds), 1).to_object(py))
})
}
}}
Expand Down Expand Up @@ -161,7 +159,7 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
let mut meds = meds.to_vec()?;
let (loss, assi, n_iter): ($ltype, _, _) = rustkmedoids::alternating(&dist.as_array(), &mut meds, max_iter);
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, meds), n_iter).to_object(py))
Ok((loss, PyArray1::from_vec_bound(py, assi), PyArray1::from_vec_bound(py, meds), n_iter).to_object(py))
})
}
}}
Expand Down Expand Up @@ -191,7 +189,7 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, m
let (loss, assi, n_iter, n_swap, best_meds, losses): ($ltype, _, _, _, _, _) = rustkmedoids::dynmsc(&dist.as_array(), &mut meds, minimum_k, max_iter);
let bestk = best_meds.len();
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
Ok((loss, PyArray1::from_vec(py, assi), PyArray1::from_vec(py, best_meds), bestk, PyArray1::from_vec(py, losses), (minimum_k..maxk).collect::<Vec<usize>>(), n_iter, n_swap).to_object(py))
Ok((loss, PyArray1::from_vec_bound(py, assi), PyArray1::from_vec_bound(py, best_meds), bestk, PyArray1::from_vec_bound(py, losses), (minimum_k..maxk).collect::<Vec<usize>>(), n_iter, n_swap).to_object(py))
})
}
}}
Expand All @@ -216,7 +214,7 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, assi: PyReadonlyArray1<'_, usize>, s
assert_eq!(dist.shape()[0], dist.shape()[1]);
let (sil, sils): (f64, _) = rustkmedoids::silhouette(&dist.as_array(), &assi.to_vec()?, samples);
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
Ok((sil, PyArray1::from_vec(py, sils)).to_object(py))
Ok((sil, PyArray1::from_vec_bound(py, sils)).to_object(py))
})
}
}}
Expand Down Expand Up @@ -271,7 +269,7 @@ fn $name(dist: PyReadonlyArray2<'_, $type>, meds: PyReadonlyArray1<'_, usize>, s
assert_eq!(dist.shape()[0], dist.shape()[1]);
let (sil, sils): (f64, _) = rustkmedoids::medoid_silhouette(&dist.as_array(), &meds.to_vec()?, samples);
Python::with_gil(|py| -> PyResult<Py<PyAny>> {
Ok((sil, PyArray1::from_vec(py, sils)).to_object(py))
Ok((sil, PyArray1::from_vec_bound(py, sils)).to_object(py))
})
}
}}
Expand All @@ -282,7 +280,7 @@ medoid_silhouette_call!(medoid_silhouette_i32, i32);

#[pymodule]
#[allow(unused_variables)]
fn kmedoids(py: Python, m: &PyModule) -> PyResult<()> {
fn kmedoids(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("_fasterpam_f32", wrap_pyfunction!(fasterpam_f32, m)?)?;
m.add("_fasterpam_f64", wrap_pyfunction!(fasterpam_f64, m)?)?;
m.add("_fasterpam_i32", wrap_pyfunction!(fasterpam_i32, m)?)?;
Expand Down Expand Up @@ -335,4 +333,3 @@ fn kmedoids(py: Python, m: &PyModule) -> PyResult<()> {
// not supported: m.add("_medoid_silhouette_i64", wrap_pyfunction!(medoid_silhouette_i64, m)?)?;
Ok(())
}

0 comments on commit ccb60aa

Please sign in to comment.