BLAS++ 2024.05.31
BLAS C++ API
Loading...
Searching...
No Matches
rot.hh
1// Copyright (c) 2017-2023, University of Tennessee. All rights reserved.
2// SPDX-License-Identifier: BSD-3-Clause
3// This program is free software: you can redistribute it and/or modify it under
4// the terms of the BSD 3-Clause license. See the accompanying LICENSE file.
5
6#ifndef BLAS_ROT_HH
7#define BLAS_ROT_HH
8
9#include "blas/util.hh"
10
11#include <limits>
12
13namespace blas {
14
15// =============================================================================
51
52template <typename TX, typename TY>
53void rot(
54 int64_t n,
55 TX *x, int64_t incx,
56 TY *y, int64_t incy,
57 blas::real_type<TX, TY> c,
58 blas::scalar_type<TX, TY> s )
59{
60 typedef scalar_type<TX, TY> scalar_t;
61
62 // check arguments
63 blas_error_if( n < 0 ); // standard BLAS returns, doesn't fail
64 blas_error_if( incx == 0 );
65 blas_error_if( incy == 0 );
66
67 scalar_t zero( 0 );
68
69 // quick return
70 if (n == 0 || (c == 1 && s == zero))
71 return;
72
73 if (incx == 1 && incy == 1) {
74 // unit stride
75 for (int64_t i = 0; i < n; ++i) {
76 scalar_t stmp = c*x[i] + s*y[i];
77 y[i] = c*y[i] - conj(s)*x[i];
78 x[i] = stmp;
79 }
80 }
81 else {
82 // non-unit stride
83 int64_t ix = (incx > 0 ? 0 : (-n + 1)*incx);
84 int64_t iy = (incy > 0 ? 0 : (-n + 1)*incy);
85 for (int64_t i = 0; i < n; ++i) {
86 scalar_t stmp = c*x[ix] + s*y[iy];
87 y[iy] = c*y[iy] - conj(s)*x[ix];
88 x[ix] = stmp;
89 ix += incx;
90 iy += incy;
91 }
92 }
93}
94
95} // namespace blas
96
97#endif // #ifndef BLAS_ROT_HH
void rot(int64_t n, TX *x, int64_t incx, TY *y, int64_t incy, blas::real_type< TX, TY > c, blas::scalar_type< TX, TY > s)
Apply plane rotation:
Definition rot.hh:53