


import random
import unittest

import torch

from diffusers import IFImgaImgPipeline
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):
     SCREAMING_SNAKE_CASE__				      =      IFImgaImgPipeline
     SCREAMING_SNAKE_CASE__				      =      TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''width''', '''height'''}
     SCREAMING_SNAKE_CASE__				      =      TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
     SCREAMING_SNAKE_CASE__				      =      PipelineTesterMixin.required_optional_params - {'''latents'''}





     def 					__A (self	)					->       Any:
      return self._get_dummy_components()





     def 					__A (self		,					UpperCAmelCase		,					UpperCAmelCase=0	)					->       Union[str, Any]:
      if str(UpperCAmelCase	).startswith('''mps'''	):
       _lowercase											=torch.manual_seed(UpperCAmelCase	)
      else:
       _lowercase											=torch.Generator(device=UpperCAmelCase	).manual_seed(UpperCAmelCase	)

      _lowercase											=floats_tensor((1, 3, 3_2, 3_2)		,					rng=random.Random(UpperCAmelCase	)	).to(UpperCAmelCase	)

      _lowercase											={
          '''prompt''': '''A painting of a squirrel eating a burger''',
          '''image''': image,
          '''generator''': generator,
          '''num_inference_steps''': 2,
          '''output_type''': '''numpy''',
      }

      return inputs





     def 					__A (self	)					->       Optional[int]:
      self._test_save_load_optional_components()





     @unittest.skipIf(
         torch_device != '''cuda''' or not is_xformers_available()		,					reason='''XFormers attention is only available with CUDA and `xformers` installed'''		,					)
     def 					__A (self	)					->       Tuple:
      self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=1e-3	)





     @unittest.skipIf(torch_device != '''cuda'''		,					reason='''float16 requires CUDA'''	)
     def 					__A (self	)					->       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	)





     @unittest.skipIf(torch_device != '''cuda'''		,					reason='''float16 requires CUDA'''	)
     def 					__A (self	)					->       List[str]:
      super().test_floataa_inference(expected_max_diff=1e-1	)





     def 					__A (self	)					->       Tuple:
      self._test_attention_slicing_forward_pass(expected_max_diff=1e-2	)





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





     def 					__A (self	)					->       List[str]:
      self._test_inference_batch_single_identical(
          expected_max_diff=1e-2		,					)





UpperCAmelCase__            =							[
    [0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
    [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0],
    [0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
]
def     UpperCAmelCase_ (							__snake_case					,						__snake_case					,						__snake_case					,						__snake_case						)					->      bool:







 """simple docstring"""


 return 0 <= row < rows and 0 <= col < cols
def     UpperCAmelCase_ (							__snake_case					,						__snake_case					,						__snake_case					,						__snake_case						)					->      int:







 """simple docstring"""


 _lowercase											=len(__snake_case						)
 _lowercase											=len(mat[0]						)
 if is_safe(__snake_case					,						__snake_case					,						__snake_case					,						__snake_case						) and (row, col) not in seen and mat[row][col] == 1:
  seen.add((row, col)						)
  return (
      1
      + depth_first_search(row + 1					,						__snake_case					,						__snake_case					,						__snake_case						)
      + depth_first_search(row - 1					,						__snake_case					,						__snake_case					,						__snake_case						)
      + depth_first_search(__snake_case					,						col + 1					,						__snake_case					,						__snake_case						)
      + depth_first_search(__snake_case					,						col - 1					,						__snake_case					,						__snake_case						)
  )
 else:
  return 0
def     UpperCAmelCase_ (							__snake_case						)					->      int:







 """simple docstring"""


 _lowercase											=set()

 _lowercase											=0
 for row, line in enumerate(__snake_case						):
  for col, item in enumerate(__snake_case						):
   if item == 1 and (row, col) not in seen:
    # Maximizing the area
    _lowercase											=max(__snake_case					,						depth_first_search(__snake_case					,						__snake_case					,						__snake_case					,						__snake_case						)						)
 return max_area


if __name__ == "__main__":
  import doctest

  print(find_max_area(matrix))  # Output -> 6
  doctest.testmod()

