<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
geqr2.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_GEQR2_HH
13#define TLAPACK_GEQR2_HH
14
18
19namespace tlapack {
20
31template <class T, TLAPACK_SMATRIX matrix_t, TLAPACK_VECTOR vector_t>
32constexpr WorkInfo geqr2_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 n = ncols(A);
39
40 if (n > 1) {
41 auto&& C = cols(A, range{1, n});
43 col(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 = std::min<idx_t>(m, n - 1);
69
70 // check arguments
71 tlapack_check_false((idx_t)size(tau) < min(m, n));
72
73 // quick return
74 if (n <= 0 || m <= 0) return 0;
75
76 for (idx_t i = 0; i < k; ++i) {
77 // Define v := A[i:m,i]
78 auto v = slice(A, range{i, m}, i);
79
80 // Generate the (i+1)-th elementary Householder reflection on v
82
83 // Define C := A[i:m,i+1:n]
84 auto C = slice(A, range{i, m}, range{i + 1, n});
85
86 // C := ( I - conj(tau_i) v v^H ) C
88 work);
89 }
90 if (n - 1 < m) {
91 // Define v := A[n-1:m,n-1]
92 auto v = slice(A, range{n - 1, m}, n - 1);
93 // Generate the n-th elementary Householder reflection on v
95 }
96
97 return 0;
98}
99
131template <TLAPACK_SMATRIX matrix_t, TLAPACK_VECTOR vector_t>
133{
134 using idx_t = size_type<matrix_t>;
135 using T = type_t<matrix_t>;
136
137 // Functor
139
140 // constants
141 const idx_t m = nrows(A);
142 const idx_t n = ncols(A);
143
144 // quick return
145 if (n <= 0 || m <= 0) return 0;
146
147 // Allocates workspace
149 std::vector<T> work_;
150 auto work = new_matrix(work_, workinfo.m, workinfo.n);
151
152 return geqr2_work(A, tau, work);
153}
154
155} // namespace tlapack
156
157#endif // TLAPACK_GEQR2_HH
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 geqr2(matrix_t &A, vector_t &tau)
Computes a QR factorization of a matrix A.
Definition geqr2.hpp:132
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 geqr2_work(matrix_t &A, vector_t &tau, work_t &work)
Computes a QR factorization of a matrix A. Workspace is provided as an argument.
Definition geqr2.hpp:60
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
constexpr WorkInfo geqr2_worksize(const matrix_t &A, const vector_t &tau)
Worspace query of geqr2()
Definition geqr2.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