@@ -711,7 +711,7 @@ class AbstractFunction(sympy.Function, Basic, Pickable, Evaluable):
711711 effect if autopadding is disabled, which is the default behavior.
712712 """
713713
714- __rkwargs__ = ('name' , 'dtype' , 'grid' , 'halo' , 'padding' , ' ghost' ,
714+ __rkwargs__ = ('name' , 'dtype' , 'grid' , 'halo' , 'ghost' ,
715715 'alias' , 'space' , 'function' , 'is_transient' , 'avg_mode' )
716716
717717 __properties__ = ('is_const' , 'is_transient' )
@@ -743,17 +743,16 @@ def __new__(cls, *args, **kwargs):
743743 return function
744744
745745 # If dimensions have been replaced, then it is necessary to set `function`
746- # to None. It may also be necessary to remove halo and padding so that
747- # they are rebuilt with the new dimensions
746+ # to None. It may also be necessary to remove halo so that it is rebuilt
747+ # with the new dimensions
748748 if function is not None and function .dimensions != dimensions :
749749 function = kwargs ['function' ] = None
750- for i in ('halo' , 'padding' ):
751- if len (kwargs [i ]) != len (dimensions ):
752- kwargs .pop (i )
753- else :
754- # Downcast from DimensionTuple so that the new `dimensions`
755- # are used down the line
756- kwargs [i ] = tuple (kwargs [i ])
750+ if len (kwargs ['halo' ]) != len (dimensions ):
751+ kwargs .pop ('halo' )
752+ else :
753+ # Downcast from DimensionTuple so that the new `dimensions`
754+ # are used down the line
755+ kwargs ['halo' ] = tuple (kwargs ['halo' ])
757756
758757 with sympy_mutex :
759758 # Go straight through Basic, thus bypassing caching and machinery
@@ -890,8 +889,10 @@ def __halo_setup__(self, **kwargs):
890889 halo = tuple (kwargs .get ('halo' , ((0 , 0 ),)* self .ndim ))
891890 return DimensionTuple (* halo , getters = self .dimensions )
892891
893- def __padding_setup__ (self , padding = None , ** kwargs ):
894- padding = tuple (padding or ((0 , 0 ),)* self .ndim )
892+ def __padding_setup__ (self , ** kwargs ):
893+ # `padding=` is never honored: derived from policy to avoid stride
894+ # inconsistencies between Functions sharing dimensions/halo
895+ padding = ((0 , 0 ),)* self .ndim
895896 return DimensionTuple (* padding , getters = self .dimensions )
896897
897898 @cached_property
@@ -906,36 +907,26 @@ def __padding_dtype__(self):
906907 return np .float32
907908
908909 def __padding_setup_smart__ (self , ** kwargs ):
909- nopadding = ((0 , 0 ),)* self .ndim
910-
911- if not self .__padding_dtype__ :
912- return nopadding
913-
914- # The padded Dimension
915- if not self .space_dimensions :
916- return nopadding
917- d = self .space_dimensions [- 1 ]
910+ padding = [(0 , 0 )]* self .ndim
918911
919- # Last space Dimension is not the most inner Dimension
920- if d != self .dimensions [- 1 ]:
921- return nopadding
912+ if not self .__padding_dtype__ or not self ._padded_dimensions :
913+ return tuple (padding )
922914
923915 mmts = configuration ['platform' ].max_mem_trans_size (self .__padding_dtype__ )
924916
925- snp = self ._size_nopad [d ]
926- remainder = snp % mmts
927- if remainder == 0 :
928- # Already a multiple of `mmts`, no need to pad
929- return nopadding
930- else :
917+ for d in self ._padded_dimensions :
918+ snp = self ._size_nopad [d ]
919+ remainder = snp % mmts
920+ if remainder == 0 :
921+ # Already a multiple of `mmts`, no need to pad
922+ continue
923+
931924 from devito .symbolics import RoundUp # noqa
932925 v = RoundUp (snp , mmts ) - snp
933926 if v .is_Integer :
934927 v = int (v )
935928
936- dpadding = (0 , v )
937- padding = [(0 , 0 )]* self .ndim
938- padding [self .dimensions .index (d )] = dpadding
929+ padding [self .dimensions .index (d )] = (0 , v )
939930
940931 return tuple (padding )
941932
@@ -986,6 +977,18 @@ def dimensions(self):
986977 """Tuple of Dimensions representing the object indices."""
987978 return DimensionTuple (* self ._dimensions , getters = self ._dimensions )
988979
980+ @property
981+ def _padded_dimensions (self ):
982+ try :
983+ d = self .space_dimensions [- 1 ]
984+ except IndexError :
985+ return ()
986+
987+ if d is self .dimensions [- 1 ]:
988+ return (d ,)
989+ else :
990+ return ()
991+
989992 @cached_property
990993 def space_dimensions (self ):
991994 """Tuple of Dimensions defining the physical space."""
0 commit comments