bdtCrossprod: Efficient Matrix Transposed Cross-Product Computation

View source: R/RcppExports.R

bdtCrossprodR Documentation

Efficient Matrix Transposed Cross-Product Computation

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.

Usage

bdtCrossprod(
  A,
  B = NULL,
  transposed = NULL,
  block_size = NULL,
  paral = NULL,
  threads = NULL
)

Arguments

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.

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.

Value

Numeric matrix containing the transposed cross-product result.

References

  • 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.

See Also

  • bdCrossprod for standard cross-product

  • bdblockMult for block-based matrix multiplication

Examples


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

# Two-matrix transposed cross-product
# Both matrices must have the same number of columns
n <- 100
p <- 60
Y <- matrix(rnorm(n*p), nrow=n, ncol=p)
res <- bdtCrossprod(X, Y)
all.equal(tcrossprod(X, Y), res)

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


BigDataStatMeth documentation built on May 15, 2026, 1:07 a.m.