



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


__magic_name__       =     1000


class 	a__       :


					"""simple docstring"""



					def __init__(		self     :Dict      ,  lowercase__     :Any      ,  lowercase__     :List[Any]=1.2      ,  lowercase__     :List[str]="g"      ,  lowercase__     :Optional[int]=0.5      ,  lowercase__     :Optional[Any]="-"      ,  lowercase__     :int="test_out.jpg"      ,  lowercase__     :Dict=True      ,  lowercase__     :List[Any]=False      ,  lowercase__     :Dict=None      ,  lowercase__     :str=None      ,  lowercase__     :List[Any]=0.7      ,  ):
										if isinstance(lowercase__      ,  torch.Tensor    ):
															lowercase						   =       img.numpy().astype('np.uint8'    )
										if isinstance(lowercase__      ,  lowercase__    ):
															lowercase						   =       img_tensorize(lowercase__    )
										assert isinstance(lowercase__      ,  np.ndarray    )

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

										lowercase						   =       saveas
										lowercase						   =       rgb
										lowercase						   =       pynb
										lowercase						   =       img
										lowercase						   =       edgecolor
										lowercase						   =       0.5
										lowercase						   =       linestyle
										lowercase						   =       int(np.sqrt(min(lowercase__      ,  lowercase__    )    ) * scale // 3    )
										lowercase						   =       width
										lowercase						   =       height
										lowercase						   =       scale
										lowercase						   =       fig
										lowercase						   =       ax
										lowercase						   =       pad
										lowercase						   =       idaobj
										lowercase						   =       idaattr
										lowercase						   =       FigureCanvasAgg(lowercase__    )

					def 				__UpperCAmelCase		(		self     :int      ,  lowercase__     :int      ,  lowercase__     :Any=None    ):
										if color is None:
															lowercase						   =       self.edgecolor
										((lowercase)   ,      (lowercase)   ,      (lowercase)   ,      (lowercase))						   =       box
										lowercase						   =       xa - xa
										lowercase						   =       ya - ya
										self.ax.add_patch(
										    mpl.patches.Rectangle(
										        (xa, ya)      ,  lowercase__      ,  lowercase__      ,  fill=lowercase__      ,  edgecolor=lowercase__      ,  linewidth=self.font_size // 3      ,  alpha=self.alpha      ,  linestyle=self.linestyle      ,  )    )

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

										lowercase						   =       [self._random_color(maximum=1    ) for _ in range(len(lowercase__    )    )]
										lowercase						   =       [assigned_colors[idx] for idx in sorted_idxs]
										if obj_ids is not None:
															lowercase						   =       self._create_text_labels_attr(lowercase__      ,  lowercase__      ,  lowercase__      ,  lowercase__    )
															for i in range(len(lowercase__    )    ):
																				lowercase						   =       assigned_colors[i]
																				self.add_box(boxes[i]      ,  lowercase__    )
																				self.draw_labels(labels[i]      ,  boxes[i]      ,  lowercase__    )

					def 				__UpperCAmelCase		(		self     :int      ,  lowercase__     :Tuple      ,  lowercase__     :Optional[int]      ,  lowercase__     :Tuple    ):
										lowercase   ,      lowercase   ,      lowercase   ,      lowercase						   =       box
										lowercase						   =       (xa, ya)
										lowercase						   =       (ya - ya) * (xa - xa)
										lowercase						   =       _SMALL_OBJ * self.scale
										if instance_area < small or ya - ya < 40 * self.scale:
															if ya >= self.height - 5:
																				lowercase						   =       (xa, ya)
															else:
																				lowercase						   =       (xa, ya)

										lowercase						   =       (ya - ya) / np.sqrt(self.height * self.width    )
										lowercase						   =       self._change_color_brightness(lowercase__      ,  brightness_factor=0.7    )
										lowercase						   =       np.clip((height_ratio - 0.02) / 0.08 + 1      ,  1.2      ,  2    )
										font_size *= 0.75 * self.font_size

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

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

					def 				__UpperCAmelCase		(		self     :List[str]      ,  lowercase__     :Tuple=None    ):
										if saveas is None:
															lowercase						   =       self.saveas
										if saveas.lower().endswith('.jpg'    ) or saveas.lower().endswith('.png'    ):
															cva.imwrite(
															    lowercase__      ,  self._get_buffer()[:, :, ::-1]      ,  )
										else:
															self.fig.savefig(lowercase__    )

					def 				__UpperCAmelCase		(		self     :str      ,  lowercase__     :Tuple      ,  lowercase__     :Union[str, Any]      ,  lowercase__     :str      ,  lowercase__     :int    ):
										lowercase						   =       [self.idaobj[i] for i in classes]
										lowercase						   =       [self.idaattr[i] for i in attr_classes]
										lowercase						   =       [
										    F"""{label} {score:.2f} {attr} {attr_score:.2f}"""
										    for label, score, attr, attr_score in zip(lowercase__      ,  lowercase__      ,  lowercase__      ,  lowercase__    )
										]
										return labels

					def 				__UpperCAmelCase		(		self     :List[str]      ,  lowercase__     :List[str]      ,  lowercase__     :Any    ):
										lowercase						   =       [self.idaobj[i] for i in classes]
										if scores is not None:
															if labels is None:
																				lowercase						   =       ['{:.0f}%'.format(s * 100    ) for s in scores]
															else:
																				lowercase						   =       ['{} {:.0f}%'.format(lowercase__      ,  s * 100    ) for li, s in zip(lowercase__      ,  lowercase__    )]
										return labels

					def 				__UpperCAmelCase		(		self     :Union[str, Any]      ,  lowercase__     :Any=255    ):
										lowercase						   =       np.random.randint(0      ,  len(_COLORS    )    )
										lowercase						   =       _COLORS[idx] * maximum
										if not self.rgb:
															lowercase						   =       ret[::-1]
										return ret

					def 				__UpperCAmelCase		(		self     :Tuple    ):
										if not self.pynb:
															lowercase   ,      lowercase						   =       self.canvas.print_to_buffer()
															if (width, height) != (self.width, self.height):
																				lowercase						   =       cva.resize(self.img      ,  (width, height)    )
															else:
																				lowercase						   =       self.img
										else:
															lowercase						   =       io.BytesIO()  # works for cairo backend
															self.canvas.print_rgba(lowercase__    )
															lowercase   ,      lowercase						   =       self.width, self.height
															lowercase						   =       buf.getvalue()
															lowercase						   =       self.img

										lowercase						   =       np.frombuffer(lowercase__      ,  dtype='uint8'    )
										lowercase						   =       buffer.reshape(lowercase__      ,  lowercase__      ,  4    )
										lowercase   ,      lowercase						   =       np.split(lowercase__      ,  [3]      ,  axis=2    )

										try:
															import numexpr as ne  # fuse them with numexpr

															lowercase						   =       ne.evaluate('img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)'    )
										except ImportError:
															lowercase						   =       alpha.astype('float32'    ) / 255.0
															lowercase						   =       img * (1 - alpha) + rgb * alpha

										return visualized_image.astype('uint8'    )



					def 				__UpperCAmelCase		(		self     :str      ,  lowercase__     :List[Any]      ,  lowercase__     :List[str]    ):
										assert brightness_factor >= -1.0 and brightness_factor <= 1.0
										lowercase						   =       mplc.to_rgb(lowercase__    )
										lowercase						   =       colorsys.rgb_to_hls(*mplc.to_rgb(lowercase__    )    )
										lowercase						   =       polygon_color[1] + (brightness_factor * polygon_color[1])
										lowercase						   =       0.0 if modified_lightness < 0.0 else modified_lightness
										lowercase						   =       1.0 if modified_lightness > 1.0 else modified_lightness
										lowercase						   =       colorsys.hls_to_rgb(polygon_color[0]      ,  lowercase__      ,  polygon_color[2]    )
										return modified_color




__magic_name__       =     (
    np.array(
        [
            0.0_0_0,
            0.4_4_7,
            0.7_4_1,
            0.8_5_0,
            0.3_2_5,
            0.0_9_8,
            0.9_2_9,
            0.6_9_4,
            0.1_2_5,
            0.4_9_4,
            0.1_8_4,
            0.5_5_6,
            0.4_6_6,
            0.6_7_4,
            0.1_8_8,
            0.3_0_1,
            0.7_4_5,
            0.9_3_3,
            0.6_3_5,
            0.0_7_8,
            0.1_8_4,
            0.3_0_0,
            0.3_0_0,
            0.3_0_0,
            0.6_0_0,
            0.6_0_0,
            0.6_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.7_4_9,
            0.7_4_9,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.3_3_3,
            0.0_0_0,
            0.3_3_3,
            0.6_6_7,
            0.0_0_0,
            0.3_3_3,
            1.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.3_3_3,
            0.0_0_0,
            0.6_6_7,
            0.6_6_7,
            0.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.5_0_0,
            0.0_0_0,
            0.6_6_7,
            0.5_0_0,
            0.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.3_3_3,
            0.0_0_0,
            0.5_0_0,
            0.3_3_3,
            0.3_3_3,
            0.5_0_0,
            0.3_3_3,
            0.6_6_7,
            0.5_0_0,
            0.3_3_3,
            1.0_0_0,
            0.5_0_0,
            0.6_6_7,
            0.0_0_0,
            0.5_0_0,
            0.6_6_7,
            0.3_3_3,
            0.5_0_0,
            0.6_6_7,
            0.6_6_7,
            0.5_0_0,
            0.6_6_7,
            1.0_0_0,
            0.5_0_0,
            1.0_0_0,
            0.0_0_0,
            0.5_0_0,
            1.0_0_0,
            0.3_3_3,
            0.5_0_0,
            1.0_0_0,
            0.6_6_7,
            0.5_0_0,
            1.0_0_0,
            1.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.3_3_3,
            1.0_0_0,
            0.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            1.0_0_0,
            0.3_3_3,
            0.3_3_3,
            1.0_0_0,
            0.3_3_3,
            0.6_6_7,
            1.0_0_0,
            0.3_3_3,
            1.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.0_0_0,
            1.0_0_0,
            0.6_6_7,
            0.3_3_3,
            1.0_0_0,
            0.6_6_7,
            0.6_6_7,
            1.0_0_0,
            0.6_6_7,
            1.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.0_0_0,
            1.0_0_0,
            1.0_0_0,
            0.3_3_3,
            1.0_0_0,
            1.0_0_0,
            0.6_6_7,
            1.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_6_7,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_6_7,
            0.0_0_0,
            0.0_0_0,
            0.3_3_3,
            0.0_0_0,
            0.0_0_0,
            0.5_0_0,
            0.0_0_0,
            0.0_0_0,
            0.6_6_7,
            0.0_0_0,
            0.0_0_0,
            0.8_3_3,
            0.0_0_0,
            0.0_0_0,
            1.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.0_0_0,
            0.1_4_3,
            0.1_4_3,
            0.1_4_3,
            0.8_5_7,
            0.8_5_7,
            0.8_5_7,
            1.0_0_0,
            1.0_0_0,
            1.0_0_0,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)











from collections.abc import Callable

__magic_name__       =     Callable[[float], float]  # type alias for a real -> real function





def 		__snake_case						(    _UpperCAmelCase       ,			_UpperCAmelCase       ,			_UpperCAmelCase       ,			):
					"""simple docstring"""






					lowercase						   =       float(_UpperCAmelCase				)
					while True:
										try:
															lowercase						   =       prev_guess - function(_UpperCAmelCase				) / derivative(_UpperCAmelCase				)
										except ZeroDivisionError:
															raise ZeroDivisionError('Could not find root'				) from None
										if abs(prev_guess - next_guess				) < 10**-5:
															return next_guess
										lowercase						   =       next_guess





def 		__snake_case						(    _UpperCAmelCase				):
					"""simple docstring"""






					return (x**3) - (2 * x) - 5





def 		__snake_case						(    _UpperCAmelCase				):
					"""simple docstring"""






					return 3 * (x**2) - 2


if __name__ == "__main__":
		print(newton(f, fa, 3))






