




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







			def __init__( self					:    Union[str, Any]					,					snake_case__					:    List[str]=None					,					**snake_case__					:    Dict   ):




									"""simple docstring"""


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







			def UpperCamelCase    ( self					:    Optional[int]					,					snake_case__					:    Any   ):




									"""simple docstring"""


									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 UpperCamelCase    ( self					:    int					,					snake_case__					:    Tuple   ):




									"""simple docstring"""


									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 UpperCamelCase    ( self					:    Union[str, Any]					,					snake_case__					:    int   ):




									"""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(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 UpperCamelCase    ( self					:    int					,					snake_case__					:    List[Any]   ):




									"""simple docstring"""


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







			def UpperCamelCase    ( self					:    Optional[Any]					,					snake_case__					:    str   ):




									"""simple docstring"""


									_UpperCAmelCase									=  self.numpy_arrow_extractor().extract_row(lowerCamelCase__   )
									_UpperCAmelCase									=  self.python_features_decoder.decode_row(lowerCamelCase__   )
									return self.recursive_tensorize(lowerCamelCase__   )







			def UpperCamelCase    ( self					:    Union[str, Any]					,					snake_case__					:    Optional[Any]   ):




									"""simple docstring"""


									_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 UpperCamelCase    ( self					:    Union[str, Any]					,					snake_case__					:    Optional[Any]   ):




									"""simple docstring"""


									_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 							__SCREAMING_SNAKE_CASE						(    snake_case_ = 99_8001		):

						'''simple docstring'''


						for number in range(n - 1			,					9999			,					-1		):
												_UpperCAmelCase									=  str(snake_case_		)

												# checks whether 'str_number' is a palindrome.
												if str_number == str_number[::-1]:
																		_UpperCAmelCase									=  999

																		# if 'number' is a product of two 3-digit numbers
																		# then number is the answer otherwise fetch next number.
																		while divisor != 99:
																								if (number % divisor == 0) and (len(str(number // divisor		)		) == 3.0):
																														return number
																								divisor -= 1
						raise ValueError("That number is larger than our acceptable range."		)


if __name__ == "__main__":
				print(f"""{solution() = }""")




