Linear Algebra Module#

Linear systems and preconditioners.

Linear System#

class rlaopt.linalg.LinSys(A, B, reg=0.0, w=None)[source]#

Bases: Module

Module for regularized linear systems (A + reg * I)w = B.

Parameters:
__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:

torch.Tensor

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:

torch.Tensor

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:

torch.Tensor

property device: device#

Get the device of the LinSys module.

Returns:

Device where the module’s tensors are located.

Return type:

torch.device

property dtype: dtype#

Get the data type of the LinSys module.

Returns:

Data type of the module’s tensors.

Return type:

torch.dtype

property rhs_norm: Tensor#

Get the norm of the right-hand side B.

Returns:

Norm of B.

Return type:

torch.Tensor

Preconditioner Configuration#

pydantic model rlaopt.linalg.PreconditionerConfig[source]#

Base configuration class for preconditioners.

Return type:

None

pydantic model rlaopt.linalg.IdentityConfig[source]#

Configuration for the Identity preconditioner.

Return type:

None

pydantic model rlaopt.linalg.NystromConfig[source]#

Configuration for the Nyström preconditioner.

Validators:
  • validate_rank_max » all fields

Parameters:
  • rank_init (int)

  • rank_max (int | None)

  • num_power_iters (int)

  • error_tolerance (float)

  • base_damping (float)

  • damping_mode (Literal['adaptive', 'non_adaptive'])

Return type:

None

field rank_init: int [Required]#

Initial rank of the Nyström approximation.

Constraints:
  • gt = 0

Validated by:
  • validate_rank_max

field rank_max: int | None = None#

Maximum allowable rank.

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

field base_damping: float [Required]#

Base damping parameter.

Constraints:
  • ge = 0.0

Validated by:
  • validate_rank_max

field damping_mode: Literal['adaptive', 'non_adaptive'] = 'adaptive'#

Damping mode: ‘adaptive’ adjusts based on smallest eigenvalue, ‘non_adaptive’ uses base_damping only.

Validated by:
  • validate_rank_max