| bdblockSum | R Documentation |
Performs efficient matrix addition using block-based algorithms. The function supports various input combinations (matrix-matrix, matrix-vector, vector-vector) and provides options for parallel processing and block-based computation.
bdblockSum(
A,
B,
block_size = NULL,
paral = NULL,
byBlocks = TRUE,
threads = NULL
)
A |
Matrix or vector. First input operand. |
B |
Matrix or vector. Second input operand. |
block_size |
Integer. Block size for computation. If NULL, uses maximum allowed block size. |
paral |
Logical. If TRUE, enables parallel computation. Default is FALSE. |
byBlocks |
Logical. If TRUE (default), forces block-based computation for large matrices. Can be set to FALSE to disable blocking. |
threads |
Integer. Number of threads for parallel computation. If NULL, uses half of available threads. |
This function implements block-based matrix addition algorithms optimized for cache efficiency and memory usage. Key features:
Input combinations supported:
Matrix-matrix addition
Matrix-vector addition (both left and right)
Vector-vector addition
Performance optimizations:
Block-based computation for cache efficiency
Parallel processing for large matrices
Automatic method selection based on input size
Memory-efficient implementation
The function automatically selects the appropriate addition method based on input types and sizes. For large matrices (>2.25e+08 elements), block-based computation is used by default.
Matrix or vector containing the result of A + B.
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.
bdblockSubstract for block-based matrix subtraction
bdblockMult for block-based matrix multiplication
# Matrix-matrix addition
N <- 2500
M <- 400
nc <- 4
set.seed(555)
mat1 <- matrix(rnorm(N*M, mean=0, sd=10), N, M)
mat2 <- matrix(rnorm(N*M, mean=0, sd=10), N, M)
# Parallel block addition
result <- bdblockSum(mat1, mat2,
paral = TRUE,
threads = nc)
# Matrix-vector addition
vec <- rnorm(M)
result_mv <- bdblockSum(mat1, vec,
paral = TRUE,
threads = nc)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.