Skip to content

Commit da93e92

Browse files
committed
mdspan: layout_{left,right}_padded概要 P2645R5
1 parent ed8ddfe commit da93e92

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed

reference/mdspan.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
| [`layout_left`](mdspan/layout_left.md) | 列優先(Fortran/Matlabスタイル)レイアウトマッピングポリシー (class) | C++23 |
2222
| [`layout_right`](mdspan/layout_right.md) | 行優先(C/C++スタイル)レイアウトマッピングポリシー (class) | C++23 |
2323
| [`layout_stride`](mdspan/layout_stride.md) | ストライド幅指定レイアウトマッピングポリシー (class) | C++23 |
24+
| [`layout_left_padded`](mdspan/layout_left_padded.md) | パディングあり列優先レイアウトマッピングポリシー (class templte) | C++26 |
25+
| [`layout_right_padded`](mdspan/layout_right_padded.md) | パディングあり行優先レイアウトマッピングポリシー (class templte) | C++26 |
2426

2527

2628
## 要素アクセサ
@@ -62,3 +64,4 @@
6264
## 参照
6365
- [P0009R18 MDSPAN](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0009r18.html)
6466
- [P2630R4 Submdspan](https://open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2630r4.html)
67+
- [P2642R5 Padded mdspan layouts](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2642r5.html)

reference/mdspan/LayoutMapping.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ LayoutMappingを満たす型`M`は
9393
- [`layout_left::mapping<E>`](layout_left/mapping.md)
9494
- [`layout_right::mapping<E>`](layout_right/mapping.md)
9595
- [`layout_stride::mapping<E>`](layout_stride/mapping.md)
96+
- [`layout_left_padded<PV>::mapping<E>`](layout_left_padded/mapping.md.nolink)
97+
- [`layout_right_padded<PV>::mapping<E>`](layout_right_padded/mapping.md.nolink)
9698
- [`layout_blas_packed<T,SO>::mapping<E>`](/reference/linalg/layout_blas_packed/mapping.md)
9799

98100

reference/mdspan/LayoutMappingPolicy.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ LayoutMappingPolicyを満たす型`MP`は
4040
- [`layout_left`](layout_left.md)
4141
- [`layout_right`](layout_right.md)
4242
- [`layout_stride`](layout_stride.md)
43+
- [`layout_left_padded<PV>`](layout_left_padded.md)
44+
- [`layout_right_padded<PV>`](layout_right_padded.md)
4345
- [`linalg::layout_blas_packed<T,SO>`](/reference/linalg/layout_blas_packed.md)
4446
4547
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# layout_left_padded
2+
* mdspan[meta header]
3+
* class template[meta id-type]
4+
* std[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
template<size_t PaddingValue = dynamic_extent>
10+
struct layout_left_padded {
11+
template<class Extents>
12+
class mapping;
13+
};
14+
}
15+
```
16+
* dynamic_extent[link /reference/span/dynamic_extent.md]
17+
* Extents[link extents.md]
18+
* mapping[link layout_left_padded/mapping.md.nolink]
19+
20+
## 概要
21+
`layout_left_padded`は、多次元配列ビュー[`mdspan`](mdspan.md)に対して、パディングあり列優先(column major)[レイアウトマッピング](LayoutMapping.md)を表現するポリシークラスである。
22+
23+
全要素が隣接配置される[`layout_left`](layout_left.md)とは異なり、`layout_left_padded`では最左次元の隣次元(第1次元)ストライド幅`stride(1)`が最左次元の要素数`extent(0)`よりも大きい、つまり第1次元においてパディングが挿入される可能性がある。
24+
25+
`layout_left_padded`の特殊化は、[レイアウトマッピングポリシー要件](LayoutMappingPolicy.md)を満たす[トリビアル型](/reference/type_traits/is_trivial.md)である。
26+
27+
28+
## メンバ型
29+
30+
| 名前 | 説明 | 対応バージョン |
31+
|------|------|----------------|
32+
| [`mapping`](layout_left_padded/mapping.md.nolink) | レイアウトマッピング | C++26 |
33+
34+
35+
## 例
36+
```cpp example
37+
#include <mdspan>
38+
#include <print>
39+
40+
int main()
41+
{
42+
double arr[] = {1, 2, 0, 0, 3, 4, 0, 0, 5, 6, 0, 0};
43+
// 1 3 5
44+
// 2 4 6
45+
// - - -
46+
// - - -
47+
48+
// 要素数2x3の2次元配列/列優先レイアウト/アライメント4
49+
using Ext2x3 = std::extents<size_t, 2, 3>
50+
std::mdspan<double, Ext2x3, std::layout_left_padded<4>> mat{arr};
51+
52+
for (size_t i = 0; i < mat.extent(0); ++i) {
53+
for (size_t j = 0; j < mat.extent(1); ++j) {
54+
std::print("{}{}", (j ? " " : ""), mat[i, j]);
55+
}
56+
std::println();
57+
}
58+
}
59+
```
60+
* std::layout_left_padded[color ff0000]
61+
* extent[link mdspan/extent.md]
62+
63+
### 出力
64+
```
65+
1 3 5
66+
2 4 6
67+
```
68+
69+
70+
## バージョン
71+
### 言語
72+
- C++26
73+
74+
### 処理系
75+
- [Clang](/implementation.md#clang): ??
76+
- [GCC](/implementation.md#gcc): ??
77+
- [ICC](/implementation.md#icc): ??
78+
- [Visual C++](/implementation.md#visual_cpp): ??
79+
80+
81+
## 関連項目
82+
- [`layout_left`](layout_left.md)
83+
84+
85+
## 参照
86+
- [P2642R5 Padded mdspan layouts](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2642r5.html)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# layout_right_padded
2+
* mdspan[meta header]
3+
* class template[meta id-type]
4+
* std[meta namespace]
5+
* cpp26[meta cpp]
6+
7+
```cpp
8+
namespace std {
9+
template<size_t PaddingValue = dynamic_extent>
10+
struct layout_right_padded {
11+
template<class Extents>
12+
class mapping;
13+
};
14+
}
15+
```
16+
* dynamic_extent[link /reference/span/dynamic_extent.md]
17+
* Extents[link extents.md]
18+
* mapping[link layout_right_padded/mapping.md.nolink]
19+
20+
## 概要
21+
`layout_right_padded`は、多次元配列ビュー[`mdspan`](mdspan.md)に対して、パディングあり行優先(row major)[レイアウトマッピング](LayoutMapping.md)を表現するポリシークラスである。
22+
23+
全要素が隣接配置される[`layout_right`](layout_right.md)とは異なり、`layout_right_padded`では最右次元の隣次元(第R-2次元)ストライド幅`stride(`[`extents_type​::​rank()`](extents/rank.md) `- 2)`が最右次元の要素数`extent(extents_type​::​rank() - 1)`よりも大きい、つまり第R-2次元においてパディングが挿入される可能性がある。
24+
25+
`layout_right_padded`の特殊化は、[レイアウトマッピングポリシー要件](LayoutMappingPolicy.md)を満たす[トリビアル型](/reference/type_traits/is_trivial.md)である。
26+
27+
28+
## メンバ型
29+
30+
| 名前 | 説明 | 対応バージョン |
31+
|------|------|----------------|
32+
| [`mapping`](layout_right_padded/mapping.md.nolink) | レイアウトマッピング | C++26 |
33+
34+
35+
## 例
36+
```cpp example
37+
#include <mdspan>
38+
#include <print>
39+
40+
int main()
41+
{
42+
double arr[] = {1, 2, 3, 0, 4, 5, 6, 0};
43+
// 1 2 3 -
44+
// 4 5 6 -
45+
46+
// 要素数2x3の2次元配列/行優先レイアウト/アライメント4
47+
using Ext2x3 = std::extents<size_t, 2, 3>
48+
std::mdspan<double, Ext2x3, std::layout_right_padded<4>> mat{arr};
49+
50+
for (size_t i = 0; i < mat.extent(0); ++i) {
51+
for (size_t j = 0; j < mat.extent(1); ++j) {
52+
std::print("{}{}", (j ? " " : ""), mat[i, j]);
53+
}
54+
std::println();
55+
}
56+
}
57+
```
58+
* std::layout_right_padded[color ff0000]
59+
* extent[link mdspan/extent.md]
60+
61+
### 出力
62+
```
63+
1 2 3
64+
4 5 6
65+
```
66+
67+
68+
## バージョン
69+
### 言語
70+
- C++26
71+
72+
### 処理系
73+
- [Clang](/implementation.md#clang): ??
74+
- [GCC](/implementation.md#gcc): ??
75+
- [ICC](/implementation.md#icc): ??
76+
- [Visual C++](/implementation.md#visual_cpp): ??
77+
78+
79+
## 関連項目
80+
- [`layout_right`](layout_right.md)
81+
82+
83+
## 参照
84+
- [P2642R5 Padded mdspan layouts](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2642r5.html)

0 commit comments

Comments
 (0)