Clustering
C++20 header-only: DBSCAN, HDBSCAN, k-means.
Loading...
Searching...
No Matches
pairwise.h File Reference
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <type_traits>
#include "clustering/always_assert.h"
#include "clustering/math/defaults.h"
#include "clustering/math/detail/pairwise_threshold_outer.h"
#include "clustering/math/gemm.h"
#include "clustering/math/thread.h"
#include "clustering/ndarray.h"
#include <immintrin.h>
Include dependency graph for pairwise.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  clustering
namespace  clustering::math
namespace  clustering::math::detail

Enumerations

enum class  clustering::math::detail::PairwisePath : std::uint8_t { clustering::math::detail::Simd , clustering::math::detail::Gemm }
 Tag identifying which inner kernel executed for a pairwise distance request. More...

Functions

float clustering::math::detail::horizontalSumAvx2 (__m256 v) noexcept
double clustering::math::detail::horizontalSumAvx2 (__m256d v) noexcept
float clustering::math::detail::sqEuclideanRowAvx2 (const float *xRow, const float *yRow, std::size_t d) noexcept
double clustering::math::detail::sqEuclideanRowAvx2 (const double *xRow, const double *yRow, std::size_t d) noexcept
template<class T, Layout LX, Layout LY>
clustering::math::detail::sqEuclideanRow (const NDArray< T, 2, LX > &X, std::size_t i, const NDArray< T, 2, LY > &Y, std::size_t j) noexcept
float clustering::math::detail::sqNormRowAvx2 (const float *xRow, std::size_t d) noexcept
double clustering::math::detail::sqNormRowAvx2 (const double *xRow, std::size_t d) noexcept
template<class T, Layout LX>
clustering::math::detail::sqNormRow (const NDArray< T, 2, LX > &X, std::size_t i) noexcept
template<class T, Layout LX>
void clustering::math::detail::rowNormsSq (const NDArray< T, 2, LX > &X, NDArray< T, 1 > &norms, Pool pool)
 Row-wise sum of squares: norms(i) = sum_k X(i, k)^2.
template<class T, Layout LX, Layout LY>
void clustering::math::detail::pairwiseSqEuclideanGemm (const NDArray< T, 2, LX > &X, const NDArray< T, 2, LY > &Y, NDArray< T, 2 > &out, Pool pool)
 Large-path pairwise squared Euclidean via the GEMM identity.
template<class T, Layout LX, Layout LY>
void clustering::math::detail::pairwiseSqEuclideanSimd (const NDArray< T, 2, LX > &X, const NDArray< T, 2, LY > &Y, NDArray< T, 2 > &out, Pool pool)
 Small-path pairwise squared Euclidean via SIMD accumulation per (i, j) pair.
template<class T, Layout LX = Layout::Contig, Layout LY = Layout::Contig>
void clustering::math::pairwiseSqEuclidean (const NDArray< T, 2, LX > &X, const NDArray< T, 2, LY > &Y, NDArray< T, 2 > &out, Pool pool)
 Pairwise squared Euclidean distances between rows of two matrices.
template<class T, Layout LX = Layout::Contig, Layout LY = Layout::Contig>
PairwisePath clustering::math::detail::pairwiseSqEuclideanWithDispatchInfo (const NDArray< T, 2, LX > &X, const NDArray< T, 2, LY > &Y, NDArray< T, 2 > &out, Pool pool)
 Test-only: runs the same dispatch as pairwiseSqEuclidean and reports which kernel fired.
template<class T, Layout LX, Layout LY>
bool clustering::math::detail::canUseFusedThreshold (const NDArray< T, 2, LX > &X, const NDArray< T, 2, LY > &Y) noexcept
 Runtime predicate: true when the fused AVX2 threshold path is eligible.
template<class T, Layout LX, Layout LY, class Emit>
void clustering::math::detail::pairwiseSqEuclideanThresholdedMaterialized (const NDArray< T, 2, LX > &X, const NDArray< T, 2, LY > &Y, T radiusSq, Pool pool, Emit &&emit)
 Materialized fallback for the thresholded-emit API: compute each pair's squared distance via sqEuclideanRow and walk survivors.
template<class T, Layout LX = Layout::Contig, Layout LY = Layout::Contig, class Emit>
void clustering::math::pairwiseSqEuclideanThresholded (const NDArray< T, 2, LX > &X, const NDArray< T, 2, LY > &Y, T radiusSq, Pool pool, Emit &&emit)
 Emit every row pair (i, j) whose squared Euclidean distance is at most radiusSq.
template<class T, Layout LX = Layout::Contig, class Emit>
void clustering::math::pairwiseSqEuclideanThresholdedSymmetric (const NDArray< T, 2, LX > &X, T radiusSq, Pool pool, Emit &&emit)
 Symmetric variant of pairwiseSqEuclideanThresholded for the X == Y case.

Variables

template<class T>
constexpr std::size_t clustering::math::detail::kAvx2Lanes = std::is_same_v<T, float> ? 8 : 4