


# 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     UpperCAmelCase__       (					TensorFormatter[Mapping, "torch.Tensor", Mapping]		):



    """simple docstring"""






    def __init__(			self					,   A_=None					,   **A_    )  ->       Union[str, Any]:
         super().__init__(features=A_    )
         __UpperCamelCase    							=torch_tensor_kwargs
         import torch  # noqa import torch at initialization






    def _a					(			self					,   A_    )  ->       Union[str, Any]:
         import torch

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






    def _a					(			self					,   A_    )  ->       Any:
         import torch

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

         __UpperCamelCase    							={}

         if isinstance(A_					,   (np.number, np.ndarray)    ) and np.issubdtype(value.dtype					,   np.integer    ):
              __UpperCamelCase    							={'dtype': torch.intaa}
         elif isinstance(A_					,   (np.number, np.ndarray)    ) and np.issubdtype(value.dtype					,   np.floating    ):
              __UpperCamelCase    							={'dtype': torch.floataa}
         elif config.PIL_AVAILABLE and "PIL" in sys.modules:
              import PIL.Image

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






    def _a					(			self					,   A_    )  ->       Any:
         import torch

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






    def _a					(			self					,   A_    )  ->       List[Any]:
         return map_nested(self._recursive_tensorize					,   A_					,   map_list=A_    )






    def _a					(			self					,   A_    )  ->       Mapping:
         __UpperCamelCase    							=self.numpy_arrow_extractor().extract_row(A_    )
         __UpperCamelCase    							=self.python_features_decoder.decode_row(A_    )
         return self.recursive_tensorize(A_    )






    def _a					(			self					,   A_    )  ->       "torch.Tensor":
         __UpperCamelCase    							=self.numpy_arrow_extractor().extract_column(A_    )
         __UpperCamelCase    							=self.python_features_decoder.decode_column(A_					,   pa_table.column_names[0]    )
         __UpperCamelCase    							=self.recursive_tensorize(A_    )
         __UpperCamelCase    							=self._consolidate(A_    )
         return column






    def _a					(			self					,   A_    )  ->       Mapping:
         __UpperCamelCase    							=self.numpy_arrow_extractor().extract_batch(A_    )
         __UpperCamelCase    							=self.python_features_decoder.decode_batch(A_    )
         __UpperCamelCase    							=self.recursive_tensorize(A_    )
         for column_name in batch:
              __UpperCamelCase    							=self._consolidate(batch[column_name]    )
         return batch









from typing import TYPE_CHECKING

from ...utils import _LazyModule


_A		       =						{'tokenization_wav2vec2_phoneme': ['Wav2Vec2PhonemeCTCTokenizer']}


if TYPE_CHECKING:
   from .tokenization_wavaveca_phoneme import WavaVecaPhonemeCTCTokenizer
else:
   import sys

   _A		       =						_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)





