Learn R Programming

FastHamming (version 1.2)

hamming_distance: Pairwise Hamming distances

Description

Computes the pairwise Hamming distances between rows of a binary matrix.

Usage

hamming_distance(X, nthreads = NULL)

Value

An integer matrix of pairwise Hamming distances.

Arguments

X

A binary (0/1) numeric matrix.

nthreads

Integer; number of OpenMP threads to use. If NULL (the default) use all available cores,

Examples

Run this code
# \donttest{
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))
# }

Run the code above in your browser using DataLab