




"""simple docstring"""

import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


_lowerCamelCase	:      Union[str, Any]   =							1000

class 							lowercase   :







				def __init__(				self :       int   ,  _lowerCamelCase :       Optional[int]   ,  _lowerCamelCase :       Union[str, Any]=1.2   ,  _lowerCamelCase :       List[str]="g"   ,  _lowerCamelCase :       Optional[Any]=0.5   ,  _lowerCamelCase :       Dict="-"   ,  _lowerCamelCase :       List[str]="test_out.jpg"   ,  _lowerCamelCase :       Optional[int]=True   ,  _lowerCamelCase :       Optional[Any]=False   ,  _lowerCamelCase :       List[str]=None   ,  _lowerCamelCase :       Dict=None   ,  _lowerCamelCase :       Optional[int]=0.7   ,  ):



					"""simple docstring"""

					if isinstance(__A   ,  torch.Tensor							):
						A_	:					str						 =		img.numpy().astype('''np.uint8'''							)
					if isinstance(__A   ,  __A							):
						A_	:					int						 =		img_tensorize(__A							)
					assert isinstance(__A   ,  np.ndarray							)

					A_ ,			A_	:					str						 =		img.shape[1], img.shape[0]
					A_	:					Dict						 =		mplfigure.Figure(frameon=__A							)
					A_	:					str						 =		fig.get_dpi()
					A_	:					List[Any]						 =		(width * scale + 1E-2) / dpi
					A_	:					Any						 =		(height * scale + 1E-2) / dpi
					fig.set_size_inches(__A   ,  __A							)
					A_	:					Dict						 =		fig.add_axes([0.0, 0.0, 1.0, 1.0]							)
					ax.axis('''off'''							)
					ax.set_xlim(0.0   ,  __A							)
					ax.set_ylim(__A							)

					A_	:					Union[str, Any]						 =		saveas
					A_	:					Dict						 =		rgb
					A_	:					int						 =		pynb
					A_	:					List[str]						 =		img
					A_	:					Union[str, Any]						 =		edgecolor
					A_	:					Optional[int]						 =		0.5
					A_	:					Any						 =		linestyle
					A_	:					Any						 =		int(np.sqrt(min(__A   ,  __A							)							) * scale // 3							)
					A_	:					Dict						 =		width
					A_	:					Optional[Any]						 =		height
					A_	:					Any						 =		scale
					A_	:					Tuple						 =		fig
					A_	:					Optional[int]						 =		ax
					A_	:					Union[str, Any]						 =		pad
					A_	:					List[Any]						 =		idaobj
					A_	:					List[str]						 =		idaattr
					A_	:					int						 =		FigureCanvasAgg(__A							)







				def        a_	(				self :       List[Any]   ,  _lowerCamelCase :       str   ,  _lowerCamelCase :       int=None							):



					"""simple docstring"""

					if color is None:
						A_	:					Optional[Any]						 =		self.edgecolor
					((A_) ,			(A_) ,			(A_) ,			(A_))	:					Union[str, Any]						 =		box
					A_	:					str						 =		xa - xa
					A_	:					List[str]						 =		ya - ya
					self.ax.add_patch(
					    mpl.patches.Rectangle(
					        (xa, ya)   ,  __A   ,  __A   ,  fill=__A   ,  edgecolor=__A   ,  linewidth=self.font_size // 3   ,  alpha=self.alpha   ,  linestyle=self.linestyle   ,  )							)







				def        a_	(				self :       Dict   ,  _lowerCamelCase :       List[str]   ,  _lowerCamelCase :       List[str]=None   ,  _lowerCamelCase :       Dict=None   ,  _lowerCamelCase :       Any=None   ,  _lowerCamelCase :       List[Any]=None							):



					"""simple docstring"""

					if len(boxes.shape							) > 2:
						A_	:					int						 =		boxes[0]
					if len(obj_ids.shape							) > 1:
						A_	:					Optional[int]						 =		obj_ids[0]
					if len(obj_scores.shape							) > 1:
						A_	:					List[Any]						 =		obj_scores[0]
					if len(attr_ids.shape							) > 1:
						A_	:					str						 =		attr_ids[0]
					if len(attr_scores.shape							) > 1:
						A_	:					Tuple						 =		attr_scores[0]
					if isinstance(__A   ,  torch.Tensor							):
						A_	:					Dict						 =		boxes.numpy()
					if isinstance(__A   ,  __A							):
						A_	:					List[str]						 =		np.array(__A							)
					assert isinstance(__A   ,  np.ndarray							)
					A_	:					Optional[Any]						 =		np.prod(boxes[:, 2:] - boxes[:, :2]   ,  axis=1							)
					A_	:					int						 =		np.argsort(-areas							).tolist()
					A_	:					List[str]						 =		boxes[sorted_idxs] if boxes is not None else None
					A_	:					List[str]						 =		obj_ids[sorted_idxs] if obj_ids is not None else None
					A_	:					int						 =		obj_scores[sorted_idxs] if obj_scores is not None else None
					A_	:					Dict						 =		attr_ids[sorted_idxs] if attr_ids is not None else None
					A_	:					List[Any]						 =		attr_scores[sorted_idxs] if attr_scores is not None else None

					A_	:					List[Any]						 =		[self._random_color(maximum=1							) for _ in range(len(__A							)							)]
					A_	:					Optional[int]						 =		[assigned_colors[idx] for idx in sorted_idxs]
					if obj_ids is not None:
						A_	:					List[Any]						 =		self._create_text_labels_attr(__A   ,  __A   ,  __A   ,  __A							)
						for i in range(len(__A							)							):
							A_	:					List[Any]						 =		assigned_colors[i]
							self.add_box(boxes[i]   ,  __A							)
							self.draw_labels(labels[i]   ,  boxes[i]   ,  __A							)







				def        a_	(				self :       List[Any]   ,  _lowerCamelCase :       List[str]   ,  _lowerCamelCase :       List[Any]   ,  _lowerCamelCase :       Tuple							):



					"""simple docstring"""

					A_ ,			A_ ,			A_ ,			A_	:					Any						 =		box
					A_	:					Optional[int]						 =		(xa, ya)
					A_	:					Tuple						 =		(ya - ya) * (xa - xa)
					A_	:					Optional[Any]						 =		_SMALL_OBJ * self.scale
					if instance_area < small or ya - ya < 40 * self.scale:
						if ya >= self.height - 5:
							A_	:					Union[str, Any]						 =		(xa, ya)
						else:
							A_	:					Dict						 =		(xa, ya)

					A_	:					Optional[int]						 =		(ya - ya) / np.sqrt(self.height * self.width							)
					A_	:					Tuple						 =		self._change_color_brightness(__A   ,  brightness_factor=0.7							)
					A_	:					Optional[int]						 =		np.clip((height_ratio - 0.02) / 0.08 + 1   ,  1.2   ,  2							)
					font_size *= 0.75 * self.font_size

					self.draw_text(
					    text=__A   ,  position=__A   ,  color=__A   ,  )







				def        a_	(				self :       Optional[int]   ,  _lowerCamelCase :       Dict   ,  _lowerCamelCase :       List[str]   ,  _lowerCamelCase :       int="g"   ,  _lowerCamelCase :       Optional[int]="left"   ,  ):



					"""simple docstring"""

					A_	:					Optional[int]						 =		0
					A_	:					Tuple						 =		self.font_size
					A_	:					List[str]						 =		np.maximum(list(mplc.to_rgb(__A							)							)   ,  0.2							)
					A_	:					str						 =		max(0.8   ,  np.max(__A							)							)
					A_	:					int						 =		{
					    '''facecolor''': '''black''',
					    '''alpha''': self.alpha,
					    '''pad''': self.pad,
					    '''edgecolor''': '''none''',
					}
					A_ ,			A_	:					Optional[int]						 =		position
					self.ax.text(
					    __A   ,  __A   ,  __A   ,  size=font_size * self.scale   ,  family='''sans-serif'''   ,  bbox=__A   ,  verticalalignment='''top'''   ,  horizontalalignment=__A   ,  color=__A   ,  zorder=10   ,  rotation=__A   ,  )







				def        a_	(				self :       Any   ,  _lowerCamelCase :       str=None							):



					"""simple docstring"""

					if saveas is None:
						A_	:					Union[str, Any]						 =		self.saveas
					if saveas.lower().endswith('''.jpg'''							) or saveas.lower().endswith('''.png'''							):
						cva.imwrite(
						    __A   ,  self._get_buffer()[:, :, ::-1]   ,  )
					else:
						self.fig.savefig(__A							)







				def        a_	(				self :       Any   ,  _lowerCamelCase :       Union[str, Any]   ,  _lowerCamelCase :       str   ,  _lowerCamelCase :       List[str]   ,  _lowerCamelCase :       int							):



					"""simple docstring"""

					A_	:					Optional[Any]						 =		[self.idaobj[i] for i in classes]
					A_	:					Tuple						 =		[self.idaattr[i] for i in attr_classes]
					A_	:					Tuple						 =		[
					    F"""{label} {score:.2f} {attr} {attr_score:.2f}"""
					    for label, score, attr, attr_score in zip(__A   ,  __A   ,  __A   ,  __A							)
					]
					return labels







				def        a_	(				self :       List[Any]   ,  _lowerCamelCase :       Tuple   ,  _lowerCamelCase :       int							):



					"""simple docstring"""

					A_	:					Union[str, Any]						 =		[self.idaobj[i] for i in classes]
					if scores is not None:
						if labels is None:
							A_	:					str						 =		['''{:.0f}%'''.format(s * 1_00							) for s in scores]
						else:
							A_	:					Tuple						 =		['''{} {:.0f}%'''.format(__A   ,  s * 1_00							) for li, s in zip(__A   ,  __A							)]
					return labels







				def        a_	(				self :       str   ,  _lowerCamelCase :       List[Any]=2_55							):



					"""simple docstring"""

					A_	:					Any						 =		np.random.randint(0   ,  len(_COLORS							)							)
					A_	:					str						 =		_COLORS[idx] * maximum
					if not self.rgb:
						A_	:					Optional[int]						 =		ret[::-1]
					return ret







				def        a_	(				self :       List[str]							):



					"""simple docstring"""

					if not self.pynb:
						A_ ,			A_	:					Tuple						 =		self.canvas.print_to_buffer()
						if (width, height) != (self.width, self.height):
							A_	:					List[str]						 =		cva.resize(self.img   ,  (width, height)							)
						else:
							A_	:					int						 =		self.img
					else:
						A_	:					List[Any]						 =		io.BytesIO()  # works for cairo backend
						self.canvas.print_rgba(__A							)
						A_ ,			A_	:					Union[str, Any]						 =		self.width, self.height
						A_	:					int						 =		buf.getvalue()
						A_	:					List[Any]						 =		self.img

					A_	:					Optional[int]						 =		np.frombuffer(__A   ,  dtype='''uint8'''							)
					A_	:					Optional[Any]						 =		buffer.reshape(__A   ,  __A   ,  4							)
					A_ ,			A_	:					Dict						 =		np.split(__A   ,  [3]   ,  axis=2							)

					try:
						import numexpr as ne  # fuse them with numexpr

						A_	:					Tuple						 =		ne.evaluate('''img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)'''							)
					except ImportError:
						A_	:					List[Any]						 =		alpha.astype('''float32'''							) / 255.0
						A_	:					List[str]						 =		img * (1 - alpha) + rgb * alpha

					return visualized_image.astype('''uint8'''							)







				def        a_	(				self :       Optional[Any]   ,  _lowerCamelCase :       int   ,  _lowerCamelCase :       List[str]							):



					"""simple docstring"""

					assert brightness_factor >= -1.0 and brightness_factor <= 1.0
					A_	:					int						 =		mplc.to_rgb(__A							)
					A_	:					Optional[Any]						 =		colorsys.rgb_to_hls(*mplc.to_rgb(__A							)							)
					A_	:					List[str]						 =		polygon_color[1] + (brightness_factor * polygon_color[1])
					A_	:					List[Any]						 =		0.0 if modified_lightness < 0.0 else modified_lightness
					A_	:					Optional[Any]						 =		1.0 if modified_lightness > 1.0 else modified_lightness
					A_	:					Tuple						 =		colorsys.hls_to_rgb(polygon_color[0]   ,  __A   ,  polygon_color[2]							)
					return modified_color
_lowerCamelCase	:      Tuple   =							(
    np.array(
        [
            0.000,
            0.447,
            0.741,
            0.850,
            0.325,
            0.098,
            0.929,
            0.694,
            0.125,
            0.494,
            0.184,
            0.556,
            0.466,
            0.674,
            0.188,
            0.301,
            0.745,
            0.933,
            0.635,
            0.078,
            0.184,
            0.300,
            0.300,
            0.300,
            0.600,
            0.600,
            0.600,
            1.000,
            0.000,
            0.000,
            1.000,
            0.500,
            0.000,
            0.749,
            0.749,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.333,
            0.333,
            0.000,
            0.333,
            0.667,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            0.333,
            0.000,
            0.667,
            0.667,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            1.000,
            0.000,
            0.000,
            0.333,
            0.500,
            0.000,
            0.667,
            0.500,
            0.000,
            1.000,
            0.500,
            0.333,
            0.000,
            0.500,
            0.333,
            0.333,
            0.500,
            0.333,
            0.667,
            0.500,
            0.333,
            1.000,
            0.500,
            0.667,
            0.000,
            0.500,
            0.667,
            0.333,
            0.500,
            0.667,
            0.667,
            0.500,
            0.667,
            1.000,
            0.500,
            1.000,
            0.000,
            0.500,
            1.000,
            0.333,
            0.500,
            1.000,
            0.667,
            0.500,
            1.000,
            1.000,
            0.500,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.333,
            0.333,
            1.000,
            0.333,
            0.667,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.667,
            0.333,
            1.000,
            0.667,
            0.667,
            1.000,
            0.667,
            1.000,
            1.000,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            1.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.143,
            0.143,
            0.143,
            0.857,
            0.857,
            0.857,
            1.000,
            1.000,
            1.000,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)









"""simple docstring"""







from __future__ import annotations

import random
import string






class  __A							:






 """simple docstring"""




 def __init__(						self					,       __A = None		)   ->	None:
     a											=passcode or self.__passcode_creator()
     a											=self.__make_key_list()
     a											=self.__make_shift_key()


 def __str__(						self		)   ->	str:
     return "".join(self.__passcode		)


 def  SCREAMING_SNAKE_CASE				(						self					,       __A		)   ->	list[int]:
     for i in range(1					,       len(__A		)					,       2		):
         iterlist[i] *= -1
     return iterlist


 def  SCREAMING_SNAKE_CASE				(						self		)   ->	list[str]:
     a											=string.ascii_letters + string.digits
     a											=[random.choice(__A		) for _ in range(random.randint(10					,       20		)		)]
     return password


 def  SCREAMING_SNAKE_CASE				(						self		)   ->	list[str]:
     a											=(
         string.ascii_letters + string.digits + string.punctuation + ''' \t\n'''
     )

     a											=[]

     # creates points known as breakpoints to break the key_list_options at those
     # points and pivot each substring
     a											=sorted(set(self.__passcode		)		)
     a											=[]

     # algorithm for creating a new shuffled list, keys_l, out of key_list_options
     for i in key_list_options:
         temp_list.extend(__A		)

         # checking breakpoints at which to pivot temporary sublist and add it into
         # keys_l
         if i in breakpoints or i == key_list_options[-1]:
             keys_l.extend(temp_list[::-1]		)
             temp_list.clear()

        # returning a shuffled keys_l to prevent brute force guessing of shift key
     return keys_l


 def  SCREAMING_SNAKE_CASE				(						self		)   ->	int:
     a											=sum(self.__neg_pos([ord(__A		) for x in self.__passcode]		)		)
     return num if num > 0 else len(self.__passcode		)


 def  SCREAMING_SNAKE_CASE				(						self					,       __A		)   ->	str:
     a											=''''''

     # decoding shift like Caesar cipher algorithm implementing negative shift or
     # reverse shift or left shift
     for i in encoded_message:
         a											=self.__key_list.index(__A		)
         decoded_message += self.__key_list[
             (position - self.__shift_key) % -len(self.__key_list		)
         ]

     return decoded_message





 def  SCREAMING_SNAKE_CASE				(						self					,       __A		)   ->	str:
     a											=''''''

     # encoding shift like Caesar cipher algorithm implementing positive shift or
     # forward shift or right shift
     for i in plaintext:
         a											=self.__key_list.index(__A		)
         encoded_message += self.__key_list[
             (position + self.__shift_key) % len(self.__key_list		)
         ]

     return encoded_message

def _A		(		lowercase = "Hello, this is a modified Caesar cipher"						):







    """simple docstring"""
    a											=ShuffledShiftCipher()
    return cipa.decrypt(cipa.encrypt(lowercase						)						)


if __name__ == "__main__":
       import doctest

       doctest.testmod()