1313)
1414from devito .mpi .halo_scheme import HaloScheme , HaloTouch
1515from devito .mpi .reduction_scheme import DistReduce
16- from devito .symbolics import estimate_cost
16+ from devito .symbolics import estimate_cost , uxreplace
1717from devito .tools import (
1818 CacheInstances , as_tuple , cached_hash , filter_ordered , flatten , infer_dtype
1919)
@@ -112,7 +112,7 @@ def dimensions(self):
112112 @cached_property
113113 def exprs_dimensions (self ):
114114 """
115- The Dimensions that appear explicitly in the Cluster expressions.
115+ The Dimensions that appear explicitly in the expressions.
116116 """
117117 dims_explicit = {i for i in self .free_symbols if i .is_Dimension }
118118 dims_implicit = {d for e in self .exprs for d in e .implicit_dims }
@@ -121,7 +121,7 @@ def exprs_dimensions(self):
121121 @cached_property
122122 def guards_dimensions (self ):
123123 """
124- The Dimensions that appear explicitly in the Cluster guards.
124+ The Dimensions that appear explicitly in the guards.
125125 """
126126 syms_guards = {d for e in self .guards .values () for d in e .free_symbols }
127127 dims_guards = {i for i in syms_guards if i .is_Dimension }
@@ -142,7 +142,7 @@ def used_dimensions(self):
142142 @cached_property
143143 def dist_dimensions (self ):
144144 """
145- The Cluster's distributed Dimensions.
145+ The distributed Dimensions.
146146 """
147147 ret = set ()
148148 for f in self .functions :
@@ -168,7 +168,7 @@ def grid(self):
168168 elif len (grids ) == 1 :
169169 return grids .pop ()
170170 else :
171- raise ValueError ("Cluster has no unique Grid " )
171+ raise ValueError ("Multiple Grids detected " )
172172
173173 @cached_property
174174 def is_scalar (self ):
@@ -296,31 +296,27 @@ def is_glb_load_to_mem_shared(self):
296296 @cached_property
297297 def is_async (self ):
298298 """
299- True if an asynchronous Cluster , False otherwise.
299+ True if asynchronous, False otherwise.
300300 """
301301 return any (isinstance (s , (WithLock , PrefetchUpdate ))
302302 for s in flatten (self .syncs .values ()))
303303
304304 @cached_property
305305 def is_wait (self ):
306306 """
307- True if a Cluster waiting on a lock (that is a special synchronization
308- operation), False otherwise.
307+ True if waiting on a lock (that is a special synchronization operation),
308+ False otherwise.
309309 """
310310 return any (isinstance (s , WaitLock )
311311 for s in flatten (self .syncs .values ()))
312312
313313 @cached_property
314314 def dtype (self ):
315315 """
316- The arithmetic data type of the Cluster .
316+ The arithmetic data type of the enclosed expressions .
317317
318- If the Cluster performs floating point arithmetic, then the expressions
319- performing integer arithmetic are ignored, assuming that they are only
320- carrying out array index calculations.
321-
322- If two expressions perform calculations with different precision,
323- the data type with highest precision is returned.
318+ If two expressions perform calculations with different precision, the data
319+ type with highest precision is returned.
324320 """
325321 dtypes = set ()
326322 for i in self .exprs :
@@ -336,8 +332,8 @@ def dtype(self):
336332 @cached_property
337333 def dspace (self ):
338334 """
339- Derive the DataSpace of the Cluster from its expressions,
340- IterationSpace, and Guards.
335+ The DataSpace deriving from the enclosed expressions, IterationSpace ,
336+ and Guards.
341337 """
342338 accesses = detect_accesses (self .exprs )
343339
@@ -421,8 +417,8 @@ def ops(self):
421417 @cached_property
422418 def traffic (self ):
423419 """
424- The Cluster compulsory traffic (number of reads/writes), as a mapper
425- from Functions to IntervalGroups.
420+ The compulsory traffic (number of reads/writes), as a mapper from
421+ Functions to IntervalGroups.
426422
427423 Notes
428424 -----
@@ -509,30 +505,6 @@ def __getattr__(self, name):
509505 raise AttributeError (name ) from None
510506 return getattr (block , name )
511507
512- @property
513- def exprs (self ):
514- return self ._block .exprs
515-
516- @property
517- def ispace (self ):
518- return self ._block .ispace
519-
520- @property
521- def guards (self ):
522- return self ._block .guards
523-
524- @property
525- def properties (self ):
526- return self ._block .properties
527-
528- @property
529- def syncs (self ):
530- return self ._block .syncs
531-
532- @property
533- def halo_scheme (self ):
534- return self ._block .halo_scheme
535-
536508 @classmethod
537509 def from_clusters (cls , * clusters ):
538510 """
@@ -612,6 +584,33 @@ def rebuild(self, *args, **kwargs):
612584 syncs = syncs ,
613585 halo_scheme = halo_scheme )
614586
587+ def subs (self , mapper , compact = ()):
588+ """
589+ Build a new Cluster applying substitutions rules to `self`.
590+ """
591+ if not mapper :
592+ return self
593+
594+ if self .halo_scheme :
595+ raise NotImplementedError
596+
597+ key0 = lambda i : i .is_Block
598+ subs0 = {d : self .ispace [d ].promote (key0 ).dim for d in compact }
599+
600+ subs = {** mapper , ** subs0 }
601+ exprs = [uxreplace (e , subs ) for e in self .exprs ]
602+
603+ ispace = self .ispace .switch (mapper )
604+ key = lambda i : key0 (i ) and i in flatten (d ._defines for d in subs0 )
605+ ispace = ispace .promote (key , mode = 'total' )
606+
607+ guards = self .guards .subs (mapper ).promote (subs0 )
608+ properties = self .properties .subs (mapper ).promote (subs0 )
609+ syncs = self .syncs .subs (mapper )
610+
611+ return self .__class__ (exprs = exprs , ispace = ispace , guards = guards ,
612+ properties = properties , syncs = syncs )
613+
615614
616615class ClusterGroup (tuple ):
617616
@@ -691,7 +690,15 @@ def dspace(self):
691690 """Return the DataSpace of this ClusterGroup."""
692691 return DataSpace .union (* [i .dspace .reset () for i in self ])
693692
694- @property
693+ @cached_property
694+ def is_dense (self ):
695+ return all (i .is_dense for i in self )
696+
697+ @cached_property
698+ def is_wild (self ):
699+ return all (i .is_wild for i in self )
700+
701+ @cached_property
695702 def is_halo_touch (self ):
696703 return all (i .is_halo_touch for i in self )
697704
0 commit comments