Skip to main content

Centroid Partition - SIMD-accelerated E-means clustering

This is a SIMD-accelerated library for centroid-based clustering. The implementation is based on E-means algorithm, introduced by Swann Bessa, et al.1.

The original code from the paper is distributed along with faiss library. The Centroid Partition library is written to keep the library size small within a minimum set of dependencies. The Centroid Partition library exposes both C++ and Python API.

Installation

The C++ library could be installed into your project using vcpkg (release in progress).

vcpkg install centroid-partition

The Python bindings could be installed from PyPI like following:

pip install centroid-partition

Building

The dependencies are installed by vcpkg, so point VCPKG_ROOT to its checkout:

export VCPKG_ROOT=$HOME/vcpkg
cmake --preset=default -DCMAKE_BUILD_TYPE=Release
cmake --build build

Usage

You can use the Python package centroid_partition to cluster the points with the EMeans estimator, which follows the conventions of the scikit-learn estimators, and to find the nearest centroids of other points.

>>> import numpy as np
>>> from centroid_partition import EMeans
>>> X = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]], dtype=np.float32)
>>> emeans = EMeans(n_clusters=2, random_state=0).fit(X)
>>> emeans.labels_
array([0, 0, 0, 1, 1, 1], dtype=int32)
>>> emeans.predict([[0, 0], [12, 3]])
array([0, 1], dtype=int32)
>>> emeans.cluster_centers_
array([[ 1.,  2.],
       [10.,  2.]], dtype=float32)

With the C++ library centroid_partition you can do the same: train the centroids on the points, and find the nearest centroid of the points. The points and the centroids are the rows of the row-major arrays:

#include <cstddef>
#include <random>
#include <vector>

#include <centroid_partition/centroid_partition.h>

namespace cp = centroid_partition;

int main()
{
    const std::size_t n = 10'000, dim = 16, k = 8;

    std::mt19937 rng(1);
    std::normal_distribution<float> normal;

    std::vector<float> points(n * dim);
    for (auto& value : points) {
        value = normal(rng);
    }

    // Train the centroids on the points.
    cp::centroid_partition<float> clustering(k, dim);
    std::vector<float> centroids(k * dim);
    clustering(points.data(), points.data() + points.size(), centroids.data());

    // Find the nearest centroid of the points.
    cp::centroid_nearest_search<float> search(k, dim, centroids.data());
    std::vector<decltype(search)::index_type> nearest(n);
    search(points.data(), points.data() + points.size(), nearest.data());
}

License

The centroid_partition library is distributed under BSD 3-clause license. See the LICENSE file for full license text.

  1. Swann Bessa and Pierre-Emmanuel Mazaré and Gergely Szilvasy and Hugo Touvron and David Picard and Matthijs Douze and Hervé Jégou - e-means: outperforming k-means (in one-tenth the epochs). ↩

Metadata

Release files for centroid-partition 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for centroid-partition 1.0.0
File Actions
centroid_partition-1.0.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for centroid_partition-1.0.0-cp312-abi3-win_amd64.whl
centroid_partition-1.0.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for centroid_partition-1.0.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
centroid_partition-1.0.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64, Linux glibc 2.27+ ARM64 Details for centroid_partition-1.0.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
centroid_partition-1.0.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for centroid_partition-1.0.0-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 600.2 kB

Release files / centroid_partition-1.0.0-cp312-abi3-win_amd64.whl

Download URL centroid_partition-1.0.0-cp312-abi3-win_amd64.whl
Size 316.9 kB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
13003360e771c555b779c5f99154ed52bc08f53d41c4b773f0fbf5788798631a
BLAKE2b-256 checksum
How to use checksums
8260327d3cae8dfcbe9efa225f0b1339f4fb25139ddaf5faf311a1e0a9d619f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / centroid_partition-1.0.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL centroid_partition-1.0.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 108.8 kB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
5367c438c6b69e2faab86e93b143f6e0fa5d6870e7d7e15b8a5913ee44eece12
BLAKE2b-256 checksum
How to use checksums
bc1a6544c77e96fd8fd82351f69e795eea7558a4db2b18ebd5d707587b11c08a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / centroid_partition-1.0.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL centroid_partition-1.0.0-cp312-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 96.9 kB
Tags CPython 3.12 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
b6409aa2c2b7ac046d4b1575e84334ce2fb1b3a4f61b2e92d53fc82c77006c7a
BLAKE2b-256 checksum
How to use checksums
e1388c64d425237c9a7901a5fb09480b970d2d0c4121e9c874996d1dfc39d5a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / centroid_partition-1.0.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL centroid_partition-1.0.0-cp312-abi3-macosx_11_0_arm64.whl
Size 77.6 kB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
618caf572c83c4137ae04e1d41984989c438b1af9c97cc5b03ff181559ba6d41
BLAKE2b-256 checksum
How to use checksums
a08e3d72c663c2bf19526e0a1e5e22ef886b3816c76c6bcfb488713d27aa448c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for centroid-partition 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for centroid_partition-1.0.0-cp312-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

4 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page