
import functools
import logging
import os
import sys
import threading
from logging import (
    CRITICAL,  # NOQA
    DEBUG,  # NOQA
    ERROR,  # NOQA
    FATAL,  # NOQA
    INFO,  # NOQA
    NOTSET,  # NOQA
    WARN,  # NOQA
    WARNING,  # NOQA
)
from typing import Optional

import huggingface_hub.utils as hf_hub_utils
from tqdm import auto as tqdm_lib


__lowerCAmelCase			:     List[Any]           =   threading.Lock()
__lowerCAmelCase			:     Optional[logging.Handler]           =   None

__lowerCAmelCase			:     Optional[Any]           =   {
    'debug': logging.DEBUG,
    'info': logging.INFO,
    'warning': logging.WARNING,
    'error': logging.ERROR,
    'critical': logging.CRITICAL,
}

__lowerCAmelCase			:     List[Any]           =   logging.WARNING

__lowerCAmelCase			:     Optional[int]           =   True

def a__    (       ):






  '''simple docstring'''





  __magic_name__				     =       os.getenv("""TRANSFORMERS_VERBOSITY""",     A_					)
  if env_level_str:
    if env_level_str in log_levels:
      return log_levels[env_level_str]
    else:
      logging.getLogger().warning(
          f'''Unknown option TRANSFORMERS_VERBOSITY={env_level_str}, '''
          f'''has to be one of: { ', '.join(log_levels.keys()					) }'''					)
  return _default_log_level

def a__    (       ):






  '''simple docstring'''





  return __name__.split("""."""					)[0]

def a__    (       ):






  '''simple docstring'''





  return logging.getLogger(_get_library_name()					)

def a__    (       ):






  '''simple docstring'''





  global _default_handler

  with _lock:
    if _default_handler:
      # This library has already configured the library root logger.
      return
    __magic_name__				     =       logging.StreamHandler()  # Set sys.stderr as stream.
    __magic_name__				     =       sys.stderr.flush

    # Apply our default configuration to the library root logger.
    __magic_name__				     =       _get_library_root_logger()
    library_root_logger.addHandler(_default_handler					)
    library_root_logger.setLevel(_get_default_logging_level()					)
    __magic_name__				     =       False

def a__    (       ):






  '''simple docstring'''





  global _default_handler

  with _lock:
    if not _default_handler:
      return

    __magic_name__				     =       _get_library_root_logger()
    library_root_logger.removeHandler(_default_handler					)
    library_root_logger.setLevel(logging.NOTSET					)
    __magic_name__				     =       None

def a__    (       ):






  '''simple docstring'''





  return log_levels

def a__    (       A_ = None					):






  '''simple docstring'''





  if name is None:
    __magic_name__				     =       _get_library_name()

  _configure_library_root_logger()
  return logging.getLogger(A_					)

def a__    (       ):






  '''simple docstring'''





  _configure_library_root_logger()
  return _get_library_root_logger().getEffectiveLevel()

def a__    (       A_					):






  '''simple docstring'''





  _configure_library_root_logger()
  _get_library_root_logger().setLevel(A_					)

def a__    (       ):






  '''simple docstring'''





  return set_verbosity(A_					)

def a__    (       ):






  '''simple docstring'''





  return set_verbosity(A_					)

def a__    (       ):






  '''simple docstring'''





  return set_verbosity(A_					)

def a__    (       ):






  '''simple docstring'''





  return set_verbosity(A_					)

def a__    (       ):






  '''simple docstring'''





  _configure_library_root_logger()

  assert _default_handler is not None
  _get_library_root_logger().removeHandler(_default_handler					)

def a__    (       ):






  '''simple docstring'''





  _configure_library_root_logger()

  assert _default_handler is not None
  _get_library_root_logger().addHandler(_default_handler					)

def a__    (       A_					):






  '''simple docstring'''





  _configure_library_root_logger()

  assert handler is not None
  _get_library_root_logger().addHandler(A_					)

def a__    (       A_					):






  '''simple docstring'''





  _configure_library_root_logger()

  assert handler is not None and handler not in _get_library_root_logger().handlers
  _get_library_root_logger().removeHandler(A_					)

def a__    (       ):






  '''simple docstring'''





  _configure_library_root_logger()
  __magic_name__				     =       False

def a__    (       ):






  '''simple docstring'''





  _configure_library_root_logger()
  __magic_name__				     =       True

def a__    (       ):






  '''simple docstring'''





  __magic_name__				     =       _get_library_root_logger().handlers

  for handler in handlers:
    __magic_name__				     =       logging.Formatter("""[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s"""					)
    handler.setFormatter(A_					)

def a__    (       ):






  '''simple docstring'''





  __magic_name__				     =       _get_library_root_logger().handlers

  for handler in handlers:
    handler.setFormatter(A_					)

def a__    (       self,     *A_,     **A_					):






  '''simple docstring'''





  __magic_name__				     =       os.getenv("""TRANSFORMERS_NO_ADVISORY_WARNINGS""",     A_					)
  if no_advisory_warnings:
    return
  self.warning(*A_,     **A_					)


__lowerCAmelCase			:     int           =   warning_advice

@functools.lru_cache(A_					)
def a__    (       self,     *A_,     **A_					):






  '''simple docstring'''





  self.warning(*A_,     **A_					)


__lowerCAmelCase			:     Optional[int]           =   warning_once




