@@ -912,8 +912,30 @@ def switch(self, d0, d1, direction=None):
912912
913913 return IterationSpace (intervals , sub_iterators , directions )
914914
915- def translate (self , d , v0 = 0 , v1 = None ):
916- intervals = self .intervals .translate (d , v0 , v1 )
915+ def translate (self , maybe_dim , v0 = 0 , v1 = None ):
916+ """
917+ Translate the IterationSpace along a given set of Dimensions by
918+ given offsets.
919+
920+ This method can be invoked in three different flavours:
921+
922+ * `ispace.translate(dim, v0, v1)`;
923+ * `ispace.translate(dims, v0, v1)`
924+ Same as before, but applies the translation to all Dimensions
925+ in `dims`;
926+ * `ispace.translate({d0: (v0, v1), d1: v2, ...})`
927+ This is essentially a shortcut to avoid calling `translate` in
928+ a loop at the call site.
929+ """
930+ if not maybe_dim :
931+ return self
932+ elif isinstance (maybe_dim , dict ):
933+ intervals = self .intervals
934+ for d , v in maybe_dim .items ():
935+ intervals = intervals .translate (d , * as_tuple (v ))
936+ else :
937+ intervals = self .intervals .translate (maybe_dim , v0 , v1 )
938+
917939 return IterationSpace (intervals , self .sub_iterators , self .directions )
918940
919941 def reset (self ):
0 commit comments