Debian Codegraph @

packages/kokkos-kernels/batched/dense/impl/KokkosBatched_WilkinsonShift_Serial_Internal.hpp

raw
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 #ifndef KOKKOSBATCHED_WILKINSON_SHIFT_SERIAL_INTERNAL_HPP
17 #define KOKKOSBATCHED_WILKINSON_SHIFT_SERIAL_INTERNAL_HPP
18
19 /// \author Kyungjoo Kim ([email protected])
20
21 #include "KokkosBatched_Util.hpp"
22
23 namespace KokkosBatched {
24 ///
25 /// Serial Internal Impl
26 /// ====================
27 ///
28 /// this impl follows the flame interface of householder transformation
29 ///
30 struct SerialWilkinsonShiftInternal {
31 template <typename ValueType>
32 KOKKOS_INLINE_FUNCTION static int invoke(const ValueType a, const ValueType b, const ValueType c, const ValueType d,
33 /* */ Kokkos::complex<ValueType>* lambda1,
34 /* */ Kokkos::complex<ValueType>* lambda2,
35 /* */ bool* is_complex) {
36 /// compute eigenvalues of 2x2 system [a b;
37 /// c d]
38 /// when the system has a real complex values,
39 /// lambda1 and lambda2 are real eigenvalues
40 /// if the system has a complex eigenvalue pair,
41 /// then lambda1 and lambda2 are redefined as follows
42 /// lambda1 := lambda1 + lambda2
43 /// lambda2 := lambda1 * lambda2
44 typedef ValueType value_type;
45
46 const value_type half(0.5);
47 const value_type p = (a + d) * half;
48 const value_type q = (b * c - a * d);
49 const value_type v = p * p + q;
50
51 if (v < 0) {
52 // complex
53 const value_type sqrt_v = Kokkos::ArithTraits<value_type>::sqrt(-v);
54 *lambda1 = Kokkos::complex<value_type>(p, sqrt_v);
55 *lambda2 = Kokkos::complex<value_type>(p, -sqrt_v);
56 *is_complex = true;
57 } else {
58 // real
59 const value_type sqrt_v = Kokkos::ArithTraits<value_type>::sqrt(v);
60 *lambda1 = Kokkos::complex<value_type>(p + sqrt_v);
61 *lambda2 = Kokkos::complex<value_type>(p - sqrt_v);
62 *is_complex = false;
63 }
64 return 0;
65 }
66 };
67
68 } // end namespace KokkosBatched
69
70 #endif