


'''simple docstring'''






import random
import unittest

import torch

from diffusers import IFInpaintingSuperResolutionPipeline
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_INPAINTING_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_INPAINTING_PARAMS,
)
from ..test_pipelines_common import PipelineTesterMixin
from . import IFPipelineTesterMixin






@skip_mps
class   __snake_case			(  _SCREAMING_SNAKE_CASE      ,_SCREAMING_SNAKE_CASE      ,unittest.TestCase):







    """simple docstring"""



    lowercase  					=   IFInpaintingSuperResolutionPipeline
    lowercase  					=   TEXT_GUIDED_IMAGE_INPAINTING_PARAMS - {'width', 'height'}
    lowercase  					=   TEXT_GUIDED_IMAGE_INPAINTING_BATCH_PARAMS.union({'original_image'})
    lowercase  					=   PipelineTesterMixin.required_optional_params - {'latents'}

    def __lowercase  (  self       :    Dict						)  ->    Union[str, Any]:
      return self._get_superresolution_dummy_components()

    def __lowercase  (  self       :    str       ,		lowerCamelCase       :    List[Any]       ,		lowerCamelCase       :    Dict=0						)  ->    Tuple:
      if str(lowerCamelCase						).startswith("""mps"""						):
        lowerCAmelCase_     : Any     =  torch.manual_seed(lowerCamelCase						)
      else:
        lowerCAmelCase_     : Any     =  torch.Generator(device=lowerCamelCase						).manual_seed(lowerCamelCase						)

      lowerCAmelCase_     : Dict     =  floats_tensor((1, 3, 16, 16)       ,		rng=random.Random(lowerCamelCase						)						).to(lowerCamelCase						)
      lowerCAmelCase_     : int     =  floats_tensor((1, 3, 32, 32)       ,		rng=random.Random(lowerCamelCase						)						).to(lowerCamelCase						)
      lowerCAmelCase_     : int     =  floats_tensor((1, 3, 32, 32)       ,		rng=random.Random(lowerCamelCase						)						).to(lowerCamelCase						)

      lowerCAmelCase_     : Any     =  {
          """prompt""": """A painting of a squirrel eating a burger""",
          """image""": image,
          """original_image""": original_image,
          """mask_image""": mask_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       :    List[str]						)  ->    List[Any]:
      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1E-3						)

    def __lowercase  (  self       :    List[Any]						)  ->    Any:
      self._test_save_load_optional_components()

    @unittest.skipIf(torch_device != """cuda"""       ,		reason="""float16 requires CUDA"""						)
    def __lowercase  (  self       :    Tuple						)  ->    str:
      # 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 __lowercase  (  self       :    List[str]						)  ->    Optional[int]:
      self._test_attention_slicing_forward_pass(expected_max_diff=1E-2						)

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





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







'''simple docstring'''






from __future__ import annotations

# This is the precision for this function which can be altered.
# It is recommended for users to keep this number greater than or equal to 10.
__A   :    Tuple											= 10







def 							UpperCamelCase_     (       A__   :  int				,       A__   :  int				,       A__   :  list[int]				,       A__   :  int   ):
  '''simple docstring'''





  for i in range(A__				,       A__   ):
    if array[i] == target:
      return i
  return -1







def 							UpperCamelCase_     (       A__   :  list[int]				,       A__   :  int   ):
  '''simple docstring'''





  lowerCAmelCase_     : Optional[int]     =  0
  lowerCAmelCase_     : Union[str, Any]     =  len(A__   )
  while left <= right:
    if right - left < precision:
      return lin_search(A__				,       A__				,       A__				,       A__   )

    lowerCAmelCase_     : Dict     =  (left + right) // 3 + 1
    lowerCAmelCase_     : List[Any]     =  2 * (left + right) // 3 + 1

    if array[one_third] == target:
      return one_third
    elif array[two_third] == target:
      return two_third

    elif target < array[one_third]:
      lowerCAmelCase_     : List[str]     =  one_third - 1
    elif array[two_third] < target:
      lowerCAmelCase_     : Tuple     =  two_third + 1

    else:
      lowerCAmelCase_     : Tuple     =  one_third + 1
      lowerCAmelCase_     : Any     =  two_third - 1
  else:
    return -1







def 							UpperCamelCase_     (       A__   :  int				,       A__   :  int				,       A__   :  list[int]				,       A__   :  int   ):
  '''simple docstring'''





  if left < right:
    if right - left < precision:
      return lin_search(A__				,       A__				,       A__				,       A__   )
    lowerCAmelCase_     : Dict     =  (left + right) // 3 + 1
    lowerCAmelCase_     : Dict     =  2 * (left + right) // 3 + 1

    if array[one_third] == target:
      return one_third
    elif array[two_third] == target:
      return two_third

    elif target < array[one_third]:
      return rec_ternary_search(A__				,       one_third - 1				,       A__				,       A__   )
    elif array[two_third] < target:
      return rec_ternary_search(two_third + 1				,       A__				,       A__				,       A__   )
    else:
      return rec_ternary_search(one_third + 1				,       two_third - 1				,       A__				,       A__   )
  else:
    return -1


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  __A   :    List[Any]											= input("Enter numbers separated by comma:\n").strip()
  __A   :    Union[str, Any]											= [int(item.strip()) for item in user_input.split(",")]
  assert collection == sorted(collection), F"List must be ordered.\n{collection}."
  __A   :    List[Any]											= int(input("Enter the number to be found in the list:\n").strip())
  __A   :    str											= ite_ternary_search(collection, target)
  __A   :    Dict											= rec_ternary_search(0, len(collection) - 1, collection, target)
  if resulta != -1:
    print(F'''Iterative search: {target} found at positions: {resulta}''')
    print(F'''Recursive search: {target} found at positions: {resulta}''')
  else:
    print("Not found")



