'''simple docstring'''

# Lint as: python3
import sys
from collections.abc import Mapping
from typing import TYPE_CHECKING, Dict, Optional

import numpy as np
import pyarrow as pa

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


if TYPE_CHECKING:
  import jax
  import jaxlib

__a:			List[str]	       =       get_logger()

__a:			Optional[dict]	       =       None



class       UpperCAmelCase  (						TensorFormatter[Mapping, "jax.Array", Mapping] ):





       '''simple docstring'''



       def __init__(						self     ,       __lowerCAmelCase=None     ,       __lowerCAmelCase=None     ,       **__lowerCAmelCase			)  ->  int:
        super().__init__(features=__lowerCAmelCase			)
        import jax
        from jaxlib.xla_client import Device

        if isinstance(__lowerCAmelCase     ,       __lowerCAmelCase			):
         raise ValueError(
             F"""Expected {device} to be a `str` not {type(__lowerCAmelCase			)}, as `jaxlib.xla_extension.Device` """
             '''is not serializable neither with `pickle` nor with `dill`. Instead you can surround '''
             '''the device with `str()` to get its string identifier that will be internally mapped '''
             '''to the actual `jaxlib.xla_extension.Device`.'''			)
        lowercase__    :   Union[str, Any]						= device if isinstance(__lowerCAmelCase     ,       __lowerCAmelCase			) else str(jax.devices()[0]			)
        # using global variable since `jaxlib.xla_extension.Device` is not serializable neither
        # with `pickle` nor with `dill`, so we need to use a global variable instead
        global DEVICE_MAPPING
        if DEVICE_MAPPING is None:
         lowercase__    :   Union[str, Any]						= self._map_devices_to_str()
        if self.device not in list(DEVICE_MAPPING.keys()			):
         logger.warning(
             F"""Device with string identifier {self.device} not listed among the available """
             F"""devices: {list(DEVICE_MAPPING.keys()			)}, so falling back to the default """
             F"""device: {str(jax.devices()[0]			)}."""			)
         lowercase__    :   Optional[Any]						= str(jax.devices()[0]			)
        lowercase__    :   Optional[int]						= jnp_array_kwargs

       @staticmethod
       def _lowerCAmelCase(						)  ->  Dict[str, "jaxlib.xla_extension.Device"]:
        import jax

        return {str(__lowerCAmelCase			): device for device in jax.devices()}

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  str:
        import jax
        import jax.numpy as jnp

        if isinstance(__lowerCAmelCase     ,       __lowerCAmelCase			) and column:
         if all(
             isinstance(__lowerCAmelCase     ,       jax.Array			) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column			):
          return jnp.stack(__lowerCAmelCase     ,       axis=0			)
        return column

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Tuple:
        import jax
        import jax.numpy as jnp

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

        lowercase__    :   Any						= {}

        if isinstance(__lowerCAmelCase     ,       (np.number, np.ndarray)			) and np.issubdtype(value.dtype     ,       np.integer			):
         # the default int precision depends on the jax config
         # see https://jax.readthedocs.io/en/latest/notebooks/Common_Gotchas_in_JAX.html#double-64bit-precision
         if jax.config.jax_enable_xaa:
          lowercase__    :   Tuple						= {'''dtype''': jnp.intaa}
         else:
          lowercase__    :   Union[str, Any]						= {'''dtype''': jnp.intaa}
        elif isinstance(__lowerCAmelCase     ,       (np.number, np.ndarray)			) and np.issubdtype(value.dtype     ,       np.floating			):
         lowercase__    :   Optional[Any]						= {'''dtype''': jnp.floataa}
        elif config.PIL_AVAILABLE and "PIL" in sys.modules:
         import PIL.Image

         if isinstance(__lowerCAmelCase     ,       PIL.Image.Image			):
          lowercase__    :   Optional[int]						= np.asarray(__lowerCAmelCase			)

        # using global variable since `jaxlib.xla_extension.Device` is not serializable neither
        # with `pickle` nor with `dill`, so we need to use a global variable instead
        global DEVICE_MAPPING
        if DEVICE_MAPPING is None:
         lowercase__    :   Optional[int]						= self._map_devices_to_str()

        with jax.default_device(DEVICE_MAPPING[self.device]			):
         # calling jnp.array on a np.ndarray does copy the data
         # see https://github.com/google/jax/issues/4486
         return jnp.array(__lowerCAmelCase     ,       **{**default_dtype, **self.jnp_array_kwargs}			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Any:
        import jax

        # 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     ,       jax.Array			):
         lowercase__    :   Tuple						= data_struct.__array__()
        # support for nested types like struct of list of struct
        if isinstance(__lowerCAmelCase     ,       np.ndarray			):
         if data_struct.dtype == object:  # jax arrays 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 _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  List[str]:
        return map_nested(self._recursive_tensorize     ,       __lowerCAmelCase     ,       map_list=__lowerCAmelCase			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Mapping:
        lowercase__    :   Optional[Any]						= self.numpy_arrow_extractor().extract_row(__lowerCAmelCase			)
        lowercase__    :   Any						= self.python_features_decoder.decode_row(__lowerCAmelCase			)
        return self.recursive_tensorize(__lowerCAmelCase			)

       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  "jax.Array":
        lowercase__    :   Optional[int]						= self.numpy_arrow_extractor().extract_column(__lowerCAmelCase			)
        lowercase__    :   List[str]						= self.python_features_decoder.decode_column(__lowerCAmelCase     ,       pa_table.column_names[0]			)
        lowercase__    :   List[str]						= self.recursive_tensorize(__lowerCAmelCase			)
        lowercase__    :   Union[str, Any]						= self._consolidate(__lowerCAmelCase			)
        return column


       def _lowerCAmelCase(						self     ,       __lowerCAmelCase			)  ->  Mapping:
        lowercase__    :   Tuple						= self.numpy_arrow_extractor().extract_batch(__lowerCAmelCase			)
        lowercase__    :   str						= self.python_features_decoder.decode_batch(__lowerCAmelCase			)
        lowercase__    :   Dict						= self.recursive_tensorize(__lowerCAmelCase			)
        for column_name in batch:
         lowercase__    :   Union[str, Any]						= self._consolidate(batch[column_name]			)
        return batch


'''simple docstring'''

def       __UpperCamelCase	(       ):
 lowercase__    :   Any						= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

 lowercase__    :   Any						= 6
 lowercase__    :   Optional[Any]						= 1
 lowercase__    :   int						= 1901

 lowercase__    :   List[str]						= 0

 while year < 2001:
  day += 7

  if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
   if day > days_per_month[month - 1] and month != 2:
    month += 1
    lowercase__    :   List[Any]						= day - days_per_month[month - 2]
   elif day > 29 and month == 2:
    month += 1
    lowercase__    :   Any						= day - 29
  else:
   if day > days_per_month[month - 1]:
    month += 1
    lowercase__    :   List[Any]						= day - days_per_month[month - 2]

  if month > 12:
   year += 1
   lowercase__    :   Dict						= 1

  if year < 2001 and day == 1:
   sundays += 1
 return sundays


if __name__ == "__main__":
  print(solution())

