



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

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



       def __init__(						self				:	str	,						__SCREAMING_SNAKE_CASE				:	int=None	,						**__SCREAMING_SNAKE_CASE				:	Dict):


           '''simple docstring'''

           super().__init__(features=__SCREAMING_SNAKE_CASE)
           __a					=							tf_tensor_kwargs
           import tensorflow as tf  # noqa: import tf at initialization



       def 						_lowerCamelCase     (						self				:	Tuple	,						__SCREAMING_SNAKE_CASE				:	List[str]):


           '''simple docstring'''

           import tensorflow as tf

           if isinstance(__SCREAMING_SNAKE_CASE	,						__SCREAMING_SNAKE_CASE) and column:
               if all(
                   isinstance(__SCREAMING_SNAKE_CASE	,						tf.Tensor) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column):
                   return tf.stack(__SCREAMING_SNAKE_CASE)
               elif all(
                   isinstance(__SCREAMING_SNAKE_CASE	,						(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(__SCREAMING_SNAKE_CASE)

           return column



       def 						_lowerCamelCase     (						self				:	List[Any]	,						__SCREAMING_SNAKE_CASE				:	List[Any]):


           '''simple docstring'''

           import tensorflow as tf

           if value is None:
               return value

           __a					=							{}

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

               if isinstance(__SCREAMING_SNAKE_CASE	,						PIL.Image.Image):
                   __a					=							np.asarray(__SCREAMING_SNAKE_CASE)

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



       def 						_lowerCamelCase     (						self				:	Dict	,						__SCREAMING_SNAKE_CASE				:	List[str]):


           '''simple docstring'''

           import tensorflow as tf

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

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



       def 						_lowerCamelCase     (						self				:	str	,						__SCREAMING_SNAKE_CASE				:	dict):


           '''simple docstring'''

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



       def 						_lowerCamelCase     (						self				:	Optional[int]	,						__SCREAMING_SNAKE_CASE				:	pa.Table):


           '''simple docstring'''

           __a					=							self.numpy_arrow_extractor().extract_row(__SCREAMING_SNAKE_CASE)
           __a					=							self.python_features_decoder.decode_row(__SCREAMING_SNAKE_CASE)
           return self.recursive_tensorize(__SCREAMING_SNAKE_CASE)



       def 						_lowerCamelCase     (						self				:	Optional[int]	,						__SCREAMING_SNAKE_CASE				:	pa.Table):


           '''simple docstring'''

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





       def 						_lowerCamelCase     (						self				:	List[str]	,						__SCREAMING_SNAKE_CASE				:	pa.Table):


           '''simple docstring'''

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










def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) * 9 / 5) + 32  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round(float(_UpperCAmelCase							) + 2_73.15  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) * 9 / 5) + 4_91.67  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) - 32) * 5 / 9  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round(((float(_UpperCAmelCase							) - 32) * 5 / 9) + 2_73.15  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round(float(_UpperCAmelCase							) + 4_59.67  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round(float(_UpperCAmelCase							) - 2_73.15  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round(((float(_UpperCAmelCase							) - 2_73.15) * 9 / 5) + 32  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) * 9 / 5)  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) - 4_91.67) * 5 / 9  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round(float(_UpperCAmelCase							) - 4_59.67  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) * 5 / 9)  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) * 1.25 + 2_73.15)  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) * 2.25 + 32)  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) * 1.25)  ,					_UpperCAmelCase							)





def 	__snake_case      (     _UpperCAmelCase  ,					_UpperCAmelCase = 2							):
    return round((float(_UpperCAmelCase							) * 2.25 + 32 + 4_59.67)  ,					_UpperCAmelCase							)


if __name__ == "__main__":
 import doctest

 doctest.testmod()





