File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -4278,8 +4278,22 @@ def shape(self, value: torch.Size):
42784278 )
42794279 self ._shape = _size (value )
42804280
4281- def is_empty (self ):
4282- """Whether the composite spec contains specs or not."""
4281+ def is_empty (self , recurse : bool = False ):
4282+ """Whether the composite spec contains specs or not.
4283+
4284+ Args:
4285+ recurse (bool): whether to recursively assess if the spec is empty.
4286+ If ``True``, will return ``True`` if there are no leaves. If ``False``
4287+ (default) will return whether there is any spec defined at the root level.
4288+
4289+ """
4290+ if recurse :
4291+ for spec in self ._specs .values ():
4292+ if spec is None :
4293+ continue
4294+ if isinstance (spec , Composite ) and spec .is_empty (recurse = True ):
4295+ continue
4296+ return False
42834297 return len (self ._specs ) == 0
42844298
42854299 @property
You can’t perform that action at this time.
0 commit comments