BLAS++ 2024.05.31
BLAS C++ API
Loading...
Searching...
No Matches
rotm.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_ROTM_HH
7#define BLAS_ROTM_HH
8
9#include "blas/util.hh"
10
11#include <limits>
12
13namespace blas {
14
15// =============================================================================
48
49template <typename TX, typename TY>
50void rotm(
51 int64_t n,
52 TX *x, int64_t incx,
53 TY *y, int64_t incy,
54 blas::scalar_type<TX, TY> const param[5] )
55{
56 typedef scalar_type<TX, TY> scalar_t;
57
58 // check arguments
59 blas_error_if( n < 0 ); // standard BLAS returns, doesn't fail
60 blas_error_if( incx == 0 );
61 blas_error_if( incy == 0 );
62
63 // quick return
64 if (n == 0 || param[0] == -2)
65 return;
66
67 if (incx == 1 && incy == 1) {
68 // unit stride
69 if (param[0] == -1) {
70 const scalar_t& h11 = param[1];
71 const scalar_t& h21 = param[2];
72 const scalar_t& h12 = param[3];
73 const scalar_t& h22 = param[4];
74 for (int64_t i = 0; i < n; ++i) {
75 scalar_t stmp = h11*x[i] + h12*y[i];
76 y[i] = h22*y[i] + h21*x[i];
77 x[i] = stmp;
78 }
79 }
80 else if (param[0] == 1) {
81 const scalar_t& h11 = param[1];
82 const scalar_t& h22 = param[4];
83 for (int64_t i = 0; i < n; ++i) {
84 scalar_t stmp = h11*x[i] + y[i];
85 y[i] = h22*y[i] - x[i];
86 x[i] = stmp;
87 }
88 }
89 else if (param[0] == 0) {
90 const scalar_t& h21 = param[2];
91 const scalar_t& h12 = param[3];
92 for (int64_t i = 0; i < n; ++i) {
93 scalar_t stmp = x[i] + h12*y[i];
94 y[i] = y[i] + h21*x[i];
95 x[i] = stmp;
96 }
97 }
98 else {
99 throw Error("Invalid param[1] in blas::rotm");
100 }
101 }
102 else {
103 // non-unit stride
104 int64_t ix = (incx > 0 ? 0 : (-n + 1)*incx);
105 int64_t iy = (incy > 0 ? 0 : (-n + 1)*incy);
106 if (param[0] == -1) {
107 const scalar_t& h11 = param[1];
108 const scalar_t& h21 = param[2];
109 const scalar_t& h12 = param[3];
110 const scalar_t& h22 = param[4];
111 for (int64_t i = 0; i < n; ++i) {
112 scalar_t stmp = h11*x[ix] + h12*y[iy];
113 y[iy] = h22*y[iy] + h21*x[ix];
114 x[ix] = stmp;
115 ix += incx;
116 iy += incy;
117 }
118 }
119 else if (param[0] == 1) {
120 const scalar_t& h11 = param[1];
121 const scalar_t& h22 = param[4];
122 for (int64_t i = 0; i < n; ++i) {
123 scalar_t stmp = h11*x[ix] + y[iy];
124 y[iy] = h22*y[iy] - x[ix];
125 x[ix] = stmp;
126 ix += incx;
127 iy += incy;
128 }
129 }
130 else if (param[0] == 0) {
131 const scalar_t& h21 = param[2];
132 const scalar_t& h12 = param[3];
133 for (int64_t i = 0; i < n; ++i) {
134 scalar_t stmp = x[ix] + h12*y[iy];
135 y[iy] = y[iy] + h21*x[ix];
136 x[ix] = stmp;
137 ix += incx;
138 iy += incy;
139 }
140 }
141 else {
142 throw Error("Invalid param[1] in blas::rotm");
143 }
144 }
145}
146
147} // namespace blas
148
149#endif // #ifndef BLAS_ROTM_HH
Exception class for BLAS errors.
Definition util.hh:30
void rotm(int64_t n, TX *x, int64_t incx, TY *y, int64_t incy, blas::scalar_type< TX, TY > const param[5])
Apply modified (fast) plane rotation, H:
Definition rotm.hh:50