| Title: | Fast Computation of Pairwise Hamming Distances |
|---|---|
| Description: | Pairwise Hamming distances are computed between the rows of a binary (0/1) matrix using highly optimized 'C' code. The input is an integer matrix where each row represents a binary feature vector and returns a symmetric integer matrix of pairwise distances. Internally, rows are bit-packed into 64-bit words for fast XOR-based comparisons, with hardware-accelerated popcount operations to count differences. 'OpenMP' parallelization ensures efficient performance for large matrices. |
| Authors: | Ravi Varadhan [aut, cre] |
| Maintainer: | Ravi Varadhan <[email protected]> |
| License: | GPL-3 |
| Version: | 1.2 |
| Built: | 2026-05-17 07:00:55 UTC |
| Source: | https://github.com/cran/FastHamming |
Computes the pairwise Hamming distances between rows of a binary matrix.
hamming_distance(X, nthreads = NULL)hamming_distance(X, nthreads = NULL)
X |
A binary (0/1) numeric matrix. |
nthreads |
Integer; number of OpenMP threads to use. If |
An integer matrix of pairwise Hamming distances.
n <- 10000 m <- 1000 set.seed(2468) X <- matrix(sample(0:1, n * m, replace = TRUE), nrow = n) # Use all available threads system.time(result <- hamming_distance(X)) # limit to 2 threads system.time(hamming_distance(X, nthreads = 2))n <- 10000 m <- 1000 set.seed(2468) X <- matrix(sample(0:1, n * m, replace = TRUE), nrow = n) # Use all available threads system.time(result <- hamming_distance(X)) # limit to 2 threads system.time(hamming_distance(X, nthreads = 2))