grapes-sp-grapes: Sparsity-retaining matrix multiplication

%sp%R Documentation

Sparsity-retaining matrix multiplication

Description

Standard matrix multiplication destroys automatic sparsity detection by RTMB which is essential for models with high-dimensional random effects. This can be mitigated by changing to "plain" with TapeConfig, but this can make AD tape construction very slow. Here, we provide a different version that retains sparsity. It may be slightly slower than the standard method when constructing the AD tape.

Usage

A %sp% B

Arguments

A

matrix of dimension n x p

B

matrix of dimension p x m

Value

the matrix product of A and B, which is of dimension n x m

Examples

A <- matrix(1:6, nrow = 2, ncol = 3)
B <- matrix(7:12, nrow = 3, ncol = 2)
A %sp% B

LaMa documentation built on Nov. 5, 2025, 6:42 p.m.