



# 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 							lowerCAmelCase_						(    TensorFormatter[Mapping, "torch.Tensor", Mapping]				):
       def __init__(     self,     SCREAMING_SNAKE_CASE_=None,     **SCREAMING_SNAKE_CASE_			)	->						Tuple:
          super().__init__(features=SCREAMING_SNAKE_CASE_			)
          UpperCamelCase       :    int		      =      torch_tensor_kwargs
          import torch  # noqa import torch at initialization
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_			)	->						Dict:
          import torch

          if isinstance(SCREAMING_SNAKE_CASE_,     SCREAMING_SNAKE_CASE_			) and column:
             if all(
                 isinstance(SCREAMING_SNAKE_CASE_,     torch.Tensor			) and x.shape == column[0].shape and x.dtype == column[0].dtype
                 for x in column			):
                return torch.stack(SCREAMING_SNAKE_CASE_			)
          return column
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_			)	->						Any:
          import torch

          if isinstance(SCREAMING_SNAKE_CASE_,     (str, bytes, type(SCREAMING_SNAKE_CASE_			))			):
             return value
          elif isinstance(SCREAMING_SNAKE_CASE_,     (np.character, np.ndarray)			) and np.issubdtype(value.dtype,     np.character			):
             return value.tolist()

          UpperCamelCase       :    str		      =      {}

          if isinstance(SCREAMING_SNAKE_CASE_,     (np.number, np.ndarray)			) and np.issubdtype(value.dtype,     np.integer			):
             UpperCamelCase       :    List[str]		      =      {'dtype': torch.intaa}
          elif isinstance(SCREAMING_SNAKE_CASE_,     (np.number, np.ndarray)			) and np.issubdtype(value.dtype,     np.floating			):
             UpperCamelCase       :    int		      =      {'dtype': torch.floataa}
          elif config.PIL_AVAILABLE and "PIL" in sys.modules:
             import PIL.Image

             if isinstance(SCREAMING_SNAKE_CASE_,     PIL.Image.Image			):
                UpperCamelCase       :    str		      =      np.asarray(SCREAMING_SNAKE_CASE_			)
          return torch.tensor(SCREAMING_SNAKE_CASE_,     **{**default_dtype, **self.torch_tensor_kwargs}			)
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_			)	->						List[Any]:
          import torch

          # support for torch, tf, jax etc.
          if hasattr(SCREAMING_SNAKE_CASE_,     '__array__'			) and not isinstance(SCREAMING_SNAKE_CASE_,     torch.Tensor			):
             UpperCamelCase       :    Union[str, Any]		      =      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:  # torch 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    snake_case_			(     self,     SCREAMING_SNAKE_CASE_			)	->						int:
          return map_nested(self._recursive_tensorize,     SCREAMING_SNAKE_CASE_,     map_list=SCREAMING_SNAKE_CASE_			)
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_			)	->						Mapping:
          UpperCamelCase       :    Dict		      =      self.numpy_arrow_extractor().extract_row(SCREAMING_SNAKE_CASE_			)
          UpperCamelCase       :    Union[str, Any]		      =      self.python_features_decoder.decode_row(SCREAMING_SNAKE_CASE_			)
          return self.recursive_tensorize(SCREAMING_SNAKE_CASE_			)
       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_			)	->						"torch.Tensor":
          UpperCamelCase       :    Union[str, Any]		      =      self.numpy_arrow_extractor().extract_column(SCREAMING_SNAKE_CASE_			)
          UpperCamelCase       :    List[str]		      =      self.python_features_decoder.decode_column(SCREAMING_SNAKE_CASE_,     pa_table.column_names[0]			)
          UpperCamelCase       :    Any		      =      self.recursive_tensorize(SCREAMING_SNAKE_CASE_			)
          UpperCamelCase       :    Dict		      =      self._consolidate(SCREAMING_SNAKE_CASE_			)
          return column






       def    snake_case_			(     self,     SCREAMING_SNAKE_CASE_			)	->						Mapping:
          UpperCamelCase       :    List[Any]		      =      self.numpy_arrow_extractor().extract_batch(SCREAMING_SNAKE_CASE_			)
          UpperCamelCase       :    Optional[Any]		      =      self.python_features_decoder.decode_batch(SCREAMING_SNAKE_CASE_			)
          UpperCamelCase       :    List[str]		      =      self.recursive_tensorize(SCREAMING_SNAKE_CASE_			)
          for column_name in batch:
             UpperCamelCase       :    str		      =      self._consolidate(batch[column_name]			)
          return batch




'''simple docstring'''




def 							snake_case__				(     _A:   int					)       ->      list[int]:

		'''simple docstring'''


		if length <= 0 or not isinstance(_A ,  _A					):
				raise ValueError("""Length must be a positive integer."""					)
		return [n * (2 * n - 1) for n in range(_A					)]


if __name__ == "__main__":
						print(hexagonal_numbers(length=5))
						print(hexagonal_numbers(length=1_0))




