


'''simple docstring'''
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


UpperCamelCase__          = threading.Lock()
UpperCamelCase__          = None

UpperCamelCase__          = {
    '''debug''': logging.DEBUG,
    '''info''': logging.INFO,
    '''warning''': logging.WARNING,
    '''error''': logging.ERROR,
    '''critical''': logging.CRITICAL,
}

UpperCamelCase__          = logging.WARNING

UpperCamelCase__          = True





def    a__			(   )       ->      List[Any]:
    UpperCAmelCase__     :						Optional[Any]						=							os.getenv('''TRANSFORMERS_VERBOSITY'''    ,   lowerCAmelCase__		)
    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__			(   )       ->      str:
    return __name__.split('''.'''		)[0]





def    a__			(   )       ->      logging.Logger:
    return logging.getLogger(_get_library_name()		)





def    a__			(   )       ->      None:
    global _default_handler

    with _lock:
        if _default_handler:
            # This library has already configured the library root logger.
            return
        UpperCAmelCase__     :						str						=							logging.StreamHandler()  # Set sys.stderr as stream.
        UpperCAmelCase__     :						Union[str, Any]						=							sys.stderr.flush

        # Apply our default configuration to the library root logger.
        UpperCAmelCase__     :						List[Any]						=							_get_library_root_logger()
        library_root_logger.addHandler(_default_handler		)
        library_root_logger.setLevel(_get_default_logging_level()		)
        UpperCAmelCase__     :						List[Any]						=							False





def    a__			(   )       ->      None:
    global _default_handler

    with _lock:
        if not _default_handler:
            return

        UpperCAmelCase__     :						Union[str, Any]						=							_get_library_root_logger()
        library_root_logger.removeHandler(_default_handler		)
        library_root_logger.setLevel(logging.NOTSET		)
        UpperCAmelCase__     :						Dict						=							None





def    a__			(   )       ->      Dict:
    return log_levels





def    a__			(   lowerCAmelCase__ = None		)       ->      logging.Logger:

    if name is None:
        UpperCAmelCase__     :						List[Any]						=							_get_library_name()

    _configure_library_root_logger()
    return logging.getLogger(lowerCAmelCase__		)





def    a__			(   )       ->      int:
    _configure_library_root_logger()
    return _get_library_root_logger().getEffectiveLevel()





def    a__			(   lowerCAmelCase__		)       ->      None:
    _configure_library_root_logger()
    _get_library_root_logger().setLevel(lowerCAmelCase__		)





def    a__			(   )       ->      Tuple:
    return set_verbosity(lowerCAmelCase__		)





def    a__			(   )       ->      Union[str, Any]:
    return set_verbosity(lowerCAmelCase__		)





def    a__			(   )       ->      List[str]:
    return set_verbosity(lowerCAmelCase__		)





def    a__			(   )       ->      int:
    return set_verbosity(lowerCAmelCase__		)





def    a__			(   )       ->      None:
    _configure_library_root_logger()

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





def    a__			(   )       ->      None:
    _configure_library_root_logger()

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





def    a__			(   lowerCAmelCase__		)       ->      None:
    _configure_library_root_logger()

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





def    a__			(   lowerCAmelCase__		)       ->      None:
    _configure_library_root_logger()

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





def    a__			(   )       ->      None:
    _configure_library_root_logger()
    UpperCAmelCase__     :						List[Any]						=							False





def    a__			(   )       ->      None:
    _configure_library_root_logger()
    UpperCAmelCase__     :						str						=							True





def    a__			(   )       ->      None:
    UpperCAmelCase__     :						List[str]						=							_get_library_root_logger().handlers

    for handler in handlers:
        UpperCAmelCase__     :						str						=							logging.Formatter('''[%(levelname)s|%(filename)s:%(lineno)s] %(asctime)s >> %(message)s'''		)
        handler.setFormatter(lowerCAmelCase__		)





def    a__			(   )       ->      None:
    UpperCAmelCase__     :						Optional[Any]						=							_get_library_root_logger().handlers

    for handler in handlers:
        handler.setFormatter(lowerCAmelCase__		)





def    a__			(   self    ,   *lowerCAmelCase__    ,   **lowerCAmelCase__		)       ->      List[str]:
    UpperCAmelCase__     :						Optional[Any]						=							os.getenv('''TRANSFORMERS_NO_ADVISORY_WARNINGS'''    ,   lowerCAmelCase__		)
    if no_advisory_warnings:
        return
    self.warning(*lowerCAmelCase__    ,   **lowerCAmelCase__		)


UpperCamelCase__          = warning_advice





@functools.lru_cache(lowerCAmelCase__		)
def    a__			(   self    ,   *lowerCAmelCase__    ,   **lowerCAmelCase__		)       ->      Optional[Any]:
    self.warning(*lowerCAmelCase__    ,   **lowerCAmelCase__		)


UpperCamelCase__          = warning_once




