






'''simple docstring'''

import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
     import jax
     import jax.numpy as jnp
     from flax.jax_utils import replicate
     from flax.training.common_utils import shard






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

  def 						A__		(   self   )						->   List[Any]:



        """simple docstring"""






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

  def 						A__		(   self   )						->   List[str]:



        """simple docstring"""






        UpperCamelCase						,UpperCamelCase       						=      FlaxStableDiffusionPipeline.from_pretrained(
            """stabilityai/stable-diffusion-2"""    ,	revision="""bf16"""    ,	dtype=jnp.bfloataa    ,	)

        UpperCamelCase       						=      """A painting of a squirrel eating a burger"""
        UpperCamelCase       						=      jax.device_count()
        UpperCamelCase       						=      num_samples * [prompt]
        UpperCamelCase       						=      sd_pipe.prepare_inputs(_SCREAMING_SNAKE_CASE   )

        UpperCamelCase       						=      replicate(_SCREAMING_SNAKE_CASE   )
        UpperCamelCase       						=      shard(_SCREAMING_SNAKE_CASE   )

        UpperCamelCase       						=      jax.random.PRNGKey(0   )
        UpperCamelCase       						=      jax.random.split(_SCREAMING_SNAKE_CASE    ,	jax.device_count()   )

        UpperCamelCase       						=      sd_pipe(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	num_inference_steps=25    ,	jit=_SCREAMING_SNAKE_CASE   )[0]
        assert images.shape == (jax.device_count(), 1, 768, 768, 3)

        UpperCamelCase       						=      images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]   )
        UpperCamelCase       						=      images[0, 253:256, 253:256, -1]

        UpperCamelCase       						=      jnp.asarray(jax.device_get(image_slice.flatten()   )   )
        UpperCamelCase       						=      jnp.array([0.4_2_3_8, 0.4_4_1_4, 0.4_3_9_5, 0.4_4_5_3, 0.4_6_2_9, 0.4_5_9_0, 0.4_5_3_1, 0.4_5_5_0_8, 0.4_5_1_2]   )
        print(F"output_slice: {output_slice}"   )
        assert jnp.abs(output_slice - expected_slice   ).max() < 1e-2


  def 						A__		(   self   )						->   Any:



        """simple docstring"""






        UpperCamelCase       						=      """stabilityai/stable-diffusion-2"""
        UpperCamelCase						,UpperCamelCase       						=      FlaxDPMSolverMultistepScheduler.from_pretrained(_SCREAMING_SNAKE_CASE    ,	subfolder="""scheduler"""   )
        UpperCamelCase						,UpperCamelCase       						=      FlaxStableDiffusionPipeline.from_pretrained(
            _SCREAMING_SNAKE_CASE    ,	scheduler=_SCREAMING_SNAKE_CASE    ,	revision="""bf16"""    ,	dtype=jnp.bfloataa    ,	)
        UpperCamelCase       						=      scheduler_params

        UpperCamelCase       						=      """A painting of a squirrel eating a burger"""
        UpperCamelCase       						=      jax.device_count()
        UpperCamelCase       						=      num_samples * [prompt]
        UpperCamelCase       						=      sd_pipe.prepare_inputs(_SCREAMING_SNAKE_CASE   )

        UpperCamelCase       						=      replicate(_SCREAMING_SNAKE_CASE   )
        UpperCamelCase       						=      shard(_SCREAMING_SNAKE_CASE   )

        UpperCamelCase       						=      jax.random.PRNGKey(0   )
        UpperCamelCase       						=      jax.random.split(_SCREAMING_SNAKE_CASE    ,	jax.device_count()   )

        UpperCamelCase       						=      sd_pipe(_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	_SCREAMING_SNAKE_CASE    ,	num_inference_steps=25    ,	jit=_SCREAMING_SNAKE_CASE   )[0]
        assert images.shape == (jax.device_count(), 1, 768, 768, 3)

        UpperCamelCase       						=      images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]   )
        UpperCamelCase       						=      images[0, 253:256, 253:256, -1]

        UpperCamelCase       						=      jnp.asarray(jax.device_get(image_slice.flatten()   )   )
        UpperCamelCase       						=      jnp.array([0.4_3_3_6, 0.4_2_9_6_9, 0.4_4_5_3, 0.4_1_9_9, 0.4_2_9_7, 0.4_5_3_1, 0.4_4_3_4, 0.4_4_3_4, 0.4_2_9_7]   )
        print(F"output_slice: {output_slice}"   )
        assert jnp.abs(output_slice - expected_slice   ).max() < 1e-2








'''simple docstring'''

from math import factorial







def 					lowercase__				(   __UpperCamelCase = 20					)->				int:
      UpperCamelCase       						=      2 * n  # middle entry of odd rows starting at row 3 is the solution for n = 1,
      # 2, 3,...
      UpperCamelCase       						=      n // 2

      return int(factorial(__UpperCamelCase					) / (factorial(__UpperCamelCase					) * factorial(n - k					))					)


if __name__ == "__main__":
     import sys

     if len(sys.argv) == 1:
          print(solution(2_0))
     else:
          try:
               SCREAMING_SNAKE_CASE__											=     int(sys.argv[1])
               print(solution(n))
          except ValueError:
               print('Invalid entry - please enter a number.')
