Linear Algebra Module#
Linear systems and preconditioners.
Linear System#
- class rlaopt.linalg.LinSys(A, B, reg=0.0, w=None)[source]#
Bases:
ModuleModule for regularized linear systems (A + reg * I)w = B.
- __init__(A, B, reg=0.0, w=None)[source]#
Initialize LinSys module.
- Parameters:
A (torch.Tensor | LinearOperator) – Square matrix defining the linear system.
B (torch.Tensor) –
Right-hand side of the linear system. Must be 1D or 2D. If 1D with shape (N,), it is automatically resized
to 2D with shape (N, 1).
reg (float | torch.Tensor) –
Non-negative regularization parameter. Defaults to 0.0.
Using a tensor allows for differentiation with respect to reg.
w (torch.Tensor | None) – Initial guess for the solution. Defaults to None.
- forward(v)[source]#
Apply the linear operator (A + reg * I) to tensor v.
- Parameters:
v (torch.Tensor) – Input tensor.
- Returns:
Result of applying the linear operator to v.
- Return type:
- compute_residual(v)[source]#
Compute the residual of the linear system for a given tensor v.
- Parameters:
v (torch.Tensor) – Input tensor.
- Returns:
Residual of the linear system.
- Return type:
- compute_residual_norm(v, relative=False)[source]#
Compute the residual norm of the linear system for a given tensor v.
- Parameters:
v (torch.Tensor) – Input tensor.
relative (bool) – If True, return the relative residual norm. Defaults to False.
- Returns:
Residual norm of the linear system.
- Return type:
- property device: device#
Get the device of the LinSys module.
- Returns:
Device where the module’s tensors are located.
- Return type:
- property dtype: dtype#
Get the data type of the LinSys module.
- Returns:
Data type of the module’s tensors.
- Return type:
Preconditioner Configuration#
- pydantic model rlaopt.linalg.PreconditionerConfig[source]#
Base configuration class for preconditioners.
- Return type:
- pydantic model rlaopt.linalg.IdentityConfig[source]#
Configuration for the Identity preconditioner.
- Return type:
- pydantic model rlaopt.linalg.NystromConfig[source]#
Configuration for the Nyström preconditioner.
- Validators:
validate_rank_max»all fields
- Parameters:
- Return type:
- field rank_init: int [Required]#
Initial rank of the Nyström approximation.
- Constraints:
gt = 0
- Validated by:
validate_rank_max
- field num_power_iters: int = 10#
Number of power iterations for error estimation in rank adaptation.
- Constraints:
gt = 0
- Validated by:
validate_rank_max
- field error_tolerance: float = 0.01#
Error tolerance for rank adaptation.
- Constraints:
gt = 0.0
- Validated by:
validate_rank_max