





'''simple docstring'''


import timeit
class    a_     :





     def __init__(				self	:      Dict			,   lowercase	:      str		):





        """simple docstring"""




        if isinstance(lowercase			,   lowercase		):  # Initializes a matrix identical to the one provided.
           lowercase_    :Union[str, Any]					    =				arg
           lowercase_    :Optional[Any]					    =				len(lowercase		)
        else:  # Initializes a square matrix of the given size and set values to zero.
           lowercase_    :Optional[Any]					    =				arg
           lowercase_    :int					    =				[[0 for _ in range(self.n		)] for _ in range(self.n		)]







     def __mul__(				self	:      Dict			,   lowercase	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :Any					    =				Matrix(self.n		)
        for i in range(self.n		):
           for j in range(self.n		):
              for k in range(self.n		):
                 matrix.t[i][j] += self.t[i][k] * b.t[k][j]
        return matrix







def 							UpperCAmelCase_						(		__lowerCamelCase      :      Dict			,__lowerCamelCase      :      Tuple				):
   lowercase_    :Dict					    =				Matrix([[1, 0], [0, 1]]				)
   while b > 0:
      if b & 1:
         matrix *= a
      a *= a
      b >>= 1
   return matrix
def 							UpperCAmelCase_						(		__lowerCamelCase      :      Tuple			,__lowerCamelCase      :      Tuple			,__lowerCamelCase      :      List[str]				):
   # Trivial Cases
   if n == 1:
      return fa
   elif n == 2:
      return fa
   lowercase_    :int					    =				Matrix([[1, 1], [1, 0]]				)
   lowercase_    :Tuple					    =				modular_exponentiation(__lowerCamelCase			,n - 2				)
   return fa * matrix.t[0][0] + fa * matrix.t[0][1]
def 							UpperCAmelCase_						(		__lowerCamelCase      :      Tuple			,__lowerCamelCase      :      Optional[Any]			,__lowerCamelCase      :      Optional[int]				):
   # Trivial Cases
   if n == 1:
      return fa
   elif n == 2:
      return fa

   lowercase_    :int					    =				fa
   lowercase_    :int					    =				fa
   n -= 2

   while n > 0:
      lowercase_    :Union[str, Any]					    =				fn_a + fn_a, fn_a
      n -= 1

   return fn_a
def 							UpperCAmelCase_						(		):
   lowercase_    :Optional[Any]					    =				"\nfrom random import randint\nfrom __main__ import fibonacci_with_matrix_exponentiation\n"
   lowercase_    :Union[str, Any]					    =				"fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)"
   lowercase_    :str					    =				timeit.timeit(setup=__lowerCamelCase			,stmt=__lowerCamelCase			,number=1_00				)
   print("With matrix exponentiation the average execution time is "			,exec_time / 1_00				)
   return exec_time
def 							UpperCAmelCase_						(		):
   lowercase_    :Any					    =				"\nfrom random import randint\nfrom __main__ import simple_fibonacci\n"
   lowercase_    :List[Any]					    =				"simple_fibonacci(randint(1,70000), 1, 1)"
   lowercase_    :List[str]					    =				timeit.timeit(setup=__lowerCamelCase			,stmt=__lowerCamelCase			,number=1_00				)
   print(
       "Without matrix exponentiation the average execution time is "			,exec_time / 1_00				)
   return exec_time
def 							UpperCAmelCase_						(		):
   matrix_exponentiation_time()
   simple_fibonacci_time()


if __name__ == "__main__":
 main()









'''simple docstring'''


import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import EfficientNetImageProcessor
class    a_     (       unittest.TestCase							):





     def __init__(				self	:      int			,   lowercase	:      Optional[int]			,   lowercase	:      Tuple=13			,   lowercase	:      str=3			,   lowercase	:      List[str]=18			,   lowercase	:      Union[str, Any]=30			,   lowercase	:      Any=400			,   lowercase	:      Tuple=True			,   lowercase	:      Union[str, Any]=None			,   lowercase	:      Optional[Any]=True			,   lowercase	:      Optional[int]=[0.5, 0.5, 0.5]			,   lowercase	:      List[str]=[0.5, 0.5, 0.5]			,   ):





        """simple docstring"""




        lowercase_    :Dict					    =				size if size is not None else {"height": 18, "width": 18}
        lowercase_    :Optional[Any]					    =				parent
        lowercase_    :str					    =				batch_size
        lowercase_    :Optional[int]					    =				num_channels
        lowercase_    :str					    =				image_size
        lowercase_    :Tuple					    =				min_resolution
        lowercase_    :Optional[Any]					    =				max_resolution
        lowercase_    :List[str]					    =				do_resize
        lowercase_    :Optional[Any]					    =				size
        lowercase_    :Optional[int]					    =				do_normalize
        lowercase_    :Union[str, Any]					    =				image_mean
        lowercase_    :Dict					    =				image_std







     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "size": self.size,
        }







