





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




					def __init__(						self    ,      __lowerCAmelCase=None    ,      **__lowerCAmelCase       )						->  str:
							super().__init__(features=__lowerCAmelCase       )
							UpperCamelCase__         =	tf_tensor_kwargs
							import tensorflow as tf  # noqa: import tf at initialization




					def 	snake_case_		(						self    ,      __lowerCAmelCase       )						->  int:
							import tensorflow as tf

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

							return column




					def 	snake_case_		(						self    ,      __lowerCAmelCase       )						->  List[Any]:
							import tensorflow as tf

							if value is None:
									return value

							UpperCamelCase__         =	{}

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

									if isinstance(__lowerCAmelCase    ,      PIL.Image.Image       ):
											UpperCamelCase__         =	np.asarray(__lowerCAmelCase       )

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




					def 	snake_case_		(						self    ,      __lowerCAmelCase       )						->  List[str]:
							import tensorflow as tf

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

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




					def 	snake_case_		(						self    ,      __lowerCAmelCase       )						->  str:
							return map_nested(self._recursive_tensorize    ,      __lowerCAmelCase    ,      map_list=__lowerCAmelCase       )




					def 	snake_case_		(						self    ,      __lowerCAmelCase       )						->  Mapping:
							UpperCamelCase__         =	self.numpy_arrow_extractor().extract_row(__lowerCAmelCase       )
							UpperCamelCase__         =	self.python_features_decoder.decode_row(__lowerCAmelCase       )
							return self.recursive_tensorize(__lowerCAmelCase       )




					def 	snake_case_		(						self    ,      __lowerCAmelCase       )						->  "tf.Tensor":
							UpperCamelCase__         =	self.numpy_arrow_extractor().extract_column(__lowerCAmelCase       )
							UpperCamelCase__         =	self.python_features_decoder.decode_column(__lowerCAmelCase    ,      pa_table.column_names[0]       )
							UpperCamelCase__         =	self.recursive_tensorize(__lowerCAmelCase       )
							UpperCamelCase__         =	self._consolidate(__lowerCAmelCase       )
							return column




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












def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) * 9 / 5) + 3_2 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round(float(_lowercase       ) + 273.15 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) * 9 / 5) + 491.67 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) - 3_2) * 5 / 9 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round(((float(_lowercase       ) - 3_2) * 5 / 9) + 273.15 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round(float(_lowercase       ) + 459.67 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round(float(_lowercase       ) - 273.15 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round(((float(_lowercase       ) - 273.15) * 9 / 5) + 3_2 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) * 9 / 5) ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) - 491.67) * 5 / 9 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round(float(_lowercase       ) - 459.67 ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) * 5 / 9) ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) * 1.25 + 273.15) ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) * 2.25 + 3_2) ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) * 1.25) ,						_lowercase       )

def     a						(      _lowercase   :     float ,						_lowercase   :     int = 2       )     ->float:
		return round((float(_lowercase       ) * 2.25 + 3_2 + 459.67) ,						_lowercase       )


if __name__ == "__main__":
				import doctest

				doctest.testmod()





