



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


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import ChineseCLIPImageProcessor



class    lowerCamelCase__				(			unittest.TestCase						):






      """simple docstring"""




      def __init__(       self							:     Dict			,a__							:     str			,a__							:     Optional[Any]=7			,a__							:     Union[str, Any]=3			,a__							:     str=18			,a__							:     Any=30			,a__							:     Any=4_00			,a__							:     Tuple=True			,a__							:     List[Any]=None			,a__							:     Dict=True			,a__							:     Tuple=None			,a__							:     Tuple=True			,a__							:     List[str]=[0.4814_5466, 0.457_8275, 0.4082_1073]			,a__							:     List[Any]=[0.2686_2954, 0.2613_0258, 0.2757_7711]			,a__							:     int=True			,):
             a__								= size if size is not None else {"height": 2_24, "width": 2_24}
             a__								= crop_size if crop_size is not None else {"height": 18, "width": 18}
             a__								= parent
             a__								= batch_size
             a__								= num_channels
             a__								= image_size
             a__								= min_resolution
             a__								= max_resolution
             a__								= do_resize
             a__								= size
             a__								= do_center_crop
             a__								= crop_size
             a__								= do_normalize
             a__								= image_mean
             a__								= image_std
             a__								= do_convert_rgb




      def lowerCAmelCase_					(       self							:     int   ):
             return {
                 "do_resize": self.do_resize,
                 "size": self.size,
                 "do_center_crop": self.do_center_crop,
                 "crop_size": self.crop_size,
                 "do_normalize": self.do_normalize,
                 "image_mean": self.image_mean,
                 "image_std": self.image_std,
                 "do_convert_rgb": self.do_convert_rgb,
             }




      def lowerCAmelCase_					(       self							:     List[Any]			,a__							:     List[str]=False			,a__							:     int=False			,a__							:     Any=False   ):
             assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

             if equal_resolution:
                    a__								= []
                    for i in range(self.batch_size   ):
                           image_inputs.append(
                               np.random.randint(
                                   2_55			,size=(self.num_channels, self.max_resolution, self.max_resolution)			,dtype=np.uinta   )   )
             else:
                    a__								= []
                    for i in range(self.batch_size   ):
                           a__						,					a__								= np.random.choice(np.arange(self.min_resolution			,self.max_resolution   )			,2   )
                           image_inputs.append(np.random.randint(2_55			,size=(self.num_channels, width, height)			,dtype=np.uinta   )   )

             if not numpify and not torchify:
                    # PIL expects the channel dimension as last dimension
                    a__								= [Image.fromarray(np.moveaxis(__lowerCamelCase			,0			,-1   )   ) for x in image_inputs]

             if torchify:
                    a__								= [torch.from_numpy(__lowerCamelCase   ) for x in image_inputs]

             return image_inputs



@require_torch
@require_vision
class    lowerCamelCase__				(			__SCREAMING_SNAKE_CASE	,    unittest.TestCase						):






      """simple docstring"""
      UpperCamelCase__			 =     ChineseCLIPImageProcessor if is_vision_available() else None




      def lowerCAmelCase_					(       self							:     Any   ):
             a__								= ChineseCLIPImageProcessingTester(self			,do_center_crop=__lowerCamelCase   )




      @property
      def lowerCAmelCase_					(       self							:     List[str]   ):
             return self.image_processor_tester.prepare_image_processor_dict()




      def lowerCAmelCase_					(       self							:     Tuple   ):
             a__								= self.image_processing_class(**self.image_processor_dict   )
             self.assertTrue(hasattr(__lowerCamelCase			,"do_resize"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"size"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"do_center_crop"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"center_crop"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"do_normalize"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"image_mean"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"image_std"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"do_convert_rgb"   )   )




      def lowerCAmelCase_					(       self							:     str   ):
             a__								= self.image_processing_class.from_dict(self.image_processor_dict   )
             self.assertEqual(image_processor.size			,{"height": 2_24, "width": 2_24}   )
             self.assertEqual(image_processor.crop_size			,{"height": 18, "width": 18}   )

             a__								= 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							:     Tuple   ):
             pass




      def lowerCAmelCase_					(       self							:     Dict   ):
             a__								= self.image_processing_class(**self.image_processor_dict   )
             # create random PIL images
             a__								= self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase   )
             for image in image_inputs:
                    self.assertIsInstance(__lowerCamelCase			,Image.Image   )

             # Test not batched input
             a__								= 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.crop_size["height"],
                     self.image_processor_tester.crop_size["width"],
                 )			,)

             # Test batched
             a__								= image_processing(__lowerCamelCase			,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.crop_size["height"],
                     self.image_processor_tester.crop_size["width"],
                 )			,)




      def lowerCAmelCase_					(       self							:     Tuple   ):
             a__								= self.image_processing_class(**self.image_processor_dict   )
             # create random numpy tensors
             a__								= self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase			,numpify=__lowerCamelCase   )
             for image in image_inputs:
                    self.assertIsInstance(__lowerCamelCase			,np.ndarray   )

             # Test not batched input
             a__								= 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.crop_size["height"],
                     self.image_processor_tester.crop_size["width"],
                 )			,)

             # Test batched
             a__								= image_processing(__lowerCamelCase			,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.crop_size["height"],
                     self.image_processor_tester.crop_size["width"],
                 )			,)




      def lowerCAmelCase_					(       self							:     Tuple   ):
             a__								= self.image_processing_class(**self.image_processor_dict   )
             # create random PyTorch tensors
             a__								= self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase			,torchify=__lowerCamelCase   )
             for image in image_inputs:
                    self.assertIsInstance(__lowerCamelCase			,torch.Tensor   )

             # Test not batched input
             a__								= 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.crop_size["height"],
                     self.image_processor_tester.crop_size["width"],
                 )			,)

             # Test batched
             a__								= image_processing(__lowerCamelCase			,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.crop_size["height"],
                     self.image_processor_tester.crop_size["width"],
                 )			,)



