Computes the (possibly weighted) sample or population covariance matrix of
X. Sparse inputs use a memory-efficient path; dense inputs use a
fused GPU kernel when available, otherwise fall back to CPU centering
followed by a GPU cross-product.
Arguments
- X
Numeric matrix,
adgeMatrix, or sparseadgCMatrix/sparseMatrix, shape[n, p].- center
Logical. When
TRUE(default), columns are mean-centred before computing the cross-product.- sample
Logical. When
TRUE(default), divides byn - 1(sample covariance); whenFALSE, divides byn.- weights
Optional numeric vector of length
nwith non-negative observation weights. When supplied, a weighted covariance is computed.- block_size
Optional integer. When set, the cross-product is computed in column-blocks of this size to limit peak memory. Ignored for sparse inputs.