library(BigDataStatMeth)
# 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)
# Parallel computation
res_par <- bdCrossprod(X, Y,
paral = TRUE,
threads = 4)bdCrossprod
bdCrossprod
LINEAR_ALGEBRA
1 Description
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.
2 Usage
bdCrossprod(A, B = NULL, transposed = NULL, block_size = NULL, paral = NULL, threads = NULL)3 Arguments
| Parameter | Description |
|---|---|
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. |
4 Value
Numeric matrix containing the cross-product result.
5 Details
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.
6 Examples
7 See Also
- bdtCrossprod for transposed cross-product
- bdblockMult for block-based matrix multiplication