<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
trsv.hpp
Go to the documentation of this file.
1
3//
4// Copyright (c) 2017-2021, University of Tennessee. All rights reserved.
5// Copyright (c) 2021-2023, 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_LEGACY_TRSV_HH
12#define TLAPACK_LEGACY_TRSV_HH
13
14#include "tlapack/blas/trsv.hpp"
17
18namespace tlapack {
19namespace legacy {
20
79 template <typename TA, typename TX>
80 void trsv(Layout layout,
81 Uplo uplo,
82 Op trans,
83 Diag diag,
84 idx_t n,
85 TA const* A,
86 idx_t lda,
87 TX* x,
88 int_t incx)
89 {
90 using internal::create_matrix;
91
92 // check arguments
93 tlapack_check_false(layout != Layout::ColMajor &&
94 layout != Layout::RowMajor);
95 tlapack_check_false(uplo != Uplo::Lower && uplo != Uplo::Upper);
96 tlapack_check_false(trans != Op::NoTrans && trans != Op::Trans &&
97 trans != Op::ConjTrans);
98 tlapack_check_false(diag != Diag::NonUnit && diag != Diag::Unit);
102
103 // quick return
104 if (n == 0) return;
105
106 // for row major, swap lower <=> upper and
107 // A => A^T; A^T => A; A^H => A & doConj
108 bool doConj = false;
109 if (layout == Layout::RowMajor) {
110 uplo = (uplo == Uplo::Lower ? Uplo::Upper : Uplo::Lower);
111 if (trans == Op::NoTrans)
112 trans = Op::Trans;
113 else {
114 if (trans == Op::ConjTrans) doConj = true;
115 trans = Op::NoTrans;
116 }
117 }
118
119 // Conjugate if A is row-major and initially trans is Op::ConjTrans
120 if (doConj) {
121 for (idx_t i = 0; i < n; ++i)
122 x[i * abs(incx)] = conj(x[i * abs(incx)]);
123 }
124
125 // Matrix views
126 const auto A_ = create_matrix<TA>((TA*)A, n, n, lda);
127
129 trsv(uplo, trans, diag, A_, x_));
130
131 // Conjugate if A is row-major and initially trans is Op::ConjTrans
132 if (doConj) {
133 for (idx_t i = 0; i < n; ++i)
134 x[i * abs(incx)] = conj(x[i * abs(incx)]);
135 }
136 }
137
138} // namespace legacy
139} // namespace tlapack
140
141#endif // #ifndef TLAPACK_LEGACY_TRSV_HH
constexpr Layout layout
Layout of a matrix or vector.
Definition arrayTraits.hpp:232
Diag
Definition types.hpp:192
Op
Definition types.hpp:222
Uplo
Definition types.hpp:45
Layout
Definition types.hpp:24
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
constexpr auto diag(T &A, int diagIdx=0) noexcept
Get the Diagonal of an Eigen Matrix.
Definition eigen.hpp:576
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
void trsv(Layout layout, Uplo uplo, Op trans, Diag diag, idx_t n, TA const *A, idx_t lda, TX *x, int_t incx)
Solve the triangular matrix-vector equation.
Definition trsv.hpp:80
#define tlapack_expr_with_vector(x, TX, n, X, incx, expr)
Creates a vector object and executes an expression with it.
Definition utils.hpp:68
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