"""simple docstring"""
from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
   import PIL

_UpperCAmelCase     =			logging.get_logger(__name__)





def      __magic_name__				(							lowercase ):

   if isinstance(lowercase							,			(list, tuple) ) and isinstance(videos[0]							,			(list, tuple) ) and is_valid_image(videos[0][0] ):
      return videos

   elif isinstance(lowercase							,			(list, tuple) ) and is_valid_image(videos[0] ):
      return [videos]

   elif is_valid_image(lowercase ):
      return [[videos]]

   raise ValueError(f'''Could not make batched video from {videos}''' )
class 					a	(  _a       ):
  UpperCamelCase	:				Tuple     						=					["""pixel_values"""]



  def __init__(						self :					int       ,		lowerCAmelCase :					str = True       ,		lowerCAmelCase :					Optional[int] = None       ,		lowerCAmelCase :					Dict = PILImageResampling.BILINEAR       ,		lowerCAmelCase :					List[Any] = True       ,		lowerCAmelCase :					Optional[int] = None       ,		lowerCAmelCase :					Tuple = True       ,		lowerCAmelCase :					List[str] = 1 / 255       ,		lowerCAmelCase :					Optional[Any] = True       ,		lowerCAmelCase :					int = True       ,		lowerCAmelCase :					List[Any] = None       ,		lowerCAmelCase :					int = None       ,		**lowerCAmelCase :					Optional[int]       ,		)     ->					None:


     '''simple docstring'''




     super().__init__(**snake_case_		)
     SCREAMING_SNAKE_CASE_: Dict     			=size if size is not None else {"""shortest_edge""": 256}
     SCREAMING_SNAKE_CASE_: Tuple     			=get_size_dict(snake_case_       ,		default_to_square=snake_case_		)
     SCREAMING_SNAKE_CASE_: List[Any]     			=crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
     SCREAMING_SNAKE_CASE_: str     			=get_size_dict(snake_case_       ,		param_name="""crop_size"""		)

     SCREAMING_SNAKE_CASE_: Optional[Any]     			=do_resize
     SCREAMING_SNAKE_CASE_: Dict     			=size
     SCREAMING_SNAKE_CASE_: Optional[int]     			=do_center_crop
     SCREAMING_SNAKE_CASE_: str     			=crop_size
     SCREAMING_SNAKE_CASE_: Any     			=resample
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=do_rescale
     SCREAMING_SNAKE_CASE_: str     			=rescale_factor
     SCREAMING_SNAKE_CASE_: Any     			=offset
     SCREAMING_SNAKE_CASE_: Optional[int]     			=do_normalize
     SCREAMING_SNAKE_CASE_: Optional[int]     			=image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=image_std if image_std is not None else IMAGENET_STANDARD_STD



  def 	lowerCamelCase__       (						self :					int       ,		lowerCAmelCase :					Dict       ,		lowerCAmelCase :					Optional[Any]       ,		lowerCAmelCase :					Tuple = PILImageResampling.BILINEAR       ,		lowerCAmelCase :					int = None       ,		**lowerCAmelCase :					Dict       ,		)     ->					np.ndarray:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Any     			=get_size_dict(snake_case_       ,		default_to_square=snake_case_		)
     if "shortest_edge" in size:
        SCREAMING_SNAKE_CASE_: Optional[Any]     			=get_resize_output_image_size(snake_case_       ,		size["""shortest_edge"""]       ,		default_to_square=snake_case_		)
     elif "height" in size and "width" in size:
        SCREAMING_SNAKE_CASE_: Any     			=(size["""height"""], size["""width"""])
     else:
        raise ValueError(f'''Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'''		)
     return resize(snake_case_       ,		size=snake_case_       ,		resample=snake_case_       ,		data_format=snake_case_       ,		**snake_case_		)



  def 	lowerCamelCase__       (						self :					int       ,		lowerCAmelCase :					List[Any]       ,		lowerCAmelCase :					Union[str, Any]       ,		lowerCAmelCase :					int = None       ,		**lowerCAmelCase :					Optional[Any]       ,		)     ->					np.ndarray:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: int     			=get_size_dict(snake_case_		)
     if "height" not in size or "width" not in size:
        raise ValueError(f'''Size must have \'height\' and \'width\' as keys. Got {size.keys()}'''		)
     return center_crop(snake_case_       ,		size=(size["""height"""], size["""width"""])       ,		data_format=snake_case_       ,		**snake_case_		)



  def 	lowerCamelCase__       (						self :					Tuple       ,		lowerCAmelCase :					Tuple       ,		lowerCAmelCase :					Dict       ,		lowerCAmelCase :					Any = True       ,		lowerCAmelCase :					str = None       ,		**lowerCAmelCase :					List[Any]       ,		)     ->					str:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: Optional[int]     			=image.astype(np.floataa		)
     if offset:
        SCREAMING_SNAKE_CASE_: Dict     			=image - (scale / 2)
     return rescale(snake_case_       ,		scale=snake_case_       ,		data_format=snake_case_       ,		**snake_case_		)



  def 	lowerCamelCase__       (						self :					Any       ,		lowerCAmelCase :					Optional[int]       ,		lowerCAmelCase :					Tuple       ,		lowerCAmelCase :					Optional[Any]       ,		lowerCAmelCase :					List[Any] = None       ,		**lowerCAmelCase :					Any       ,		)     ->					np.ndarray:


     '''simple docstring'''




     return normalize(snake_case_       ,		mean=snake_case_       ,		std=snake_case_       ,		data_format=snake_case_       ,		**snake_case_		)



  def 	lowerCamelCase__       (						self :					Dict       ,		lowerCAmelCase :					Dict       ,		lowerCAmelCase :					Tuple = None       ,		lowerCAmelCase :					str = None       ,		lowerCAmelCase :					Optional[Any] = None       ,		lowerCAmelCase :					Tuple = None       ,		lowerCAmelCase :					Any = None       ,		lowerCAmelCase :					Optional[int] = None       ,		lowerCAmelCase :					List[str] = None       ,		lowerCAmelCase :					Optional[int] = None       ,		lowerCAmelCase :					Tuple = None       ,		lowerCAmelCase :					List[Any] = None       ,		lowerCAmelCase :					List[Any] = None       ,		lowerCAmelCase :					int = ChannelDimension.FIRST       ,		)     ->					np.ndarray:


     '''simple docstring'''




     if do_resize and size is None or resample is None:
        raise ValueError("""Size and resample must be specified if do_resize is True."""		)

     if do_center_crop and crop_size is None:
        raise ValueError("""Crop size must be specified if do_center_crop is True."""		)

     if do_rescale and rescale_factor is None:
        raise ValueError("""Rescale factor must be specified if do_rescale is True."""		)

     if do_normalize and (image_mean is None or image_std is None):
        raise ValueError("""Image mean and std must be specified if do_normalize is True."""		)

     if offset and not do_rescale:
        raise ValueError("""For offset, do_rescale must also be set to True."""		)

     # All transformations expect numpy arrays.
     SCREAMING_SNAKE_CASE_: List[Any]     			=to_numpy_array(snake_case_		)

     if do_resize:
        SCREAMING_SNAKE_CASE_: Optional[int]     			=self.resize(image=snake_case_       ,		size=snake_case_       ,		resample=snake_case_		)

     if do_center_crop:
        SCREAMING_SNAKE_CASE_: Dict     			=self.center_crop(snake_case_       ,		size=snake_case_		)

     if do_rescale:
        SCREAMING_SNAKE_CASE_: Optional[Any]     			=self.rescale(image=snake_case_       ,		scale=snake_case_       ,		offset=snake_case_		)

     if do_normalize:
        SCREAMING_SNAKE_CASE_: Union[str, Any]     			=self.normalize(image=snake_case_       ,		mean=snake_case_       ,		std=snake_case_		)

     SCREAMING_SNAKE_CASE_: str     			=to_channel_dimension_format(snake_case_       ,		snake_case_		)
     return image





  def 	lowerCamelCase__       (						self :					int       ,		lowerCAmelCase :					Union[str, Any]       ,		lowerCAmelCase :					Any = None       ,		lowerCAmelCase :					str = None       ,		lowerCAmelCase :					Any = None       ,		lowerCAmelCase :					str = None       ,		lowerCAmelCase :					Any = None       ,		lowerCAmelCase :					Optional[Any] = None       ,		lowerCAmelCase :					List[str] = None       ,		lowerCAmelCase :					Dict = None       ,		lowerCAmelCase :					Optional[Any] = None       ,		lowerCAmelCase :					List[str] = None       ,		lowerCAmelCase :					Any = None       ,		lowerCAmelCase :					str = None       ,		lowerCAmelCase :					Tuple = ChannelDimension.FIRST       ,		**lowerCAmelCase :					List[str]       ,		)     ->					PIL.Image.Image:


     '''simple docstring'''




     SCREAMING_SNAKE_CASE_: int     			=do_resize if do_resize is not None else self.do_resize
     SCREAMING_SNAKE_CASE_: List[Any]     			=resample if resample is not None else self.resample
     SCREAMING_SNAKE_CASE_: int     			=do_center_crop if do_center_crop is not None else self.do_center_crop
     SCREAMING_SNAKE_CASE_: List[str]     			=do_rescale if do_rescale is not None else self.do_rescale
     SCREAMING_SNAKE_CASE_: Tuple     			=rescale_factor if rescale_factor is not None else self.rescale_factor
     SCREAMING_SNAKE_CASE_: Optional[int]     			=offset if offset is not None else self.offset
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=do_normalize if do_normalize is not None else self.do_normalize
     SCREAMING_SNAKE_CASE_: Union[str, Any]     			=image_mean if image_mean is not None else self.image_mean
     SCREAMING_SNAKE_CASE_: Optional[Any]     			=image_std if image_std is not None else self.image_std

     SCREAMING_SNAKE_CASE_: Optional[Any]     			=size if size is not None else self.size
     SCREAMING_SNAKE_CASE_: List[Any]     			=get_size_dict(snake_case_       ,		default_to_square=snake_case_		)
     SCREAMING_SNAKE_CASE_: Any     			=crop_size if crop_size is not None else self.crop_size
     SCREAMING_SNAKE_CASE_: int     			=get_size_dict(snake_case_       ,		param_name="""crop_size"""		)

     if not valid_images(snake_case_		):
        raise ValueError(
            """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
            """torch.Tensor, tf.Tensor or jax.ndarray."""		)

     SCREAMING_SNAKE_CASE_: List[Any]     			=make_batched(snake_case_		)

     SCREAMING_SNAKE_CASE_: Optional[Any]     			=[
         [
             self._preprocess_image(
                 image=snake_case_       ,		do_resize=snake_case_       ,		size=snake_case_       ,		resample=snake_case_       ,		do_center_crop=snake_case_       ,		crop_size=snake_case_       ,		do_rescale=snake_case_       ,		rescale_factor=snake_case_       ,		offset=snake_case_       ,		do_normalize=snake_case_       ,		image_mean=snake_case_       ,		image_std=snake_case_       ,		data_format=snake_case_       ,		)
             for img in video
         ]
         for video in videos
     ]

     SCREAMING_SNAKE_CASE_: Dict     			={"""pixel_values""": videos}
     return BatchFeature(data=snake_case_       ,		tensor_type=snake_case_		)








"""simple docstring"""
def      __magic_name__				(							lowercase ):
   if upper_limit < 0:
      raise ValueError("""Limit for the Catalan sequence must be ≥ 0""" )

   SCREAMING_SNAKE_CASE_: Tuple     			=[0] * (upper_limit + 1)

   # Base case: C(0) = C(1) = 1
   SCREAMING_SNAKE_CASE_: Any     			=1
   if upper_limit > 0:
      SCREAMING_SNAKE_CASE_: List[str]     			=1

   # Recurrence relation: C(i) = sum(C(j).C(i-j-1)), from j = 0 to i
   for i in range(2							,			upper_limit + 1 ):
      for j in range(lowercase ):
         catalan_list[i] += catalan_list[j] * catalan_list[i - j - 1]

   return catalan_list


if __name__ == "__main__":
   print("""\n********* Catalan Numbers Using Dynamic Programming ************\n""")
   print("""\n*** Enter -1 at any time to quit ***""")
   print("""\nEnter the upper limit (≥ 0) for the Catalan number sequence: """, end="""""")
   try:
      while True:
         _UpperCAmelCase     =			int(input().strip())
         if N < 0:
            print("""\n********* Goodbye!! ************""")
            break
         else:
            print(f"""The Catalan numbers from 0 through {N} are:""")
            print(catalan_numbers(N))
            print("""Try another upper limit for the sequence: """, end="""""")
   except (NameError, ValueError):
      print("""\n********* Invalid input, goodbye! ************\n""")

   import doctest

   doctest.testmod()



