





'''simple docstring'''







import unittest
from dataclasses import dataclass
from typing import Optional

from transformers.utils import ModelOutput


@dataclass
class        __a   (lowerCamelCase  ):
							__a       : float
							__a       : Optional[float]          =							None
							__a       : Optional[float]          =							None





class        __a   (unittest.TestCase  ):

							def      UpperCAmelCase__						(				self				:  Tuple )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   Tuple      =	ModelOutputTest(a=30 )
													self.assertEqual(x.a							,  30 )
													self.assertIsNone(x.b )
													self.assertIsNone(x.c )
													with self.assertRaises(__magic_name__ ):
																			UpperCAmelCase_      :   List[Any]      =	x.d

							def      UpperCAmelCase__						(				self				:  Dict )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Union[str, Any]      =	ModelOutputTest(a=30							,  b=10 )
													self.assertEqual(x[0]							,  30 )
													self.assertEqual(x[1]							,  10 )
													self.assertEqual(x[:2]							,  (30, 10) )
													self.assertEqual(x[:]							,  (30, 10) )

													UpperCAmelCase_      :   Tuple      =	ModelOutputTest(a=30							,  c=10 )
													self.assertEqual(x[0]							,  30 )
													self.assertEqual(x[1]							,  10 )
													self.assertEqual(x[:2]							,  (30, 10) )
													self.assertEqual(x[:]							,  (30, 10) )

							def      UpperCAmelCase__						(				self				:  str )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   str      =	ModelOutputTest(a=30							,  b=10 )
													self.assertEqual(x['''a''']							,  30 )
													self.assertEqual(x['''b''']							,  10 )
													with self.assertRaises(__magic_name__ ):
																			UpperCAmelCase_      :   Optional[Any]      =	x['''c''']

													UpperCAmelCase_      :   int      =	ModelOutputTest(a=30							,  c=10 )
													self.assertEqual(x['''a''']							,  30 )
													self.assertEqual(x['''c''']							,  10 )
													with self.assertRaises(__magic_name__ ):
																			UpperCAmelCase_      :   Union[str, Any]      =	x['''b''']

							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	ModelOutputTest(a=30 )
													self.assertEqual(list(x.keys() )							,  ['''a'''] )
													self.assertEqual(list(x.values() )							,  [30] )
													self.assertEqual(list(x.items() )							,  [('''a''', 30)] )
													self.assertEqual(list(__magic_name__ )							,  ['''a'''] )

													UpperCAmelCase_      :   str      =	ModelOutputTest(a=30							,  b=10 )
													self.assertEqual(list(x.keys() )							,  ['''a''', '''b'''] )
													self.assertEqual(list(x.values() )							,  [30, 10] )
													self.assertEqual(list(x.items() )							,  [('''a''', 30), ('''b''', 10)] )
													self.assertEqual(list(__magic_name__ )							,  ['''a''', '''b'''] )

													UpperCAmelCase_      :   int      =	ModelOutputTest(a=30							,  c=10 )
													self.assertEqual(list(x.keys() )							,  ['''a''', '''c'''] )
													self.assertEqual(list(x.values() )							,  [30, 10] )
													self.assertEqual(list(x.items() )							,  [('''a''', 30), ('''c''', 10)] )
													self.assertEqual(list(__magic_name__ )							,  ['''a''', '''c'''] )

													with self.assertRaises(__magic_name__ ):
																			UpperCAmelCase_      :   Any      =	x.update({'''d''': 20} )
													with self.assertRaises(__magic_name__ ):
																			del x["a"]
													with self.assertRaises(__magic_name__ ):
																			UpperCAmelCase_      :   Tuple      =	x.pop('''a''' )
													with self.assertRaises(__magic_name__ ):
																			UpperCAmelCase_      :   List[Any]      =	x.setdefault('''d'''							,  32 )

							def      UpperCAmelCase__						(				self				:  Tuple )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	ModelOutputTest(a=30 )
													UpperCAmelCase_      :   Union[str, Any]      =	10
													self.assertEqual(x.a							,  10 )
													self.assertEqual(x['''a''']							,  10 )

							def      UpperCAmelCase__						(				self				:  Tuple )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   int      =	ModelOutputTest(a=30 )
													UpperCAmelCase_      :   Dict      =	10
													self.assertEqual(x.a							,  10 )
													self.assertEqual(x['''a''']							,  10 )

							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   Dict      =	ModelOutputTest({'''a''': 30, '''b''': 10} )
													self.assertEqual(list(x.keys() )							,  ['''a''', '''b'''] )
													self.assertEqual(x.a							,  30 )
													self.assertEqual(x.b							,  10 )



							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							Tuple:







													"""simple docstring"""
													UpperCAmelCase_      :   Dict      =	ModelOutputTest([('''a''', 30), ('''b''', 10)] )
													self.assertEqual(list(x.keys() )							,  ['''a''', '''b'''] )
													self.assertEqual(x.a							,  30 )
													self.assertEqual(x.b							,  10 )

													with self.assertRaises(__magic_name__ ):
																			UpperCAmelCase_      :   str      =	ModelOutputTest([('''a''', 30), (10, 10)] )

													UpperCAmelCase_      :   str      =	ModelOutputTest(a=(30, 30) )
													self.assertEqual(list(x.keys() )							,  ['''a'''] )
													self.assertEqual(x.a							,  (30, 30) )









'''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       __UpperCamelCase     (     _A     :					List[str]					)     ->   Any:




	"""simple docstring"""





	if is_torch_available():
		import torch

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

	return isinstance(_A       , np.ndarray					)






class 			lowerCAmelCase					(					a				):



	def 					lowercase  (       self     ):
		lowerCAmelCase       :     List[str]   				=			fields(self     )

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

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

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



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



	def 					lowercase  (       self			,       *snake_case__			,       **snake_case__     ):
		raise Exception(f"You cannot use ``setdefault`` on a {self.__class__.__name__} instance."     )



	def 					lowercase  (       self			,       *snake_case__			,       **snake_case__     ):
		raise Exception(f"You cannot use ``pop`` on a {self.__class__.__name__} instance."     )



	def 					lowercase  (       self			,       *snake_case__			,       **snake_case__     ):
		raise Exception(f"You cannot use ``update`` on a {self.__class__.__name__} instance."     )



	def __getitem__(       self			,       snake_case__     ):
		if isinstance(snake_case__			,       snake_case__     ):
			lowerCAmelCase       :     Dict   				=			dict(self.items()     )
			return inner_dict[k]
		else:
			return self.to_tuple()[k]



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



	def __setitem__(       self			,       snake_case__			,       snake_case__     ):
		# Will raise a KeyException if needed
		super().__setitem__(snake_case__			,       snake_case__     )
		# Don't call self.__setattr__ to avoid recursion errors
		super().__setattr__(snake_case__			,       snake_case__     )



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