
'''simple docstring'''
import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter







class 			__A					(			TensorFormatter[Mapping, np.ndarray, Mapping]      ):
 def __init__( self      :     Any					, lowerCamelCase      :     List[Any]=None					, **lowerCamelCase      :     str							):



   """simple docstring"""





   super().__init__(features=_lowerCAmelCase							)
   __A		:  str       				=		np_array_kwargs
 def 		lowercase_( self      :     Union[str, Any]					, lowerCamelCase      :     Union[str, Any]							):



   """simple docstring"""





   if isinstance(_lowerCAmelCase					, _lowerCAmelCase							):
     if column and all(
         isinstance(_lowerCAmelCase					, np.ndarray							) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column							):
       return np.stack(_lowerCAmelCase							)
     else:
       # don't use np.array(column, dtype=object)
       # since it fails in certain cases
       # see https://stackoverflow.com/q/51005699
       __A		:  List[str]       				=		np.empty(len(_lowerCAmelCase							)					, dtype=_lowerCAmelCase							)
       __A		:  str       				=		column
       return out
   return column
 def 		lowercase_( self      :     Dict					, lowerCamelCase      :     Union[str, Any]							):



   """simple docstring"""





   if isinstance(_lowerCAmelCase					, (str, bytes, type(_lowerCAmelCase							))							):
     return value
   elif isinstance(_lowerCAmelCase					, (np.character, np.ndarray)							) and np.issubdtype(value.dtype					, np.character							):
     return value
   elif isinstance(_lowerCAmelCase					, np.number							):
     return value

   __A		:  int       				=		{}

   if isinstance(_lowerCAmelCase					, np.ndarray							) and np.issubdtype(value.dtype					, np.integer							):
     __A		:  Optional[int]       				=		{"""dtype""": np.intaa}
   elif isinstance(_lowerCAmelCase					, np.ndarray							) and np.issubdtype(value.dtype					, np.floating							):
     __A		:  Dict       				=		{"""dtype""": np.floataa}
   elif config.PIL_AVAILABLE and "PIL" in sys.modules:
     import PIL.Image

     if isinstance(_lowerCAmelCase					, PIL.Image.Image							):
       return np.asarray(_lowerCAmelCase					, **self.np_array_kwargs							)

   return np.asarray(_lowerCAmelCase					, **{**default_dtype, **self.np_array_kwargs}							)
 def 		lowercase_( self      :     Union[str, Any]					, lowerCamelCase      :     Any							):



   """simple docstring"""





   if config.TORCH_AVAILABLE and "torch" in sys.modules:
     import torch

     if isinstance(_lowerCAmelCase					, torch.Tensor							):
       return self._tensorize(data_struct.detach().cpu().numpy()[()]							)
   if hasattr(_lowerCAmelCase					, """__array__"""							) and not isinstance(_lowerCAmelCase					, (np.ndarray, np.character, np.number)							):
     __A		:  Any       				=		data_struct.__array__()
   # support for nested types like struct of list of struct
   if isinstance(_lowerCAmelCase					, np.ndarray							):
     if data_struct.dtype == object:
       return self._consolidate([self.recursive_tensorize(_lowerCAmelCase							) for substruct in data_struct]							)
   if isinstance(_lowerCAmelCase					, (list, tuple)							):
     return self._consolidate([self.recursive_tensorize(_lowerCAmelCase							) for substruct in data_struct]							)
   return self._tensorize(_lowerCAmelCase							)
 def 		lowercase_( self      :     Optional[int]					, lowerCamelCase      :     dict							):



   """simple docstring"""





   return map_nested(self._recursive_tensorize					, _lowerCAmelCase					, map_list=_lowerCAmelCase							)
 def 		lowercase_( self      :     str					, lowerCamelCase      :     pa.Table							):



   """simple docstring"""





   __A		:  List[str]       				=		self.numpy_arrow_extractor().extract_row(_lowerCAmelCase							)
   __A		:  Dict       				=		self.python_features_decoder.decode_row(_lowerCAmelCase							)
   return self.recursive_tensorize(_lowerCAmelCase							)
 def 		lowercase_( self      :     Any					, lowerCamelCase      :     pa.Table							):



   """simple docstring"""





   __A		:  Any       				=		self.numpy_arrow_extractor().extract_column(_lowerCAmelCase							)
   __A		:  Tuple       				=		self.python_features_decoder.decode_column(_lowerCAmelCase					, pa_table.column_names[0]							)
   __A		:  Optional[int]       				=		self.recursive_tensorize(_lowerCAmelCase							)
   __A		:  Dict       				=		self._consolidate(_lowerCAmelCase							)
   return column






 def 		lowercase_( self      :     Tuple					, lowerCamelCase      :     pa.Table							):



   """simple docstring"""





   __A		:  Dict       				=		self.numpy_arrow_extractor().extract_batch(_lowerCAmelCase							)
   __A		:  List[str]       				=		self.python_features_decoder.decode_batch(_lowerCAmelCase							)
   __A		:  str       				=		self.recursive_tensorize(_lowerCAmelCase							)
   for column_name in batch:
     __A		:  Any       				=		self._consolidate(batch[column_name]							)
   return batch







from ..utils import DummyObject, requires_backends

class      __snake_case				(   metaclass=_UpperCAmelCase):
					SCREAMING_SNAKE_CASE_		:       str								=			["torch", "transformers", "k_diffusion"]
					def __init__(						self       :						Tuple	,      *_lowerCAmelCase       :						Union[str, Any]	,      **_lowerCAmelCase       :						Union[str, Any]  )							->					Dict:



											'''simple docstring'''





											requires_backends(self	,      ['torch', 'transformers', 'k_diffusion']  )
					@classmethod
					def 	a			(						cls       :						Optional[int]	,      *_lowerCAmelCase       :						Any	,      **_lowerCAmelCase       :						Optional[Any]  )							->					Optional[Any]:



											'''simple docstring'''





											requires_backends(cls	,      ['torch', 'transformers', 'k_diffusion']  )







					@classmethod
					def 	a			(						cls       :						Union[str, Any]	,      *_lowerCAmelCase       :						Tuple	,      **_lowerCAmelCase       :						str  )							->					Tuple:



											'''simple docstring'''





											requires_backends(cls	,      ['torch', 'transformers', 'k_diffusion']  )

