Skip to content

Commit 5e86be5

Browse files
committed
New issue from Mark Hoemmen: "Clarify mdspan layout mapping requirements for rank == 0"
1 parent 0d1a9c5 commit 5e86be5

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

xml/issue4217.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4217" status="New">
5+
<title>Clarify `mdspan` layout mapping requirements for `rank == 0`</title>
6+
<section>
7+
<sref ref="[mdspan.layout.reqmts]"/>
8+
</section>
9+
<submitter>Mark Hoemmen</submitter>
10+
<date>03 Mar 2025</date>
11+
<priority>99</priority>
12+
13+
<discussion>
14+
<p>
15+
<sref ref="[mdspan.layout.reqmts]"/> p19-21 says that a layout mapping needs to
16+
provide `m.stride(r)`. However, <sref ref="[mdspan.layout.left.obs]"/> p5 constrains
17+
<tt>layout_left::mapping&lt;Extents&gt;::stride(r)</tt> on <tt>Extents::rank() &gt; 0</tt>
18+
being `true`. The same is true of `layout_right::mapping`
19+
(<sref ref="[mdspan.layout.right.obs]"/> p5). (The other Standard mappings in
20+
<sref ref="[views.multidim]"/> and <sref ref="[linalg]"/> do not have this constraint.)
21+
This suggests that a rank-zero `layout_{left,right}::mapping` does not
22+
conform with the layout mapping requirements.
23+
<p/>
24+
On the other hand, other parts of <sref ref="[mdspan.layout.reqmts]"/> imply that
25+
`r` must be in the range [0, `rank()`) for the layout mapping's
26+
extents type. If such an `r` does not exist, which is the case for a
27+
rank-zero layout mapping, then the `m.stride(r)` requirement is
28+
vacuous. This implies that a rank-zero `layout_{left,right}::mapping`
29+
fully conforms with the layout mapping requirements.
30+
<p/>
31+
It is definitely the design intent for rank-zero `mdspan` to work, and
32+
for it to represent a view of a single element. Users can create
33+
rank-zero `mdspan` by invoking its constructor, or by using
34+
`submdspan` where all the slice arguments are convertible to
35+
`index_type`. Even though the normative wording permits this, adding
36+
a <i>Note</i> would clarify the design intent without making the wording
37+
redundant. This was the preferred change per LWG reflector
38+
discussion.
39+
</p>
40+
</discussion>
41+
42+
<resolution>
43+
<p>
44+
This wording is relative to <paper num="N5001"/>.
45+
</p>
46+
47+
<ol>
48+
<li><p>Modify <sref ref="[mdspan.layout.reqmts]"/> as indicated:</p>
49+
50+
<blockquote>
51+
<pre>
52+
m.stride(r)
53+
</pre>
54+
<blockquote>
55+
<p>
56+
-19- <i>Preconditions</i>: `m.is_strided()` is `true`.
57+
<p/>
58+
-20- <i>Result</i>: `typename M::index_type`
59+
<p/>
60+
-21- <i>Returns</i>: `sr` as defined in `m.is_strided()` above.
61+
<p/>
62+
<ins>[<i>Note ?</i>: It is not required for `m.stride(r)` to be well-formed if
63+
`m.extents().rank()` is zero, even if `m.is_always_strided()` is `true`. &mdash;
64+
<i>end note</i>]</ins>
65+
</p>
66+
</blockquote>
67+
</blockquote>
68+
</li>
69+
70+
</ol>
71+
72+
</resolution>
73+
74+
</issue>

0 commit comments

Comments
 (0)