|
98 | 98 |
|
99 | 99 |
|
100 | 100 | ## 例 |
| 101 | +**[注意] 処理系にあるコンパイラで確認していないため、間違っているかもしれません。** |
| 102 | +
|
| 103 | +```cpp example |
| 104 | +#include <cmath> |
| 105 | +#include <complex> |
| 106 | +#include <initializer_list> |
| 107 | +#include <execution> |
| 108 | +#include <iostream> |
| 109 | +#include <linalg> |
| 110 | +#include <mdspan> |
| 111 | +#include <vector> |
| 112 | +
|
| 113 | +template <class Vector> |
| 114 | +void print(Vector v) { |
| 115 | + for (int i = 0; i < v.extent(0) - 1; ++i) { |
| 116 | + std::cout << v[i] << ", "; |
| 117 | + } |
| 118 | + std::cout << v[v.extent(0) - 1] << std::endl; |
| 119 | +} |
| 120 | +
|
| 121 | +int main() |
| 122 | +{ |
| 123 | + constexpr size_t N = 2; |
| 124 | +
|
| 125 | + using Complex = std::complex<double>; |
| 126 | +
|
| 127 | + { |
| 128 | + std::initializer_list<double> a_coeff = {1, std::sqrt(3.0)}; |
| 129 | + std::initializer_list<double> b_coeff = {std::sqrt(3.0), -0.5}; |
| 130 | +
|
| 131 | + std::vector<double> a_vec(a_coeff); |
| 132 | + std::mdspan a(a_vec.data(), N); |
| 133 | +
|
| 134 | + std::vector<double> b_vec(b_coeff); |
| 135 | + std::mdspan b(b_vec.data(), N); |
| 136 | +
|
| 137 | + double c = 0.5; |
| 138 | + double s = -std::sqrt(3.0) / 2; |
| 139 | +
|
| 140 | + // (1) |
| 141 | + std::linalg::apply_givens_rotation(a, b, c, s); |
| 142 | + print(a); |
| 143 | + print(b); |
| 144 | +
|
| 145 | + // (2) |
| 146 | + // aとbを初期化 |
| 147 | + a_vec = a_coeff; |
| 148 | + b_vec = b_coeff; |
| 149 | + std::linalg::apply_givens_rotation(std::execution::par, a, b, c, s); |
| 150 | + print(a); |
| 151 | + print(b); |
| 152 | + } |
| 153 | +
|
| 154 | + { |
| 155 | + std::initializer_list<Complex> a_coeff = {Complex{1, 0}, Complex{std::sqrt(3.0), 0}}; |
| 156 | + std::initializer_list<Complex> b_coeff = {Complex{0, std::sqrt(3.0)}, Complex{0, -0.5}}; |
| 157 | +
|
| 158 | + std::vector<Complex> a_vec(a_coeff); |
| 159 | + std::mdspan a(a_vec.data(), N); |
| 160 | +
|
| 161 | + std::vector<Complex> b_vec(b_coeff); |
| 162 | + std::mdspan b(b_vec.data(), N); |
| 163 | +
|
| 164 | + double c = 0.5; |
| 165 | + Complex s = Complex{0, -std::sqrt(3.0) / 2}; |
| 166 | +
|
| 167 | + // (3) |
| 168 | + std::linalg::apply_givens_rotation(a, b, c, s); |
| 169 | + print(a); |
| 170 | + print(b); |
| 171 | +
|
| 172 | + // (4) |
| 173 | + // aとbを初期化 |
| 174 | + a_vec = a_coeff; |
| 175 | + b_vec = b_coeff; |
| 176 | + std::linalg::apply_givens_rotation(std::execution::par, a, b, c, s); |
| 177 | + print(a); |
| 178 | + print(b); |
| 179 | + } |
| 180 | +
|
| 181 | + return 0; |
| 182 | +} |
| 183 | +``` |
| 184 | +* std::linalg::apply_givens_rotation[color ff0000] |
101 | 185 |
|
102 | 186 |
|
103 | 187 | ### 出力 |
| 188 | +``` |
| 189 | +(1) |
| 190 | +1, 0 |
| 191 | +0, -1 |
| 192 | +(2) |
| 193 | +1, 0 |
| 194 | +0, -1 |
| 195 | +(3) |
| 196 | +(1,0), (0,0) |
| 197 | +(0,0), (0,-1) |
| 198 | +(4) |
| 199 | +(1,0), (0,0) |
| 200 | +(0,0), (0,-1) |
| 201 | +``` |
104 | 202 |
|
105 | 203 |
|
106 | 204 | ## バージョン |
|
0 commit comments