






'''simple docstring'''


from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

lowerCamelCase_					:			Tuple     						=				TypeVar('''T''')
lowerCamelCase_					:			Optional[int]     						=				TypeVar('''U''')
class  _SCREAMING_SNAKE_CASE				(		Generic[T, U]						):


			'''simple docstring'''





			def __init__( self				:    str			,   lowercase				:    T | None			,   lowercase				:    U | None      )				->     List[Any]:

									'''simple docstring'''







									UpperCamelCase__       =			key
									UpperCamelCase__       =			val
									UpperCamelCase__       =			0
									UpperCamelCase__       =			None
									UpperCamelCase__       =			None







			def __repr__( self				:    List[str]      )				->     str:

									'''simple docstring'''







									return "Node: key: {}, val: {}, freq: {}, has next: {}, has prev: {}".format(
									    self.key			,   self.val			,   self.freq			,   self.next is not None			,   self.prev is not None      )
class  _SCREAMING_SNAKE_CASE				(		Generic[T, U]						):


			'''simple docstring'''





			def __init__( self				:    Optional[int]      )				->     None:

									'''simple docstring'''







									UpperCamelCase__       =			DoubleLinkedListNode(lowercase			,   lowercase      )
									UpperCamelCase__       =			DoubleLinkedListNode(lowercase			,   lowercase      )
									UpperCamelCase__     , UpperCamelCase__       =			self.rear, self.head






			def __repr__( self				:    str      )				->     str:

									'''simple docstring'''







									UpperCamelCase__       =			["""DoubleLinkedList"""]
									UpperCamelCase__       =			self.head
									while node.next is not None:
															rep.append(str(lowercase      )      )
															UpperCamelCase__       =			node.next
									rep.append(str(self.rear      )      )
									return ",\n    ".join(lowercase      )






			def 					A   ( self				:    Optional[int]			,   lowercase				:    DoubleLinkedListNode[T, U]      )				->     None:

									'''simple docstring'''







									UpperCamelCase__       =			self.rear.prev

									# All nodes other than self.head are guaranteed to have non-None previous
									assert previous is not None

									UpperCamelCase__       =			node
									UpperCamelCase__       =			previous
									UpperCamelCase__       =			node
									UpperCamelCase__       =			self.rear
									node.freq += 1
									self._position_node(lowercase      )






			def 					A   ( self				:    Union[str, Any]			,   lowercase				:    DoubleLinkedListNode[T, U]      )				->     None:

									'''simple docstring'''







									while node.prev is not None and node.prev.freq > node.freq:
															# swap node with previous node
															UpperCamelCase__       =			node.prev

															UpperCamelCase__       =			previous_node.prev
															UpperCamelCase__       =			node.prev
															UpperCamelCase__       =			previous_node
															UpperCamelCase__       =			node







			def 					A   ( self				:    Tuple			,   lowercase				:    DoubleLinkedListNode[T, U]      )				->     DoubleLinkedListNode[T, U] | None:

									'''simple docstring'''







									if node.prev is None or node.next is None:
															return None

									UpperCamelCase__       =			node.next
									UpperCamelCase__       =			node.prev
									UpperCamelCase__       =			None
									UpperCamelCase__       =			None
									return node
class  _SCREAMING_SNAKE_CASE				(		Generic[T, U]						):


			'''simple docstring'''





			__a				:				dict[Callable[[T], U], LFUCache[T, U]]         =       {}






			def __init__( self				:    Dict			,   lowercase				:    int      )				->     Union[str, Any]:

									'''simple docstring'''







									UpperCamelCase__       =			DoubleLinkedList()
									UpperCamelCase__       =			capacity
									UpperCamelCase__       =			0
									UpperCamelCase__       =			0
									UpperCamelCase__       =			0
									UpperCamelCase__       =			{}






			def __repr__( self				:    List[str]      )				->     str:

									'''simple docstring'''







									return (
									    f"CacheInfo(hits={self.hits}, misses={self.miss}, "
									    f"capacity={self.capacity}, current_size={self.num_keys})"
									)






			def __contains__( self				:    Any			,   lowercase				:    T      )				->     bool:

									'''simple docstring'''







									return key in self.cache






			def 					A   ( self				:    str			,   lowercase				:    T      )				->     U | None:

									'''simple docstring'''







									if key in self.cache:
															self.hits += 1
															UpperCamelCase__       =			self.cache[key]
															UpperCamelCase__       =			self.list.remove(self.cache[key]      )
															assert node == value_node

															# node is guaranteed not None because it is in self.cache
															assert node is not None
															self.list.add(lowercase      )
															return node.val
									self.miss += 1
									return None






			def 					A   ( self				:    Any			,   lowercase				:    T			,   lowercase				:    U      )				->     None:

									'''simple docstring'''







									if key not in self.cache:
															if self.num_keys >= self.capacity:
																					# delete first node when over capacity
																					UpperCamelCase__       =			self.list.head.next

																					# guaranteed to have a non-None first node when num_keys > 0
																					# explain to type checker via assertions
																					assert first_node is not None
																					assert first_node.key is not None
																					assert self.list.remove(lowercase      ) is not None
																					# first_node guaranteed to be in list

																					del self.cache[first_node.key]
																					self.num_keys -= 1
															UpperCamelCase__       =			DoubleLinkedListNode(lowercase			,   lowercase      )
															self.list.add(self.cache[key]      )
															self.num_keys += 1

									else:
															UpperCamelCase__       =			self.list.remove(self.cache[key]      )
															assert node is not None  # node guaranteed to be in list
															UpperCamelCase__       =			value
															self.list.add(lowercase      )







			@classmethod
			def 					A   ( cls				:    type[LFUCache[T, U]]			,   lowercase				:    int = 1_2_8      )				->     Callable[[Callable[[T], U]], Callable[..., U]]:

									'''simple docstring'''







									def cache_decorator_inner(lowercase				:    Callable[[T], U]      ) -> Callable[..., U]:
															def cache_decorator_wrapper(*lowercase				:    T      ) -> U:
																					if func not in cls.decorator_function_to_instance_map:
																											UpperCamelCase__       =			LFUCache(lowercase      )

																					UpperCamelCase__       =			cls.decorator_function_to_instance_map[func].get(args[0]      )
																					if result is None:
																											UpperCamelCase__       =			func(*lowercase      )
																											cls.decorator_function_to_instance_map[func].put(args[0]			,   lowercase      )
																					return result

															def cache_info() -> LFUCache[T, U]:
																					return cls.decorator_function_to_instance_map[func]

															setattr(lowercase			,   """cache_info"""			,   lowercase      )  # noqa: B010

															return cache_decorator_wrapper

									return cache_decorator_inner


if __name__ == "__main__":
					import doctest

					doctest.testmod()








'''simple docstring'''


from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available
@dataclass
# Copied from diffusers.pipelines.stable_diffusion.__init__.StableDiffusionPipelineOutput with Stable->Alt
class  _SCREAMING_SNAKE_CASE				(		SCREAMING_SNAKE_CASE						):


			'''simple docstring'''





			__a				:				Union[List[PIL.Image.Image], np.ndarray]
			__a				:				Optional[List[bool]]


if is_transformers_available() and is_torch_available():
					from .modeling_roberta_series import RobertaSeriesModelWithTransformation
					from .pipeline_alt_diffusion import AltDiffusionPipeline
					from .pipeline_alt_diffusion_imgaimg import AltDiffusionImgaImgPipeline
