c_weighted_jaccard_dense: Dense weighted Jaccard similarity via C++

View source: R/weighted_jaccard.R

c_weighted_jaccard_denseR Documentation

Dense weighted Jaccard similarity via C++

Description

Compute the full weighted Jaccard similarity matrix for a dgCMatrix, returning a dense matrix (or a dist-layout vector).

Usage

c_weighted_jaccard_dense(
  x,
  transpose = FALSE,
  threads = NULL,
  triangle = FALSE,
  distance = FALSE
)

Arguments

x

A dgCMatrix (sparse column-compressed matrix)

transpose

If FALSE, compare columns; if TRUE, compare rows

threads

Number of threads for parallel computation. The default NULL applies the package thread policy (respecting getOption("Ncpus") and the OMP_THREAD_LIMIT environment variable, else 2). Set to 0 to use all available cores.

triangle

If TRUE, return only the lower triangle as a flat numeric vector in dist layout. If FALSE (default), return a full square matrix.

distance

If TRUE, return distance (1 - similarity) instead of similarity. Default FALSE.

Details

Uses an adaptive dense accumulation strategy: for small output matrices a feature-oriented loop, switching to a column-oriented loop for larger outputs for better cache performance.

Value

A dense numeric similarity matrix, or a numeric vector in dist layout when triangle = TRUE.

See Also

c_weighted_jaccard_sparse for the sparse equivalent

Examples

## Not run: 
library(Matrix)
m <- sparseMatrix(i = c(1,2,1,2,3,3), j = c(1,1,2,2,2,3),
                  x = c(4,2,1,3,3,1), dims = c(3,3))
c_weighted_jaccard_dense(m)

## End(Not run)

natcpp documentation built on Sept. 26, 2026, 9:06 a.m.