@require_torch
@require_vision
class    lowerCamelCase__				(			__SCREAMING_SNAKE_CASE	,    unittest.TestCase						):






      """simple docstring"""
      UpperCamelCase__			 =     ChineseCLIPImageProcessor if is_vision_available() else None




      def lowerCAmelCase_					(       self							:     int   ):
             a__								= ChineseCLIPImageProcessingTester(self			,num_channels=4			,do_center_crop=__lowerCamelCase   )
             a__								= 3




      @property
      def lowerCAmelCase_					(       self							:     str   ):
             return self.image_processor_tester.prepare_image_processor_dict()




      def lowerCAmelCase_					(       self							:     str   ):
             a__								= self.image_processing_class(**self.image_processor_dict   )
             self.assertTrue(hasattr(__lowerCamelCase			,"do_resize"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"size"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"do_center_crop"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"center_crop"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"do_normalize"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"image_mean"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"image_std"   )   )
             self.assertTrue(hasattr(__lowerCamelCase			,"do_convert_rgb"   )   )




      def lowerCAmelCase_					(       self							:     Optional[Any]   ):
             pass




      def lowerCAmelCase_					(       self							:     str   ):
             a__								= self.image_processing_class(**self.image_processor_dict   )
             # create random PIL images
             a__								= self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase   )
             for image in image_inputs:
                    self.assertIsInstance(__lowerCamelCase			,Image.Image   )

             # Test not batched input
             a__								= image_processing(image_inputs[0]			,return_tensors="pt"   ).pixel_values
             self.assertEqual(
                 encoded_images.shape			,(
                     1,
                     self.expected_encoded_image_num_channels,
                     self.image_processor_tester.crop_size["height"],
                     self.image_processor_tester.crop_size["width"],
                 )			,)

             # Test batched
             a__								= image_processing(__lowerCamelCase			,return_tensors="pt"   ).pixel_values
             self.assertEqual(
                 encoded_images.shape			,(
                     self.image_processor_tester.batch_size,
                     self.expected_encoded_image_num_channels,
                     self.image_processor_tester.crop_size["height"],
                     self.image_processor_tester.crop_size["width"],
                 )			,)





"""simple docstring"""






from itertools import product




def 			snake_case		(		lowerCAmelCase_  ,						lowerCAmelCase_	)						->				list[int]:
  _snake_case   	=      sides_number
  _snake_case   	=      max_face_number * dice_number
  _snake_case   	=      [0] * (max_total + 1)

  _snake_case   	=      1
  _snake_case   	=      range(lowerCAmelCase_  ,						max_face_number + 1	)
  for dice_numbers in product(lowerCAmelCase_  ,						repeat=lowerCAmelCase_	):
    _snake_case   	=      sum(lowerCAmelCase_	)
    totals_frequencies[total] += 1

  return totals_frequencies




def 			snake_case		(		)						->				float:
  _snake_case   	=      total_frequency_distribution(
      sides_number=4  ,						dice_number=9	)
  _snake_case   	=      total_frequency_distribution(
      sides_number=6  ,						dice_number=6	)

  _snake_case   	=      0
  _snake_case   	=      9
  _snake_case   	=      4 * 9
  _snake_case   	=      6
  for peter_total in range(lowerCAmelCase_  ,						max_peter_total + 1	):
    peter_wins_count += peter_totals_frequencies[peter_total] * sum(
        colin_totals_frequencies[min_colin_total:peter_total]	)

  _snake_case   	=      (4**9) * (6**6)
  _snake_case   	=      peter_wins_count / total_games_number

  _snake_case   	=      round(lowerCAmelCase_  ,						ndigits=7	)

  return rounded_peter_win_probability


if __name__ == "__main__":
     print(F"{solution() = }")





