




'''simple docstring'''


import re
def 				SCREAMING_SNAKE_CASE(      __lowercase  ) ->   str:
     def docstring_decorator(__lowercase  ):
          A:		Optional[int]        =		fn.__doc__
          A:		str        =		func_doc.split('''\n'''  )
          A:		int        =		0
          while i < len(__lowercase  ) and re.search(r'''^\s*Examples?:\s*$'''		,							lines[i]  ) is None:
               i += 1
          if i < len(__lowercase  ):
               A:		List[Any]        =		example_docstring
               A:		List[Any]        =		'''\n'''.join(__lowercase  )
          else:
               raise ValueError(
                   F"""The function {fn} should have an empty 'Examples:' in its docstring as placeholder, """
                   F"""current docstring is:\n{func_doc}"""  )
          A:		Optional[Any]        =		func_doc
          return fn

     return docstring_decorator












'''simple docstring'''


from collections import OrderedDict
from dataclasses import fields
from typing import Any, Tuple

import numpy as np

from .import_utils import is_torch_available
def 				SCREAMING_SNAKE_CASE(      __lowercase  ) ->   Tuple:
     if is_torch_available():
          import torch

          if isinstance(__lowercase		,							torch.Tensor  ):
               return True

     return isinstance(__lowercase		,							np.ndarray  )






class 	lowerCAmelCase_  (					UpperCAmelCase_       ):







  '''simple docstring'''

  def 				_snake_case    (   self							:       Union[str, Any]  ) ->		Dict:







       '''simple docstring'''



       A:		List[str]        =		fields(self  )

       # Safety and consistency checks
       if not len(SCREAMING_SNAKE_CASE_  ):
            raise ValueError(f"""{self.__class__.__name__} has no fields."""  )

       A:		Optional[Any]        =		getattr(self				,     class_fields[0].name  )
       A:		Any        =		all(getattr(self				,     field.name  ) is None for field in class_fields[1:]  )

       if other_fields_are_none and isinstance(SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_  ):
            for key, value in first_field.items():
                 A:		Any        =		value
       else:
            for field in class_fields:
                 A:		List[Any]        =		getattr(self				,     field.name  )
                 if v is not None:
                      A:		int        =		v



  def __delitem__(   self							:       Optional[int]				,     *SCREAMING_SNAKE_CASE_							:       Union[str, Any]				,     **SCREAMING_SNAKE_CASE_							:       List[str]  ) ->		List[str]:







       '''simple docstring'''



       raise Exception(f"""You cannot use ``__delitem__`` on a {self.__class__.__name__} instance."""  )



  def 				_snake_case    (   self							:       int				,     *SCREAMING_SNAKE_CASE_							:       Optional[Any]				,     **SCREAMING_SNAKE_CASE_							:       Any  ) ->		str:







       '''simple docstring'''



       raise Exception(f"""You cannot use ``setdefault`` on a {self.__class__.__name__} instance."""  )



  def 				_snake_case    (   self							:       int				,     *SCREAMING_SNAKE_CASE_							:       Dict				,     **SCREAMING_SNAKE_CASE_							:       Any  ) ->		Optional[Any]:







       '''simple docstring'''



       raise Exception(f"""You cannot use ``pop`` on a {self.__class__.__name__} instance."""  )



  def 				_snake_case    (   self							:       int				,     *SCREAMING_SNAKE_CASE_							:       int				,     **SCREAMING_SNAKE_CASE_							:       Optional[Any]  ) ->		int:







       '''simple docstring'''



       raise Exception(f"""You cannot use ``update`` on a {self.__class__.__name__} instance."""  )



  def __getitem__(   self							:       int				,     SCREAMING_SNAKE_CASE_							:       List[Any]  ) ->		Tuple:







       '''simple docstring'''



       if isinstance(SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_  ):
            A:		Any        =		dict(self.items()  )
            return inner_dict[k]
       else:
            return self.to_tuple()[k]



  def __setattr__(   self							:       Optional[Any]				,     SCREAMING_SNAKE_CASE_							:       Union[str, Any]				,     SCREAMING_SNAKE_CASE_							:       Union[str, Any]  ) ->		Dict:







       '''simple docstring'''



       if name in self.keys() and value is not None:
            # Don't call self.__setitem__ to avoid recursion errors
            super().__setitem__(SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_  )
       super().__setattr__(SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_  )



  def __setitem__(   self							:       Optional[Any]				,     SCREAMING_SNAKE_CASE_							:       Union[str, Any]				,     SCREAMING_SNAKE_CASE_							:       Union[str, Any]  ) ->		int:







       '''simple docstring'''



       super().__setitem__(SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_  )
       # Don't call self.__setattr__ to avoid recursion errors
       super().__setattr__(SCREAMING_SNAKE_CASE_				,     SCREAMING_SNAKE_CASE_  )




  def 				_snake_case    (   self							:       Optional[Any]  ) ->		Tuple[Any]:







       '''simple docstring'''



       return tuple(self[k] for k in self.keys()  )






