<T>LAPACK 0.1.2
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
tik_qr.hpp
Go to the documentation of this file.
1
5//
6// Copyright (c) 2025, 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_TIK_QR_HH
13#define TLAPACK_TIK_QR_HH
14
15#include <tlapack/blas/trsm.hpp>
19
31using namespace tlapack;
32
38{
39 // Initliazation for basic utilities
40 using T = type_t<matrixA_t>;
41 using idx_t = size_type<matrixA_t>;
43
45
48
49 const idx_t m = nrows(A);
50 const idx_t n = ncols(A);
51 const idx_t k = ncols(b);
52
53 // Do a QR factorization on A
54 std::vector<T> tau1_;
55 auto tau1 = new_vector(tau1_, n);
56
57 geqrf(A, tau1);
58
59 // Apply Q1.H*b
61
62 // Initailize R augmented L
63 std::vector<T> Raug_;
64 auto Raug = new_matrix(Raug_, n + n, n);
65 laset(GENERAL, real_t(0), real_t(0), Raug);
66
67 auto lam_view = slice(Raug, range{n, n + n}, range{0, n});
68
69 lacpy(UPPER_TRIANGLE, slice(A, range{0, n}, range{0, n}), Raug);
71
72 // Do a QR factorization on Raug
73 std::vector<T> tau2_;
74 auto tau2 = new_vector(tau2_, n);
75
76 geqrf(Raug, tau2);
77
78 // Initalize b augmented with zeros
79 std::vector<T> baug_;
80 auto baug = new_matrix(baug_, n + n, k);
81
82 auto b_bottom = slice(baug, range{n, n + n}, range{0, k});
83
84 lacpy(GENERAL, slice(b, range{0, n}, range{0, k}), baug);
86
87 // Apply Q2.H*(Q1.H*b)
89
90 // Solve R2*x = Q2.H*(Q1.H*b)
91 auto bview = slice(baug, range{0, n}, range{0, k});
92
94 slice(Raug, range{0, n}, range{0, n}), bview);
95
96 // Copy solution to output
98}
99#endif // TLAPACK_TIK_QR_HH
#define TLAPACK_MATRIX
Macro for tlapack::concepts::Matrix compatible with C++17.
Definition concepts.hpp:896
#define TLAPACK_REAL
Macro for tlapack::concepts::Real compatible with C++17.
Definition concepts.hpp:918
int geqrf(A_t &A, tau_t &tau, const GeqrfOpts &opts={})
Computes a QR factorization of an m-by-n matrix A using a blocked algorithm.
Definition geqrf.hpp:158
void laset(uplo_t uplo, const type_t< matrix_t > &alpha, const type_t< matrix_t > &beta, matrix_t &A)
Initializes a matrix to diagonal and off-diagonal values.
Definition laset.hpp:38
void lacpy(uplo_t uplo, const matrixA_t &A, matrixB_t &B)
Copies a matrix from A to B.
Definition lacpy.hpp:38
void trsm(Side side, Uplo uplo, Op trans, Diag diag, const alpha_t &alpha, const matrixA_t &A, matrixB_t &B)
Solve the triangular matrix-vector equation.
Definition trsm.hpp:76
int unmqr(side_t side, trans_t trans, const matrixA_t &A, const tau_t &tau, matrixC_t &C, const UnmqrOpts &opts={})
Applies orthogonal matrix op(Q) to a matrix C using a blocked code.
Definition unmqr.hpp:158
Multiplies the general m-by-n matrix C by Q from tlapack::geqrf()
Sort the numbers in D in increasing order (if ID = 'I') or in decreasing order (if ID = 'D' ).
Definition arrayTraits.hpp:15
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
constexpr internal::UpperTriangle UPPER_TRIANGLE
Upper Triangle access.
Definition types.hpp:186
constexpr internal::GeneralAccess GENERAL
General access.
Definition types.hpp:180
constexpr internal::NonUnitDiagonal NON_UNIT_DIAG
The main diagonal is not assumed to consist of 1's.
Definition types.hpp:220
constexpr internal::ConjTranspose CONJ_TRANS
conjugate transpose
Definition types.hpp:264
constexpr internal::NoTranspose NO_TRANS
no transpose
Definition types.hpp:260
constexpr internal::LeftSide LEFT_SIDE
left side
Definition types.hpp:294
void tik_qr(matrixA_t &A, matrixb_t &b, real_t lambda)
Solves Tikhonov regularized least squares using QR factorization.
Definition tik_qr.hpp:37