| bdCrossprod | R Documentation |
Computes matrix cross-products efficiently using block-based algorithms and optional parallel processing. Supports both single-matrix (X'X) and two-matrix (X'Y) cross-products.
bdCrossprod(
A,
B = NULL,
transposed = NULL,
block_size = NULL,
paral = NULL,
threads = NULL
)
A |
Numeric matrix. First input matrix. |
B |
Optional numeric matrix. If provided, computes A'B instead of A'A. |
transposed |
Logical. If TRUE, uses transposed input matrix. |
block_size |
Integer. Block size for computation. If NULL, uses optimal block size based on matrix dimensions and cache size. |
paral |
Logical. If TRUE, enables parallel computation. |
threads |
Integer. Number of threads for parallel computation. If NULL, uses all available threads. |
This function implements efficient cross-product computation using block-based algorithms optimized for cache efficiency and memory usage. Key features:
Operation modes:
Single matrix: Computes X'X
Two matrices: Computes X'Y
Performance optimizations:
Block-based computation for cache efficiency
Parallel processing for large matrices
Automatic block size selection
Memory-efficient implementation
The function automatically selects optimal computation strategies based on input size and available resources. For large matrices, block-based computation is used to improve cache utilization.
Numeric matrix containing the cross-product result.
Golub, G. H., & Van Loan, C. F. (2013). Matrix Computations, 4th Edition. Johns Hopkins University Press.
Kumar, V. et al. (1994). Introduction to Parallel Computing: Design and Analysis of Algorithms. Benjamin/Cummings Publishing Company.
bdtCrossprod for transposed cross-product
bdblockMult for block-based matrix multiplication
# Single matrix cross-product
n <- 100
p <- 60
X <- matrix(rnorm(n*p), nrow=n, ncol=p)
res <- bdCrossprod(X)
# Verify against base R
all.equal(crossprod(X), res)
# Two-matrix cross-product
n <- 100
p <- 100
Y <- matrix(rnorm(n*p), nrow=n)
res <- bdCrossprod(X, Y)
all.equal(crossprod(X, Y), res)
# Parallel computation
res_par <- bdCrossprod(X, paral = TRUE, threads = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.