Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
Loading...
Searching...
No Matches
clustering::kmeans::LloydFusedGemm< T > Class Template Reference

Fused-argmin-GEMM Lloyd driver. More...

#include <clustering/kmeans/policy/lloyd_fused_gemm.h>

Public Member Functions

 LloydFusedGemm ()
void run (const NDArray< T, 2, Layout::Contig > &X, NDArray< T, 2, Layout::Contig > &centroids, std::size_t k, std::size_t maxIter, T tol, math::Pool pool, NDArray< std::int32_t, 1 > &outLabels, double &outInertia, std::size_t &outNIter, bool &outConverged)
 Run the Lloyd loop against caller-seeded centroids.

Static Public Attributes

static constexpr std::size_t kahanNThreshold = 100000
 n threshold at which the centroid accumulator switches to Kahan-compensated summation.

Detailed Description

template<class T>
class clustering::kmeans::LloydFusedGemm< T >

Fused-argmin-GEMM Lloyd driver.

Runs the Lloyd iteration over caller-seeded centroids: assignment via the fused AVX2 argmin-GEMM hot path at d <= math::defaults::pairwiseArgminMaxD and the chunked materialized fallback above it, label-grouped fold into per-cluster sums (Kahan-compensated at n >= LloydFusedGemm::kahanNThreshold), empty-cluster reseed against the current per-point distance scratch, mean step, and convergence test on the Kahan-summed total squared shift. All scratch buffers live inside the policy instance; no allocation fires between the first assignment call and the convergence check of any iteration once the shape has been warmed.

Template Parameters
TElement type; float or double.

Definition at line 98 of file lloyd_fused_gemm.h.

Constructor & Destructor Documentation

◆ LloydFusedGemm()

template<class T>
clustering::kmeans::LloydFusedGemm< T >::LloydFusedGemm ( )
inline

Definition at line 103 of file lloyd_fused_gemm.h.

Member Function Documentation

◆ run()

template<class T>
void clustering::kmeans::LloydFusedGemm< T >::run ( const NDArray< T, 2, Layout::Contig > & X,
NDArray< T, 2, Layout::Contig > & centroids,
std::size_t k,
std::size_t maxIter,
T tol,
math::Pool pool,
NDArray< std::int32_t, 1 > & outLabels,
double & outInertia,
std::size_t & outNIter,
bool & outConverged )
inline

Run the Lloyd loop against caller-seeded centroids.

Parameters
XContiguous n x d dataset. Borrowed; caller retains ownership.
centroidsk x d centroid matrix. Caller has already populated the rows with the seeder's output; this routine overwrites them in place with the iteration-final values.
kNumber of clusters.
maxIterIteration cap.
tolConvergence tolerance relative to the mean column variance of X (sklearn convention). Internally converted to a sum-of-shift-squared threshold as tol * mean(var(X, axis=0)) and compared against the Kahan-summed per-centroid shift-squared.
poolParallelism injection.
outLabelsLength-n assignment; each entry in [0, k).
outInertiaKahan-summed f64 total of per-point squared distance to assignment.
outNIterIterations executed before tol or maxIter fired.
outConvergedtrue iff iteration stopped because centroid shift fell at or below tol.

Definition at line 146 of file lloyd_fused_gemm.h.

Member Data Documentation

◆ kahanNThreshold

template<class T>
std::size_t clustering::kmeans::LloydFusedGemm< T >::kahanNThreshold = 100000
staticconstexpr

n threshold at which the centroid accumulator switches to Kahan-compensated summation.

Definition at line 123 of file lloyd_fused_gemm.h.


The documentation for this class was generated from the following file: