docstr: Context manager to set the backend for TensorLy.
  
  Parameters
  ----------
  backend : {'numpy', 'pytorch', 'tensorflow', 'cupy'}
      The name of the backend to use. Default is 'numpy'.
  local_threadsafe : bool, 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
docstr_tok: ["Context","manager","to","set","the","backend","for","TensorLy",".","Parameters","--","--","--","--","--","backend",":","{","'numpy","'",",","'pytorch","'",",","'tensorflow","'",",","'cupy","'","}","The","name","of","the","backend","to","use",".","Default","is","'numpy","'",".","local_threadsafe",":","bool",",","optional","If","True",",","the","backend","will","not","become","the","default","backend","for","all","threads",".","Note","that","this","only","affects","threads","where","the","backend","has","n'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"]
code: def backend_context(cls, backend, local_threadsafe=False):
      """Context manager to set the backend for TensorLy.
  
      Parameters
      ----------
      backend : {'numpy', 'pytorch', 'tensorflow', 'cupy'}
          The name of the backend to use. Default is 'numpy'.
      local_threadsafe : bool, 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
      """
      _old_backend = cls.current_backend()
      cls.set_backend(backend, local_threadsafe=local_threadsafe)
      try:
          yield
      finally:
          cls.set_backend(_old_backend)
  
imports: import warnings
  from .core import Backend, backend_array
  import importlib
  import os
  import threading
  from contextlib import contextmanager
  import inspect
  import types
  import sys
label_desc: Use image node_id 7 for calling the BackendManager obj's underlying member method code with example usage: obj.backend_context(cls, backend, local_threadsafe) without return types