






'''simple docstring'''


import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
  from PIL import Image




class 							lowerCAmelCase					(							unittest.TestCase							,      lowerCamelCase__   ):







   """simple docstring"""







   def    __magic_name__    ( self			)    ->   Union[str, Any]:
    __a    :	Dict									=						load_tool('image-captioning'			)
    self.tool.setup()
    __a    :	List[str]									=						load_tool('image-captioning'   ,   remote=_A			)



   def    __magic_name__    ( self			)    ->   int:
    __a    :	List[Any]									=						Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'			)			) / '000000039769.png'			)
    __a    :	Dict									=						self.tool(_A			)
    self.assertEqual(_A   ,   'two cats sleeping on a couch'			)



   def    __magic_name__    ( self			)    ->   str:
    __a    :	Union[str, Any]									=						Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'			)			) / '000000039769.png'			)
    __a    :	Dict									=						self.remote_tool(_A			)
    self.assertEqual(_A   ,   'two cats sleeping on a couch'			)



   def    __magic_name__    ( self			)    ->   List[str]:
    __a    :	Optional[int]									=						Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'			)			) / '000000039769.png'			)
    __a    :	List[Any]									=						self.tool(image=_A			)
    self.assertEqual(_A   ,   'two cats sleeping on a couch'			)



   def    __magic_name__    ( self			)    ->   Dict:
    __a    :	Optional[Any]									=						Image.open(Path(get_tests_dir('fixtures/tests_samples/COCO'			)			) / '000000039769.png'			)
    __a    :	Optional[int]									=						self.remote_tool(image=_A			)
    self.assertEqual(_A   ,   'two cats sleeping on a couch'			)












'''simple docstring'''


import math
from timeit import timeit






def   lowerCAmelCase__			(					SCREAMING_SNAKE_CASE__		):
 __a    :	Any									=						0
 __a    :	List[Any]									=						abs(SCREAMING_SNAKE_CASE__		)
 while True:
  __a    :	int									=						n // 10
  digits += 1
  if n == 0:
   break
 return digits






def   lowerCAmelCase__			(					SCREAMING_SNAKE_CASE__		):
 return 1 if n == 0 else math.floor(math.log(abs(SCREAMING_SNAKE_CASE__		)       ,		10		) + 1		)






def   lowerCAmelCase__			(					SCREAMING_SNAKE_CASE__		):
 return len(str(abs(SCREAMING_SNAKE_CASE__		)		)		)






def   lowerCAmelCase__			(					):
 from collections.abc import Callable

 def benchmark_a_function(SCREAMING_SNAKE_CASE__       ,		SCREAMING_SNAKE_CASE__		) -> None:
  __a    :	Tuple									=						f'''{func.__name__}({value})'''
  __a    :	List[Any]									=						timeit(f'''__main__.{call}'''       ,		setup='import __main__'		)
  print(f'''{call}: {func(SCREAMING_SNAKE_CASE__		)} -- {timing} seconds'''		)

 for value in (262144, 1125899906842624, 1267650600228229401496703205376):
  for func in (num_digits, num_digits_fast, num_digits_faster):
   benchmark_a_function(SCREAMING_SNAKE_CASE__       ,		SCREAMING_SNAKE_CASE__		)
  print()


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  benchmark()




