<T>LAPACK 0.1.2
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
trsm_tri.hpp
Go to the documentation of this file.
1
4//
5// Copyright (c) 2025, University of Colorado Denver. All rights reserved.
6//
7// This file is part of <T>LAPACK.
8// <T>LAPACK is free software: you can redistribute it and/or modify it under
9// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
10
11#ifndef TLAPACK_TRSM_TRI
12#define TLAPACK_TRSM_TRI
13
15#include "tlapack/blas/trmm.hpp"
18
19namespace tlapack {
20
98template <typename matrixA_t, typename matrixB_t, TLAPACK_SCALAR alpha_t>
100 Uplo uploB,
101 Op transA,
102 Diag diagA,
103 const alpha_t& alpha,
104 const matrixA_t& A,
105 matrixB_t& B)
106{
108 using idx_t = tlapack::size_type<matrixB_t>;
109 using range = std::pair<idx_t, idx_t>;
111
116 else
117 uploA = uploB;
118
119 idx_t n = nrows(A);
120
121 // lascl(uploB, T(1.), alpha, B); this does not work
122
123 if (uploB == Uplo::Upper) {
124 for (idx_t j = 0; j < n; j++) {
125 for (idx_t i = 0; i < j + 1; i++) {
126 B(i, j) *= alpha;
127 }
128 }
129 }
130 else {
131 for (idx_t j = 0; j < n; j++) {
132 for (idx_t i = j; i < n; i++) {
133 B(i, j) *= alpha;
134 }
135 }
136 }
137
138 if (n == 1) {
139 if (diagA == Diag::NonUnit) {
141 B(0, 0) /= conj(A(0, 0));
142 else
143 B(0, 0) /= A(0, 0);
144 return;
145 }
146 else {
147 return;
148 }
149 }
150
151 idx_t nd = n / 2;
152
153 auto A00 = slice(A, range(0, nd), range(0, nd));
154 auto A01 = slice(A, range(0, nd), range(nd, n));
155 auto A10 = slice(A, range(nd, n), range(0, nd));
156 auto A11 = slice(A, range(nd, n), range(nd, n));
157
158 auto B00 = slice(B, range(0, nd), range(0, nd));
159 auto B01 = slice(B, range(0, nd), range(nd, n));
160 auto B10 = slice(B, range(nd, n), range(0, nd));
161 auto B11 = slice(B, range(nd, n), range(nd, n));
162
163 if (sideA == tlapack::Side::Left) {
165 // Form: B := alpha*inv(A)*B
167 // Left, NoTrans, Upper, Diag
169
171
173 real_t(-1), B11, A01, real_t(1), B01);
174
176
177 return;
178 }
179 else {
180 // Left, NoTrans, Lower, Diag
182
184
186 real_t(-1), B00, A10, real_t(1), B10);
187
189
190 return;
191 }
192 }
193 else {
194 // Form: B := alpha*inv(A**T)*B
195 // Form: B := alpha*inv(A**H)*B
197 // Left, Trans or ConjTrans, Upper, Diag
198
200
202
204 real_t(-1), B11, A10, real_t(1), B01);
205
207
208 return;
209 }
210 else {
211 // Left, Trans or ConjTrans, Lower, Diag
212
214
216
218 real_t(-1), B00, A01, real_t(1), B10);
219
221 return;
222 }
223 }
224 }
225 else {
227 // Form: B := alpha*B*inv(A)
229 // Right, NoTrans, Upper, Diag
230
232
234
236 real_t(-1), B00, A01, real_t(1), B01);
237
239
240 return;
241 }
242 else {
243 // Right, NoTrans, Lower, Diag
245
247
249 real_t(-1), B11, A10, real_t(1), B10);
250
252
253 return;
254 }
255 }
256 else {
257 // Form: B := alpha*B*inv(A**T)
258 // Form: B := alpha*B*inv(A**H)
259
261 // Right, Trans or ConjTrans, Upper, Diag
263
265
267 real_t(-1), B00, A10, real_t(1), B01);
268
270
271 return;
272 }
273 else {
274 // Right, Trans or ConjTrans, Lower, Diag
275
277
279
281 real_t(-1), B11, A01, real_t(1), B10);
282
284 return;
285 }
286 }
287 }
288}
289} // namespace tlapack
290
291#endif // TLAPACK_TRSM_TRI
void trmm_out(Side side, Uplo uplo, Op transA, Diag diag, Op transB, const alpha_t &alpha, const matrixA_t &A, const matrixB_t &B, const beta_t &beta, matrixC_t &C)
Triangular matrix-matrix multiply:
Definition trmm_out.hpp:82
void trsm_tri(Side sideA, Uplo uploB, Op transA, Diag diagA, const alpha_t &alpha, const matrixA_t &A, matrixB_t &B)
Solve the triangular matrix-matrix equation.
Definition trsm_tri.hpp:99
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
Multiplies a matrix by a scalar.
Recursive QR factorization using compact WY Householder representation.
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 T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
Diag
Definition types.hpp:197
@ NonUnit
The main diagonal is not assumed to consist of 1's.
Side
Definition types.hpp:271
@ Right
right side
@ Left
left side
Op
Definition types.hpp:227
@ NoTrans
no transpose
@ ConjTrans
conjugate transpose
Uplo
Definition types.hpp:50
@ Upper
0 <= i <= j, 0 <= j <= n.
@ Lower
0 <= i <= m, 0 <= j <= i.