
"""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   __lowerCAmelCase (						self    :List[str]		, lowerCamelCase_    :Union[str, Any]		, lowerCamelCase_    :Optional[Any]					)							->			str:







			'''simple docstring'''




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





	def   __lowerCAmelCase (						self    :Tuple					)							->			str:







			'''simple docstring'''




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





	def   __lowerCAmelCase (						self    :List[str]		, lowerCamelCase_    :List[Any]=0		, lowerCamelCase_    :List[Any]=(4, 4, 64, 64)		, lowerCamelCase_    :Dict=False					)							->			List[str]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Optional[int]				= jnp.bfloataa if fpaa else jnp.floataa
			SCREAMING_SNAKE_CASE       :     Any				= jnp.array(load_hf_numpy(self.get_file_format(__lowerCamelCase		, __lowerCamelCase					)					)		, dtype=__lowerCamelCase					)
			return image





	def   __lowerCAmelCase (						self    :str		, lowerCamelCase_    :Dict=False		, lowerCamelCase_    :Optional[Any]="CompVis/stable-diffusion-v1-4"					)							->			Union[str, Any]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Optional[int]				= jnp.bfloataa if fpaa else jnp.floataa
			SCREAMING_SNAKE_CASE       :     Optional[int]				= "bf16" if fpaa else None

			SCREAMING_SNAKE_CASE       :     Optional[int]				= FlaxUNetaDConditionModel.from_pretrained(
			    __lowerCamelCase		, subfolder='''unet'''		, dtype=__lowerCamelCase		, revision=__lowerCamelCase					)
			return model, params





	def   __lowerCAmelCase (						self    :Tuple		, lowerCamelCase_    :Tuple=0		, lowerCamelCase_    :List[Any]=(4, 77, 7_68)		, lowerCamelCase_    :Dict=False					)							->			Union[str, Any]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     str				= jnp.bfloataa if fpaa else jnp.floataa
			SCREAMING_SNAKE_CASE       :     Optional[Any]				= jnp.array(load_hf_numpy(self.get_file_format(__lowerCamelCase		, __lowerCamelCase					)					)		, dtype=__lowerCamelCase					)
			return hidden_states





	@parameterized.expand(
	    [
	        # fmt: off
	        [83, 4, [-0.2_3_2_3, -0.1_3_0_4, 0.0_8_1_3, -0.3_0_9_3, -0.0_9_1_9, -0.1_5_7_1, -0.1_1_2_5, -0.5_8_0_6]],
	        [17, 0.5_5, [-0.0_8_3_1, -0.2_4_4_3, 0.0_9_0_1, -0.0_9_1_9, 0.3_3_9_6, 0.0_1_0_3, -0.3_7_4_3, 0.0_7_0_1]],
	        [8, 0.8_9, [-0.4_8_6_3, 0.0_8_5_9, 0.0_8_7_5, -0.1_6_5_8, 0.9_1_9_9, -0.0_1_1_4, 0.4_8_3_9, 0.4_6_3_9]],
	        [3, 10_00, [-0.5_6_4_9, 0.2_4_0_2, -0.5_5_1_8, 0.1_2_4_8, 1.1_3_2_8, -0.2_4_4_3, -0.0_3_2_5, -1.0_0_7_8]],
	        # fmt: on
	    ]					)
	def   __lowerCAmelCase (						self    :List[str]		, lowerCamelCase_    :Optional[Any]		, lowerCamelCase_    :List[str]		, lowerCamelCase_    :Optional[Any]					)							->			Union[str, Any]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     Tuple				= self.get_unet_model(model_id='''CompVis/stable-diffusion-v1-4'''		, fpaa=__lowerCamelCase					)
			SCREAMING_SNAKE_CASE       :     int				= self.get_latents(__lowerCamelCase		, fpaa=__lowerCamelCase					)
			SCREAMING_SNAKE_CASE       :     int				= self.get_encoder_hidden_states(__lowerCamelCase		, fpaa=__lowerCamelCase					)

			SCREAMING_SNAKE_CASE       :     int				= model.apply(
			    {'''params''': params}		, __lowerCamelCase		, jnp.array(__lowerCamelCase		, dtype=jnp.intaa					)		, encoder_hidden_states=__lowerCamelCase		, ).sample

			assert sample.shape == latents.shape

			SCREAMING_SNAKE_CASE       :     Optional[int]				= jnp.asarray(jax.device_get((sample[-1, -2:, -2:, :2].flatten())					)		, dtype=jnp.floataa					)
			SCREAMING_SNAKE_CASE       :     List[Any]				= jnp.array(__lowerCamelCase		, dtype=jnp.floataa					)

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







	@parameterized.expand(
	    [
	        # fmt: off
	        [83, 4, [0.1_5_1_4, 0.0_8_0_7, 0.1_6_2_4, 0.1_0_1_6, -0.1_8_9_6, 0.0_2_6_3, 0.0_6_7_7, 0.2_3_1_0]],
	        [17, 0.5_5, [0.1_1_6_4, -0.0_2_1_6, 0.0_1_7_0, 0.1_5_8_9, -0.3_1_2_0, 0.1_0_0_5, -0.0_5_8_1, -0.1_4_5_8]],
	        [8, 0.8_9, [-0.1_7_5_8, -0.0_1_6_9, 0.1_0_0_4, -0.1_4_1_1, 0.1_3_1_2, 0.1_1_0_3, -0.1_9_9_6, 0.2_1_3_9]],
	        [3, 10_00, [0.1_2_1_4, 0.0_3_5_2, -0.0_7_3_1, -0.1_5_6_2, -0.0_9_9_4, -0.0_9_0_6, -0.2_3_4_0, -0.0_5_3_9]],
	        # fmt: on
	    ]					)
	def   __lowerCAmelCase (						self    :Optional[int]		, lowerCamelCase_    :int		, lowerCamelCase_    :Dict		, lowerCamelCase_    :Optional[Any]					)							->			List[Any]:







			'''simple docstring'''




			SCREAMING_SNAKE_CASE       :     str				= self.get_unet_model(model_id='''stabilityai/stable-diffusion-2'''		, fpaa=__lowerCamelCase					)
			SCREAMING_SNAKE_CASE       :     Dict				= self.get_latents(__lowerCamelCase		, shape=(4, 4, 96, 96)		, fpaa=__lowerCamelCase					)
			SCREAMING_SNAKE_CASE       :     str				= self.get_encoder_hidden_states(__lowerCamelCase		, shape=(4, 77, 10_24)		, fpaa=__lowerCamelCase					)

			SCREAMING_SNAKE_CASE       :     Union[str, Any]				= model.apply(
			    {'''params''': params}		, __lowerCamelCase		, jnp.array(__lowerCamelCase		, dtype=jnp.intaa					)		, encoder_hidden_states=__lowerCamelCase		, ).sample

			assert sample.shape == latents.shape

			SCREAMING_SNAKE_CASE       :     str				= jnp.asarray(jax.device_get((sample[-1, -2:, -2:, :2].flatten())					)		, dtype=jnp.floataa					)
			SCREAMING_SNAKE_CASE       :     Optional[Any]				= jnp.array(__lowerCamelCase		, dtype=jnp.floataa					)

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







"""simple docstring"""






def __A						(   a_ :							int     )->							list[int]:




		'''simple docstring'''






		if num <= 0:
				raise ValueError('''Input must be a positive integer'''     )

		SCREAMING_SNAKE_CASE       :     Optional[int]				= [True] * (num + 1)

		SCREAMING_SNAKE_CASE       :     Optional[Any]				= 2
		while p * p <= num:
				if primes[p]:
						for i in range(p * p		,		num + 1		,		a_     ):
								SCREAMING_SNAKE_CASE       :     Any				= False
				p += 1

		return [prime for prime in range(2		,		num + 1     ) if primes[prime]]


if __name__ == "__main__":
					import doctest

					doctest.testmod()

					lowerCamelCase__ :       str						     =			int(input("Enter a positive integer: ").strip())
					print(prime_sieve_eratosthenes(user_num))





