<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
unghr.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_UNGHR_HH
13#define TLAPACK_UNGHR_HH
14
17
18namespace tlapack {
19
38template <class T, TLAPACK_SMATRIX matrix_t, TLAPACK_SVECTOR vector_t>
41 const matrix_t& A,
42 const vector_t& tau)
43{
44 using idx_t = size_type<matrix_t>;
46
47 // constants
48 const idx_t nh = (ihi > ilo + 1) ? ihi - 1 - ilo : 0;
49
50 if (nh > 0 && ilo + 1 < ihi) {
51 auto&& A_s = slice(A, range{ilo + 1, ihi}, range{ilo + 1, ihi});
52 auto&& tau_s = slice(tau, range{ilo, ihi - 1});
54 }
55 return WorkInfo(0);
56}
57
66template <TLAPACK_SMATRIX matrix_t,
67 TLAPACK_SVECTOR vector_t,
68 TLAPACK_WORKSPACE work_t>
71 matrix_t& A,
72 const vector_t& tau,
73 work_t& work)
74{
75 using T = type_t<matrix_t>;
76 using real_t = real_type<T>;
77 using idx_t = size_type<matrix_t>;
79
80 // constants
81 const real_t zero(0);
82 const real_t one(1);
83 const idx_t m = nrows(A);
84 const idx_t n = ncols(A);
85 const idx_t nh = ihi > ilo + 1 ? ihi - 1 - ilo : 0;
86
87 // check arguments
88 tlapack_check_false((idx_t)size(tau) < min(m, n));
89
90 // Shift the vectors which define the elementary reflectors one
91 // column to the right, and set the first ilo and the last n-ihi
92 // rows and columns to those of the unit matrix
93
94 // This is currently optimised for column matrices, it may be interesting
95 // to also write these loops for row matrices
96 for (idx_t j = ihi - 1; j > ilo; --j) {
97 for (idx_t i = 0; i < j; ++i) {
98 A(i, j) = zero;
99 }
100 for (idx_t i = j + 1; i < ihi; ++i) {
101 A(i, j) = A(i, j - 1);
102 }
103 for (idx_t i = ihi; i < n; ++i) {
104 A(i, j) = zero;
105 }
106 }
107 for (idx_t j = 0; j < ilo + 1; ++j) {
108 for (idx_t i = 0; i < n; ++i) {
109 A(i, j) = zero;
110 }
111 A(j, j) = one;
112 }
113 for (idx_t j = ihi; j < n; ++j) {
114 for (idx_t i = 0; i < n; ++i) {
115 A(i, j) = zero;
116 }
117 A(j, j) = one;
118 }
119
120 // Now that the vectors are shifted, we can call orgqr to generate the
121 // matrix orgqr is not yet implemented, so we call org2r instead
122 if (nh > 0) {
123 auto A_s = slice(A, range{ilo + 1, ihi}, range{ilo + 1, ihi});
124 auto tau_s = slice(tau, range{ilo, ihi - 1});
126 }
127 else {
128 return 0;
129 }
130}
131
150template <TLAPACK_SMATRIX matrix_t, TLAPACK_SVECTOR vector_t>
153 matrix_t& A,
154 const vector_t& tau)
155{
156 using T = type_t<matrix_t>;
157
158 // Functor
160
161 // Allocates workspace
163 std::vector<T> work_;
164 auto work = new_matrix(work_, workinfo.m, workinfo.n);
165
166 return unghr_work(ilo, ihi, A, tau, work);
167}
168
169} // namespace tlapack
170
171#endif // TLAPACK_UNGHR_HH
constexpr internal::Forward FORWARD
Forward direction.
Definition types.hpp:376
constexpr internal::ColumnwiseStorage COLUMNWISE_STORAGE
Columnwise storage.
Definition types.hpp:409
#define TLAPACK_SVECTOR
Macro for tlapack::concepts::SliceableVector compatible with C++17.
Definition concepts.hpp:909
#define TLAPACK_SMATRIX
Macro for tlapack::concepts::SliceableMatrix compatible with C++17.
Definition concepts.hpp:899
#define TLAPACK_WORKSPACE
Macro for tlapack::concepts::Workspace compatible with C++17.
Definition concepts.hpp:912
int ungq_work(direction_t direction, storage_t storeMode, matrix_t &A, const vector_t &tau, work_t &work, const UngqOpts &opts={})
Generates a matrix Q that is the product of elementary reflectors. Workspace is provided as an argu...
Definition ungq.hpp:138
int unghr_work(size_type< matrix_t > ilo, size_type< matrix_t > ihi, matrix_t &A, const vector_t &tau, work_t &work)
Generates a m-by-n matrix Q with orthogonal columns. Workspace is provided as an argument.
Definition unghr.hpp:69
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
int unghr(size_type< matrix_t > ilo, size_type< matrix_t > ihi, matrix_t &A, const vector_t &tau)
Generates a m-by-n matrix Q with orthogonal columns.
Definition unghr.hpp:151
constexpr WorkInfo unghr_worksize(size_type< matrix_t > ilo, size_type< matrix_t > ihi, const matrix_t &A, const vector_t &tau)
Worspace query of unghr()
Definition unghr.hpp:39
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
Output information in the workspace query.
Definition workspace.hpp:16