






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     _UpperCAmelCase  (						_a			,   _a			,   unittest.TestCase     ):
    __lowerCamelCase:				Any						    =      IFSuperResolutionPipeline
    __lowerCamelCase:				str						    =      TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'width', 'height'}
    __lowerCamelCase:				Union[str, Any]						    =      TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
    __lowerCamelCase:				int						    =      PipelineTesterMixin.required_optional_params - {'latents'}




    def 			lowerCAmelCase__			(     self					:    Any     ):






       '''simple docstring'''






       return self._get_superresolution_dummy_components()




    def 			lowerCAmelCase__			(     self					:    Optional[int]					,       a					:    Tuple					,       a					:    Dict=0     ):






       '''simple docstring'''






       if str(a     ).startswith("mps"     ):
          lowercase_		:      Optional[int]          =       torch.manual_seed(a     )
       else:
          lowercase_		:      List[Any]          =       torch.Generator(device=a     ).manual_seed(a     )

       lowercase_		:      str          =       floats_tensor((1, 3, 3_2, 3_2)					,       rng=random.Random(a     )     ).to(a     )

       lowercase_		:      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 			lowerCAmelCase__			(     self					:    str     ):






       '''simple docstring'''






       self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3     )




    def 			lowerCAmelCase__			(     self					:    int     ):






       '''simple docstring'''






       self._test_save_load_optional_components()




    @unittest.skipIf(torch_device != "cuda"					,       reason="float16 requires CUDA"     )
    def 			lowerCAmelCase__			(     self					:    Union[str, Any]     ):






       '''simple docstring'''






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




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






       '''simple docstring'''






       self._test_attention_slicing_forward_pass(expected_max_diff=1e-2     )




    def 			lowerCAmelCase__			(     self					:    str     ):






       '''simple docstring'''






       self._test_save_load_local()





    def 			lowerCAmelCase__			(     self					:    Optional[int]     ):






       '''simple docstring'''






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












'''simple docstring'''
UpperCamelCase__	=     (1, 153, 370, 371, 1634, 24678051, 115132219018763992565095597973971522401)
UpperCamelCase__	=     (-153, -1, 0, 1.2, 200, "A", [], {}, None)




def 						__SCREAMING_SNAKE_CASE   (					_UpperCamelCase							):


   """simple docstring"""




   if not isinstance(_UpperCamelCase  ,						_UpperCamelCase							) or n < 1:
      return False

   # Initialization of sum and number of digits.
   lowercase_		:      Optional[int]          =       0
   lowercase_		:      Any          =       0
   lowercase_		:      Optional[Any]          =       n
   # Calculation of digits of the number
   while temp > 0:
      number_of_digits += 1
      temp //= 10
   # Dividing number into separate digits and find Armstrong number
   lowercase_		:      int          =       n
   while temp > 0:
      lowercase_		:      Any          =       temp % 10
      total += rem**number_of_digits
      temp //= 10
   return n == total




def 						__SCREAMING_SNAKE_CASE   (					_UpperCamelCase							):


   """simple docstring"""




   if not isinstance(_UpperCamelCase  ,						_UpperCamelCase							) or n < 1:
      return False

   # Init a "histogram" of the digits
   lowercase_		:      Optional[Any]          =       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
   lowercase_		:      Tuple          =       0
   lowercase_		:      Any          =       0
   lowercase_		:      Tuple          =       n
   while temp > 0:
      lowercase_      ,						lowercase_		:      Optional[Any]          =       divmod(_UpperCamelCase  ,						10							)
      digit_histogram[rem] += 1
      digit_total += 1

   for cnt, i in zip(_UpperCamelCase  ,						range(len(_UpperCamelCase							)							)							):
      total += cnt * i**digit_total

   return n == total




def 						__SCREAMING_SNAKE_CASE   (					_UpperCamelCase							):


   """simple docstring"""




   if not isinstance(_UpperCamelCase  ,						_UpperCamelCase							) or n < 1:
      return False
   lowercase_		:      List[str]          =       len(str(_UpperCamelCase							)							)  # the power that all digits will be raised to
   # check if sum of each digit multiplied expo times is equal to number
   return n == sum(int(_UpperCamelCase							) ** expo for i in str(_UpperCamelCase							)							)




def 						__SCREAMING_SNAKE_CASE   (					):


   """simple docstring"""




   lowercase_		:      Dict          =       int(input("Enter an integer to see if it is an Armstrong number: "							).strip()							)
   print(F"""{num} is {"" if armstrong_number(_UpperCamelCase							) else "not "}an Armstrong number."""							)
   print(F"""{num} is {"" if narcissistic_number(_UpperCamelCase							) else "not "}an Armstrong number."""							)
   print(F"""{num} is {"" if pluperfect_number(_UpperCamelCase							) else "not "}an Armstrong number."""							)


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 main()




