




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 tensorflow as tf


class  lowerCamelCase     (		TensorFormatter[Mapping, '''tf.Tensor''', Mapping]    ):






			'''simple docstring'''





			def __init__(			self      : Any							,    lowerCamelCase_      : List[str]=None							,    **lowerCamelCase_      : Optional[Any]	)    -> List[str]:
								super().__init__(features=__UpperCamelCase	)
								__magic_name__				:						List[str]     				=				tf_tensor_kwargs
								import tensorflow as tf  # noqa: import tf at initialization

			def 				UpperCAmelCase__							(			self      : str							,    lowerCamelCase_      : int	)    -> List[Any]:
								import tensorflow as tf

								if isinstance(__UpperCamelCase							,    __UpperCamelCase	) and column:
													if all(
													    isinstance(__UpperCamelCase							,    tf.Tensor	) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column	):
																		return tf.stack(__UpperCamelCase	)
													elif all(
													    isinstance(__UpperCamelCase							,    (tf.Tensor, tf.RaggedTensor)	) and x.ndim == 1 and x.dtype == column[0].dtype
													    for x in column	):
																		# only rag 1-D tensors, otherwise some dimensions become ragged even though they were consolidated
																		return tf.ragged.stack(__UpperCamelCase	)

								return column

			def 				UpperCAmelCase__							(			self      : Dict							,    lowerCamelCase_      : Optional[Any]	)    -> Any:
								import tensorflow as tf

								if value is None:
													return value

								__magic_name__				:						List[str]     				=				{}

								if isinstance(__UpperCamelCase							,    (np.number, np.ndarray)	) and np.issubdtype(value.dtype							,    np.integer	):
													__magic_name__				:						List[str]     				=				{'''dtype''': tf.intaa}
								elif isinstance(__UpperCamelCase							,    (np.number, np.ndarray)	) and np.issubdtype(value.dtype							,    np.floating	):
													__magic_name__				:						Optional[Any]     				=				{'''dtype''': tf.floataa}
								elif config.PIL_AVAILABLE and "PIL" in sys.modules:
													import PIL.Image

													if isinstance(__UpperCamelCase							,    PIL.Image.Image	):
																		__magic_name__				:						Tuple     				=				np.asarray(__UpperCamelCase	)

								return tf.convert_to_tensor(__UpperCamelCase							,    **{**default_dtype, **self.tf_tensor_kwargs}	)

			def 				UpperCAmelCase__							(			self      : Tuple							,    lowerCamelCase_      : Union[str, Any]	)    -> Tuple:
								import tensorflow as tf

								# support for torch, tf, jax etc.
								if config.TORCH_AVAILABLE and "torch" in sys.modules:
													import torch

													if isinstance(__UpperCamelCase							,    torch.Tensor	):
																		return self._tensorize(data_struct.detach().cpu().numpy()[()]	)
								if hasattr(__UpperCamelCase							,    '''__array__'''	) and not isinstance(__UpperCamelCase							,    tf.Tensor	):
													__magic_name__				:						int     				=				data_struct.__array__()
								# support for nested types like struct of list of struct
								if isinstance(__UpperCamelCase							,    np.ndarray	):
													if data_struct.dtype == object:  # tf 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 				UpperCAmelCase__							(			self      : List[str]							,    lowerCamelCase_      : int	)    -> Optional[Any]:
								return map_nested(self._recursive_tensorize							,    __UpperCamelCase							,    map_list=__UpperCamelCase	)

			def 				UpperCAmelCase__							(			self      : Optional[Any]							,    lowerCamelCase_      : Dict	)    -> Mapping:
								__magic_name__				:						Optional[Any]     				=				self.numpy_arrow_extractor().extract_row(__UpperCamelCase	)
								__magic_name__				:						List[Any]     				=				self.python_features_decoder.decode_row(__UpperCamelCase	)
								return self.recursive_tensorize(__UpperCamelCase	)

			def 				UpperCAmelCase__							(			self      : str							,    lowerCamelCase_      : Dict	)    -> "tf.Tensor":
								__magic_name__				:						str     				=				self.numpy_arrow_extractor().extract_column(__UpperCamelCase	)
								__magic_name__				:						Tuple     				=				self.python_features_decoder.decode_column(__UpperCamelCase							,    pa_table.column_names[0]	)
								__magic_name__				:						Tuple     				=				self.recursive_tensorize(__UpperCamelCase	)
								__magic_name__				:						Any     				=				self._consolidate(__UpperCamelCase	)
								return column


			def 				UpperCAmelCase__							(			self      : int							,    lowerCamelCase_      : Dict	)    -> Mapping:
								__magic_name__				:						Optional[Any]     				=				self.numpy_arrow_extractor().extract_batch(__UpperCamelCase	)
								__magic_name__				:						Optional[Any]     				=				self.python_features_decoder.decode_batch(__UpperCamelCase	)
								__magic_name__				:						int     				=				self.recursive_tensorize(__UpperCamelCase	)
								for column_name in batch:
													__magic_name__				:						List[str]     				=				self._consolidate(batch[column_name]	)
								return batch







'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


lowercase__					  =		{
    "configuration_swin2sr": ["SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP", "Swin2SRConfig"],
}


try:
   if not is_torch_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowercase__					  =		[
       "SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST",
       "Swin2SRForImageSuperResolution",
       "Swin2SRModel",
       "Swin2SRPreTrainedModel",
   ]


try:
   if not is_vision_available():
      raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
   pass
else:
   lowercase__					  =		["Swin2SRImageProcessor"]


if TYPE_CHECKING:
   from .configuration_swinasr import SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP, SwinaSRConfig

   try:
      if not is_torch_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .modeling_swinasr import (
          SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST,
          SwinaSRForImageSuperResolution,
          SwinaSRModel,
          SwinaSRPreTrainedModel,
      )

   try:
      if not is_vision_available():
         raise OptionalDependencyNotAvailable()
   except OptionalDependencyNotAvailable:
      pass
   else:
      from .image_processing_swinasr import SwinaSRImageProcessor


else:
   import sys

   lowercase__					  =		_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

