



'''simple docstring'''







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 				__lowerCAmelCase(							lowerCAmelCase__		,			lowerCAmelCase__		,			unittest.TestCase      ):
			__snake_case  :		List[Any]		=      IFSuperResolutionPipeline
			__snake_case  :		Optional[Any]		=      TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
			__snake_case  :		Optional[int]		=      TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
			__snake_case  :		Dict		=      PipelineTesterMixin.required_optional_params - {'latents'}






			def 				_lowercase	(   self  :							str	):




					"""simple docstring"""







					return self._get_superresolution_dummy_components()






			def 				_lowercase	(   self  :							Optional[Any]      ,       SCREAMING_SNAKE_CASE  :							Optional[int]      ,       SCREAMING_SNAKE_CASE  :							Optional[Any]=0	):




					"""simple docstring"""







					if str(SCREAMING_SNAKE_CASE	).startswith('mps'	):
							SCREAMING_SNAKE_CASE_						:List[str]										=      torch.manual_seed(SCREAMING_SNAKE_CASE	)
					else:
							SCREAMING_SNAKE_CASE_						:Optional[Any]										=      torch.Generator(device=SCREAMING_SNAKE_CASE	).manual_seed(SCREAMING_SNAKE_CASE	)

					SCREAMING_SNAKE_CASE_						:Any										=      floats_tensor((1, 3, 32, 32)      ,       rng=random.Random(SCREAMING_SNAKE_CASE	)	).to(SCREAMING_SNAKE_CASE	)

					SCREAMING_SNAKE_CASE_						:List[Any]										=      {
					    '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 				_lowercase	(   self  :							Tuple	):




					"""simple docstring"""







					self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3	)






			def 				_lowercase	(   self  :							Optional[int]	):




					"""simple docstring"""







					self._test_save_load_optional_components()






			@unittest.skipIf(torch_device != 'cuda'      ,       reason='float16 requires CUDA'	)
			def 				_lowercase	(   self  :							str	):




					"""simple docstring"""







					super().test_save_load_floataa(expected_max_diff=1E-1	)






			def 				_lowercase	(   self  :							Optional[int]	):




					"""simple docstring"""







					self._test_attention_slicing_forward_pass(expected_max_diff=1E-2	)






			def 				_lowercase	(   self  :							Optional[Any]	):




					"""simple docstring"""







					self._test_save_load_local()






			def 				_lowercase	(   self  :							str	):




					"""simple docstring"""







					self._test_inference_batch_single_identical(
					    expected_max_diff=1E-2      ,       )




def   snake_case_    (			__lowercase      ,							__lowercase      ,							__lowercase      ,							__lowercase							):
   UpperCAmelCase_				:   Optional[int]							= int((lower_bound + upper_bound) // 2							)
   if array[r] == value:
      return r
   if lower_bound >= upper_bound:
      return -1
   if array[r] < value:
      return binary_search(__lowercase      ,							r + 1      ,							__lowercase      ,							__lowercase							)
   else:
      return binary_search(__lowercase      ,							__lowercase      ,							r - 1      ,							__lowercase							)
def   snake_case_    (			__lowercase      ,							__lowercase							):
   UpperCAmelCase_				:   Union[str, Any]							= 0
   if matrix[index][0] == value:
      return [index, 0]
   while index < len(__lowercase							) and matrix[index][0] < value:
      UpperCAmelCase_				:   str							= binary_search(matrix[index]      ,							0      ,							len(matrix[index]							) - 1      ,							__lowercase							)
      if r != -1:
         return [index, r]
      index += 1
   return [-1, -1]


if __name__ == "__main__":
       import doctest

       doctest.testmod()