


"""simple docstring"""






# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING

import numpy as np
import pyarrow as pa

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


if TYPE_CHECKING:
							import torch





class      lowerCamelCase__   (     TensorFormatter[Mapping, """torch.Tensor""", Mapping]				):







					"""simple docstring"""


					def __init__(       self    : Tuple ,       UpperCamelCase    : List[Any]=None ,       **UpperCamelCase    : Dict  ):
												'''simple docstring'''






												super().__init__(features=UpperCamelCase  )
												__UpperCAmelCase   :						Tuple      							=					torch_tensor_kwargs
												import torch  # noqa import torch at initialization






					def lowerCamelCase__							(       self    : Union[str, Any] ,       UpperCamelCase    : Union[str, Any]  ):
												'''simple docstring'''






												import torch

												if isinstance(UpperCamelCase ,       UpperCamelCase  ) and column:
																			if all(
																			    isinstance(UpperCamelCase ,       torch.Tensor  ) and x.shape == column[0].shape and x.dtype == column[0].dtype
																			    for x in column  ):
																										return torch.stack(UpperCamelCase  )
												return column






					def lowerCamelCase__							(       self    : int ,       UpperCamelCase    : Any  ):
												'''simple docstring'''






												import torch

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

												__UpperCAmelCase   :						int      							=					{}

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

																			if isinstance(UpperCamelCase ,       PIL.Image.Image  ):
																										__UpperCAmelCase   :						int      							=					np.asarray(UpperCamelCase  )
												return torch.tensor(UpperCamelCase ,       **{**default_dtype, **self.torch_tensor_kwargs}  )






					def lowerCamelCase__							(       self    : List[str] ,       UpperCamelCase    : int  ):
												'''simple docstring'''






												import torch

												# support for torch, tf, jax etc.
												if hasattr(UpperCamelCase ,       """__array__"""  ) and not isinstance(UpperCamelCase ,       torch.Tensor  ):
																			__UpperCAmelCase   :						str      							=					data_struct.__array__()
												# support for nested types like struct of list of struct
												if isinstance(UpperCamelCase ,       np.ndarray  ):
																			if data_struct.dtype == object:  # torch tensors cannot be instantied from an array of objects
																										return self._consolidate([self.recursive_tensorize(UpperCamelCase  ) for substruct in data_struct]  )
												elif isinstance(UpperCamelCase ,       (list, tuple)  ):
																			return self._consolidate([self.recursive_tensorize(UpperCamelCase  ) for substruct in data_struct]  )
												return self._tensorize(UpperCamelCase  )






					def lowerCamelCase__							(       self    : List[Any] ,       UpperCamelCase    : dict  ):
												'''simple docstring'''






												return map_nested(self._recursive_tensorize ,       UpperCamelCase ,       map_list=UpperCamelCase  )






					def lowerCamelCase__							(       self    : Dict ,       UpperCamelCase    : pa.Table  ):
												'''simple docstring'''






												__UpperCAmelCase   :						str      							=					self.numpy_arrow_extractor().extract_row(UpperCamelCase  )
												__UpperCAmelCase   :						List[str]      							=					self.python_features_decoder.decode_row(UpperCamelCase  )
												return self.recursive_tensorize(UpperCamelCase  )






					def lowerCamelCase__							(       self    : Optional[Any] ,       UpperCamelCase    : pa.Table  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[int]      							=					self.numpy_arrow_extractor().extract_column(UpperCamelCase  )
												__UpperCAmelCase   :						Optional[Any]      							=					self.python_features_decoder.decode_column(UpperCamelCase ,       pa_table.column_names[0]  )
												__UpperCAmelCase   :						Optional[int]      							=					self.recursive_tensorize(UpperCamelCase  )
												__UpperCAmelCase   :						Any      							=					self._consolidate(UpperCamelCase  )
												return column






					def lowerCamelCase__							(       self    : str ,       UpperCamelCase    : pa.Table  ):
												'''simple docstring'''






												__UpperCAmelCase   :						Optional[Any]      							=					self.numpy_arrow_extractor().extract_batch(UpperCamelCase  )
												__UpperCAmelCase   :						Optional[int]      							=					self.python_features_decoder.decode_batch(UpperCamelCase  )
												__UpperCAmelCase   :						Optional[Any]      							=					self.recursive_tensorize(UpperCamelCase  )
												for column_name in batch:
																			__UpperCAmelCase   :						Tuple      							=					self._consolidate(batch[column_name]  )
												return batch




"""simple docstring"""






from ..utils import DummyObject, requires_backends





class      lowerCamelCase__   (     metaclass=A				):







					"""simple docstring"""


					__a	       =							["""note_seq"""]






					def __init__(       self    : List[Any] ,       *UpperCamelCase    : List[Any] ,       **UpperCamelCase    : Tuple  ):
												'''simple docstring'''






												requires_backends(self ,       ["""note_seq"""]  )






					@classmethod
					def lowerCamelCase__							(       cls    : Union[str, Any] ,       *UpperCamelCase    : Union[str, Any] ,       **UpperCamelCase    : str  ):
												'''simple docstring'''






												requires_backends(cls ,       ["""note_seq"""]  )






					@classmethod
					def lowerCamelCase__							(       cls    : List[str] ,       *UpperCamelCase    : Optional[Any] ,       **UpperCamelCase    : Union[str, Any]  ):
												'''simple docstring'''






												requires_backends(cls ,       ["""note_seq"""]  )