class      lowerCamelCase_  :






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


          '''simple docstring'''


          UpperCAmelCase__     :						Dict						=							args[0] if args else None






      def __iter__(   self							:       List[Any]					):


          '''simple docstring'''


          return iter(self._iterator					)






      def __getattr__(   self							:       Dict		,		_A							:       Union[str, Any]					):


          '''simple docstring'''


          def empty_fn(*_A							:       int		,		**_A							:       str					):  # pylint: disable=unused-argument
              return

          return empty_fn






      def __enter__(   self							:       Dict					):


          '''simple docstring'''


          return self






      def __exit__(   self							:       Any		,		_A							:       Union[str, Any]		,		_A							:       int		,		_A							:       str					):


          '''simple docstring'''


          return




class      lowerCamelCase_  :






      def __call__(   self							:       List[Any]		,		*_A							:       int		,		**_A							:       List[str]					):


          '''simple docstring'''


          if _tqdm_active:
              return tqdm_lib.tqdm(*_A		,		**_A					)
          else:
              return EmptyTqdm(*_A		,		**_A					)






      def lowercase_				(   self							:       Tuple		,		*_A							:       Dict		,		**_A							:       Optional[Any]					):


          '''simple docstring'''


          UpperCAmelCase__     :						Optional[int]						=							None
          if _tqdm_active:
              return tqdm_lib.tqdm.set_lock(*_A		,		**_A					)






      def lowercase_				(   self							:       Any					):


          '''simple docstring'''


          if _tqdm_active:
              return tqdm_lib.tqdm.get_lock()

UpperCamelCase__          = _tqdm_cls()





def    a__			(   )       ->      bool:
    global _tqdm_active
    return bool(_tqdm_active		)





def    a__			(   )       ->      List[str]:
    global _tqdm_active
    UpperCAmelCase__     :						int						=							True
    hf_hub_utils.enable_progress_bars()







def    a__			(   )       ->      List[str]:
    global _tqdm_active
    UpperCAmelCase__     :						Optional[Any]						=							False
    hf_hub_utils.disable_progress_bars()





def A    (							__UpperCamelCase			,						__UpperCamelCase       )    ->   Optional[int]:
			A__	  =     0
			A__	  =     len(__UpperCamelCase       ) - 1

			while left <= right:
						# avoid divided by 0 during interpolation
						if sorted_collection[left] == sorted_collection[right]:
									if sorted_collection[left] == item:
												return left
									else:
												return None

						A__	  =     left + ((item - sorted_collection[left]) * (right - left)) // (
						    sorted_collection[right] - sorted_collection[left]
						)

						# out of range check
						if point < 0 or point >= len(__UpperCamelCase       ):
									return None

						A__	  =     sorted_collection[point]
						if current_item == item:
									return point
						else:
									if point < left:
												A__	  =     left
												A__	  =     point
									elif point > right:
												A__	  =     right
												A__	  =     point
									else:
												if item < current_item:
															A__	  =     point - 1
												else:
															A__	  =     point + 1
			return None


def A    (							__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase       )    ->   int:

			# avoid divided by 0 during interpolation
			if sorted_collection[left] == sorted_collection[right]:
						if sorted_collection[left] == item:
									return left
						else:
									return None

			A__	  =     left + ((item - sorted_collection[left]) * (right - left)) // (
			    sorted_collection[right] - sorted_collection[left]
			)

			# out of range check
			if point < 0 or point >= len(__UpperCamelCase       ):
						return None

			if sorted_collection[point] == item:
						return point
			elif point < left:
						return interpolation_search_by_recursion(__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase       )
			elif point > right:
						return interpolation_search_by_recursion(__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase       )
			else:
						if sorted_collection[point] > item:
									return interpolation_search_by_recursion(
									    __UpperCamelCase			,						__UpperCamelCase			,						__UpperCamelCase			,						point - 1       )
						else:
									return interpolation_search_by_recursion(
									    __UpperCamelCase			,						__UpperCamelCase			,						point + 1			,						__UpperCamelCase       )


def A    (							__UpperCamelCase       )    ->   List[str]:
			if collection != sorted(__UpperCamelCase       ):
						raise ValueError('Collection must be ascending sorted'       )
			return True


if __name__ == "__main__":
							import sys
							SCREAMING_SNAKE_CASE__   			=   0
							if debug == 1:
														SCREAMING_SNAKE_CASE__   			=   [1_0, 3_0, 4_0, 4_5, 5_0, 6_6, 7_7, 9_3]
														try:
																					__assert_sorted(collection)
														except ValueError:
																					sys.exit('''Sequence must be ascending sorted to apply interpolation search''')
														SCREAMING_SNAKE_CASE__   			=   6_7

							SCREAMING_SNAKE_CASE__   			=   interpolation_search(collection, target)
							if result is not None:
														print(f'{target} found at positions: {result}')
							else:
														print('''Not found''')




