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



				def __init__(self       :   List[Any]			,						_A       :   Any=None			,						**_A       :   Optional[int])					->			Optional[int]:
					super().__init__(features=_A)
					__snake_case    :							Any   	=				torch_tensor_kwargs
					import torch  # noqa import torch at initialization



				def       _lowercase  (self       :   List[str]			,						_A       :   str)					->			Dict:
					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       _lowercase  (self       :   Optional[Any]			,						_A       :   int)					->			List[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()

					__snake_case    :							Any   	=				{}

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

						if isinstance(_A			,						PIL.Image.Image):
							__snake_case    :							Optional[Any]   	=				np.asarray(_A)
					return torch.tensor(_A			,						**{**default_dtype, **self.torch_tensor_kwargs})



				def       _lowercase  (self       :   Dict			,						_A       :   str)					->			int:
					import torch

					# support for torch, tf, jax etc.
					if hasattr(_A			,						'__array__') and not isinstance(_A			,						torch.Tensor):
						__snake_case    :							Union[str, Any]   	=				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       _lowercase  (self       :   Tuple			,						_A       :   dict)					->			Union[str, Any]:
					return map_nested(self._recursive_tensorize			,						_A			,						map_list=_A)



				def       _lowercase  (self       :   Any			,						_A       :   pa.Table)					->			Mapping:
					__snake_case    :							str   	=				self.numpy_arrow_extractor().extract_row(_A)
					__snake_case    :							Dict   	=				self.python_features_decoder.decode_row(_A)
					return self.recursive_tensorize(_A)



				def       _lowercase  (self       :   List[Any]			,						_A       :   pa.Table)					->			"torch.Tensor":
					__snake_case    :							int   	=				self.numpy_arrow_extractor().extract_column(_A)
					__snake_case    :							List[Any]   	=				self.python_features_decoder.decode_column(_A			,						pa_table.column_names[0])
					__snake_case    :							Tuple   	=				self.recursive_tensorize(_A)
					__snake_case    :							List[str]   	=				self._consolidate(_A)
					return column






				def       _lowercase  (self       :   List[Any]			,						_A       :   pa.Table)					->			Mapping:
					__snake_case    :							Union[str, Any]   	=				self.numpy_arrow_extractor().extract_batch(_A)
					__snake_case    :							str   	=				self.python_features_decoder.decode_batch(_A)
					__snake_case    :							Optional[int]   	=				self.recursive_tensorize(_A)
					for column_name in batch:
						__snake_case    :							int   	=				self._consolidate(batch[column_name])
					return batch






"""simple docstring"""







import numpy as np
def 						__UpperCAmelCase       (					UpperCAmelCase_					:       np.array						)							->    np.array:

	'''simple docstring'''





	return 1 / (1 + np.exp(-vector						))


if __name__ == "__main__":
	import doctest

	doctest.testmod()





