





'''simple docstring'''


import gc
import unittest

import numpy as np
import torch

from diffusers import StableDiffusionKDiffusionPipeline
from diffusers.utils import slow, torch_device
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu


enable_full_determinism()






@slow
@require_torch_gpu
class       UpperCamelCase__  (		unittest.TestCase     ):







	def 						__a   (				self			:   Optional[Any]		):




				'''simple docstring'''
				# clean up the VRAM after each test
				super().tearDown()
				gc.collect()
				torch.cuda.empty_cache()







	def 						__a   (				self			:   List[Any]		):




				'''simple docstring'''
				a__     = StableDiffusionKDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4"		)
				a__     = sd_pipe.to(lowerCamelCase		)
				sd_pipe.set_progress_bar_config(disable=lowerCamelCase		)

				sd_pipe.set_scheduler("sample_euler"		)

				a__     = "A painting of a squirrel eating a burger"
				a__     = torch.manual_seed(0		)
				a__     = sd_pipe([prompt] , generator=lowerCamelCase , guidance_scale=9.0 , num_inference_steps=2_0 , output_type="np"		)

				a__     = output.images

				a__     = image[0, -3:, -3:, -1]

				assert image.shape == (1, 5_1_2, 5_1_2, 3)
				a__     = np.array([0.0447, 0.0492, 0.0468, 0.0408, 0.0383, 0.0408, 0.0354, 0.0380, 0.0339]		)

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







	def 						__a   (				self			:   List[str]		):




				'''simple docstring'''
				a__     = StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base"		)
				a__     = sd_pipe.to(lowerCamelCase		)
				sd_pipe.set_progress_bar_config(disable=lowerCamelCase		)

				sd_pipe.set_scheduler("sample_euler"		)

				a__     = "A painting of a squirrel eating a burger"
				a__     = torch.manual_seed(0		)
				a__     = sd_pipe([prompt] , generator=lowerCamelCase , guidance_scale=9.0 , num_inference_steps=2_0 , output_type="np"		)

				a__     = output.images

				a__     = image[0, -3:, -3:, -1]

				assert image.shape == (1, 5_1_2, 5_1_2, 3)
				a__     = np.array([0.1237, 0.1320, 0.1438, 0.1359, 0.1390, 0.1132, 0.1277, 0.1175, 0.1112]		)

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







	def 						__a   (				self			:   Tuple		):




				'''simple docstring'''
				a__     = StableDiffusionKDiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base"		)
				a__     = sd_pipe.to(lowerCamelCase		)
				sd_pipe.set_progress_bar_config(disable=lowerCamelCase		)

				sd_pipe.set_scheduler("sample_dpmpp_2m"		)

				a__     = "A painting of a squirrel eating a burger"
				a__     = torch.manual_seed(0		)
				a__     = sd_pipe(
				    [prompt] , generator=lowerCamelCase , guidance_scale=7.5 , num_inference_steps=1_5 , output_type="np" , use_karras_sigmas=lowerCamelCase , )

				a__     = output.images

				a__     = image[0, -3:, -3:, -1]

				assert image.shape == (1, 5_1_2, 5_1_2, 3)
				a__     = np.array(
				    [0.11381689, 0.12112921, 0.1389457, 0.12549606, 0.1244964, 0.10831517, 0.11562866, 0.10867816, 0.10499048]		)

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










'''simple docstring'''


class       UpperCamelCase__  :







	def __init__(				self			:   str , lowerCamelCase			:   int , lowerCamelCase			:   List[str]=None , lowerCamelCase			:   int=None		):




				'''simple docstring'''
				a__     = data
				a__     = previous
				a__     = next_node







	def __str__(				self			:   List[Any]		):




				'''simple docstring'''
				return F'''{self.data}'''







	def 						__a   (				self			:   List[Any]		):




				'''simple docstring'''
				return self.data







	def 						__a   (				self			:   Tuple		):




				'''simple docstring'''
				return self.next







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




				'''simple docstring'''
				return self.previous






class       UpperCamelCase__  :







	def __init__(				self			:   int , lowerCamelCase			:   Tuple		):




				'''simple docstring'''
				a__     = head







	def __iter__(				self			:   Any		):




				'''simple docstring'''
				return self







	def 						__a   (				self			:   List[Any]		):




				'''simple docstring'''
				if not self.current:
							raise StopIteration
				else:
							a__     = self.current.get_data()
							a__     = self.current.get_next()
							return value






