

"""simple docstring"""




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			:  Tuple      ,			__UpperCAmelCase			:  int=None      ,			**__UpperCAmelCase			:  str    )				->      str:
      super().__init__(features=__UpperCAmelCase    )
      SCREAMING_SNAKE_CASE__									= tf_tensor_kwargs
      import tensorflow as tf  # noqa: import tf at initialization

   def    SCREAMING_SNAKE_CASE			(   self			:  Dict      ,			__UpperCAmelCase			:  Union[str, Any]    )				->      List[str]:
      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    SCREAMING_SNAKE_CASE			(   self			:  int      ,			__UpperCAmelCase			:  Optional[int]    )				->      Optional[int]:
      import tensorflow as tf

      if value is None:
         return value

      SCREAMING_SNAKE_CASE__									= {}

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

         if isinstance(__UpperCAmelCase      ,			PIL.Image.Image    ):
            SCREAMING_SNAKE_CASE__									= np.asarray(__UpperCAmelCase    )

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

   def    SCREAMING_SNAKE_CASE			(   self			:  Any      ,			__UpperCAmelCase			:  str    )				->      str:
      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    ):
         SCREAMING_SNAKE_CASE__									= 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    SCREAMING_SNAKE_CASE			(   self			:  Optional[Any]      ,			__UpperCAmelCase			:  dict    )				->      str:
      return map_nested(self._recursive_tensorize      ,			__UpperCAmelCase      ,			map_list=__UpperCAmelCase    )

   def    SCREAMING_SNAKE_CASE			(   self			:  int      ,			__UpperCAmelCase			:  pa.Table    )				->      Mapping:
      SCREAMING_SNAKE_CASE__									= self.numpy_arrow_extractor().extract_row(__UpperCAmelCase    )
      SCREAMING_SNAKE_CASE__									= self.python_features_decoder.decode_row(__UpperCAmelCase    )
      return self.recursive_tensorize(__UpperCAmelCase    )

   def    SCREAMING_SNAKE_CASE			(   self			:  Any      ,			__UpperCAmelCase			:  pa.Table    )				->      "tf.Tensor":
      SCREAMING_SNAKE_CASE__									= self.numpy_arrow_extractor().extract_column(__UpperCAmelCase    )
      SCREAMING_SNAKE_CASE__									= self.python_features_decoder.decode_column(__UpperCAmelCase      ,			pa_table.column_names[0]    )
      SCREAMING_SNAKE_CASE__									= self.recursive_tensorize(__UpperCAmelCase    )
      SCREAMING_SNAKE_CASE__									= self._consolidate(__UpperCAmelCase    )
      return column





   def    SCREAMING_SNAKE_CASE			(   self			:  Union[str, Any]      ,			__UpperCAmelCase			:  pa.Table    )				->      Mapping:
      SCREAMING_SNAKE_CASE__									= self.numpy_arrow_extractor().extract_batch(__UpperCAmelCase    )
      SCREAMING_SNAKE_CASE__									= self.python_features_decoder.decode_batch(__UpperCAmelCase    )
      SCREAMING_SNAKE_CASE__									= self.recursive_tensorize(__UpperCAmelCase    )
      for column_name in batch:
         SCREAMING_SNAKE_CASE__									= self._consolidate(batch[column_name]    )
      return batch





"""simple docstring"""




class 				lowerCamelCase  :

			def __init__(   self			:  Dict    )				->      None:
						SCREAMING_SNAKE_CASE__									= [0, 1]





			def    SCREAMING_SNAKE_CASE			(   self			:  Optional[int]      ,			__UpperCAmelCase			:  int    )				->      list:
						if (difference := index - (len(self.sequence    ) - 2)) >= 1:
									for _ in range(__UpperCAmelCase    ):
												self.sequence.append(self.sequence[-1] + self.sequence[-2]    )
						return self.sequence[:index]

def 		A    (       ):




			'''simple docstring'''


			print(
			    """Fibonacci Series Using Dynamic Programming\n"""						,			"""Enter the index of the Fibonacci number you want to calculate """						,			"""in the prompt below. (To exit enter exit or Ctrl-C)\n"""						,			sep=""""""						,			)
			SCREAMING_SNAKE_CASE__									= Fibonacci()

			while True:
						SCREAMING_SNAKE_CASE__									= input(""">> """      )
						if prompt in {"exit", "quit"}:
									break

						try:
									SCREAMING_SNAKE_CASE__									= int(snake_case__      )
						except ValueError:
									print("""Enter a number or 'exit'"""      )
									continue

						print(fibonacci.get(snake_case__      )      )


if __name__ == "__main__":
						main()


