<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
71template <typename matrixA_t, typename matrixB_t, TLAPACK_SCALAR alpha_t>
73 Uplo uploB,
74 Op transA,
75 Diag diagA,
76 const alpha_t& alpha,
77 const matrixA_t& A,
78 matrixB_t& B)
79{
82 using range = std::pair<idx_t, idx_t>;
84
89 else
90 uploA = uploB;
91
92 idx_t n = nrows(A);
93
94 // lascl(uploB, T(1.), alpha, B); this does not work
95
96 if (uploB == Uplo::Upper) {
97 for (idx_t j = 0; j < n; j++) {
98 for (idx_t i = 0; i < j + 1; i++) {
99 B(i, j) *= alpha;
100 }
101 }
102 }
103 else {
104 for (idx_t j = 0; j < n; j++) {
105 for (idx_t i = j; i < n; i++) {
106 B(i, j) *= alpha;
107 }
108 }
109 }
110
111 if (n == 1) {
112 if (diagA == Diag::NonUnit) {
114 B(0, 0) /= conj(A(0, 0));
115 else
116 B(0, 0) /= A(0, 0);
117 return;
118 }
119 else {
120 // if (transA == tlapack::Op::ConjTrans)
121 // B(0, 0) /= conj(A(0, 0));
122 // else
123 // B(0, 0) /= A(0, 0);
124 return;
125 }
126 }
127
128 idx_t nd = n / 2;
129
130 auto A00 = slice(A, range(0, nd), range(0, nd));
131 auto A01 = slice(A, range(0, nd), range(nd, n));
132 auto A10 = slice(A, range(nd, n), range(0, nd));
133 auto A11 = slice(A, range(nd, n), range(nd, n));
134
135 auto B00 = slice(B, range(0, nd), range(0, nd));
136 auto B01 = slice(B, range(0, nd), range(nd, n));
137 auto B10 = slice(B, range(nd, n), range(0, nd));
138 auto B11 = slice(B, range(nd, n), range(nd, n));
139
140 if (sideA == tlapack::Side::Left) {
142 // Form: B := alpha*inv(A)*B
144 // Left, NoTrans, Upper, Diag
146
148
150 real_t(-1), B11, A01, real_t(1), B01);
151
153
154 return;
155 }
156 else {
157 // Left, NoTrans, Lower, Diag
159
161
163 real_t(-1), B00, A10, real_t(1), B10);
164
166
167 return;
168 }
169 }
170 else {
171 // Form: B := alpha*inv(A**T)*B
172 // Form: B := alpha*inv(A**H)*B
174 // Left, Trans or ConjTrans, Upper, Diag
175
177
179
181 real_t(-1), B11, A10, real_t(1), B01);
182
184
185 return;
186 }
187 else {
188 // Left, Trans or ConjTrans, Lower, Diag
189
191
193
195 real_t(-1), B00, A01, real_t(1), B10);
196
198 return;
199 }
200 }
201 }
202 else {
204 // Form: B := alpha*B*inv(A)
206 // Right, NoTrans, Upper, Diag
207
209
211
213 real_t(-1), B00, A01, real_t(1), B01);
214
216
217 return;
218 }
219 else {
220 // Right, NoTrans, Lower, Diag
222
224
226 real_t(-1), B11, A10, real_t(1), B10);
227
229
230 return;
231 }
232 }
233 else {
234 // Form: B := alpha*B*inv(A**T)
235 // Form: B := alpha*B*inv(A**H)
236
238 // Right, Trans or ConjTrans, Upper, Diag
240
242
244 real_t(-1), B00, A10, real_t(1), B01);
245
247
248 return;
249 }
250 else {
251 // Right, Trans or ConjTrans, Lower, Diag
252
254
256
258 real_t(-1), B11, A01, real_t(1), B10);
259
261 return;
262 }
263 }
264 }
265}
266} // namespace tlapack
267
268#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-vector equation.
Definition trsm_tri.hpp:72
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.
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 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.