





'''simple docstring'''

import sys
from collections.abc import Mapping

import numpy as np
import pyarrow as pa

from .. import config
from ..utils.py_utils import map_nested
from .formatting import TensorFormatter





class lowerCamelCase    (TensorFormatter[Mapping, np.ndarray, Mapping]       ):







  def __init__(		self  ,  lowercase__=None  ,  **lowercase__		)		->    Tuple:






        """simple docstring"""





        super().__init__(features=lowercase__		)
        _snake_case		:						List[Any]         =  np_array_kwargs







  def 					UpperCAmelCase_					(		self  ,  lowercase__		)		->    Tuple:






        """simple docstring"""





        if isinstance(lowercase__  ,  lowercase__		):
              if column and all(
                  isinstance(lowercase__  ,  np.ndarray		) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column		):
                    return np.stack(lowercase__		)
              else:
                    # don't use np.array(column, dtype=object)
                    # since it fails in certain cases
                    # see https://stackoverflow.com/q/51005699
                    _snake_case		:						Union[str, Any]         =  np.empty(len(lowercase__		)  ,  dtype=lowercase__		)
                    _snake_case		:						List[Any]         =  column
                    return out
        return column







  def 					UpperCAmelCase_					(		self  ,  lowercase__		)		->    List[str]:






        """simple docstring"""





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

        _snake_case		:						Optional[Any]         =  {}

        if isinstance(lowercase__  ,  np.ndarray		) and np.issubdtype(value.dtype  ,  np.integer		):
              _snake_case		:						str         =  {'''dtype''': np.intaa}
        elif isinstance(lowercase__  ,  np.ndarray		) and np.issubdtype(value.dtype  ,  np.floating		):
              _snake_case		:						Union[str, Any]         =  {'''dtype''': np.floataa}
        elif config.PIL_AVAILABLE and "PIL" in sys.modules:
              import PIL.Image

              if isinstance(lowercase__  ,  PIL.Image.Image		):
                    return np.asarray(lowercase__  ,  **self.np_array_kwargs		)

        return np.asarray(lowercase__  ,  **{**default_dtype, **self.np_array_kwargs}		)







  def 					UpperCAmelCase_					(		self  ,  lowercase__		)		->    str:






        """simple docstring"""





        if config.TORCH_AVAILABLE and "torch" in sys.modules:
              import torch

              if isinstance(lowercase__  ,  torch.Tensor		):
                    return self._tensorize(data_struct.detach().cpu().numpy()[()]		)
        if hasattr(lowercase__  ,  '''__array__'''		) and not isinstance(lowercase__  ,  (np.ndarray, np.character, np.number)		):
              _snake_case		:						Union[str, Any]         =  data_struct.__array__()
        # support for nested types like struct of list of struct
        if isinstance(lowercase__  ,  np.ndarray		):
              if data_struct.dtype == object:
                    return self._consolidate([self.recursive_tensorize(lowercase__		) for substruct in data_struct]		)
        if isinstance(lowercase__  ,  (list, tuple)		):
              return self._consolidate([self.recursive_tensorize(lowercase__		) for substruct in data_struct]		)
        return self._tensorize(lowercase__		)







  def 					UpperCAmelCase_					(		self  ,  lowercase__		)		->    Optional[Any]:






        """simple docstring"""





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







  def 					UpperCAmelCase_					(		self  ,  lowercase__		)		->    Mapping:






        """simple docstring"""





        _snake_case		:						Tuple         =  self.numpy_arrow_extractor().extract_row(lowercase__		)
        _snake_case		:						int         =  self.python_features_decoder.decode_row(lowercase__		)
        return self.recursive_tensorize(lowercase__		)







  def 					UpperCAmelCase_					(		self  ,  lowercase__		)		->    np.ndarray:






        """simple docstring"""





        _snake_case		:						Tuple         =  self.numpy_arrow_extractor().extract_column(lowercase__		)
        _snake_case		:						str         =  self.python_features_decoder.decode_column(lowercase__  ,  pa_table.column_names[0]		)
        _snake_case		:						List[str]         =  self.recursive_tensorize(lowercase__		)
        _snake_case		:						Union[str, Any]         =  self._consolidate(lowercase__		)
        return column







  def 					UpperCAmelCase_					(		self  ,  lowercase__		)		->    Mapping:






        """simple docstring"""





        _snake_case		:						str         =  self.numpy_arrow_extractor().extract_batch(lowercase__		)
        _snake_case		:						Tuple         =  self.python_features_decoder.decode_batch(lowercase__		)
        _snake_case		:						int         =  self.recursive_tensorize(lowercase__		)
        for column_name in batch:
              _snake_case		:						Optional[int]         =  self._consolidate(batch[column_name]		)
        return batch









'''simple docstring'''

def  _a     (				lowerCAmelCase_ = 4_000_000						):





      """simple docstring"""



      _snake_case		:						Optional[int]         =  1
      _snake_case		:						Tuple         =  2
      _snake_case		:						Optional[Any]         =  0
      while j <= n:
            if j % 2 == 0:
                  total += j
            _snake_case  ,				_snake_case		:						str         =  j, i + j

      return total


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


