<T>LAPACK 0.1.1
C++ Template Linear Algebra PACKage
Loading...
Searching...
No Matches
gemv.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_GEMV_HH
12#define TLAPACK_LEGACY_GEMV_HH
13
14#include "tlapack/blas/gemv.hpp"
17
18namespace tlapack {
19namespace legacy {
20
86 template <typename TA, typename TX, typename TY>
87 void gemv(Layout layout,
88 Op trans,
89 idx_t m,
90 idx_t n,
92 TA const* A,
93 idx_t lda,
94 TX const* x,
95 int_t incx,
97 TY* y,
98 int_t incy)
99 {
100 using internal::create_matrix;
102
103 // check arguments
104 tlapack_check_false(layout != Layout::ColMajor &&
105 layout != Layout::RowMajor);
106 tlapack_check_false(trans != Op::NoTrans && trans != Op::Trans &&
107 trans != Op::ConjTrans);
108 tlapack_check_false(m < 0);
109 tlapack_check_false(n < 0);
110 tlapack_check_false(lda < ((layout == Layout::ColMajor) ? m : n));
113
114 // quick return
115 if (m == 0 || n == 0 ||
116 ((alpha == scalar_t(0)) && (beta == scalar_t(1))))
117 return;
118
119 // Transpose if Row Major
120 bool doConj = false;
121 if (layout == Layout::RowMajor) {
122 // A => A^T; A^T => A; A^H => A & doConj
123 std::swap(m, n);
124 if (trans == Op::NoTrans)
125 trans = Op::Trans;
126 else {
127 if (trans == Op::ConjTrans) doConj = true;
128 trans = Op::NoTrans;
129 }
130 }
131
132 // Initialize indexes
133 const idx_t lenx = ((trans == Op::NoTrans) ? n : m);
134 const idx_t leny = ((trans == Op::NoTrans) ? m : n);
135
136 // Conjugate if A is row-major and initially trans is Op::ConjTrans
137 if (doConj) {
138 TX* x2 = const_cast<TX*>(x);
139 for (idx_t i = 0; i < lenx; ++i)
140 x2[i * abs(incx)] = conj(x2[i * abs(incx)]);
141 for (idx_t i = 0; i < leny; ++i)
142 y[i * abs(incy)] = conj(y[i * abs(incy)]);
143 }
144
145 // Matrix views
146 const auto A_ = create_matrix<TA>((TA*)A, m, n, lda);
147
148 if (alpha == scalar_t(0)) {
150 y_, TY, leny, y, incy,
151 if (beta == scalar_t(0)) for (idx_t i = 0; i < leny; ++i)
152 y_[i] = TY(0);
153 else for (idx_t i = 0; i < leny; ++i) y_[i] *=
154 (doConj) ? conj(beta) : beta);
155 }
156 else {
158 x_, TX, lenx, x, incx, y_, TY, leny, y, incy,
159 if (beta == scalar_t(0))
160 gemv(trans, (doConj) ? conj(alpha) : alpha, A_, x_, y_);
161 else gemv(trans, (doConj) ? conj(alpha) : alpha, A_, x_,
162 (doConj) ? conj(beta) : beta, y_));
163 }
164
165 // Conjugate if A is row-major and initially trans is Op::ConjTrans
166 if (doConj) {
167 TX* x2 = const_cast<TX*>(x);
168 for (idx_t i = 0; i < lenx; ++i)
169 x2[i * abs(incx)] = conj(x2[i * abs(incx)]);
170 for (idx_t i = 0; i < leny; ++i)
171 y[i * abs(incy)] = conj(y[i * abs(incy)]);
172 }
173 }
174
175} // namespace legacy
176} // namespace tlapack
177
178#endif // #ifndef TLAPACK_LEGACY_GEMV_HH
constexpr Layout layout
Layout of a matrix or vector.
Definition arrayTraits.hpp:232
Op
Definition types.hpp:222
Layout
Definition types.hpp:24
constexpr T conj(const T &x) noexcept
Extends std::conj() to real datatypes.
Definition utils.hpp:100
#define tlapack_check_false(cond)
Throw an error if cond is true.
Definition exceptionHandling.hpp:113
void gemv(Layout layout, Op trans, idx_t m, idx_t n, scalar_type< TA, TX, TY > alpha, TA const *A, idx_t lda, TX const *x, int_t incx, scalar_type< TA, TX, TY > beta, TY *y, int_t incy)
General matrix-vector multiply:
Definition gemv.hpp:87
#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
#define tlapack_expr_with_2vectors(x, TX, n, X, incx, y, TY, m, Y, incy, expr)
Creates two vector objects and executes an expression with them.
Definition utils.hpp:33
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