<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
gerq2.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_GERQ2_HH
13#define TLAPACK_GERQ2_HH
14
18
19namespace tlapack {
20
31template <class T, TLAPACK_SMATRIX matrix_t, TLAPACK_VECTOR vector_t>
32constexpr WorkInfo gerq2_worksize(const matrix_t& A, const vector_t& tau)
33{
34 using idx_t = size_type<matrix_t>;
36
37 // constants
38 const idx_t m = nrows(A);
39
40 if (m > 1) {
41 auto&& C = rows(A, range{1, m});
43 row(A, 0), tau[0], C);
44 }
45
46 return WorkInfo(0);
47}
48
57template <TLAPACK_SMATRIX matrix_t,
58 TLAPACK_VECTOR vector_t,
59 TLAPACK_WORKSPACE work_t>
61{
62 using idx_t = size_type<matrix_t>;
64
65 // constants
66 const idx_t m = nrows(A);
67 const idx_t n = ncols(A);
68 const idx_t k = min(m, n);
69
70 // check arguments
71 tlapack_check_false((idx_t)size(tau) < k);
72
73 // quick return
74 if (n <= 0) return 0;
75
76 for (idx_t i2 = 0; i2 < k; ++i2) {
77 idx_t i = k - 1 - i2;
78
79 // Define v := A[m-1-i2,0:n-i2]
80 auto v = slice(A, m - 1 - i2, range{0, n - i2});
81
82 // Generate the (i+1)-th elementary Householder reflection on v
84
85 // Apply the reflector to the rest of the matrix
86 if (m > i2 + 1) {
87 auto C = slice(A, range{0, m - 1 - i2}, range{0, n - i2});
89 work);
90 }
91 }
92
93 return 0;
94}
95
129template <TLAPACK_SMATRIX matrix_t, TLAPACK_VECTOR vector_t>
131{
132 using idx_t = size_type<matrix_t>;
133 using T = type_t<matrix_t>;
134
135 // functor
137
138 // constants
139 const idx_t n = ncols(A);
140
141 // quick return
142 if (n <= 0) return 0;
143
144 // Allocates workspace
146 std::vector<T> work_;
147 auto work = new_matrix(work_, workinfo.m, workinfo.n);
148
149 return gerq2_work(A, tau, work);
150}
151
152} // namespace tlapack
153
154#endif // TLAPACK_GERQ2_HH
constexpr internal::Backward BACKWARD
Backward direction.
Definition types.hpp:378
constexpr internal::RightSide RIGHT_SIDE
right side
Definition types.hpp:291
constexpr internal::RowwiseStorage ROWWISE_STORAGE
Rowwise storage.
Definition types.hpp:411
#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 gerq2(matrix_t &A, vector_t &tau)
Computes an RQ factorization of a matrix A.
Definition gerq2.hpp:130
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 gerq2_work(matrix_t &A, vector_t &tau, work_t &work)
Computes an RQ factorization of a matrix A. Workspace is provided as an argument.
Definition gerq2.hpp:60
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
constexpr WorkInfo gerq2_worksize(const matrix_t &A, const vector_t &tau)
Worspace query of gerq2()
Definition gerq2.hpp:32
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