






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 		SCREAMING_SNAKE_CASE__   (     TensorFormatter[Mapping, np.ndarray, Mapping]    ):



		def __init__(    self:    Any				,   a:    str=None				,   **a:    Any)  ->Any:






								'''simple docstring'''


								super().__init__(features=a)
								a_				     =   np_array_kwargs



		def _lowerCAmelCase     (    self:    Any				,   a:    Tuple)  ->List[str]:






								'''simple docstring'''


								if isinstance(a				,   a):
														if column and all(
														    isinstance(a				,   np.ndarray) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column):
																				return np.stack(a)
														else:
																				# don't use np.array(column, dtype=object)
																				# since it fails in certain cases
																				# see https://stackoverflow.com/q/51005699
																				a_				     =   np.empty(len(a)				,   dtype=a)
																				a_				     =   column
																				return out
								return column



		def _lowerCAmelCase     (    self:    str				,   a:    Optional[int])  ->str:






								'''simple docstring'''


								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
								elif isinstance(a				,   np.number):
														return value

								a_				     =   {}

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

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

								return np.asarray(a				,   **{**default_dtype, **self.np_array_kwargs})



		def _lowerCAmelCase     (    self:    Optional[int]				,   a:    Any)  ->Any:






								'''simple docstring'''


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

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



		def _lowerCAmelCase     (    self:    Optional[Any]				,   a:    Optional[int])  ->Union[str, Any]:






								'''simple docstring'''


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



		def _lowerCAmelCase     (    self:    Optional[int]				,   a:    Optional[int])  ->Optional[int]:






								'''simple docstring'''


								a_				     =   self.numpy_arrow_extractor().extract_row(a)
								a_				     =   self.python_features_decoder.decode_row(a)
								return self.recursive_tensorize(a)



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






								'''simple docstring'''


								a_				     =   self.numpy_arrow_extractor().extract_column(a)
								a_				     =   self.python_features_decoder.decode_column(a				,   pa_table.column_names[0])
								a_				     =   self.recursive_tensorize(a)
								a_				     =   self._consolidate(a)
								return column




		def _lowerCAmelCase     (    self:    Optional[int]				,   a:    Optional[int])  ->Dict:






								'''simple docstring'''


								a_				     =   self.numpy_arrow_extractor().extract_batch(a)
								a_				     =   self.python_features_decoder.decode_batch(a)
								a_				     =   self.recursive_tensorize(a)
								for column_name in batch:
														a_				     =   self._consolidate(batch[column_name])
								return batch











'''simple docstring'''





from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


a_      = {
    'configuration_segformer': ['SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'SegformerConfig', 'SegformerOnnxConfig']
}

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a_      = ['SegformerFeatureExtractor']
							a_      = ['SegformerImageProcessor']

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a_      = [
							    'SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'SegformerDecodeHead',
							    'SegformerForImageClassification',
							    'SegformerForSemanticSegmentation',
							    'SegformerLayer',
							    'SegformerModel',
							    'SegformerPreTrainedModel',
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							a_      = [
							    'TF_SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST',
							    'TFSegformerDecodeHead',
							    'TFSegformerForImageClassification',
							    'TFSegformerForSemanticSegmentation',
							    'TFSegformerModel',
							    'TFSegformerPreTrainedModel',
							]


if TYPE_CHECKING:
							from .configuration_segformer import SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, SegformerConfig, SegformerOnnxConfig

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_segformer import SegformerFeatureExtractor
														from .image_processing_segformer import SegformerImageProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_segformer import (
														    SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
														    SegformerDecodeHead,
														    SegformerForImageClassification,
														    SegformerForSemanticSegmentation,
														    SegformerLayer,
														    SegformerModel,
														    SegformerPreTrainedModel,
														)
							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_segformer import (
														    TF_SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFSegformerDecodeHead,
														    TFSegformerForImageClassification,
														    TFSegformerForSemanticSegmentation,
														    TFSegformerModel,
														    TFSegformerPreTrainedModel,
														)

else:
							import sys

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



