Spectral#
2026-08-27
1 min read time
This page provides C++ class references for the publicly-exposed elements of the raft/spectral package. The spectral methods in RAFT provide graph-based clustering and partitioning algorithms that operate on sparse matrix representations.
Graph Partitioning#
#include <raft/spectral/partition.cuh>
namespace raft::spectral
- template<typename vertex_t, typename weight_t, typename nnz_t> void analyzePartition (raft::resources const &handle, matrix::sparse_matrix_t< vertex_t, weight_t, nnz_t > const &csr_m, vertex_t nClusters, const vertex_t *__restrict__ clusters, weight_t &edgeCut, weight_t &cost)
Compute cost function for partition.
This function determines the edges cut by a partition and a cost function: Cost = \(sum_i\) (Edges cut by ith partition)/(Vertices in ith partition) Graph is assumed to be weighted and undirected.
- Parameters:
handle – raft handle for managing expensive resources
csr_m – Weighted graph in CSR format
nClusters – Number of partitions.
clusters – (Input, device memory, n entries) Partition assignments.
edgeCut – On exit, weight of edges cut by partition.
cost – On exit, partition cost function.
Modularity Maximization#
#include <raft/spectral/modularity_maximization.cuh>
namespace raft::spectral
- template<typename vertex_t, typename weight_t, typename nnz_t> void analyzeModularity (raft::resources const &handle, matrix::sparse_matrix_t< vertex_t, weight_t, nnz_t > const &csr_m, vertex_t nClusters, vertex_t const *__restrict__ clusters, weight_t &modularity)
Compute modularity.
This function determines the modularity based on a graph and cluster assignments
- Parameters:
handle – raft handle for managing expensive resources
csr_m – Weighted graph in CSR format
nClusters – Number of clusters.
clusters – (Input, device memory, n entries) Cluster assignments.
modularity – On exit, modularity