Computes a tuple of coordinates from a linear index and a shape.
Behavior is undefined if idx is out of the index space defined by shp.