MCPcopy Create free account
hub / github.com/NVIDIA/DALI / _StackEntry

Class _StackEntry

dali/python/nvidia/dali/_conditionals.py:67–174  ·  view source on GitHub ↗

Information about 1 nesting level of if/else statement. Keeps the current branch (if we entered if/else branch) and the data nodes that were produced in their scopes. Keeps the mapping of DataNodes produced in higher scopes that were already split for use in this scope.

Source from the content-addressed store, hash-verified

65
66
67class _StackEntry:
68 """Information about 1 nesting level of if/else statement.
69
70 Keeps the current branch (if we entered if/else branch) and the data nodes that were
71 produced in their scopes. Keeps the mapping of DataNodes produced in higher scopes that
72 were already split for use in this scope.
73 """
74
75 def __init__(self, predicate):
76 self.predicate = predicate
77 self.branch = _Branch.Undefined
78 self.splits = {}
79 self.produced_true = set()
80 self.produced_false = set()
81 # The produced_special handles the case of producing something visible on the same nesting
82 # level, but not in one of the branches and is used by merge code.
83 self.produced_special = set()
84
85 @property
86 def produced(self):
87 """
88 Access the set of hashes of DataNodes produced in the scope of currently selected branch.
89 """
90 if self.branch == _Branch.TrueBranch:
91 return self.produced_true
92 elif self.branch == _Branch.FalseBranch:
93 return self.produced_false
94 else:
95 return self.produced_special | self.produced_true | self.produced_false
96
97 @produced.setter
98 def produced(self, value):
99 """
100 Access the set of hashes of DataNodes produced in the scope of currently selected branch
101 """
102 if self.branch == _Branch.TrueBranch:
103 self.produced_true = value
104 elif self.branch == _Branch.FalseBranch:
105 self.produced_false = value
106 else:
107 self.produced_special = value
108
109 def add_produced(self, data_node):
110 """Add the DataNode or DataNodes to produced in the scope of currently selected branch."""
111 if isinstance(data_node, _DataNode):
112 self.produced |= {_data_node_repr(data_node)}
113 elif isinstance(data_node, list):
114 if not data_node:
115 return
116 if isinstance(data_node[0], _DataNode):
117 self.produced |= set(_data_node_repr(dn) for dn in data_node)
118 elif isinstance(data_node[0], list):
119 flat_list = [item for sublist in data_node for item in sublist]
120 self.add_produced(flat_list)
121 else:
122 raise ValueError(
123 f"Unexpected operator result to register: {data_node}. Expected up to"
124 " two-level nesting of DataNode."

Callers 2

__init__Method · 0.85
push_predicateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected