Skip to content

Commit c47e021

Browse files
committed
linalg : vector_two_normを追加 (#1233)
Signed-off-by: Yuya Asano <64895419+sukeya@users.noreply.github.com>
1 parent d741acc commit c47e021

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

reference/linalg.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ BLAS 1, 2, 3のアルゴリズムでテンプレートパラメータが特に
6969
| [`dotc`](linalg/dotc.md) | xDOTC: 2つのベクトルの複素共役ドット積を求める (function template) | C++26 |
7070
| [`sum_of_squares_result`](linalg/sum_of_squares_result.md) | `vector_sum_of_squares`の結果型 (class template) | C++26 |
7171
| [`vector_sum_of_squares`](linalg/vector_sum_of_squares.md) | xLASSQ: ベクトル要素の平方和を求める (function template) | C++26 |
72-
| `vector_two_norm` | xNRM2: ベクトルのユークリッドノルム(Euclidean norm)を求める (function template) | C++26 |
72+
| [`vector_two_norm`](linalg/vector_two_norm.md) | xNRM2: ベクトルのユークリッドノルム(Euclidean norm)を求める (function template) | C++26 |
7373
| `vector_abs_sum` | xASUM: ベクトル要素の絶対値和を求める (function template) | C++26 |
7474
| `vector_idx_abs_max` | xIAMAX: ベクトル要素のうち最大絶対値インデクスを返す (function template) | C++26 |
7575
| `matrix_frob_norm` | 行列のフロベニウスノルム(Frobenius norm)を求める (function template) | C++26 |
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# vector_two_norm
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<in-vector InVec,
12+
class Scalar>
13+
Scalar vector_two_norm(InVec v,
14+
Scalar init); // (1)
15+
16+
template<class ExecutionPolicy,
17+
in-vector InVec,
18+
class Scalar>
19+
Scalar vector_two_norm(ExecutionPolicy&& exec,
20+
InVec v,
21+
Scalar init); // (2)
22+
}
23+
```
24+
25+
26+
## 概要
27+
ベクトルのユークリッドノルムを計算する。
28+
29+
- (1): 逐次実行する。
30+
- (2): 指定された実行ポリシーに応じて実行する。
31+
32+
33+
## 適格要件
34+
- `decltype(init + `[`abs-if-needed`](abs-if-needed.md)`(declval<typename InVec::value_type>()) * abs-if-needed(declval<typename InVec::value_type>()))`が`Scalar`に変換可能。
35+
36+
37+
## 戻り値
38+
`n`を`v`の次元とすると、
39+
40+
$$
41+
\sqrt{\sum_{i = 0}^{n - 1} |\verb|v[|i\verb|]||^2 + \verb|init|^2}
42+
$$
43+
44+
を返す。
45+
46+
47+
## 備考
48+
- `init.scaled_sum_of_squares`は0以上でなければならない。
49+
- もし`InVec::value_type`と`Scalar`がどちらも浮動小数点数型または`std::complex`の特殊化で、`Scalar`が`InVec::value_type`より精度が高い場合、和の各項は`Scalar`またはより高い精度の型が使われる。
50+
51+
52+
## 例
53+
54+
55+
### 出力
56+
57+
58+
## バージョン
59+
### 言語
60+
- C++26
61+
62+
### 処理系
63+
- [Clang](/implementation.md#clang): ??
64+
- [GCC](/implementation.md#gcc): ??
65+
- [ICC](/implementation.md#icc): ??
66+
- [Visual C++](/implementation.md#visual_cpp): ??
67+
68+
69+
## 関連項目
70+
- [`execution`](/reference/execution.md)
71+
- [`mdspan`](/reference/mdspan.md)
72+
73+
74+
## 参照
75+
- [P0788R3 Standard Library Specification in a Concepts and Contracts World](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0788r3.pdf)
76+
- [LAPACK: dnrm2](https://netlib.org/lapack/explore-html/d1/d2a/group__nrm2_gab5393665c8f0e7d5de9bd1dd2ff0d9d0.html#gab5393665c8f0e7d5de9bd1dd2ff0d9d0)
77+

0 commit comments

Comments
 (0)