class       UpperCamelCase__  :







	def __init__(				self			:   Tuple		):




				'''simple docstring'''
				a__     = None  # First node in list
				a__     = None  # Last node in list







	def __str__(				self			:   Any		):




				'''simple docstring'''
				a__     = self.head
				a__     = []
				while current is not None:
							nodes.append(current.get_data()		)
							a__     = current.get_next()
				return " ".join(str(lowerCamelCase		) for node in nodes		)







	def __contains__(				self			:   Optional[int] , lowerCamelCase			:   int		):




				'''simple docstring'''
				a__     = self.head
				while current:
							if current.get_data() == value:
										return True
							a__     = current.get_next()
				return False







	def __iter__(				self			:   int		):




				'''simple docstring'''
				return LinkedListIterator(self.head		)







	def 						__a   (				self			:   str		):




				'''simple docstring'''
				if self.head:
							return self.head.get_data()
				return None







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




				'''simple docstring'''
				if self.tail:
							return self.tail.get_data()
				return None







	def 						__a   (				self			:   List[Any] , lowerCamelCase			:   Node		):




				'''simple docstring'''
				if self.head is None:
							a__     = node
							a__     = node
				else:
							self.insert_before_node(self.head , lowerCamelCase		)







	def 						__a   (				self			:   List[str] , lowerCamelCase			:   Node		):




				'''simple docstring'''
				if self.head is None:
							self.set_head(lowerCamelCase		)
				else:
							self.insert_after_node(self.tail , lowerCamelCase		)







	def 						__a   (				self			:   List[str] , lowerCamelCase			:   int		):




				'''simple docstring'''
				a__     = Node(lowerCamelCase		)
				if self.head is None:
							self.set_head(lowerCamelCase		)
				else:
							self.set_tail(lowerCamelCase		)







	def 						__a   (				self			:   Any , lowerCamelCase			:   Node , lowerCamelCase			:   Node		):




				'''simple docstring'''
				a__     = node
				a__     = node.previous

				if node.get_previous() is None:
							a__     = node_to_insert
				else:
							a__     = node_to_insert

				a__     = node_to_insert







	def 						__a   (				self			:   Tuple , lowerCamelCase			:   Node , lowerCamelCase			:   Node		):




				'''simple docstring'''
				a__     = node
				a__     = node.next

				if node.get_next() is None:
							a__     = node_to_insert
				else:
							a__     = node_to_insert

				a__     = node_to_insert







	def 						__a   (				self			:   Union[str, Any] , lowerCamelCase			:   int , lowerCamelCase			:   int		):




				'''simple docstring'''
				a__     = 1
				a__     = Node(lowerCamelCase		)
				a__     = self.head
				while node:
							if current_position == position:
										self.insert_before_node(lowerCamelCase , lowerCamelCase		)
										return
							current_position += 1
							a__     = node.next
				self.insert_after_node(self.tail , lowerCamelCase		)







	def 						__a   (				self			:   List[Any] , lowerCamelCase			:   int		):




				'''simple docstring'''
				a__     = self.head
				while node:
							if node.get_data() == item:
										return node
							a__     = node.get_next()
				raise Exception("Node not found"		)







	def 						__a   (				self			:   List[Any] , lowerCamelCase			:   List[str]		):




				'''simple docstring'''
				if (node := self.get_node(lowerCamelCase		)) is not None:
							if node == self.head:
										a__     = self.head.get_next()

							if node == self.tail:
										a__     = self.tail.get_previous()

							self.remove_node_pointers(lowerCamelCase		)







	@staticmethod
	def 						__a   (				lowerCamelCase			:   Node		):




				'''simple docstring'''
				if node.get_next():
							a__     = node.previous

				if node.get_previous():
							a__     = node.next

				a__     = None
				a__     = None







	def 						__a   (				self			:   List[str]		):




				'''simple docstring'''
				return self.head is None







def    _lowerCamelCase  ()   ->    None:
			pass


if __name__ == "__main__":
		import doctest

		doctest.testmod()



