






"""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    snake_case						(				_lowerCAmelCase  ,      _lowerCAmelCase  ,      unittest.TestCase		):


   '''simple docstring'''

   A_		:      Optional[int]							=					IFSuperResolutionPipeline
   A_		:      Tuple							=					TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {"width", "height"}
   A_		:      Tuple							=					TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
   A_		:      Any							=					PipelineTesterMixin.required_optional_params - {"latents"}


   def 							_SCREAMING_SNAKE_CASE							(      self					:	List[str]    ):

     '''simple docstring'''
     return self._get_superresolution_dummy_components()


   def 							_SCREAMING_SNAKE_CASE							(      self					:	List[str],			_lowerCamelCase					:	int,			_lowerCamelCase					:	str=0    ):

     '''simple docstring'''
     if str(_lowerCamelCase    ).startswith('''mps'''    ):
       __A		     =					torch.manual_seed(_lowerCamelCase    )
     else:
       __A		     =					torch.Generator(device=_lowerCamelCase    ).manual_seed(_lowerCamelCase    )

     __A		     =					floats_tensor((1, 3, 32, 32),			rng=random.Random(_lowerCamelCase    )    ).to(_lowerCamelCase    )

     __A		     =					{
         '''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 							_SCREAMING_SNAKE_CASE							(      self					:	Union[str, Any]    ):

     '''simple docstring'''
     self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3    )


   def 							_SCREAMING_SNAKE_CASE							(      self					:	Union[str, Any]    ):

     '''simple docstring'''
     self._test_save_load_optional_components()


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

     '''simple docstring'''
     # 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 							_SCREAMING_SNAKE_CASE							(      self					:	str    ):

     '''simple docstring'''
     self._test_attention_slicing_forward_pass(expected_max_diff=1e-2    )


   def 							_SCREAMING_SNAKE_CASE							(      self					:	List[Any]    ):

     '''simple docstring'''
     self._test_save_load_local()






   def 							_SCREAMING_SNAKE_CASE							(      self					:	Optional[Any]    ):

     '''simple docstring'''
     self._test_inference_batch_single_identical(
         expected_max_diff=1e-2,			)









def 						_lowerCAmelCase    (					__lowerCamelCase :  int  ):



 """simple docstring"""





 if not isinstance(__lowerCamelCase		,						__lowerCamelCase  ):
  __SCREAMING_SNAKE_CASE							:     Union[str, Any]							=						(
      "operation can not be conducted on a object of type "
      F"""{type(__lowerCamelCase  ).__name__}"""
  )
  raise TypeError(__lowerCamelCase  )
 __SCREAMING_SNAKE_CASE							:     List[str]							=						""
 for _ in range(0		,						32  ):
  bit_string += str(number % 2  )
  __SCREAMING_SNAKE_CASE							:     Union[str, Any]							=						number >> 1
 return bit_string






def 						_lowerCAmelCase    (					__lowerCamelCase :  int  ):



 """simple docstring"""





 if number < 0:
  raise ValueError("the value of input must be positive"  )
 elif isinstance(__lowerCamelCase		,						__lowerCamelCase  ):
  raise TypeError("Input value must be a 'int' type"  )
 elif isinstance(__lowerCamelCase		,						__lowerCamelCase  ):
  raise TypeError("'<' not supported between instances of 'str' and 'int'"  )
 __SCREAMING_SNAKE_CASE							:     Any							=						0
 # iterator over [1 to 32],since we are dealing with 32 bit integer
 for _ in range(1		,						33  ):
  # left shift the bits by unity
  __SCREAMING_SNAKE_CASE							:     Optional[int]							=						result << 1
  # get the end bit
  __SCREAMING_SNAKE_CASE							:     Union[str, Any]							=						number % 2
  # right shift the bits by unity
  __SCREAMING_SNAKE_CASE							:     Optional[Any]							=						number >> 1
  # add that bit to our ans
  __SCREAMING_SNAKE_CASE							:     Optional[int]							=						result | end_bit
 return get_reverse_bit_string(__lowerCamelCase  )


if __name__ == "__main__":
      import doctest

      doctest.testmod()






