LEWG Kona 11/2023 mdarray

Open
#434 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp
Domain
documentation

Research direction

The issue contains an mdarray design sketch but names no repository file, test, or entry point. Start by reviewing the stated relationship to mdspan, then turn the listed constructors, container behavior, layouts, and move requirements into a scoped proposal; the issue does not define a concrete completion criterion.

Written by the indexing model from the issue text.

Description

Super Brief mdarray introduction

Why we want mdarray

Creating a simple 2D array with mdspan requires multiple steps because mdspan is non-owning.

// Create a mapping:
layout_left map(extents(N,M));

// Create an allocation
vector<int> data(map.required_span_size());

// Create mdspan:
mdspan a(data.data(), map);

mdarray is a multidimensional array with value-semantics and makes the above simpler

// default layout
mdarray a(N,M);
// other layout
mdarray b(layout_left(extents(N,M))); 
What aspects of mdspan does mdarray have

mdarray has the

  • element_type,
  • extents and
  • layout policy aspects of mdspan

The accessor policy is replaced by a container type.

template<class ElementType, class Extents, class Layout, class Accessor>
class mdspan {
   public:
   ...
     template<class ... Indices>
     reference operator [] (Indices ... idx) const { return acc_.access(ptr_, map_(idx...)); }
   private:
     typename Accessor::data_handle_type ptr_;
     Layout::mapping<Extents> map_;
     Accessor acc_;
};

template<class ElementType, class Extents, class Layout, class Container>
class mdarray {
   public:
   ...
     template<class ... Indices>
     reference operator [] (Indices ... idx) { return ctr_[map_(idx...)]); }

   private:
     Layout::mapping<Extents> map_;
     Container ctr_;
};

This means mdarray does not have the kind of access modality customization point functionality of mdspan, but that functionality is anyway intended for local specialization of accesses, and thus more suited for the view-like class.

Constructors
  • have constructors similar to mdspan
    • indicies
    • extents
    • mapping
  • Combine those with copy from container, and move from container
  • Combine all of those with add optional allocator
Move behavior
  • relies on containers move behavior
  • preconditions on problematic functions to check that container size is larger or equal to required_span_size()
Dominant language
HTML
Stars
29
Forks
26
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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.

More from ORNL/cpp-proposals-pub

All issues in ORNL/cpp-proposals-pub

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.