

import random
import unittest

import torch

from diffusers import IFSuperResolutionPipeline
from diffusers.utils import floats_tensor
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import skip_mps, torch_device

from ..pipeline_params import TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS, TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin


@skip_mps
class 			_SCREAMING_SNAKE_CASE      (  __a ,    __a ,    unittest.TestCase):
						_UpperCamelCase:Any	=		IFSuperResolutionPipeline
						_UpperCamelCase:Any	=		TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
						_UpperCamelCase:List[str]	=		TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
						_UpperCamelCase:Dict	=		PipelineTesterMixin.required_optional_params - {"latents"}







						def        _snake_case				(			self							)->							List[Any]:
													return self._get_superresolution_dummy_components()







						def        _snake_case				(			self     ,						_SCREAMING_SNAKE_CASE     ,						_SCREAMING_SNAKE_CASE=0							)->							List[Any]:







													if str(lowerCAmelCase_							).startswith("""mps"""							):
																				lowerCamelCase_								=torch.manual_seed(lowerCAmelCase_							)
													else:
																				lowerCamelCase_								=torch.Generator(device=lowerCAmelCase_							).manual_seed(lowerCAmelCase_							)

													lowerCamelCase_								=floats_tensor((1, 3, 32, 32)     ,						rng=random.Random(lowerCAmelCase_							)							).to(lowerCAmelCase_							)

													lowerCamelCase_								={
													    """prompt""": """A painting of a squirrel eating a burger""",
													    """image""": image,
													    """generator""": generator,
													    """num_inference_steps""": 2,
													    """output_type""": """numpy""",
													}

													return inputs







						@unittest.skipIf(
						    torch_device != """cuda""" or not is_xformers_available()     ,						reason="""XFormers attention is only available with CUDA and `xformers` installed"""     ,						)
						def        _snake_case				(			self							)->							List[str]:
													self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3							)







						def        _snake_case				(			self							)->							str:
													self._test_save_load_optional_components()







						@unittest.skipIf(torch_device != """cuda"""     ,						reason="""float16 requires CUDA"""							)
						def        _snake_case				(			self							)->							Dict:
													super().test_save_load_floataa(expected_max_diff=1E-1							)







						def        _snake_case				(			self							)->							Tuple:
													self._test_attention_slicing_forward_pass(expected_max_diff=1E-2							)







						def        _snake_case				(			self							)->							int:
													self._test_save_load_local()







						def        _snake_case				(			self							)->							str:
													self._test_inference_batch_single_identical(
													    expected_max_diff=1E-2     ,						)





'''simple docstring'''


import unittest
from dataclasses import dataclass
from typing import List, Union

import numpy as np
import PIL.Image

from diffusers.utils.outputs import BaseOutput







@dataclass
class 						UpperCAmelCase						(		__a):


 '''simple docstring'''




 __magic_name__       :			Union[List[PIL.Image.Image], np.ndarray]







class 						UpperCAmelCase						(		unittest.TestCase):


 '''simple docstring'''




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



      """simple docstring"""







      a_									=CustomOutput(images=np.random.rand(1				,	3				,	4				,	4))

      # check every way of getting the attribute
      assert isinstance(outputs.images				,	np.ndarray)
      assert outputs.images.shape == (1, 3, 4, 4)
      assert isinstance(outputs["images"]				,	np.ndarray)
      assert outputs["images"].shape == (1, 3, 4, 4)
      assert isinstance(outputs[0]				,	np.ndarray)
      assert outputs[0].shape == (1, 3, 4, 4)

      # test with a non-tensor attribute
      a_									=CustomOutput(images=[PIL.Image.new("RGB"				,	(4, 4))])

      # check every way of getting the attribute
      assert isinstance(outputs.images				,	lowerCAmelCase_)
      assert isinstance(outputs.images[0]				,	PIL.Image.Image)
      assert isinstance(outputs["images"]				,	lowerCAmelCase_)
      assert isinstance(outputs["images"][0]				,	PIL.Image.Image)
      assert isinstance(outputs[0]				,	lowerCAmelCase_)
      assert isinstance(outputs[0][0]				,	PIL.Image.Image)




 def    lowercase_	( self)			->   Optional[int]:



      """simple docstring"""







      a_									=CustomOutput({"images": np.random.rand(1				,	3				,	4				,	4)})

      # check every way of getting the attribute
      assert isinstance(outputs.images				,	np.ndarray)
      assert outputs.images.shape == (1, 3, 4, 4)
      assert isinstance(outputs["images"]				,	np.ndarray)
      assert outputs["images"].shape == (1, 3, 4, 4)
      assert isinstance(outputs[0]				,	np.ndarray)
      assert outputs[0].shape == (1, 3, 4, 4)

      # test with a non-tensor attribute
      a_									=CustomOutput({"images": [PIL.Image.new("RGB"				,	(4, 4))]})

      # check every way of getting the attribute
      assert isinstance(outputs.images				,	lowerCAmelCase_)
      assert isinstance(outputs.images[0]				,	PIL.Image.Image)
      assert isinstance(outputs["images"]				,	lowerCAmelCase_)
      assert isinstance(outputs["images"][0]				,	PIL.Image.Image)
      assert isinstance(outputs[0]				,	lowerCAmelCase_)
      assert isinstance(outputs[0][0]				,	PIL.Image.Image)


