





from typing import List

import PIL
import torch
from PIL import Image

from ...configuration_utils import ConfigMixin
from ...models.modeling_utils import ModelMixin
from ...utils import PIL_INTERPOLATION

class 						UpperCamelCase__					( __UpperCAmelCase				, __UpperCAmelCase  ):



     '''simple docstring'''

     def __init__(				self		:       Tuple			)	->						Tuple:




           '''simple docstring'''


           super().__init__()

           self.register_buffer("""watermark_image"""		,torch.zeros((62, 62, 4)			)			)
           SCREAMING_SNAKE_CASE						=		None






     def 							SCREAMING_SNAKE_CASE__    (				self		:       Union[str, Any]		,lowerCamelCase__		:       List[PIL.Image.Image]		,lowerCamelCase__		:       Dict=None			)	->						Optional[Any]:




           '''simple docstring'''


           SCREAMING_SNAKE_CASE						=		images[0].height
           SCREAMING_SNAKE_CASE						=		images[0].width

           SCREAMING_SNAKE_CASE						=		sample_size or h

           SCREAMING_SNAKE_CASE						=		min(h / sample_size		,w / sample_size			)
           SCREAMING_SNAKE_CASE						=		(int(h / coef			), int(w / coef			)) if coef < 1 else (h, w)

           SCREAMING_SNAKE_CASE						=		1024**2, img_w * img_h
           SCREAMING_SNAKE_CASE						=		(Sa / Sa) ** 0.5
           SCREAMING_SNAKE_CASE						=		int(K * 62			), img_w - int(14 * K			), img_h - int(14 * K			)

           if self.watermark_image_as_pil is None:
                 SCREAMING_SNAKE_CASE						=		self.watermark_image.to(torch.uinta			).cpu().numpy()
                 SCREAMING_SNAKE_CASE						=		Image.fromarray(_lowerCamelCase		,mode="""RGBA"""			)
                 SCREAMING_SNAKE_CASE						=		watermark_image

           SCREAMING_SNAKE_CASE						=		self.watermark_image_as_pil.resize(
               (wm_size, wm_size)		,PIL_INTERPOLATION["""bicubic"""]		,reducing_gap=_lowerCamelCase			)

           for pil_img in images:
                 pil_img.paste(_lowerCamelCase		,box=(wm_x - wm_size, wm_y - wm_size, wm_x, wm_y)		,mask=wm_img.split()[-1]			)

           return images








"""simple docstring"""

from __future__ import annotations

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase						):




	"""simple docstring"""






	assert (
	    c % greatest_common_divisor(_UpperCAmelCase	,   _UpperCAmelCase						) == 0
	)  # greatest_common_divisor(a,b) function implemented below
	((A_) ,			(A_) ,			(A_))	:					List[Any]						 =		extended_gcd(_UpperCAmelCase	,   _UpperCAmelCase						)  # extended_gcd(a,b) function implemented below
	A_	:					int						 =		c / d
	return (r * x, r * y)

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase = 2						):




	"""simple docstring"""






	((A_) ,			(A_))	:					Any						 =		diophantine(_UpperCAmelCase	,   _UpperCAmelCase	,   _UpperCAmelCase						)  # Initial value
	A_	:					Union[str, Any]						 =		greatest_common_divisor(_UpperCAmelCase	,   _UpperCAmelCase						)
	A_	:					List[str]						 =		a // d
	A_	:					str						 =		b // d

	for i in range(_UpperCAmelCase						):
		A_	:					int						 =		xa + i * q
		A_	:					str						 =		ya - i * p
		print(_UpperCAmelCase	,   _UpperCAmelCase						)

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase						):




	"""simple docstring"""






	if a < b:
		A_ ,			A_	:					Tuple						 =		b, a

	while a % b != 0:
		A_ ,			A_	:					int						 =		b, a % b

	return b

def 		lowercase_   (		_UpperCAmelCase	,   _UpperCAmelCase						):




	"""simple docstring"""






	assert a >= 0 and b >= 0

	if b == 0:
		A_ ,			A_ ,			A_	:					str						 =		a, 1, 0
	else:
		((A_) ,			(A_) ,			(A_))	:					List[str]						 =		extended_gcd(_UpperCAmelCase	,   a % b						)
		A_	:					Optional[int]						 =		q
		A_	:					Tuple						 =		p - q * (a // b)

	assert a % d == 0 and b % d == 0
	assert d == a * x + b * y

	return (d, x, y)


if __name__ == "__main__":
		from doctest import testmod

		testmod(name='diophantine', verbose=True)
		testmod(name='diophantine_all_soln', verbose=True)
		testmod(name='extended_gcd', verbose=True)
		testmod(name='greatest_common_divisor', verbose=True)





