Skip to content

Instantly share code, notes, and snippets.

@frapac
Created June 7, 2021 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frapac/12149b111005d341ec67d0378ecb131a to your computer and use it in GitHub Desktop.
Save frapac/12149b111005d341ec67d0378ecb131a to your computer and use it in GitHub Desktop.
An abstract interface for (direct and iterative) linear solvers.
abstract type AbstractLinearSolver end
"""
introduce(solver::AbstractLinearSolver)
Print the name of the linear system.
"""
function introduce end
####
# Direct linear solver
####
abstract type DirectLinearSolver <: AbstractLinearSolver end
"Sparse direct linear solver"
abstract type SparseDirectLinearSolver <: DirectLinearSolver end
"Dense direct linear solver"
abstract type DenseDirectLinearSolver <: DirectLinearSolver end
"""
factorize!(solver::DirectLinearSolver, M::AbstractMatrix)
Factorize the matrix `M` with linear solver `solver`.
"""
function factorize! end
# TODO: determine if we should support multiple right hand side here
"""
triangular_solve!(solver::DirectLinearSolver, x::AbstractVector, y::AbstractLinearSolver)
Solve the triangular system ``L x = y` with factorization stored inside solver.
"""
function triangular_solve! end
"""
solve!(solver::DirectLinearSolver, x::AbstractVector, M::AbstractMatrix, y::AbstractVector)
Solve linear system ``M x = y`` with linear solver `solver`. Factorization
is updated directly inside `solver`.
"""
function solve!(solver::DirectLinearSolver, x::AbstractVector, M::AbstractMatrix, y::AbstractVector)
factorize!(solver, M)
triangular_solve!(solver, x, y)
end
"""
has_inertia(solver::DirectLinearSolver)
Return `true` if we can compute inertia with linear solver `solver`.
"""
function has_inertia end
"""
inertia(solver::DirectLinearSolver)
Return inertia `(m, n, p)::Tuple{Int, Int, Int}` computed with
linear solver `solver`, provided it supports inertia (`has_inertia(solver) = true`).
"""
function inertia end
"""
can_improve(::DirectLinearSolver)
Return whether solution can be improved (useful for HSL's solvers).
"""
function can_improve end
####
# Iterative linear solver
####
"Iterative linear solver"
abstract type IterativeLinearSolver <: AbstractLinearSolver end
"""
solve!(solver::IterativeLinearSolver, x::AbstractVector, M::AbstractMatrix, y::AbstractVector)
Use iterative linear solver `solver` to solve the linear system ``M x = y``.
"""
####
# Linear system scaler
####
## N.B: useful to wrap HSL MC19
"Utilities to scale the linear system during presolve."
abstract type AbstractLinearSystemScaler end
"""
scale!(scaler::AbstractLinearSystemScaler, M::AbstractMatrix)
Scale matrix `M` with linear system scaler `scaler`.
"""
function scale! end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment