num::thomas¶
Defined in header <linear/factorization/thomas.hpp>
template <typename Float = double>
void thomas(const vec<Float> &a, const vec<Float> &b, const vec<Float> &c,
const vec<Float> &d, vec<Float> &x);
Solve tridiagonal linear system \(a_{i-1} x_{i-1} + b_i x_i + c_i x_{i+1} = d_i\) in \(\mathcal{O}(n)\) time.
Executes the Thomas algorithm (specialized Gaussian elimination for tridiagonal systems) with zero heap allocations. Picks LAPACK (dgtsv) if configured, else the in-tree sequential elimination. To force a specific one (including the CUDA batched kernel when built with CUDA), call num::lapack::thomas/num::seq::thomas/num::cuda::thomas.
Template parameters¶
Float: Floating-point scalar type (double,float).
Parameters¶
a: Subdiagonal entries (\(n-1\) elements: \(a_0, \dots, a_{n-2}\)).b: Main diagonal entries (\(n\) elements: \(b_0, \dots, b_{n-1}\)).c: Superdiagonal entries (\(n-1\) elements: \(c_0, \dots, c_{n-2}\)).d: Right-hand side vector (\(n\) elements).x: Output solution vector (\(n\) elements).
Exceptions¶
std::invalid_argument: If dimensions do not match (\(a, c\) size \(n-1\), \(b, d, x\) size \(n\)).