numerics
0.1.0
Loading...
Searching...
No Matches
thomas.hpp
Go to the documentation of this file.
1
/// @file factorization/thomas.hpp
2
/// @brief Thomas algorithm -- direct O(n) tridiagonal solver
3
///
4
/// Solves the tridiagonal system:
5
///
6
/// [ b[0] c[0] ] [ x[0] ] [ d[0] ]
7
/// [ a[0] b[1] c[1] ] [ x[1] ] = [ d[1] ]
8
/// [ a[1] b[2] c[2] ] [ x[2] ] [ d[2] ]
9
/// [ ... ... ... ] [ : ] [ : ]
10
/// [ a[n-2] b[n-1] ] [ x[n-1] ] [ d[n-1] ]
11
///
12
/// Algorithm: LU factorisation of the tridiagonal structure, O(n) time and
13
/// O(n) extra space. Numerically stable for strictly diagonally dominant
14
/// or symmetric positive definite tridiagonals; may fail for singular pivots.
15
#pragma once
16
17
#include "
core/policy.hpp
"
18
#include "
core/types.hpp
"
19
#include "
core/vector.hpp
"
20
21
namespace
num
{
22
23
/// @brief Thomas algorithm (LU for tridiagonal systems), O(n).
24
///
25
/// @param a Sub-diagonal, size n-1
26
/// @param b Main diagonal, size n
27
/// @param c Super-diagonal, size n-1
28
/// @param d Right-hand side vector, size n
29
/// @param x Solution vector (output), size n
30
/// @param backend Backend::lapack uses LAPACKE_dgtsv (default when available).
31
/// Backend::seq uses our 3-sweep O(n) implementation.
32
/// Backend::gpu uses CUDA batched tridiagonal (batch=1).
33
void
thomas
(
const
Vector
&a,
const
Vector
&b,
const
Vector
&c,
const
Vector
&d,
34
Vector
&x,
Backend
backend =
lapack_backend
);
35
36
}
// namespace num
policy.hpp
Backend enum for linear algebra operations.
types.hpp
Core type definitions.
num
Definition
quadrature.hpp:8
num::Backend
Backend
Selects which backend handles a linalg operation.
Definition
policy.hpp:19
num::thomas
void thomas(const Vector &a, const Vector &b, const Vector &c, const Vector &d, Vector &x, Backend backend=lapack_backend)
Thomas algorithm (LU for tridiagonal systems), O(n).
Definition
thomas.cpp:17
num::lapack_backend
constexpr Backend lapack_backend
Definition
policy.hpp:124
num::Vector
BasicVector< real > Vector
Real-valued dense vector with full backend dispatch (CPU + GPU)
Definition
vector.hpp:130
vector.hpp
Vector operations.
include
linalg
factorization
thomas.hpp
Generated by
1.9.8