<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
gebd2.hpp
Go to the documentation of this file.
1
6//
7// Copyright (c) 2021-2023, University of Colorado Denver. All rights reserved.
8//
9// This file is part of <T>LAPACK.
10// <T>LAPACK is free software: you can redistribute it and/or modify it under
11// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
12
13#ifndef TLAPACK_GEBD2_HH
14#define TLAPACK_GEBD2_HH
15
19
20namespace tlapack {
21
35template <class T, TLAPACK_SMATRIX matrix_t, TLAPACK_VECTOR vector_t>
37 const vector_t& tauv,
38 const vector_t& tauw)
39{
40 using idx_t = size_type<matrix_t>;
42
43 // constants
44 const idx_t m = nrows(A);
45 const idx_t n = ncols(A);
46
48 if (n > 1) {
49 auto&& A11 = cols(A, range{1, n});
51 col(A, 0), tauv[0], A11);
52
53 if (m > 1) {
54 auto&& B11 = rows(A11, range{1, m});
55 auto&& row0 = slice(A, 0, range{1, n});
56
59 }
60 }
61
62 return workinfo;
63}
64
73template <TLAPACK_SMATRIX matrix_t,
74 TLAPACK_VECTOR vector_t,
75 TLAPACK_WORKSPACE work_t>
77{
78 using idx_t = size_type<matrix_t>;
80 using T = type_t<matrix_t>;
81
82 // constants
83 const idx_t m = nrows(A);
84 const idx_t n = ncols(A);
85
86 // check arguments
87 tlapack_check_false((idx_t)size(tauv) < min(m, n));
88 tlapack_check_false((idx_t)size(tauw) < min(m, n));
89
90 // quick return
91 if (n <= 0) return 0;
92
93 if (m >= n) {
94 //
95 // Reduce to upper bidiagonal form
96 //
97 for (idx_t j = 0; j < n; ++j) {
98 // Generate elementary reflector H(j) to annihilate A(j+1:m,j)
99 auto v = slice(A, range(j, m), j);
101
102 if (j < n - 1) {
103 // Apply H(j)**H to A(j:m,j+1:n) from the left
104 auto A11 = slice(A, range(j, m), range(j + 1, n));
106 conj(tauv[j]), A11, work);
107
108 // Generate elementary reflector G(j) to annihilate A(j,j+2:n)
109 auto w = slice(A, j, range(j + 1, n));
111
112 // Apply G(j) to A(j+1:m,j+1:n) from the right
113 if (j < m - 1) {
114 auto B11 = slice(A, range(j + 1, m), range(j + 1, n));
116 B11, work);
117 }
118 }
119 else {
120 tauw[j] = T(0);
121 }
122 }
123 }
124 else {
125 //
126 // Reduce to lower bidiagonal form
127 //
128 for (idx_t j = 0; j < m; ++j) {
129 // Generate elementary reflector G(j) to annihilate A(j,j+1:n)
130 auto w = slice(A, j, range(j, n));
132
133 if (j < m - 1) {
134 // Apply G(j) to A(j+1:m,j:n) from the right
135 auto A11 = slice(A, range(j + 1, m), range(j, n));
137 work);
138
139 // Generate elementary reflector H(j) to annihilate A(j+2:m,j)
140 auto v = slice(A, range(j + 1, m), j);
142
143 // Apply H(j)**H to A(j+1:m,j+1:n) from the left
144 if (j < n - 1) {
145 auto B11 = slice(A, range(j + 1, m), range(j + 1, n));
147 conj(tauv[j]), B11, work);
148 }
149 }
150 else {
151 tauv[j] = T(0);
152 }
153 }
154 }
155
156 return 0;
157}
158
209template <TLAPACK_SMATRIX matrix_t, TLAPACK_VECTOR vector_t>
211{
212 using idx_t = size_type<matrix_t>;
213 using T = type_t<matrix_t>;
214
215 // Functors
217
218 // constants
219 const idx_t n = ncols(A);
220
221 // quick return
222 if (n <= 0) return 0;
223
224 // Allocates workspace
226 std::vector<T> work_;
227 auto work = new_matrix(work_, workinfo.m, workinfo.n);
228
229 return gebd2_work(A, tauv, tauw, work);
230}
231
232} // namespace tlapack
233
234#endif // TLAPACK_GEBD2_HH
constexpr internal::RightSide RIGHT_SIDE
right side
Definition types.hpp:291
constexpr internal::RowwiseStorage ROWWISE_STORAGE
Rowwise storage.
Definition types.hpp:411
constexpr internal::Forward FORWARD
Forward direction.
Definition types.hpp:376
constexpr internal::ColumnwiseStorage COLUMNWISE_STORAGE
Columnwise storage.
Definition types.hpp:409
constexpr internal::LeftSide LEFT_SIDE
left side
Definition types.hpp:289
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
#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
#define TLAPACK_VECTOR
Macro for tlapack::concepts::Vector compatible with C++17.
Definition concepts.hpp:906
int gebd2(matrix_t &A, vector_t &tauv, vector_t &tauw)
Reduces a general m by n matrix A to an upper real bidiagonal form B by a unitary transformation:
Definition gebd2.hpp:210
void larfg(storage_t storeMode, type_t< vector_t > &alpha, vector_t &x, type_t< vector_t > &tau)
Generates a elementary Householder reflection.
Definition larfg.hpp:73
void larf_work(side_t side, storage_t storeMode, vector_t const &x, const tau_t &tau, vectorC0_t &C0, matrixC1_t &C1, work_t &work)
Applies an elementary reflector defined by tau and v to a m-by-n matrix C decomposed into C0 and C1....
Definition larf.hpp:48
int gebd2_work(matrix_t &A, vector_t &tauv, vector_t &tauw, work_t &work)
Reduces a general m by n matrix A to an upper real bidiagonal form B by a unitary transformation: W...
Definition gebd2.hpp:76
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
constexpr WorkInfo gebd2_worksize(const matrix_t &A, const vector_t &tauv, const vector_t &tauw)
Worspace query of gebd2().
Definition gebd2.hpp:36
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