def copy(self):
"""Copies the link hierarchy to new one.
The whole hierarchy rooted by this link is copied. The copy is
basically shallow, except that the parameter variables are also
shallowly copied. It means that the parameter variables of copied one
are different from ones of original link, while they share the data and
gradient arrays.
The name of the link is reset on the copy, since the copied instance
does not belong to the original parent chain (even if exists).
Returns:
Link: Copied link object.
"""
ret = copy.copy(self)
ret._params = list(self._params)
ret._persistent = list(self._persistent)
ret.name = None
d = ret.__dict__
for name in ret._params:
d[name] = copy.copy(d[name])
return ret
评论列表
文章目录