<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
pttrf.hpp
Go to the documentation of this file.
1
4//
5// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
6//
7// This file is part of <T>LAPACK.
8// <T>LAPACK is free software: you can redistribute it and/or modify it under
9// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
10
11#ifndef TLAPACK_PTTRF_HH
12#define TLAPACK_PTTRF_HH
13
15
16namespace tlapack {
17
46template <class d_t,
47 class e_t,
48 enable_if_t<is_same_v<real_type<type_t<d_t>>, real_type<type_t<e_t>>>,
49 int> = 0>
50int pttrf(d_t& D, e_t& E, const EcOpts& opts = {})
51{
52 using T = type_t<d_t>;
53 using real_t = real_type<T>;
54 using idx_t = size_type<d_t>;
55 // Constants
56 const idx_t n = size(D);
57 // check arguments
58 tlapack_check(size(D) == size(E) + 1);
59 // Quick return
60 if (n <= 0) return 0;
61 for (idx_t i = 0; i < n - 1; ++i) {
62 if (real(D[i]) <= real_t(0)) {
64 opts.ec.internal, i + 1,
65 "The leading minor of the reported order is not positive "
66 "definite,"
67 " and the factorization could not be completed.");
68 return i + 1;
69 }
70 T Ei = E[i];
71 E[i] = Ei / real(D[i]);
72 D[i + 1] -= real(E[i] * conj(Ei));
73 }
74 if (real(D[n - 1]) <= real_t(0)) {
76 opts.ec.internal, n,
77 "The leading minor of the highest order is not positive "
78 "definite.");
79 return n;
80 }
81 return 0;
82}
83
84} // namespace tlapack
85
86#endif // TLAPACK_PTTRF_HH
constexpr real_type< T > real(const T &x) noexcept
Extends std::real() to real datatypes.
Definition utils.hpp:71
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
#define tlapack_error_if(cond, info, detailedInfo)
Error handler with conditional.
Definition exceptionHandling.hpp:171
#define tlapack_check(cond)
Throw an error if cond is false.
Definition exceptionHandling.hpp:98
int pttrf(d_t &D, e_t &E, const EcOpts &opts={})
Computes the Cholesky factorization of a Hermitian positive definite tridiagonal matrix A.
Definition pttrf.hpp:50
typename traits::real_type_traits< Types..., int >::type real_type
The common real type of the list of types.
Definition scalar_type_traits.hpp:113
Options for error checking.
Definition exceptionHandling.hpp:76