




'''simple docstring'''



import unittest

import torch

from diffusers import VQModel
from diffusers.utils import floats_tensor, torch_device
from diffusers.utils.testing_utils import enable_full_determinism

from .test_modeling_common import ModelTesterMixin, UNetTesterMixin


enable_full_determinism()





class      lowerCAmelCase (			__lowerCAmelCase					, __lowerCAmelCase					, unittest.TestCase):
       __lowercase	:   List[Any]										=      VQModel
       __lowercase	:   str										=      '''sample'''


       @property
       def    lowerCAmelCase   ( self     ,	__SCREAMING_SNAKE_CASE=(32, 32)	)   ->	Dict:



            '''simple docstring'''




            __snake_case            =	4
            __snake_case            =	3

            __snake_case            =	floats_tensor((batch_size, num_channels) + sizes	).to(__SCREAMING_SNAKE_CASE	)

            return {"sample": image}


       @property
       def    lowerCAmelCase   ( self	)   ->	Optional[Any]:



            '''simple docstring'''




            return (3, 32, 32)


       @property
       def    lowerCAmelCase   ( self	)   ->	Tuple:



            '''simple docstring'''




            return (3, 32, 32)


       def    lowerCAmelCase   ( self	)   ->	Optional[int]:



            '''simple docstring'''




            __snake_case            =	{
                '''block_out_channels''': [32, 64],
                '''in_channels''': 3,
                '''out_channels''': 3,
                '''down_block_types''': ['''DownEncoderBlock2D''', '''DownEncoderBlock2D'''],
                '''up_block_types''': ['''UpDecoderBlock2D''', '''UpDecoderBlock2D'''],
                '''latent_channels''': 3,
            }
            __snake_case            =	self.dummy_input
            return init_dict, inputs_dict


       def    lowerCAmelCase   ( self	)   ->	Tuple:



            '''simple docstring'''




            pass


       def    lowerCAmelCase   ( self	)   ->	Optional[Any]:



            '''simple docstring'''




            pass


       def    lowerCAmelCase   ( self	)   ->	Tuple:



            '''simple docstring'''




            __snake_case       ,     __snake_case            =	VQModel.from_pretrained('''fusing/vqgan-dummy'''     ,	output_loading_info=__SCREAMING_SNAKE_CASE	)
            self.assertIsNotNone(__SCREAMING_SNAKE_CASE	)
            self.assertEqual(len(loading_info['''missing_keys''']	)     ,	0	)

            model.to(__SCREAMING_SNAKE_CASE	)
            __snake_case            =	model(**self.dummy_input	)

            assert image is not None, "Make sure output is not None"




       def    lowerCAmelCase   ( self	)   ->	Any:



            '''simple docstring'''




            __snake_case            =	VQModel.from_pretrained('''fusing/vqgan-dummy'''	)
            model.to(__SCREAMING_SNAKE_CASE	).eval()

            torch.manual_seed(0	)
            if torch.cuda.is_available():
                 torch.cuda.manual_seed_all(0	)

            __snake_case            =	torch.randn(1     ,	model.config.in_channels     ,	model.config.sample_size     ,	model.config.sample_size	)
            __snake_case            =	image.to(__SCREAMING_SNAKE_CASE	)
            with torch.no_grad():
                 __snake_case            =	model(__SCREAMING_SNAKE_CASE	).sample

            __snake_case            =	output[0, -1, -3:, -3:].flatten().cpu()
            # fmt: off
            __snake_case            =	torch.tensor([-0.0_153, -0.4_044, -0.1_880, -0.5_161, -0.2_418, -0.4_072, -0.1_612, -0.0_633, -0.0_143]	)
            # fmt: on
            self.assertTrue(torch.allclose(__SCREAMING_SNAKE_CASE     ,	__SCREAMING_SNAKE_CASE     ,	atol=1E-3	)	)












'''simple docstring'''



from collections import deque







def       _UpperCamelCase			(_lowerCamelCase				:  Union[str, Any]						)-> Optional[int]:




     '''simple docstring'''





     __snake_case            =	len(_lowerCamelCase						)
     __snake_case            =	deque()
     __snake_case            =	[False for _ in range(_lowerCamelCase						)]
     __snake_case            =	[-1 for _ in range(_lowerCamelCase						)]
     __snake_case            =	index_of[:]

     def strong_connect(_lowerCamelCase				:  Any ,						_lowerCamelCase				:  Dict ,						_lowerCamelCase				:  List[str]						):
          __snake_case            =	index  # the number when this node is seen
          __snake_case            =	index  # lowest rank node reachable from here
          index += 1
          stack.append(_lowerCamelCase						)
          __snake_case            =	True

          for w in g[v]:
               if index_of[w] == -1:
                    __snake_case            =	strong_connect(_lowerCamelCase ,						_lowerCamelCase ,						_lowerCamelCase						)
                    __snake_case            =	(
                        lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
                    )
               elif on_stack[w]:
                    __snake_case            =	(
                        lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
                    )

          if lowlink_of[v] == index_of[v]:
               __snake_case            =	[]
               __snake_case            =	stack.pop()
               __snake_case            =	False
               component.append(_lowerCamelCase						)
               while w != v:
                    __snake_case            =	stack.pop()
                    __snake_case            =	False
                    component.append(_lowerCamelCase						)
               components.append(_lowerCamelCase						)
          return index

     __snake_case            =	[]
     for v in range(_lowerCamelCase						):
          if index_of[v] == -1:
               strong_connect(_lowerCamelCase ,						0 ,						_lowerCamelCase						)

     return components







def       _UpperCamelCase			(_lowerCamelCase				:  Tuple ,						_lowerCamelCase				:  Optional[Any]						)-> Dict:




     '''simple docstring'''





     __snake_case            =	[[] for _ in range(_lowerCamelCase						)]
     for u, v in edges:
          g[u].append(_lowerCamelCase						)
     return g


if __name__ == "__main__":
     # Test
     UpperCAmelCase_							:	List[str]	     =		7
     UpperCAmelCase_							:	int	     =		[0, 0, 1, 2, 3, 3, 4, 4, 6]
     UpperCAmelCase_							:	Dict	     =		[1, 3, 2, 0, 1, 4, 5, 6, 5]
     UpperCAmelCase_							:	List[str]	     =		[(u, v) for u, v in zip(source, target)]
     UpperCAmelCase_							:	Tuple	     =		create_graph(n_vertices, edges)

     assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)