class        UpperCAmelCase_			:


  '''simple docstring'''







  def __init__( self			: Tuple			,							*UpperCamelCase__			: str			,							**UpperCamelCase__			: Optional[Any]    )			->	int:  # pylint: disable=unused-argument







    """simple docstring"""






    __magic_name__				     =       args[0] if args else None
  def __iter__( self			: str    )			->	Tuple:







    """simple docstring"""






    return iter(self._iterator    )
  def __getattr__( self			: Optional[int]			,							UpperCamelCase__			: List[str]    )			->	str:







    """simple docstring"""






    def empty_fn(*UpperCamelCase__			: List[Any]			,							**UpperCamelCase__			: Optional[int]    ):  # pylint: disable=unused-argument
      return

    return empty_fn
  def __enter__( self			: Union[str, Any]    )			->	List[str]:







    """simple docstring"""






    return self





  def __exit__( self			: str			,							UpperCamelCase__			: List[Any]			,							UpperCamelCase__			: Optional[Any]			,							UpperCamelCase__			: int    )			->	int:







    """simple docstring"""






    return







class        UpperCAmelCase_			:


  '''simple docstring'''







  def __call__( self			: str			,							*UpperCamelCase__			: Any			,							**UpperCamelCase__			: Dict    )			->	Tuple:







    """simple docstring"""






    if _tqdm_active:
      return tqdm_lib.tqdm(*__UpperCamelCase			,							**__UpperCamelCase    )
    else:
      return EmptyTqdm(*__UpperCamelCase			,							**__UpperCamelCase    )
  def 							_lowercase							( self			: Any			,							*UpperCamelCase__			: Optional[Any]			,							**UpperCamelCase__			: int    )			->	List[str]:







    """simple docstring"""






    __magic_name__				     =       None
    if _tqdm_active:
      return tqdm_lib.tqdm.set_lock(*__UpperCamelCase			,							**__UpperCamelCase    )





  def 							_lowercase							( self			: List[str]    )			->	Union[str, Any]:







    """simple docstring"""






    if _tqdm_active:
      return tqdm_lib.tqdm.get_lock()







__lowerCAmelCase			:     Any           =   _tqdm_cls()

def a__    (       ):






  '''simple docstring'''





  global _tqdm_active
  return bool(_tqdm_active					)

def a__    (       ):






  '''simple docstring'''





  global _tqdm_active
  __magic_name__				     =       True
  hf_hub_utils.enable_progress_bars()





def a__    (       ):






  '''simple docstring'''





  global _tqdm_active
  __magic_name__				     =       False
  hf_hub_utils.disable_progress_bars()








"""simple docstring"""
def 					A__				(			UpperCamelCase       ):
							A		=  generate_pascal_triangle(UpperCamelCase       )
							for row_idx in range(UpperCamelCase       ):
														# Print left spaces
														for _ in range(num_rows - row_idx - 1       ):
																					print(end=" "       )
														# Print row values
														for col_idx in range(row_idx + 1       ):
																					if col_idx != row_idx:
																												print(triangle[row_idx][col_idx]					,  end=" "       )
																					else:
																												print(triangle[row_idx][col_idx]					,  end=""       )
														print()






def 					A__				(			UpperCamelCase       ):

							if not isinstance(UpperCamelCase					,  UpperCamelCase       ):
														raise TypeError("The input value of 'num_rows' should be 'int'"       )

							if num_rows == 0:
														return []
							elif num_rows < 0:
														raise ValueError(
														    "The input value of 'num_rows' should be greater than or equal to 0"       )

							A		=  []
							for current_row_idx in range(UpperCamelCase       ):
														A		=  populate_current_row(UpperCamelCase					,  UpperCamelCase       )
														triangle.append(UpperCamelCase       )
							return triangle






def 					A__				(			UpperCamelCase					,  UpperCamelCase       ):
							A		=  [-1] * (current_row_idx + 1)
							# first and last elements of current row are equal to 1
							A,	A		=  1, 1
							for current_col_idx in range(1					,  UpperCamelCase       ):
														calculate_current_element(
														    UpperCamelCase					,  UpperCamelCase					,  UpperCamelCase					,  UpperCamelCase       )
							return current_row






def 					A__				(			UpperCamelCase					,  UpperCamelCase					,  UpperCamelCase					,  UpperCamelCase					,  ):
							A		=  triangle[current_row_idx - 1][current_col_idx - 1]
							A		=  triangle[current_row_idx - 1][current_col_idx]
							A		=  above_to_left_elt + above_to_right_elt






def 					A__				(			UpperCamelCase       ):

							if not isinstance(UpperCamelCase					,  UpperCamelCase       ):
														raise TypeError("The input value of 'num_rows' should be 'int'"       )

							if num_rows == 0:
														return []
							elif num_rows < 0:
														raise ValueError(
														    "The input value of 'num_rows' should be greater than or equal to 0"       )

							A		=  [[1]]

							for row_index in range(1					,  UpperCamelCase       ):
														A		=  [0] + result[-1] + [0]
														A		=  row_index + 1
														# Calculate the number of distinct elements in a row
														A		=  sum(divmod(UpperCamelCase					,  2       )       )
														A		=  [
														    temp_row[i - 1] + temp_row[i] for i in range(1					,  distinct_elements + 1       )
														]
														A		=  row_first_half[: (row_index + 1) // 2]
														row_second_half.reverse()
														A		=  row_first_half + row_second_half
														result.append(UpperCamelCase       )

							return result






def 					A__				(			):
							from collections.abc import Callable
							from timeit import timeit

							def benchmark_a_function(UpperCamelCase					,  UpperCamelCase       ) -> None:
														A		=  F"{func.__name__}({value})"
														A		=  timeit(F"__main__.{call}"					,  setup="import __main__"       )
														# print(f"{call:38} = {func(value)} -- {timing:.4f} seconds")
														print(F"{call:38} -- {timing:.4f} seconds"       )

							for value in range(15       ):  # (1, 7, 14):
														for func in (generate_pascal_triangle, generate_pascal_triangle_optimized):
																					benchmark_a_function(UpperCamelCase					,  UpperCamelCase       )
														print()


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		benchmark()


