





"""simple docstring"""


import gc
import unittest

from parameterized import parameterized

from diffusers import FlaxUNetaDConditionModel
from diffusers.utils import is_flax_available
from diffusers.utils.testing_utils import load_hf_numpy, require_flax, slow


if is_flax_available():
		import jax
		import jax.numpy as jnp






@slow
@require_flax
class 							lowercase__			(   unittest.TestCase	):

			"""simple docstring"""







			def   _a      (      self						,   _A						,   _A    ):






									'''simple docstring'''







									return f"""gaussian_noise_s={seed}_shape={"_".join([str(_A    ) for s in shape]    )}.npy"""







			def   _a      (      self    ):






									'''simple docstring'''







									super().tearDown()
									gc.collect()







			def   _a      (      self						,   _A=0						,   _A=(4, 4, 6_4, 6_4)						,   _A=False    ):






									'''simple docstring'''







									UpperCamelCase				:		Tuple				   =			jnp.bfloataa if fpaa else jnp.floataa
									UpperCamelCase				:		Optional[Any]				   =			jnp.array(load_hf_numpy(self.get_file_format(_A						,   _A    )    )						,   dtype=_A    )
									return image







			def   _a      (      self						,   _A=False						,   _A="CompVis/stable-diffusion-v1-4"    ):






									'''simple docstring'''







									UpperCamelCase				:		str				   =			jnp.bfloataa if fpaa else jnp.floataa
									UpperCamelCase				:		str				   =			"""bf16""" if fpaa else None

									UpperCamelCase   ,						UpperCamelCase				:		str				   =			FlaxUNetaDConditionModel.from_pretrained(
									    _A						,   subfolder="""unet"""						,   dtype=_A						,   revision=_A    )
									return model, params







			def   _a      (      self						,   _A=0						,   _A=(4, 7_7, 7_6_8)						,   _A=False    ):






									'''simple docstring'''







									UpperCamelCase				:		Dict				   =			jnp.bfloataa if fpaa else jnp.floataa
									UpperCamelCase				:		int				   =			jnp.array(load_hf_numpy(self.get_file_format(_A						,   _A    )    )						,   dtype=_A    )
									return hidden_states







			@parameterized.expand(
			    [
			        # fmt: off
			        [8_3, 4, [-0.23_23, -0.13_04, 0.08_13, -0.30_93, -0.09_19, -0.15_71, -0.11_25, -0.58_06]],
			        [1_7, 0.55, [-0.08_31, -0.24_43, 0.09_01, -0.09_19, 0.33_96, 0.01_03, -0.37_43, 0.07_01]],
			        [8, 0.89, [-0.48_63, 0.08_59, 0.08_75, -0.16_58, 0.91_99, -0.01_14, 0.48_39, 0.46_39]],
			        [3, 1_0_0_0, [-0.56_49, 0.24_02, -0.55_18, 0.12_48, 1.13_28, -0.24_43, -0.03_25, -1.00_78]],
			        # fmt: on
			    ]    )
			def   _a      (      self						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase   ,						UpperCamelCase				:		Optional[int]				   =			self.get_unet_model(model_id="""CompVis/stable-diffusion-v1-4"""						,   fpaa=_A    )
									UpperCamelCase				:		Any				   =			self.get_latents(_A						,   fpaa=_A    )
									UpperCamelCase				:		Union[str, Any]				   =			self.get_encoder_hidden_states(_A						,   fpaa=_A    )

									UpperCamelCase				:		Union[str, Any]				   =			model.apply(
									    {"""params""": params}						,   _A						,   jnp.array(_A						,   dtype=jnp.intaa    )						,   encoder_hidden_states=_A						,   ).sample

									assert sample.shape == latents.shape

									UpperCamelCase				:		Optional[int]				   =			jnp.asarray(jax.device_get((sample[-1, -2:, -2:, :2].flatten())    )						,   dtype=jnp.floataa    )
									UpperCamelCase				:		Dict				   =			jnp.array(_A						,   dtype=jnp.floataa    )

									# Found torch (float16) and flax (bfloat16) outputs to be within this tolerance, in the same hardware
									assert jnp.allclose(_A						,   _A						,   atol=1e-2    )







			@parameterized.expand(
			    [
			        # fmt: off
			        [8_3, 4, [0.15_14, 0.08_07, 0.16_24, 0.10_16, -0.18_96, 0.02_63, 0.06_77, 0.23_10]],
			        [1_7, 0.55, [0.11_64, -0.02_16, 0.01_70, 0.15_89, -0.31_20, 0.10_05, -0.05_81, -0.14_58]],
			        [8, 0.89, [-0.17_58, -0.01_69, 0.10_04, -0.14_11, 0.13_12, 0.11_03, -0.19_96, 0.21_39]],
			        [3, 1_0_0_0, [0.12_14, 0.03_52, -0.07_31, -0.15_62, -0.09_94, -0.09_06, -0.23_40, -0.05_39]],
			        # fmt: on
			    ]    )
			def   _a      (      self						,   _A						,   _A						,   _A    ):






									'''simple docstring'''







									UpperCamelCase   ,						UpperCamelCase				:		Optional[Any]				   =			self.get_unet_model(model_id="""stabilityai/stable-diffusion-2"""						,   fpaa=_A    )
									UpperCamelCase				:		List[Any]				   =			self.get_latents(_A						,   shape=(4, 4, 9_6, 9_6)						,   fpaa=_A    )
									UpperCamelCase				:		Any				   =			self.get_encoder_hidden_states(_A						,   shape=(4, 7_7, 1_0_2_4)						,   fpaa=_A    )

									UpperCamelCase				:		Optional[int]				   =			model.apply(
									    {"""params""": params}						,   _A						,   jnp.array(_A						,   dtype=jnp.intaa    )						,   encoder_hidden_states=_A						,   ).sample

									assert sample.shape == latents.shape

									UpperCamelCase				:		Dict				   =			jnp.asarray(jax.device_get((sample[-1, -2:, -2:, :2].flatten())    )						,   dtype=jnp.floataa    )
									UpperCamelCase				:		Tuple				   =			jnp.array(_A						,   dtype=jnp.floataa    )

									# Found torch (float16) and flax (bfloat16) outputs to be within this tolerance, on the same hardware
									assert jnp.allclose(_A						,   _A						,   atol=1e-2    )





import math

__magic_name__  							=	10
__magic_name__  							=	7
__magic_name__  							=	BALLS_PER_COLOUR * NUM_COLOURS





def 						SCREAMING_SNAKE_CASE__     (   __lowerCAmelCase = 20				):
    snake_case__    =					math.comb(__lowerCAmelCase     ,		__lowerCAmelCase				)
    snake_case__    =					math.comb(NUM_BALLS - BALLS_PER_COLOUR     ,		__lowerCAmelCase				)

    snake_case__    =					NUM_COLOURS * (1 - missing_colour / total)

    return F"""{result:.9f}"""


if __name__ == "__main__":
     print(solution(20))



