A function that is used to clone an expression.
Cloning is roughly equivalent to calling copy.deepcopy
.
However, the clone_leaves
argument can be used to
clone only interior (i.e. non-leaf) nodes in the expression
tree. Note that named expression objects are treated as
leaves when clone_leaves
is True
, and hence
those subexpressions are not cloned.
This function uses a non-recursive
logic, which makes it more scalable than the logic in
copy.deepcopy
.
- Parameters:
expr – The expression that will be cloned.
substitute (dict) – A dictionary mapping object ids to
objects. This dictionary has the same semantics as
the memo object used with copy.deepcopy
. Defaults
to None, which indicates that no user-defined
dictionary is used.
- Returns:
The cloned expression.