cpp-proposals-pub icon indicating copy to clipboard operation
cpp-proposals-pub copied to clipboard

P0009: Add follow-on: inverse layout mapping

Open mhoemmen opened this issue 3 years ago • 3 comments

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.

mhoemmen avatar Jun 29 '22 18:06 mhoemmen

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 avatar Jun 30 '22 15:06 crtrott

In particular if it is not exhaustive.

crtrott avatar Jun 30 '22 15:06 crtrott

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().

mhoemmen avatar Jun 30 '22 19:06 mhoemmen