Source code for femorph_solver.solvers.linear._superlu

"""SuperLU direct sparse solver via ``scipy.sparse.linalg.splu``.

Default backend — always available because SciPy ships SuperLU.  Handles
general (nonsymmetric) sparse ``A``; uses the Sherman-family permutation
``MMD_AT_PLUS_A`` by default — the standard heuristic for
SPD problems.

References
----------
- Demmel, J. W., Eisenstat, S. C., Gilbert, J. R., Li, X. S., &
  Liu, J. W. H.  "A Supernodal Approach to Sparse Partial Pivoting."
  SIAM J. Matrix Anal. Appl. 20 (3), 720-755 (1999).
  [right-looking supernodal LU — the core SuperLU algorithm]
- Li, X. S.  "An Overview of SuperLU: Algorithms, Implementation,
  and User Interface."  ACM Trans. Math. Softw. 31 (3), 302-325
  (2005).  [shipped implementation wrapped by SciPy]
"""

from __future__ import annotations

from typing import ClassVar

import numpy as np
import scipy.sparse.linalg as spla

from ._base import LinearSolverBase


[docs] class SuperLUSolver(LinearSolverBase): """SciPy's bundled SuperLU (always available).""" name: ClassVar[str] = "superlu" kind: ClassVar[str] = "direct" spd_only: ClassVar[bool] = False install_hint: ClassVar[str] = "bundled with SciPy — no install needed" def _factor(self, A): self._lu = spla.splu(A.tocsc(), permc_spec="MMD_AT_PLUS_A")
[docs] def solve(self, b: np.ndarray) -> np.ndarray: return self._lu.solve(np.ascontiguousarray(b, dtype=np.float64))