ORNL / cpp-proposals-pub

Collaborating on papers for the ISO C++ committee - public repo
26 stars 26 forks source link

P0009: Add follow-on: inverse layout mapping #275

Open mhoemmen opened 2 years ago

mhoemmen commented 2 years ago

A colleague requested that all unique layout mappings have an inverse mapping function. This would map a 1-D offset to the corresponding multidimensional index tuple, if the offset corresponds to a valid multidimensional index tuple.

My colleague proposed it as a nonmember function, constrained on is_always_unique() and preconditioned on is_unique().

An interesting use case would be to change iteration order in a flattened loop. For example, one might be iterating over [0, required_span_size()) on a 2-D square domain, but might want to view the domain using a 2-D space-filling curve. One could do this by inverting the layout_left mapping, and then giving the resulting (i,j) index pair to a space-filling curve's layout mapping.

crtrott commented 2 years ago

I don't think this is possible in general. I.e. uniqueness is NOT enough to guarantee that there IS an inverse mapping you can express without explicitly generating it, by computing all forward mapping values or?

crtrott commented 2 years ago

In particular if it is not exhaustive.

mhoemmen commented 2 years ago

Right, it's OK if the inverse doesn't always exist. I think it would be fine for the function to be constrained on is_always_unique().