<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
ungtr.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
5//
6// This file is part of <T>LAPACK.
7// <T>LAPACK is free software: you can redistribute it and/or modify it under
8// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
9
10#ifndef TLAPACK_UNGTR_HH
11#define TLAPACK_UNGTR_HH
12
16
17namespace tlapack {
18
41template <TLAPACK_SMATRIX Q_t, TLAPACK_SVECTOR tau_t, class uplo_t>
42int ungtr(uplo_t uplo, Q_t& Q, const tau_t& tau)
43{
44 using T = type_t<Q_t>;
45 using real_t = real_type<T>;
46 using idx_t = size_type<Q_t>;
47 using pair = pair<idx_t, idx_t>;
48
49 // constants
50 const idx_t n = ncols(Q);
51 const real_t one(1);
52 const real_t zero(0);
53
54 // Quick return if possible
55 if (n == 0) return 0;
56
57 if (uplo == Uplo::Lower) {
58 // Move the reflectors in Q
59 for (idx_t j2 = n - 1; j2 > 1; --j2) {
60 idx_t j = j2 - 1;
61 for (idx_t i = j + 1; i < n; ++i)
62 Q(i, j) = Q(i, j - 1);
63 }
64
65 // Complete Q with the identity
66 for (idx_t i = 1; i < n; ++i) {
67 Q(i, 0) = zero;
68 Q(0, i) = zero;
69 }
70 Q(0, 0) = one;
71
72 // Compute the Q part that use the reflectors
73 auto Qrefl = slice(Q, pair(1, n), pair(1, n));
74 // Todo: use workspace
75 return ungqr(Qrefl, tau);
76 }
77 else {
78 // Move the reflectors in Q
79 for (idx_t j = 1; j < n - 1; ++j)
80 for (idx_t i = 0; i < j; ++i)
81 Q(i, j) = Q(i, j + 1);
82
83 // Complete Q with the identity
84 for (idx_t i = 0; i < n - 1; ++i) {
85 Q(i, n - 1) = zero;
86 Q(n - 1, i) = zero;
87 }
88 Q(n - 1, n - 1) = one;
89
90 // Compute the Q part that use the reflectors
91 auto Qrefl = slice(Q, pair(0, n - 1), pair(0, n - 1));
92 // Todo: use workspace
93 return ungql(Qrefl, tau);
94 }
95}
96
97} // namespace tlapack
98
99#endif // TLAPACK_UNGTR_HH
int ungqr(matrix_t &A, const vector_t &tau, const UngqrOpts &opts={})
Generates a matrix Q with orthogonal columns.
Definition ungqr.hpp:52
int ungql(matrix_t &A, const vector_t &tau, const UngqlOpts &opts={})
Generates an m-by-n matrix Q with orthonormal columns, which is defined as the last n columns of a pr...
Definition ungql.hpp:55
int ungtr(uplo_t uplo, Q_t &Q, const tau_t &tau)
Generates a real orthogonal matrix Q which is defined as the product of k elementary reflectors of or...
Definition ungtr.hpp:42
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