<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
singularvalues22.hpp
Go to the documentation of this file.
1
5//
6// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
7//
8// This file is part of <T>LAPACK.
9// <T>LAPACK is free software: you can redistribute it and/or modify it under
10// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
11
12#ifndef TLAPACK_SINGULARVALUES22_HH
13#define TLAPACK_SINGULARVALUES22_HH
14
17
18namespace tlapack {
19
39template <typename T, enable_if_t<!is_complex<T>, bool> = true>
40void singularvalues22(const T& f, const T& g, const T& h, T& ssmin, T& ssmax)
41{
42 const T zero(0);
43 const T one(1);
44 const T two(2);
45
46 T fa = abs(f);
47 T ga = abs(g);
48 T ha = abs(h);
49 T fhmn = min(fa, ha);
50 T fhmx = max(fa, ha);
51 if (fhmn == zero) {
52 ssmin = zero;
53 if (fhmx == zero)
54 ssmax = ga;
55 else
56 ssmax = max(fhmx, ga) *
57 sqrt(one + square(min(fhmx, ga) / max(fhmx, ga)));
58 }
59 else {
60 T as, at, au, c;
61 if (ga < fhmx) {
62 as = one + fhmn / fhmx;
63 at = (fhmx - fhmn) / fhmx;
64 au = square(ga / fhmx);
65 c = two / (sqrt(as * as + au) + sqrt(at * at + au));
66 ssmin = fhmn * c;
67 ssmax = fhmx / c;
68 }
69 else {
70 au = fhmx / ga;
71 if (au == zero) {
72 // Avoid possible harmful underflow if exponent range
73 // asymmetric (true ssmin may not underflow even if
74 // au underflows)
75 ssmin = (fhmn * fhmx) / ga;
76 ssmax = ga;
77 }
78 else {
79 as = one + fhmn / fhmx;
80 at = (fhmx - fhmn) / fhmx;
81 c = one /
82 (sqrt(one + square(as * au)) + sqrt(one + square(at * au)));
83 ssmin = (fhmn * c) * au;
84 ssmin = ssmin + ssmin;
85 ssmax = ga / (c + c);
86 }
87 }
88 }
89}
90
91} // namespace tlapack
92
93#endif // TLAPACK_SINGULARVALUES22_HH
void singularvalues22(const T &f, const T &g, const T &h, T &ssmin, T &ssmax)
Computes the singular value decomposition of a 2-by-2 real triangular matrix.
Definition singularvalues22.hpp:40
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