


"""simple docstring"""







import gc
import tempfile
import unittest

import numpy as np
import torch

from diffusers import VersatileDiffusionPipeline
from diffusers.utils.testing_utils import load_image, nightly, require_torch_gpu, torch_device


__lowercase    					=      False






class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    pass






@nightly
@require_torch_gpu
class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    def 	__snake_case							(					self				:    Dict):
      # clean up the VRAM after each test
      super().tearDown()
      gc.collect()
      torch.cuda.empty_cache()






    def 	__snake_case							(					self				:    Any):
      a						:		Union[str, Any]      							=			VersatileDiffusionPipeline.from_pretrained("shi-labs/versatile-diffusion"				, torch_dtype=torch.floataa)
      pipe.to(__UpperCAmelCase)
      pipe.set_progress_bar_config(disable=__UpperCAmelCase)

      a						:		Optional[Any]      							=			load_image(
          "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg")

      a						:		Optional[Any]      							=			torch.manual_seed(0)
      a						:		Union[str, Any]      							=			pipe.dual_guided(
          prompt="first prompt"				, image=__UpperCAmelCase				, text_to_image_strength=0.75				, generator=__UpperCAmelCase				, guidance_scale=7.5				, num_inference_steps=2				, output_type="numpy"				, ).images

      with tempfile.TemporaryDirectory() as tmpdirname:
        pipe.save_pretrained(__UpperCAmelCase)
        a						:		Optional[Any]      							=			VersatileDiffusionPipeline.from_pretrained(__UpperCAmelCase				, torch_dtype=torch.floataa)
      pipe.to(__UpperCAmelCase)
      pipe.set_progress_bar_config(disable=__UpperCAmelCase)

      a						:		int      							=			generator.manual_seed(0)
      a						:		Any      							=			pipe.dual_guided(
          prompt="first prompt"				, image=__UpperCAmelCase				, text_to_image_strength=0.75				, generator=__UpperCAmelCase				, guidance_scale=7.5				, num_inference_steps=2				, output_type="numpy"				, ).images

      assert np.abs(image - new_image).sum() < 1e-5, "Models don't have the same forward pass"






    def 	__snake_case							(					self				:    List[str]):
      a						:		str      							=			VersatileDiffusionPipeline.from_pretrained("shi-labs/versatile-diffusion"				, torch_dtype=torch.floataa)
      pipe.to(__UpperCAmelCase)
      pipe.set_progress_bar_config(disable=__UpperCAmelCase)

      a						:		Any      							=			"cyberpunk 2077"
      a						:		str      							=			load_image(
          "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/versatile_diffusion/benz.jpg")
      a						:		List[str]      							=			torch.manual_seed(0)
      a						:		Optional[int]      							=			pipe.dual_guided(
          prompt=__UpperCAmelCase				, image=__UpperCAmelCase				, text_to_image_strength=0.75				, generator=__UpperCAmelCase				, guidance_scale=7.5				, num_inference_steps=50				, output_type="numpy"				, ).images

      a						:		Any      							=			image[0, 253:256, 253:256, -1]

      assert image.shape == (1, 512, 512, 3)
      a						:		str      							=			np.array([0.1_448, 0.1_619, 0.1_741, 0.1_086, 0.1_147, 0.1_128, 0.1_199, 0.1_165, 0.1_001])

      assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1

      a						:		Union[str, Any]      							=			"A painting of a squirrel eating a burger "
      a						:		Any      							=			torch.manual_seed(0)
      a						:		Tuple      							=			pipe.text_to_image(
          prompt=__UpperCAmelCase				, generator=__UpperCAmelCase				, guidance_scale=7.5				, num_inference_steps=50				, output_type="numpy").images

      a						:		List[Any]      							=			image[0, 253:256, 253:256, -1]

      assert image.shape == (1, 512, 512, 3)
      a						:		str      							=			np.array([0.3_367, 0.3_169, 0.2_656, 0.3_870, 0.4_790, 0.3_796, 0.4_009, 0.4_878, 0.4_778])

      assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1

      a						:		Dict      							=			pipe.image_variation(__UpperCAmelCase				, generator=__UpperCAmelCase				, output_type="numpy").images

      a						:		Dict      							=			image[0, 253:256, 253:256, -1]

      assert image.shape == (1, 512, 512, 3)
      a						:		Any      							=			np.array([0.3_076, 0.3_123, 0.3_284, 0.3_782, 0.3_770, 0.3_894, 0.4_297, 0.4_331, 0.4_456])

      assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-1










"""simple docstring"""







import unittest

from knapsack import knapsack as k






class 						_A  (  unittest.TestCase  ):







    """simple docstring"""




    def 	__snake_case							(					self				:    List[Any]):
      a						:		str      							=			0
      a						:		Optional[int]      							=			[0]
      a						:		Union[str, Any]      							=			[0]
      a						:		Any      							=			len(__UpperCAmelCase)
      self.assertEqual(k.knapsack(__UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase)				, 0)

      a						:		List[str]      							=			[60]
      a						:		str      							=			[10]
      a						:		Optional[int]      							=			len(__UpperCAmelCase)
      self.assertEqual(k.knapsack(__UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase)				, 0)






    def 	__snake_case							(					self				:    Optional[int]):
      a						:		Any      							=			3
      a						:		str      							=			[1, 2, 3]
      a						:		Tuple      							=			[3, 2, 1]
      a						:		Any      							=			len(__UpperCAmelCase)
      self.assertEqual(k.knapsack(__UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase)				, 5)






    def 	__snake_case							(					self				:    Tuple):
      a						:		int      							=			50
      a						:		List[Any]      							=			[60, 100, 120]
      a						:		Optional[int]      							=			[10, 20, 30]
      a						:		str      							=			len(__UpperCAmelCase)
      self.assertEqual(k.knapsack(__UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase				, __UpperCAmelCase)				, 220)


if __name__ == "__main__":
 unittest.main()






