






"""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     ):






      def 			lowerCamelCase__    (    self     ,     a_     ,     a_	)	->List[str]:







        '''simple docstring'''


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






      def 			lowerCamelCase__    (    self	)	->Dict:







        '''simple docstring'''


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






      def 			lowerCamelCase__    (    self     ,     a_=0     ,     a_=(4, 4, 6_4, 6_4)     ,     a_=False	)	->Optional[Any]:







        '''simple docstring'''


        _a							=	jnp.bfloataa if fpaa else jnp.floataa
        _a							=	jnp.array(load_hf_numpy(self.get_file_format(a_     ,     a_	)	)     ,     dtype=a_	)
        return image






      def 			lowerCamelCase__    (    self     ,     a_=False     ,     a_="CompVis/stable-diffusion-v1-4"	)	->Optional[Any]:







        '''simple docstring'''


        _a							=	jnp.bfloataa if fpaa else jnp.floataa
        _a							=	"bf16" if fpaa else None

        _a			,	_a							=	FlaxUNetaDConditionModel.from_pretrained(
            a_     ,     subfolder="unet"     ,     dtype=a_     ,     revision=a_	)
        return model, params






      def 			lowerCamelCase__    (    self     ,     a_=0     ,     a_=(4, 7_7, 7_6_8)     ,     a_=False	)	->Dict:







        '''simple docstring'''


        _a							=	jnp.bfloataa if fpaa else jnp.floataa
        _a							=	jnp.array(load_hf_numpy(self.get_file_format(a_     ,     a_	)	)     ,     dtype=a_	)
        return hidden_states






      @parameterized.expand(
          [
              # fmt: off
              [8_3, 4, [-0.2_323, -0.1_304, 0.0_813, -0.3_093, -0.0_919, -0.1_571, -0.1_125, -0.5_806]],
              [1_7, 0.55, [-0.0_831, -0.2_443, 0.0_901, -0.0_919, 0.3_396, 0.0_103, -0.3_743, 0.0_701]],
              [8, 0.89, [-0.4_863, 0.0_859, 0.0_875, -0.1_658, 0.9_199, -0.0_114, 0.4_839, 0.4_639]],
              [3, 1_0_0_0, [-0.5_649, 0.2_402, -0.5_518, 0.1_248, 1.1_328, -0.2_443, -0.0_325, -1.0_078]],
              # fmt: on
          ]	)
      def 			lowerCamelCase__    (    self     ,     a_     ,     a_     ,     a_	)	->Tuple:







        '''simple docstring'''


        _a			,	_a							=	self.get_unet_model(model_id="CompVis/stable-diffusion-v1-4"     ,     fpaa=a_	)
        _a							=	self.get_latents(a_     ,     fpaa=a_	)
        _a							=	self.get_encoder_hidden_states(a_     ,     fpaa=a_	)

        _a							=	model.apply(
            {"params": params}     ,     a_     ,     jnp.array(a_     ,     dtype=jnp.intaa	)     ,     encoder_hidden_states=a_     ,     ).sample

        assert sample.shape == latents.shape

        _a							=	jnp.asarray(jax.device_get((sample[-1, -2:, -2:, :2].flatten())	)     ,     dtype=jnp.floataa	)
        _a							=	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.1_514, 0.0_807, 0.1_624, 0.1_016, -0.1_896, 0.0_263, 0.0_677, 0.2_310]],
              [1_7, 0.55, [0.1_164, -0.0_216, 0.0_170, 0.1_589, -0.3_120, 0.1_005, -0.0_581, -0.1_458]],
              [8, 0.89, [-0.1_758, -0.0_169, 0.1_004, -0.1_411, 0.1_312, 0.1_103, -0.1_996, 0.2_139]],
              [3, 1_0_0_0, [0.1_214, 0.0_352, -0.0_731, -0.1_562, -0.0_994, -0.0_906, -0.2_340, -0.0_539]],
              # fmt: on
          ]	)
      def 			lowerCamelCase__    (    self     ,     a_     ,     a_     ,     a_	)	->List[str]:







        '''simple docstring'''


        _a			,	_a							=	self.get_unet_model(model_id="stabilityai/stable-diffusion-2"     ,     fpaa=a_	)
        _a							=	self.get_latents(a_     ,     shape=(4, 4, 9_6, 9_6)     ,     fpaa=a_	)
        _a							=	self.get_encoder_hidden_states(a_     ,     shape=(4, 7_7, 1_0_2_4)     ,     fpaa=a_	)

        _a							=	model.apply(
            {"params": params}     ,     a_     ,     jnp.array(a_     ,     dtype=jnp.intaa	)     ,     encoder_hidden_states=a_     ,     ).sample

        assert sample.shape == latents.shape

        _a							=	jnp.asarray(jax.device_get((sample[-1, -2:, -2:, :2].flatten())	)     ,     dtype=jnp.floataa	)
        _a							=	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	)










"""simple docstring"""




def        lowerCAmelCase (      UpperCamelCase_:							Optional[int]     , UpperCamelCase_:							str					)       ->							List[Any]:







  '''simple docstring'''







  _a							=	(boundary[1] - boundary[0]) / steps
  _a							=	boundary[0]
  _a							=	boundary[1]
  _a							=	make_points(UpperCamelCase_     , UpperCamelCase_     , UpperCamelCase_					)
  _a							=	0.0
  y += (h / 2.0) * f(UpperCamelCase_					)
  for i in x_i:
    # print(i)
    y += h * f(UpperCamelCase_					)
  y += (h / 2.0) * f(UpperCamelCase_					)
  return y






def        lowerCAmelCase (      UpperCamelCase_:							str     , UpperCamelCase_:							Any     , UpperCamelCase_:							Any					)       ->							str:







  '''simple docstring'''







  _a							=	a + h
  while x < (b - h):
    yield x
    _a							=	x + h






def        lowerCAmelCase (      UpperCamelCase_:							List[str]					)       ->							int:  # enter your function here







  '''simple docstring'''







  _a							=	(x - 0) * (x - 0)
  return y






def        lowerCAmelCase (      )       ->							Tuple:







  '''simple docstring'''







  _a							=	0.0  # Lower bound of integration
  _a							=	1.0  # Upper bound of integration
  _a							=	10.0  # define number of steps or resolution
  _a							=	[a, b]  # define boundary of integration
  _a							=	method_a(UpperCamelCase_     , UpperCamelCase_					)
  print(f'''y = {y}'''					)


if __name__ == "__main__":
     main()


