tensorly.backend_context

backend_context(backend, local_threadsafe=False)

Context manager to set the backend for TensorLy.

Parameters:
backend{‘numpy’, ‘pytorch’, ‘tensorflow’, ‘cupy’, ‘paddle’}

The name of the backend to use. Default is ‘numpy’.

local_threadsafebool, optional

If True, the backend will not become the default backend for all threads. Note that this only affects threads where the backend hasn’t already been explicitly set. If False (default) the backend is set for the entire session.

Examples

Set the backend to numpy globally for this thread: >>> import tensorly as tl >>> tl.set_backend(‘numpy’) >>> with tl.backend_context(‘pytorch’): … pass >>> with tl.backend_context(‘paddle’): … pass