MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / copy

Method copy

tensorflow/python/autograph/pyct/ast_util.py:37–60  ·  view source on GitHub ↗

Returns a deep copy of node (excluding some fields, see copy_clean).

(self, node)

Source from the content-addressed store, hash-verified

35 self.preserve_annos = preserve_annos
36
37 def copy(self, node):
38 """Returns a deep copy of node (excluding some fields, see copy_clean)."""
39
40 if isinstance(node, list):
41 return [self.copy(n) for n in node]
42 elif isinstance(node, tuple):
43 return tuple(self.copy(n) for n in node)
44 elif not isinstance(node, (gast.AST, ast.AST)):
45 # Assuming everything that's not an AST, list or tuple is a value type
46 # and may simply be assigned.
47 return node
48
49 assert isinstance(node, (gast.AST, ast.AST))
50
51 new_fields = {}
52 for f in node._fields:
53 if not f.startswith('__') and hasattr(node, f):
54 new_fields[f] = self.copy(getattr(node, f))
55 new_node = type(node)(**new_fields)
56
57 if self.preserve_annos:
58 for k in self.preserve_annos:
59 anno.copyanno(node, new_node, k)
60 return new_node
61
62
63def copy_clean(node, preserve_annos=None):

Callers 15

emit_countersMethod · 0.45
__setitem__Method · 0.45
_VariableRankTestMethod · 0.45
_np_transposeMethod · 0.45
testPermTypeMethod · 0.45
_VariableRankTestMethod · 0.45
_npRelu6Method · 0.45
_VariableRankTestMethod · 0.45
testGradientWithZerosMethod · 0.45
setUpMethod · 0.45

Calls 2

tupleFunction · 0.85
typeFunction · 0.85

Tested by 15

__setitem__Method · 0.36
_VariableRankTestMethod · 0.36
_np_transposeMethod · 0.36
testPermTypeMethod · 0.36
_VariableRankTestMethod · 0.36
_npRelu6Method · 0.36
_VariableRankTestMethod · 0.36
testGradientWithZerosMethod · 0.36
setUpMethod · 0.36