kokkos / kokkos/mdspan

Structured bindings for `extents`

Open
#102 9 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
507
Forks
87
Avg merge
15h 27m
Merged PRs (30d)
2

Description

The extents class could provide support for structured bindings to improve its usability. This way, we could transform your example from:

  stdex::mdspan m{d.data(), stdex::extents{3, 3}};
  for (std::size_t i = 0; i < m.extent(0); ++i)
    for (std::size_t j = 0; j < m.extent(1); ++j) // was m.extent(0)

to:

  stdex::mdspan m{d.data(), stdex::extents{3, 3}};
  const auto [rows, cols] = m.extents();
  for (std::size_t i = 0; i < rows; ++i)
    for (std::size_t j = 0; j < cols; ++j)

See your modified example: https://godbolt.org/z/enYcvbG8a

It's not a huge improvement, but with increasing rank, it can save some redundant mentioning of m.extents(...). Or prevent accidentially passing the wrong index ;)
It also helps when I pass an instance of extents around without its surrounding mdspan. Then instead of:

const auto x = e.extent(0);
const auto y = e.extent(1);
const auto z = e.extent(2);

I can write:

const auto [x, y, z] = e;

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no implementation file or test. Start by reading the extents API and the linked Compiler Explorer example, then identify the existing test location for extents behavior; done means an extents instance supports the shown structured-binding forms while preserving its extent values.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.