<T>LAPACK 0.1.2
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
mult_uhu.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2025, University of Colorado Denver. All rights reserved.
5//
6// This file is part of <T>LAPACK.
7// <T>LAPACK is free software: you can redistribute it and/or modify it under
8// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
9
10#ifndef TLAPACK_MULT_UHU
11#define TLAPACK_MULT_UHU
12
14#include "tlapack/blas/herk.hpp"
15#include "tlapack/blas/trmm.hpp"
16
17namespace tlapack {
18
23 size_t nx = 1;
24};
25
40template <TLAPACK_SMATRIX matrix_t>
42{
43 using idx_t = size_type<matrix_t>;
44 using T = type_t<matrix_t>;
45 using real_t = real_type<T>;
46 using range = pair<idx_t, idx_t>;
47
48 const idx_t n = nrows(U);
49 tlapack_check(n == ncols(U));
50 tlapack_check(opts.nx >= 1);
51
52 // quick return
53 if (n == 0) return;
54
55 if (n <= opts.nx) {
56 for (idx_t j = n; j-- > 0;) {
57 T real_part_of_ujj;
58 real_part_of_ujj =
59 real(U(j, j)) * real(U(j, j)) + imag(U(j, j)) * imag(U(j, j));
60 for (idx_t k = 0; k < j; ++k) {
61 real_part_of_ujj += real(U(k, j)) * real(U(k, j)) +
62 imag(U(k, j)) * imag(U(k, j));
63 }
64 U(j, j) = real_part_of_ujj;
65 for (idx_t i = j; i-- > 0;) {
66 U(i, j) = conj(U(i, i)) * U(i, j);
67 for (idx_t k = i; k-- > 0;) {
68 U(i, j) += conj(U(k, i)) * U(k, j);
69 }
70 }
71 }
72 return;
73 }
74
75 const idx_t n0 = n / 2;
76
77 auto U00 = slice(U, range(0, n0), range(0, n0));
78 auto U01 = slice(U, range(0, n0), range(n0, n));
79 auto U11 = slice(U, range(n0, n), range(n0, n));
80
81 // U11 = U11^H*U11
82 mult_uhu(U11, opts);
83
84 // U11+= U01^H*U01
85 herk(Uplo::Upper, Op::ConjTrans, real_t(1), U01, real_t(1), U11);
86
87 // U01 = U00^H*U01
88 trmm(Side::Left, Uplo::Upper, Op::ConjTrans, Diag::NonUnit, real_t(1), U00,
89 U01);
90
91 // U00 = U00^H*U00
92 mult_uhu(U00, opts);
93
94 return;
95}
96
97} // namespace tlapack
98
99#endif // TLAPACK_MULT_UHU
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
void mult_uhu(matrix_t &U, const mult_uhu_Opts &opts={})
in-place multiplication of upper triangular matrix U and lower triangular matrix U^H.
Definition mult_uhu.hpp:41
void herk(Uplo uplo, Op trans, const alpha_t &alpha, const matrixA_t &A, const beta_t &beta, matrixC_t &C)
Hermitian rank-k update:
Definition herk.hpp:68
void trmm(Side side, Uplo uplo, Op trans, Diag diag, const alpha_t &alpha, const matrixA_t &A, matrixB_t &B)
Triangular matrix-matrix multiply:
Definition trmm.hpp:72
#define tlapack_check(cond)
Throw an error if cond is false.
Definition exceptionHandling.hpp:98
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
Options struct for mult_uhu()
Definition mult_uhu.hpp:20
size_t nx
Optimization parameter.
Definition mult_uhu.hpp:23