<T>LAPACK 0.1.2
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
mult_llh.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_LLH
11#define TLAPACK_MULT_LLH
12
14#include "tlapack/blas/trmm.hpp"
15
16namespace tlapack {
17
22 size_t nx = 1;
23};
24
39template <TLAPACK_SMATRIX matrix_t>
40void mult_llh(matrix_t& L, const mult_llh_Opts& opts = {})
41{
42 using idx_t = size_type<matrix_t>;
43 using T = type_t<matrix_t>;
44 using real_t = real_type<T>;
45 using range = pair<idx_t, idx_t>;
46
47 const idx_t n = nrows(L);
48 tlapack_check(n == ncols(L));
49 tlapack_check(opts.nx >= 1);
50
51 // Quick return
52 if (n == 0) return;
53
54 if (n <= opts.nx) {
55 for (idx_t j = n; j-- > 0;) {
56 T real_part_of_ljj;
57 real_part_of_ljj =
58 real(L(j, j)) * real(L(j, j)) + imag(L(j, j)) * imag(L(j, j));
59 for (idx_t k = 0; k < j; ++k) {
60 // sum += C(i, k) * std::conj(C(i, k));
61 real_part_of_ljj += real(L(j, k)) * real(L(j, k)) +
62 imag(L(j, k)) * imag(L(j, k));
63 }
64 L(j, j) = real_part_of_ljj;
65
66 for (idx_t i = j; i-- > 0;) {
67 L(j, i) = L(j, i) * conj(L(i, i));
68 for (idx_t k = 0; k < i; ++k) {
69 L(j, i) += L(j, k) * conj(L(i, k));
70 }
71 }
72 }
73
74 return;
75 }
76
77 // Recursive case: divide into blocks
78 const idx_t n0 = n / 2;
79
80 auto L00 = slice(L, range(0, n0), range(0, n0));
81 auto L10 = slice(L, range(n0, n), range(0, n0));
82 auto L11 = slice(L, range(n0, n), range(n0, n));
83
84 // L11 = L11*L11^H
85 mult_llh(L11, opts);
86
87 // L11 += L10 * L10^H
88 herk(Uplo::Lower, Op::NoTrans, real_t(1), L10, real_t(1), L11);
89
90 // A10 = A10 * A00^H
91 trmm(Side::Right, Uplo::Lower, Op::ConjTrans, Diag::NonUnit, T(1), L00,
92 L10);
93
94 // A00 = A00 * A00^H
95 mult_llh(L00, opts);
96
97 return;
98}
99
100} // namespace tlapack
101
102#endif // TLAPACK_MULT_LLH
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
void mult_llh(matrix_t &L, const mult_llh_Opts &opts={})
in-place multiplication of lower triangular matrix L and upper triangular matrix L^H.
Definition mult_llh.hpp:40
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 llh_mult()
Definition mult_llh.hpp:19
size_t nx
Optimization parameter.
Definition mult_llh.hpp:22