




'''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_video_inputs


if is_torch_available():
     import torch

if is_vision_available():
     from PIL import Image

     from transformers import VideoMAEImageProcessor





class 			lowerCAmelCase      (       unittest.TestCase):


       def __init__(      self			,     __SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE=7			,     __SCREAMING_SNAKE_CASE=3			,     __SCREAMING_SNAKE_CASE=10			,     __SCREAMING_SNAKE_CASE=18			,     __SCREAMING_SNAKE_CASE=30			,     __SCREAMING_SNAKE_CASE=400			,     __SCREAMING_SNAKE_CASE=True			,     __SCREAMING_SNAKE_CASE=None			,     __SCREAMING_SNAKE_CASE=True			,     __SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]			,     __SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5]			,     __SCREAMING_SNAKE_CASE=None			,     )					->     Union[str, Any]:



            '''simple docstring'''




            __snake_case			    =     size if size is not None else {'''shortest_edge''': 18}
            __snake_case			    =     crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

            __snake_case			    =     parent
            __snake_case			    =     batch_size
            __snake_case			    =     num_channels
            __snake_case			    =     num_frames
            __snake_case			    =     image_size
            __snake_case			    =     min_resolution
            __snake_case			    =     max_resolution
            __snake_case			    =     do_resize
            __snake_case			    =     size
            __snake_case			    =     do_normalize
            __snake_case			    =     image_mean
            __snake_case			    =     image_std
            __snake_case			    =     crop_size




       def 					lowerCAmelCase					(      self     )					->     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,
                "crop_size": self.crop_size,
            }





@require_torch
@require_vision
class 			lowerCAmelCase      (       __lowerCAmelCase ,      unittest.TestCase):
       __lowercase     :					Any       				=	VideoMAEImageProcessor if is_vision_available() else None


       def 					lowerCAmelCase					(      self     )					->     Dict:



            '''simple docstring'''




            __snake_case			    =     VideoMAEImageProcessingTester(self     )


       @property
       def 					lowerCAmelCase					(      self     )					->     Optional[Any]:



            '''simple docstring'''




            return self.image_processor_tester.prepare_image_processor_dict()


       def 					lowerCAmelCase					(      self     )					->     Optional[int]:



            '''simple docstring'''




            __snake_case			    =     self.image_processing_class(**self.image_processor_dict     )
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE			,     '''image_mean'''     )     )
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE			,     '''image_std'''     )     )
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE			,     '''do_normalize'''     )     )
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE			,     '''do_resize'''     )     )
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE			,     '''do_center_crop'''     )     )
            self.assertTrue(hasattr(__SCREAMING_SNAKE_CASE			,     '''size'''     )     )


       def 					lowerCAmelCase					(      self     )					->     Optional[int]:



            '''simple docstring'''




            __snake_case			    =     self.image_processing_class.from_dict(self.image_processor_dict     )
            self.assertEqual(image_processor.size			,     {'''shortest_edge''': 18}     )
            self.assertEqual(image_processor.crop_size			,     {'''height''': 18, '''width''': 18}     )

            __snake_case			    =     self.image_processing_class.from_dict(self.image_processor_dict			,     size=42			,     crop_size=84     )
            self.assertEqual(image_processor.size			,     {'''shortest_edge''': 42}     )
            self.assertEqual(image_processor.crop_size			,     {'''height''': 84, '''width''': 84}     )


       def 					lowerCAmelCase					(      self     )					->     Optional[int]:



            '''simple docstring'''




            pass


       def 					lowerCAmelCase					(      self     )					->     Dict:



            '''simple docstring'''




            __snake_case			    =     self.image_processing_class(**self.image_processor_dict     )
            # create random PIL videos
            __snake_case			    =     prepare_video_inputs(self.image_processor_tester			,     equal_resolution=__SCREAMING_SNAKE_CASE     )
            for video in video_inputs:
                 self.assertIsInstance(__SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE     )
                 self.assertIsInstance(video[0]			,     Image.Image     )

            # Test not batched input
            __snake_case			    =     image_processing(video_inputs[0]			,     return_tensors='''pt'''     ).pixel_values
            self.assertEqual(
                encoded_videos.shape			,     (
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )			,     )

            # Test batched
            __snake_case			    =     image_processing(__SCREAMING_SNAKE_CASE			,     return_tensors='''pt'''     ).pixel_values
            self.assertEqual(
                encoded_videos.shape			,     (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )			,     )


       def 					lowerCAmelCase					(      self     )					->     str:



            '''simple docstring'''




            __snake_case			    =     self.image_processing_class(**self.image_processor_dict     )
            # create random numpy tensors
            __snake_case			    =     prepare_video_inputs(self.image_processor_tester			,     equal_resolution=__SCREAMING_SNAKE_CASE			,     numpify=__SCREAMING_SNAKE_CASE     )
            for video in video_inputs:
                 self.assertIsInstance(__SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE     )
                 self.assertIsInstance(video[0]			,     np.ndarray     )

            # Test not batched input
            __snake_case			    =     image_processing(video_inputs[0]			,     return_tensors='''pt'''     ).pixel_values
            self.assertEqual(
                encoded_videos.shape			,     (
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )			,     )

            # Test batched
            __snake_case			    =     image_processing(__SCREAMING_SNAKE_CASE			,     return_tensors='''pt'''     ).pixel_values
            self.assertEqual(
                encoded_videos.shape			,     (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )			,     )




       def 					lowerCAmelCase					(      self     )					->     Dict:



            '''simple docstring'''




            __snake_case			    =     self.image_processing_class(**self.image_processor_dict     )
            # create random PyTorch tensors
            __snake_case			    =     prepare_video_inputs(self.image_processor_tester			,     equal_resolution=__SCREAMING_SNAKE_CASE			,     torchify=__SCREAMING_SNAKE_CASE     )
            for video in video_inputs:
                 self.assertIsInstance(__SCREAMING_SNAKE_CASE			,     __SCREAMING_SNAKE_CASE     )
                 self.assertIsInstance(video[0]			,     torch.Tensor     )

            # Test not batched input
            __snake_case			    =     image_processing(video_inputs[0]			,     return_tensors='''pt'''     ).pixel_values
            self.assertEqual(
                encoded_videos.shape			,     (
                    1,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )			,     )

            # Test batched
            __snake_case			    =     image_processing(__SCREAMING_SNAKE_CASE			,     return_tensors='''pt'''     ).pixel_values
            self.assertEqual(
                encoded_videos.shape			,     (
                    self.image_processor_tester.batch_size,
                    self.image_processor_tester.num_frames,
                    self.image_processor_tester.num_channels,
                    self.image_processor_tester.crop_size['''height'''],
                    self.image_processor_tester.crop_size['''width'''],
                )			,     )












'''simple docstring'''



def 	_UpperCamelCase       (_lowerCamelCase							:   list[list[int]]      ,		_lowerCamelCase							:   list[list[int]]		)->      list[list[int]]:




     '''simple docstring'''





     __snake_case			    =     []
     __snake_case			    =     len(_lowerCamelCase		)
     for i in range(_lowerCamelCase		):
          __snake_case			    =     []
          for j in range(_lowerCamelCase		):
               __snake_case			    =     0
               for k in range(_lowerCamelCase		):
                    __snake_case			    =     val + matrix_a[i][k] * matrix_b[k][j]
               list_a.append(_lowerCamelCase		)
          matrix_c.append(_lowerCamelCase		)
     return matrix_c







def 	_UpperCamelCase       (_lowerCamelCase							:   int		)->      list[list[int]]:




     '''simple docstring'''





     return [[int(row == column		) for column in range(_lowerCamelCase		)] for row in range(_lowerCamelCase		)]







def 	_UpperCamelCase       (_lowerCamelCase							:   int		)->      int:




     '''simple docstring'''





     if n <= 1:
          return n
     __snake_case			    =     identity(2		)
     __snake_case			    =     [[1, 1], [1, 0]]
     __snake_case			    =     n - 1
     while n > 0:
          if n % 2 == 1:
               __snake_case			    =     multiply(_lowerCamelCase      ,		_lowerCamelCase		)
          __snake_case			    =     multiply(_lowerCamelCase      ,		_lowerCamelCase		)
          __snake_case			    =     int(n / 2		)
     return res_matrix[0][0]







def 	_UpperCamelCase       (_lowerCamelCase							:   int		)->      int:




     '''simple docstring'''





     if n <= 1:
          return n
     __snake_case			    =     0
     __snake_case			    =     1
     for _ in range(2      ,		n + 1		):
          __snake_case    ,			__snake_case			    =     fiba, fiba + fiba
     return fiba







def 	_UpperCamelCase       ()->      None:




     '''simple docstring'''





     for ordinal in "0th 1st 2nd 3rd 10th 100th 1000th".split():
          __snake_case			    =     int(''''''.join(c for c in ordinal if c in '''0123456789'''		)		)  # 1000th --> 1000
          print(
              f'''{ordinal} fibonacci number using matrix exponentiation is '''
              f'''{nth_fibonacci_matrix(_lowerCamelCase		)} and using bruteforce is '''
              f'''{nth_fibonacci_bruteforce(_lowerCamelCase		)}\n'''		)
     # from timeit import timeit
     # print(timeit("nth_fibonacci_matrix(1000000)",
     #              "from main import nth_fibonacci_matrix", number=5))
     # print(timeit("nth_fibonacci_bruteforce(1000000)",
     #              "from main import nth_fibonacci_bruteforce", number=5))
     # 2.3342058970001744
     # 57.256506615000035


if __name__ == "__main__":
     import doctest

     doctest.testmod()
     main()






