cagpjax.operators.lazy_kernel
Lazy kernel operator
Classes:
-
LazyKernel–A lazy kernel operator that avoids materializing large kernel matrices.
LazyKernel
LazyKernel(kernel: AbstractKernel, x1: Float[Array, 'M D'], x2: Float[Array, 'N D'], /, *, max_memory_mb: int = 2 ** 10, batch_size: int | None = None, checkpoint: bool = False)
Bases: LinearOperator
A lazy kernel operator that avoids materializing large kernel matrices.
This class implements a lazy kernel operator that computes rows/cols of a kernel matrix in blocks, preventing memory issues with large datasets.
Parameters:
-
(kernelAbstractKernel) –The kernel function to use for computations.
-
(x1Float[Array, 'M D']) –First set of input points for kernel evaluation.
-
(x2Float[Array, 'N D']) –Second set of input points for kernel evaluation.
-
(max_memory_mbint, default:2 ** 10) –Maximum number of megabytes of memory to allocate for batching the kernel matrix. If
batch_sizeis provided, this is ignored. -
(batch_sizeint | None, default:None) –Number of rows/cols to materialize at once. If
None, the batch size is determined based onmax_memory_mb. -
(checkpointbool, default:False) –Whether to checkpoint the computation. This is usually necessary to prevent all materialized submatrices from being retained in memory for gradient computation.
Attributes:
-
batch_size_col(int) –Maximum number of columns to materialize at once during left mat(-vec)muls.
-
batch_size_row(int) –Maximum number of rows to materialize at once during right mat(-vec)muls.
-
max_elements(int) –Maximum number of elements to store in memory during matmul operations.
Source code in src/cagpjax/operators/lazy_kernel.py
batch_size_col
property
Maximum number of columns to materialize at once during left mat(-vec)muls.
batch_size_row
property
Maximum number of rows to materialize at once during right mat(-vec)muls.