Skip to content

Commit f44efba

Browse files
committed
linalg : setup_givens_rotationとタグ定数を追加(#1233)
Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com>
1 parent 1815c86 commit f44efba

File tree

3 files changed

+175
-16
lines changed

3 files changed

+175
-16
lines changed

reference/linalg.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,24 @@ BLAS互換アルゴリズムは、演算対象データの次元数や計算オ
4242
| [`conjugate_transposed`](linalg/conjugate_transposed.md) | 読み取り専用の複素共役転置ビュー`std::mdspan`を作る (function template) | C++26 |
4343

4444

45+
## BLASの要件
46+
BLAS 1, 2, 3のアルゴリズムでテンプレートパラメータが特に制約されていない場合、テンプレートパラメータの名前によって以下の制約を満たすとする。
47+
48+
| 名前 | 制約 |
49+
|------|------|
50+
| `ExecutionPolicy` | `is_execution_policy<ExecutionPolicy>::value == true` |
51+
| `Real` | `complex<Real>`が規定できる型 |
52+
| `Triangle` | `upper_triangle_t`または`lower_triangle_t` |
53+
| `DiagonalStorage` | `implicit_unit_diagonal_t`または`implicit_unit_diagonal_t` |
54+
55+
4556
## BLAS 1アルゴリズム
57+
`std::mpspan`をパラメータに持つ、この節の全てのアルゴリズムの計算量は渡された`std::mdspan``extents`の積の最大値、つまりベクトルや行列の要素数の最大値に線形である。
4658

4759
| 名前 | 説明 | 対応バージョン |
4860
|------|------|----------------|
49-
| `setup_givens_rotation_result` | `setup_givens_rotation`の結果型 (class template) | C++26 |
50-
| `setup_givens_rotation` | xLARTG: ギブンス回転をセットアップする (function template) | C++26 |
61+
| [`setup_givens_rotation_result`](linalg/setup_givens_rotation_result.md) | `setup_givens_rotation`の結果型 (class template) | C++26 |
62+
| [`setup_givens_rotation`](linalg/setup_givens_rotation.md) | xLARTG: ギブンス回転をセットアップする (function template) | C++26 |
5163
| `apply_givens_rotation` | xROT: ベクトルにギブンス回転を適用する (function template) | C++26 |
5264
| `swap_elements` | xSWAP: 2つのベクトル/行列の要素を交換する (function template) | C++26 |
5365
| `scale` | xSCAL: ベクトル/行列の要素にスカラ値を乗算する (function template) | C++26 |
@@ -103,35 +115,38 @@ BLAS互換アルゴリズムは、演算対象データの次元数や計算オ
103115
## タグ
104116
`<linalg>`ヘッダでは、行列の格納順序や三角行列の上下をタグを使って表現している。
105117

106-
以下、型名を掲載するが、定数も次のように定義されている。
107-
108-
```cpp
109-
inline constexpr tag_name_t tag_name{};
110-
```
111118

112119
### 格納順序
113120
行列の格納順序を表すタグ。
114121

115-
| 型名 | 説明 | 対応バージョン |
122+
| 名前 | 説明 | 対応バージョン |
116123
|------|------|----------------|
117-
| [`column_major_t`](linalg/column_major_t.md) | 列優先(column-major) | C++26 |
118-
| [`row_major_t`](linalg/row_major_t.md) | 行優先(row-major) | C++26 |
124+
| [`column_major_t`](linalg/column_major_t.md) | 列優先(column-major)を表すタグ型 | C++26 |
125+
| [`column_major`](linalg/column_major_t.md) | 列優先(column-major)を表すタグ値 | C++26 |
126+
| [`row_major_t`](linalg/row_major_t.md) | 行優先(row-major)を表すタグ型 | C++26 |
127+
| [`row_major`](linalg/row_major_t.md) | 行優先(row-major)を表すタグ値 | C++26 |
128+
119129

120130
### 三角行列
121131
上三角行列か下三角行列かを表すタグ。
122132

123-
| 型名 | 説明 | 対応バージョン |
133+
| 名前 | 説明 | 対応バージョン |
124134
|------|------|----------------|
125-
| [`upper_triangle_t`](linalg/upper_triangle_t.md) | 上三角行列 | C++26 |
126-
| [`lower_triangle_t`](linalg/lower_triangle_t.md) | 下三角行列 | C++26 |
135+
| [`upper_triangle_t`](linalg/upper_triangle_t.md) | 上三角行列を表すタグ型 | C++26 |
136+
| [`upper_triangle`](linalg/upper_triangle_t.md) | 上三角行列を表すタグ値 | C++26 |
137+
| [`lower_triangle_t`](linalg/lower_triangle_t.md) | 下三角行列を表すタグ型 | C++26 |
138+
| [`lower_triangle`](linalg/lower_triangle_t.md) | 下三角行列を表すタグ値 | C++26 |
139+
127140

128141
### 対角成分
129142
行列の全ての対角成分を暗黙に乗法における単位元とみなすかどうかを表すタグ。みなした場合、行列の対角成分にはアクセスせず、値が乗法における単位元であるとして計算する。
130143

131-
| 型名 | 説明 | 対応バージョン |
144+
| 名前 | 説明 | 対応バージョン |
132145
|------|------|----------------|
133-
| [`implicit_unit_diagonal_t`](linalg/implicit_unit_diagonal_t.md) | 全ての対角成分を暗黙に乗法における単位元とみなす | C++26 |
134-
| [`explicit_diagonal_t`](linalg/explicit_diagonal_t.md) | 全ての対角成分にアクセスする | C++26 |
146+
| [`implicit_unit_diagonal_t`](linalg/implicit_unit_diagonal_t.md) | 全ての対角成分を暗黙に乗法における単位元とみなすタグ型 | C++26 |
147+
| [`implicit_unit_diagonal`](linalg/implicit_unit_diagonal_t.md) | 全ての対角成分を暗黙に乗法における単位元とみなすタグ値 | C++26 |
148+
| [`explicit_diagonal_t`](linalg/explicit_diagonal_t.md) | 全ての対角成分にアクセスするタグ型 | C++26 |
149+
| [`explicit_diagonal`](linalg/explicit_diagonal_t.md) | 全ての対角成分にアクセスするタグ値 | C++26 |
135150

136151

137152
## バージョン
@@ -148,3 +163,4 @@ inline constexpr tag_name_t tag_name{};
148163
- [P1674R2: Evolving a Standard C++ Linear Algebra Library from the BLAS](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p1674r2.html)
149164
- [std::linalg: Linear Algebra Coming to Standard C++](https://github.com/CppCon/CppCon2023/blob/main/Presentations/stdlinalg_linear_algebra_coming_to_standard_cpp.pdf), CppCon 2023
150165
- [BLAS (Basic Linear Algebra Subprograms)](https://www.netlib.org/blas/)
166+
- [Numerics library](https://eel.is/c++draft/complex.numbers)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# setup_givens_rotation
2+
3+
* [mathjax enable]
4+
* linalg[meta header]
5+
* function template[meta id-type]
6+
* std::linalg[meta namespace]
7+
* cpp26[meta cpp]
8+
9+
```cpp
10+
namespace std::linalg {
11+
template<class Real>
12+
setup_givens_rotation_result<Real> setup_givens_rotation(Real a, Real b) noexcept; // (1)
13+
14+
template<class Real>
15+
setup_givens_rotation_result<complex<Real>> setup_givens_rotation(complex<Real> a, complex<Real> b) noexcept; // (2)
16+
}
17+
```
18+
19+
20+
## 概要
21+
ギブンス回転を計算する。すなわち、以下の式が成り立つような、`Real`型の値`c`と `s`, `r`を計算する。
22+
23+
$$
24+
\begin{split}
25+
\begin{pmatrix}
26+
c & s \\
27+
-\overline{s} & c
28+
\end{pmatrix}
29+
\begin{pmatrix}
30+
a \\
31+
b
32+
\end{pmatrix}
33+
&=
34+
\begin{pmatrix}
35+
r \\
36+
0
37+
\end{pmatrix},\\
38+
c^2 + |s|^2 &= 1
39+
\end{split}
40+
$$
41+
42+
ただし、`s`と`r`の型は`a`と`b`の型による。
43+
44+
- (1) `a`と`b`の型が`Real`の場合、`s`と`r`の型も`Real`。`r`は$(a, b)^T$のユークリッドノルム、つまり$\sqrt{|a|^2 + |b|^2}$である。
45+
- (2) `a`と`b`の型が`complex<Real>`の場合、`s`と`r`の型も`complex<Real>`。以下で定義される$sgn$関数を用いると、`r`は$sgn(a) * \sqrt{|a|^2 + |b|^2}$である。
46+
$$
47+
sgn(x)=
48+
\begin{cases}
49+
\frac{x}{|x|} & \text{($x \neq 0$)} \\
50+
1 & \text{($x = 0$)}
51+
\end{cases}
52+
$$
53+
54+
55+
## テンプレートパラメータ制約
56+
- `Real`は`complex<Real>`が規定できる型であること。
57+
58+
59+
## 戻り値
60+
`c`と`s`が入力$(a, b)^T$に対するギブンス回転行列の成分で、`r`を入力$(a, b)^T$のユークリッドノルムとすると、戻り値は`{c, s, r}`である。
61+
62+
63+
## 例
64+
65+
66+
### 出力
67+
68+
69+
## バージョン
70+
### 言語
71+
- C++26
72+
73+
### 処理系
74+
- [Clang](/implementation.md#clang): ??
75+
- [GCC](/implementation.md#gcc): ??
76+
- [ICC](/implementation.md#icc): ??
77+
- [Visual C++](/implementation.md#visual_cpp): ??
78+
79+
80+
## 関連項目
81+
- [`setup_givens_rotation_result`](setup_givens_rotation_result.md)
82+
83+
84+
## 参照
85+
- [P0788R3 Standard Library Specification in a Concepts and Contracts World](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0788r3.pdf)
86+
- [Working Draft Programming Languages — C++: 28 Numerics libarary](https://eel.is/c++draft/complex.numbers)
87+
- [LAPACK: clartg](https://netlib.org/lapack/explore-html/da/dd3/group__lartg_ga45afd4405cf6da478ce4de9576303369.html#ga45afd4405cf6da478ce4de9576303369)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# setup_givens_rotation_result
2+
* linalg[meta header]
3+
* class template[meta id-type]
4+
* std::linalg[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std::linalg {
9+
template<class Real>
10+
struct setup_givens_rotation_result {
11+
Real c;
12+
Real s;
13+
Real r;
14+
};
15+
16+
template<class Real>
17+
struct setup_givens_rotation_result<complex<Real>> {
18+
Real c;
19+
complex<Real> s;
20+
complex<Real> r;
21+
};
22+
}
23+
```
24+
25+
## 概要
26+
ギブンス回転の結果を表すクラス。詳しくは、[`setup_givens_rotation`](setup_givens_rotation.md)にて。
27+
28+
29+
## テンプレートパラメータ制約
30+
- `Real`は`complex<Real>`が規定できる型であること。
31+
32+
33+
## 例
34+
35+
36+
### 出力
37+
38+
39+
## バージョン
40+
### 言語
41+
- C++26
42+
43+
### 処理系
44+
- [Clang](/implementation.md#clang): ??
45+
- [GCC](/implementation.md#gcc): ??
46+
- [ICC](/implementation.md#icc): ??
47+
- [Visual C++](/implementation.md#visual_cpp): ??
48+
49+
50+
## 関連項目
51+
- [`setup_givens_rotation`](setup_givens_rotation.md)
52+
53+
54+
## 参照
55+
- [P1673R13 A free function linear algebra interface based on the BLAS](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p1673r13.html)
56+
- [Numerics library](https://eel.is/c++draft/complex.numbers)

0 commit comments

Comments
 (0)