


"""simple docstring"""


import unittest

import numpy as np

from transformers.testing_utils import is_flaky, 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 DonutImageProcessor
class 						_UpperCamelCase						(     unittest.TestCase	):
							'''simple docstring'''







							def __init__(  self					,     __a					,     __a=7					,     __a=3					,     __a=18					,     __a=30					,     __a=4_00					,     __a=True					,     __a=None					,     __a=True					,     __a=False					,     __a=True					,     __a=True					,     __a=[0.5, 0.5, 0.5]					,     __a=[0.5, 0.5, 0.5]					,     ):
										__lowerCAmelCase       					=    parent
										__lowerCAmelCase       					=    batch_size
										__lowerCAmelCase       					=    num_channels
										__lowerCAmelCase       					=    image_size
										__lowerCAmelCase       					=    min_resolution
										__lowerCAmelCase       					=    max_resolution
										__lowerCAmelCase       					=    do_resize
										__lowerCAmelCase       					=    size if size is not None else {"height": 18, "width": 20}
										__lowerCAmelCase       					=    do_thumbnail
										__lowerCAmelCase       					=    do_align_axis
										__lowerCAmelCase       					=    do_pad
										__lowerCAmelCase       					=    do_normalize
										__lowerCAmelCase       					=    image_mean
										__lowerCAmelCase       					=    image_std



							def     snake_case       (  self			):
										return {
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "do_thumbnail": self.do_thumbnail,
										    "do_align_long_axis": self.do_align_axis,
										    "do_pad": self.do_pad,
										    "do_normalize": self.do_normalize,
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										}
@require_torch
@require_vision
class 						_UpperCamelCase						(     lowerCAmelCase__ ,unittest.TestCase	):
							'''simple docstring'''







							__UpperCAmelCase		:					Optional[Any]          =DonutImageProcessor if is_vision_available() else None

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    DonutImageProcessingTester(self			)

							@property
							def     snake_case       (  self			):
										return self.image_processor_tester.prepare_image_processor_dict()

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.image_processing_class(**self.image_processor_dict			)
										self.assertTrue(hasattr(__a					,     "do_resize"			)			)
										self.assertTrue(hasattr(__a					,     "size"			)			)
										self.assertTrue(hasattr(__a					,     "do_thumbnail"			)			)
										self.assertTrue(hasattr(__a					,     "do_align_long_axis"			)			)
										self.assertTrue(hasattr(__a					,     "do_pad"			)			)
										self.assertTrue(hasattr(__a					,     "do_normalize"			)			)
										self.assertTrue(hasattr(__a					,     "image_mean"			)			)
										self.assertTrue(hasattr(__a					,     "image_std"			)			)

							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.image_processing_class.from_dict(self.image_processor_dict			)
										self.assertEqual(image_processor.size					,     {"height": 18, "width": 20}			)

										__lowerCAmelCase       					=    self.image_processing_class.from_dict(self.image_processor_dict					,     size=42			)
										self.assertEqual(image_processor.size					,     {"height": 42, "width": 42}			)

										# Previous config had dimensions in (width, height) order
										__lowerCAmelCase       					=    self.image_processing_class.from_dict(self.image_processor_dict					,     size=(42, 84)			)
										self.assertEqual(image_processor.size					,     {"height": 84, "width": 42}			)

							def     snake_case       (  self			):
										pass

							@is_flaky()
							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.image_processing_class(**self.image_processor_dict			)
										# create random PIL images
										__lowerCAmelCase       					=    prepare_image_inputs(self.image_processor_tester					,     equal_resolution=__a			)
										for image in image_inputs:
													self.assertIsInstance(__a					,     Image.Image			)

										# Test not batched input
										__lowerCAmelCase       					=    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
										__lowerCAmelCase       					=    image_processing(__a					,     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"],
										    )					,     )

							@is_flaky()
							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.image_processing_class(**self.image_processor_dict			)
										# create random numpy tensors
										__lowerCAmelCase       					=    prepare_image_inputs(self.image_processor_tester					,     equal_resolution=__a					,     numpify=__a			)
										for image in image_inputs:
													self.assertIsInstance(__a					,     np.ndarray			)

										# Test not batched input
										__lowerCAmelCase       					=    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
										__lowerCAmelCase       					=    image_processing(__a					,     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"],
										    )					,     )



							@is_flaky()
							def     snake_case       (  self			):
										__lowerCAmelCase       					=    self.image_processing_class(**self.image_processor_dict			)
										# create random PyTorch tensors
										__lowerCAmelCase       					=    prepare_image_inputs(self.image_processor_tester					,     equal_resolution=__a					,     torchify=__a			)
										for image in image_inputs:
													self.assertIsInstance(__a					,     torch.Tensor			)

										# Test not batched input
										__lowerCAmelCase       					=    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
										__lowerCAmelCase       					=    image_processing(__a					,     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"],
										    )					,     )








"""simple docstring"""


from itertools import product


def _lowerCamelCase			(	_UpperCamelCase					,				_UpperCamelCase   ):

			'''simple docstring'''




			__lowerCAmelCase       					=    sides_number
			__lowerCAmelCase       					=    max_face_number * dice_number
			__lowerCAmelCase       					=    [0] * (max_total + 1)

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

			return totals_frequencies


def _lowerCamelCase			(	):

			'''simple docstring'''




			__lowerCAmelCase       					=    total_frequency_distribution(
			    sides_number=4					,				dice_number=9   )
			__lowerCAmelCase       					=    total_frequency_distribution(
			    sides_number=6					,				dice_number=6   )

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

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

			__lowerCAmelCase       					=    round(_UpperCamelCase					,				ndigits=7   )

			return rounded_peter_win_probability


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




