



'''simple docstring'''
from unittest import TestCase

from datasets import Sequence, Value
from datasets.arrow_dataset import Dataset






class 							lowercase__	(							lowercase   ):





	def 	UpperCamelCase_  ( self					:				Optional[Any] ):







							'''simple docstring'''
							return [
							    {"col_1": 3, "col_2": "a"},
							    {"col_1": 2, "col_2": "b"},
							    {"col_1": 1, "col_2": "c"},
							    {"col_1": 0, "col_2": "d"},
							]





	def 	UpperCamelCase_  ( self					:				Optional[int] ):







							'''simple docstring'''
							_UpperCamelCase					:		Tuple 				=   {'col_1': [3, 2, 1, 0], 'col_2': ['a', 'b', 'c', 'd']}
							return Dataset.from_dict(lowerCamelCase__ )





	def 	UpperCamelCase_  ( self					:				List[str] ):







							'''simple docstring'''
							_UpperCamelCase					:		Union[str, Any] 				=   self._create_example_records()
							_UpperCamelCase					:		Any 				=   Dataset.from_list(lowerCamelCase__ )
							self.assertListEqual(dset.column_names ,['col_1', 'col_2'] )
							for i, r in enumerate(lowerCamelCase__ ):
													self.assertDictEqual(lowerCamelCase__ ,example_records[i] )





	def 	UpperCamelCase_  ( self					:				List[Any] ):







							'''simple docstring'''
							_UpperCamelCase					:		List[Any] 				=   self._create_example_records()
							_UpperCamelCase					:		Any 				=   Dataset.from_list(lowerCamelCase__ )
							_UpperCamelCase					:		str 				=   Dataset.from_dict({k: [r[k] for r in example_records] for k in example_records[0]} )
							self.assertEqual(dset.info ,dset_from_dict.info )





	def 	UpperCamelCase_  ( self					:				List[Any] ):  # checks what happens with missing columns







							'''simple docstring'''
							_UpperCamelCase					:		str 				=   [{'col_1': 1}, {'col_2': 'x'}]
							_UpperCamelCase					:		Tuple 				=   Dataset.from_list(lowerCamelCase__ )
							self.assertDictEqual(dset[0] ,{'col_1': 1} )
							self.assertDictEqual(dset[1] ,{'col_1': None} )  # NB: first record is used for columns





	def 	UpperCamelCase_  ( self					:				Optional[int] ):  # checks if the type can be inferred from the second record







							'''simple docstring'''
							_UpperCamelCase					:		Any 				=   [{'col_1': []}, {'col_1': [1, 2]}]
							_UpperCamelCase					:		int 				=   Dataset.from_list(lowerCamelCase__ )
							self.assertEqual(dset.info.features['col_1'] ,Sequence(Value('int64' ) ) )





	def 	UpperCamelCase_  ( self					:				int ):







							'''simple docstring'''
							_UpperCamelCase					:		Optional[int] 				=   Dataset.from_list([] )
							self.assertEqual(len(lowerCamelCase__ ) ,0 )
							self.assertListEqual(dset.column_names ,[] )







"""simple docstring"""
import random
import unittest

import torch

from diffusers import IFImgaImgSuperResolutionPipeline
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 							_UpperCAmelCase							( a		,a		,unittest.TestCase      ):





     '''simple docstring'''



     a__									=IFImgaImgSuperResolutionPipeline
     a__									=TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
     a__									=TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS.union({'''original_image'''}      )
     a__									=PipelineTesterMixin.required_optional_params - {'''latents'''}





     def  __lowerCAmelCase	(					self		)							->					List[str]:
         return self._get_superresolution_dummy_components()





     def  __lowerCAmelCase	(					self       ,	A       ,	A=0		)							->					Union[str, Any]:
         if str(A		).startswith('''mps'''		):
             _UpperCAmelCase							:  Any											=    torch.manual_seed(A		)
         else:
             _UpperCAmelCase							:  int											=    torch.Generator(device=A		).manual_seed(A		)

         _UpperCAmelCase							:  str											=    floats_tensor((1, 3, 3_2, 3_2)       ,	rng=random.Random(A		)		).to(A		)
         _UpperCAmelCase							:  Dict											=    floats_tensor((1, 3, 1_6, 1_6)       ,	rng=random.Random(A		)		).to(A		)

         _UpperCAmelCase							:  List[Any]											=    {
             '''prompt''': '''A painting of a squirrel eating a burger''',
             '''image''': image,
             '''original_image''': original_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  __lowerCAmelCase	(					self		)							->					List[Any]:
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3		)





     def  __lowerCAmelCase	(					self		)							->					List[str]:
         self._test_save_load_optional_components()





     @unittest.skipIf(torch_device != '''cuda'''       ,	reason='''float16 requires CUDA'''		)
     def  __lowerCAmelCase	(					self		)							->					Optional[Any]:
         # Due to non-determinism in save load of the hf-internal-testing/tiny-random-t5 text encoder
         super().test_save_load_floataa(expected_max_diff=1E-1		)





     def  __lowerCAmelCase	(					self		)							->					int:
         self._test_attention_slicing_forward_pass(expected_max_diff=1E-2		)





     def  __lowerCAmelCase	(					self		)							->					Union[str, Any]:
         self._test_save_load_local()





     def  __lowerCAmelCase	(					self		)							->					Union[str, Any]:
         self._test_inference_batch_single_identical(
             expected_max_diff=1E-2       ,	)