@require_torch
@require_vision
class    a_     (       _lowerCAmelCase			,		unittest.TestCase							):
     __A  				=    EfficientNetImageProcessor if is_vision_available() else None





     def 							lowercase__   (				self	:      Optional[int]		):





        """simple docstring"""




        lowercase_    :List[Any]					    =				EfficientNetImageProcessorTester(self		)





     @property
     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        return self.image_processor_tester.prepare_image_processor_dict()





     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




        lowercase_    :Optional[Any]					    =				self.image_processing_class(**self.image_processor_dict		)
        self.assertTrue(hasattr(lowercase			,   "image_mean"		)		)
        self.assertTrue(hasattr(lowercase			,   "image_std"		)		)
        self.assertTrue(hasattr(lowercase			,   "do_normalize"		)		)
        self.assertTrue(hasattr(lowercase			,   "do_resize"		)		)
        self.assertTrue(hasattr(lowercase			,   "size"		)		)





     def 							lowercase__   (				self	:      str		):





        """simple docstring"""




        lowercase_    :Tuple					    =				self.image_processing_class.from_dict(self.image_processor_dict		)
        self.assertEqual(image_processor.size			,   {"height": 18, "width": 18}		)

        lowercase_    :List[str]					    =				self.image_processing_class.from_dict(self.image_processor_dict			,   size=42		)
        self.assertEqual(image_processor.size			,   {"height": 42, "width": 42}		)





     def 							lowercase__   (				self	:      Optional[int]		):





        """simple docstring"""




        lowercase_    :List[Any]					    =				self.image_processing_class(**self.image_processor_dict		)
        # create random PIL images
        lowercase_    :Tuple					    =				prepare_image_inputs(self.image_processor_tester			,   equal_resolution=lowercase		)
        for image in image_inputs:
           self.assertIsInstance(lowercase			,   Image.Image		)

        # Test not batched input
        lowercase_    :Optional[Any]					    =				image_processing(image_inputs[0]			,   return_tensors="pt"		).pixel_values
        self.assertEqual(
            encoded_images.shape			,   (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["height"],
                self.image_processor_tester.size["width"],
            )			,   )

        # Test batched
        lowercase_    :Optional[Any]					    =				image_processing(lowercase			,   return_tensors="pt"		).pixel_values
        self.assertEqual(
            encoded_images.shape			,   (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["height"],
                self.image_processor_tester.size["width"],
            )			,   )





     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




        lowercase_    :int					    =				self.image_processing_class(**self.image_processor_dict		)
        # create random numpy tensors
        lowercase_    :List[Any]					    =				prepare_image_inputs(self.image_processor_tester			,   equal_resolution=lowercase			,   numpify=lowercase		)
        for image in image_inputs:
           self.assertIsInstance(lowercase			,   np.ndarray		)

        # Test not batched input
        lowercase_    :Optional[Any]					    =				image_processing(image_inputs[0]			,   return_tensors="pt"		).pixel_values
        self.assertEqual(
            encoded_images.shape			,   (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["height"],
                self.image_processor_tester.size["width"],
            )			,   )

        # Test batched
        lowercase_    :Any					    =				image_processing(lowercase			,   return_tensors="pt"		).pixel_values
        self.assertEqual(
            encoded_images.shape			,   (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["height"],
                self.image_processor_tester.size["width"],
            )			,   )







     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




        lowercase_    :str					    =				self.image_processing_class(**self.image_processor_dict		)
        # create random PyTorch tensors
        lowercase_    :Tuple					    =				prepare_image_inputs(self.image_processor_tester			,   equal_resolution=lowercase			,   torchify=lowercase		)
        for image in image_inputs:
           self.assertIsInstance(lowercase			,   torch.Tensor		)

        # Test not batched input
        lowercase_    :str					    =				image_processing(image_inputs[0]			,   return_tensors="pt"		).pixel_values
        self.assertEqual(
            encoded_images.shape			,   (
                1,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["height"],
                self.image_processor_tester.size["width"],
            )			,   )

        # Test batched
        lowercase_    :Optional[int]					    =				image_processing(lowercase			,   return_tensors="pt"		).pixel_values
        self.assertEqual(
            encoded_images.shape			,   (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.size["height"],
                self.image_processor_tester.size["width"],
            )			,   )


