bdtCrossprod

bdtCrossprod

LINEAR_ALGEBRA

1 Description

Computes matrix transposed cross-products efficiently using block-based algorithms and optional parallel processing. Supports both single-matrix (XX’) and two-matrix (XY’) transposed cross-products.

2 Usage

bdtCrossprod(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 XY’ instead of XX’.
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 transposed cross-product result.

5 Details

This function implements efficient transposed cross-product computation using block-based algorithms optimized for cache efficiency and memory usage. Key features: - Operation modes: - Single matrix: Computes XX’ - Two matrices: Computes XY’ - 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

library(BigDataStatMeth)

# Single matrix transposed cross-product
n <- 100
p <- 60
X <- matrix(rnorm(n*p), nrow=n, ncol=p)
res <- bdtCrossprod(X)

# Verify against base R
all.equal(tcrossprod(X), res)

# Two-matrix transposed cross-product
n <- 100
p <- 100
Y <- matrix(rnorm(n*p), nrow=n)
res <- bdtCrossprod(X, Y)

# Parallel computation
res_par <- bdtCrossprod(X, Y,
                        paral = TRUE,
                        threads = 4)

7 See Also