estimate_dense_matrix_mb: Estimate dense cost-matrix memory footprint in megabytes

View source: R/matching_memory.R

estimate_dense_matrix_mbR Documentation

Estimate dense cost-matrix memory footprint in megabytes

Description

What the matrix itself costs a process, which is more than the 8 bytes a cell occupies: matrix(0, n, m) at the R level is copied into a lap::CostMatrix (8B data + 4B mask), and the two coexist while garbage collection lags. Building the matrix and stopping there peaked at 1.8, 1.7 and 1.5 times the raw cell bytes at 5,000, 10,000 and 20,000 units on the memory benchmark, so the default multiplier is above what has been measured rather than fitted to it. n/m are coerced to double before multiplying so the estimate itself can't overflow the way lap::CostMatrix's old int flat-index arithmetic did.

Usage

estimate_dense_matrix_mb(n, m, overhead_factor = 4)

Arguments

n, m

Problem dimensions.

overhead_factor

Multiplier on the raw cell bytes.

Details

This is the matrix, not the solve. estimate_dense_solve_mb() is what the memory guard reads; see there for why the two differ by more than a copy.

Value

Numeric scalar, the estimated footprint of the matrix in megabytes.

Examples

estimate_dense_matrix_mb(5000, 5000)

couplr documentation built on Sept. 17, 2026, 1:08 a.m.