"""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   _lowerCamelCase ( UpperCAmelCase__					)							->     Union[str, Any]:


   '''simple docstring'''


   if is_torch_available():
      import torch

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

   return isinstance(lowercase_,np.ndarray					)




class SCREAMING_SNAKE_CASE     (    __UpperCAmelCase	):







 """simple docstring"""


 def        _lowerCAmelCase				(   self		:      List[Any]				)				->			Any:




    '''simple docstring'''






    a__     				=		fields(self				)

    # Safety and consistency checks
    if not len(lowercase_				):
       raise ValueError(F'''{self.__class__.__name__} has no fields.'''				)

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

    if other_fields_are_none and isinstance(lowercase_					,   lowercase_				):
       for key, value in first_field.items():
          a__     				=		value
    else:
       for field in class_fields:
          a__     				=		getattr(self					,   field.name				)
          if v is not None:
             a__     				=		v


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




    '''simple docstring'''






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


 def        _lowerCAmelCase				(   self		:      Union[str, Any]					,   *_snake_case		:      str					,   **_snake_case		:      List[Any]				)				->			Union[str, Any]:




    '''simple docstring'''






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


 def        _lowerCAmelCase				(   self		:      int					,   *_snake_case		:      Tuple					,   **_snake_case		:      Any				)				->			int:




    '''simple docstring'''






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


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




    '''simple docstring'''






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


 def __getitem__(   self		:      str					,   _snake_case		:      List[Any]				)				->			Optional[int]:




    '''simple docstring'''






    if isinstance(lowercase_					,   lowercase_				):
       a__     				=		dict(self.items()				)
       return inner_dict[k]
    else:
       return self.to_tuple()[k]


 def __setattr__(   self		:      Optional[int]					,   _snake_case		:      int					,   _snake_case		:      int				)				->			Union[str, Any]:




    '''simple docstring'''






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


 def __setitem__(   self		:      Optional[Any]					,   _snake_case		:      List[str]					,   _snake_case		:      Any				)				->			Union[str, Any]:




    '''simple docstring'''






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



 def        _lowerCAmelCase				(   self		:      Dict				)				->			Tuple[Any]:




    '''simple docstring'''






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



"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__magic_name__    				=					{
    "configuration_donut_swin": ["DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP", "DonutSwinConfig"],
    "processing_donut": ["DonutProcessor"],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __magic_name__    				=					[
         "DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST",
         "DonutSwinModel",
         "DonutSwinPreTrainedModel",
     ]

try:
     if not is_vision_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     __magic_name__    				=					["DonutFeatureExtractor"]
     __magic_name__    				=					["DonutImageProcessor"]


if TYPE_CHECKING:
     from .configuration_donut_swin import DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP, DonutSwinConfig
     from .processing_donut import DonutProcessor

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_donut_swin import (
              DONUT_SWIN_PRETRAINED_MODEL_ARCHIVE_LIST,
              DonutSwinModel,
              DonutSwinPreTrainedModel,
          )

     try:
          if not is_vision_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .feature_extraction_donut import DonutFeatureExtractor
          from .image_processing_donut import DonutImageProcessor

else:
     import sys

     __magic_name__    				=					_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


