numerics
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/types.hpp
"
18
#include "
core/vector.hpp
"
19
#include "
core/policy.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::seq (CPU) or Backend::gpu (CUDA batched, batch=1)
31
void
thomas
(
const
Vector
&
a
,
const
Vector
&
b
,
const
Vector
& c,
32
const
Vector
&
d
,
Vector
& x,
Backend
backend =
Backend::seq
);
33
34
}
// namespace num
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::Backend::seq
@ seq
Naive textbook loops – always available.
num::ipow
constexpr T ipow(T x) noexcept
Compute x^N at compile time via repeated squaring.
Definition
integer_pow.hpp:34
num::Vector
BasicVector< real > Vector
Real-valued dense vector with full backend dispatch (CPU + GPU)
Definition
vector.hpp:122
num::thomas
void thomas(const Vector &a, const Vector &b, const Vector &c, const Vector &d, Vector &x, Backend backend=Backend::seq)
Thomas algorithm (LU for tridiagonal systems), O(n).
Definition
thomas.cpp:7
policy.hpp
Backend enum for linear algebra operations.
vector.hpp
Vector operations.
include
linalg
factorization
thomas.hpp
Generated by
1.9.8