MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / _find_var_recursive

Method _find_var_recursive

python/paddle/base/framework.py:4528–4562  ·  view source on GitHub ↗

Get a Variable by name from this block recursively. Args: name(str): the Variable's name. Returns: Variable: the Variable with the giving name. Or None if not found.

(self, name)

Source from the content-addressed store, hash-verified

4526 return v
4527
4528 def _find_var_recursive(self, name):
4529 """
4530 Get a Variable by name from this block recursively.
4531
4532 Args:
4533 name(str): the Variable's name.
4534
4535 Returns:
4536 Variable: the Variable with the giving name. Or None if not found.
4537 """
4538 frontier = []
4539 visited = set()
4540
4541 frontier.append(self)
4542
4543 prog = self.program
4544
4545 while len(frontier) != 0: # BFS
4546 cur = frontier[0]
4547 frontier = frontier[1:]
4548
4549 if id(cur) in visited:
4550 continue
4551
4552 if cur.has_var(name):
4553 return cur.var(name)
4554
4555 if cur.parent_idx != -1:
4556 frontier.append(prog.block(cur.parent_idx))
4557
4558 if cur.forward_block_idx != -1:
4559 frontier.append(prog.block(cur.forward_block_idx))
4560
4561 visited.add(id(cur))
4562 return None
4563
4564 def _var_recursive(self, name):
4565 """

Callers 15

_var_recursiveMethod · 0.95
_update_grad_persistableFunction · 0.80
completeMethod · 0.80
_completeMethod · 0.80
copy_var_to_parent_blockFunction · 0.80
_insert_cast_opFunction · 0.80
get_promote_dtypeFunction · 0.80
get_amp_dst_dtypeFunction · 0.80

Calls 7

setClass · 0.85
idFunction · 0.50
appendMethod · 0.45
has_varMethod · 0.45
varMethod · 0.45
blockMethod · 0.45
addMethod · 0.45

Tested by 1

test_recurrent_feedMethod · 0.64