laplax.util.mv
Matrix-free array operations for matrix-vector products.
diagonal ¶
diagonal(mv: Callable | ndarray, layout: Layout | None = None, *, mv_jittable: bool = True, **kwargs: Kwargs) -> Array
Compute the diagonal of a matrix represented by a matrix-vector product function.
This function extracts the diagonal of a matrix using basis vectors and a matrix-vector product (MVP) function. If the input is already a dense matrix, its diagonal is directly computed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mv
|
Callable | ndarray
|
Either:
|
required |
layout
|
Layout | None
|
Specifies the structure of the matrix:
|
None
|
mv_jittable
|
bool
|
Whether to JIT compile the basis vector generator. |
True
|
**kwargs
|
Kwargs
|
diagonal_batch_size: Batch size for applying the MVP function. |
{}
|
Returns:
Type | Description |
---|---|
Array
|
An array representing the diagonal of the matrix. |
Raises:
Type | Description |
---|---|
TypeError
|
If |
Source code in laplax/util/mv.py
to_dense ¶
Generate a dense matrix representation from a matrix-vector product function.
Converts a matrix-vector product function into its equivalent dense matrix form by applying the function to identity-like basis vectors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mv
|
Callable
|
A callable implementing the matrix-vector product function. |
required |
layout
|
Layout
|
Specifies the structure of the input:
|
required |
**kwargs
|
Kwargs
|
Additional options:
|
{}
|
Returns:
Type | Description |
---|---|
Array
|
A dense matrix representation of the MVP function. |
Raises:
Type | Description |
---|---|
TypeError
|
If |