latest (dev)
Copy
Latest development documentation · Updated 2026-10-08
tensorplay.func.functionalize
- tensorplay.func.functionalize(func: Callable, *, remove: str = 'mutations') Callable
Returns a version of
functhat leaves its arguments untouched.funcmay write into its inputs in place; the wrapper hands it private copies instead, so the caller’s tensors – and any views onto them – come back exactly as they went in, while the returned value is unchanged.- Parameters:
func (Callable) – the function to make side-effect free.
remove (str) –
"mutations"copies every tensor argument."mutations_and_views"additionally detaches the copies from any aliasing they arrived with, so writes through a view of an argument cannot reach another argument either.
Example
>>> def f(x): ... x.add_(1) ... return x >>> x = tensorplay.zeros(3) >>> out = functionalize(f)(x) >>> x # unchanged tensor([0., 0., 0.])
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

