Expand description
Mathematical utilities for distance computations and center finding.
This module contains optimized functions for computing squared L2 norms, finding closest centers, and processing residuals. These are primarily used in k-means clustering and disk index partitioning.
Functionsยง
- compute_
closest_ centers - Given data in num_points * new_dim row major Pivots stored in full_pivot_data as num_centers * new_dim row major Calculate the k closest pivot for each point and store it in vector closest_centers_ivf (row major, num_points*k) (which needs to be allocated outside) Additionally, if inverted index is not null (and pre-allocated), it will return inverted index for each center, assuming each of the inverted indices is an empty vector. Additionally, if pts_norms_squared is not null, then it will assume that point norms are pre-computed and use those values
- compute_
closest_ centers_ in_ block - Calculate k closest centers to data of num_points * dim (row-major) Centers is num_centers * dim (row-major) data_l2sq has pre-computed squared norms of data centers_l2sq has pre-computed squared norms of centers Pre-allocated center_index will contain id of nearest center Pre-allocated dist_matrix should be num_points * num_centers and contain squared distances Default value of k is 1 Ideally used only by compute_closest_centers
- compute_
vecs_ l2sq - Compute L2-squared norms of data stored in row-major num_points * dim, need to be pre-allocated