


'''simple docstring'''







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 		_snake_case    (				__lowerCamelCase  ,  __lowerCamelCase		):






						'''simple docstring'''







						def __init__(  self:	Optional[Any]     )							->	Any:
										super().__init__()

										self.register_buffer("watermark_image"      ,							torch.zeros((62, 62, 4)     )     )
										__magic_name__				:					List[Any]						       =       None







						def lowerCAmelCase__ (  self:	Tuple      ,							__UpperCamelCase:	Optional[Any]      ,							__UpperCamelCase:	Optional[Any]=None     )							->	Dict:
										# copied from https://github.com/deep-floyd/IF/blob/b77482e36ca2031cb94dbca1001fc1e6400bf4ab/deepfloyd_if/modules/base.py#L287

										__magic_name__				:					Union[str, Any]						       =       images[0].height
										__magic_name__				:					Optional[Any]						       =       images[0].width

										__magic_name__				:					int						       =       sample_size or h

										__magic_name__				:					str						       =       min(h / sample_size      ,							w / sample_size     )
										__magic_name__				:					Union[str, Any]						       =       (int(h / coef     ), int(w / coef     )) if coef < 1 else (h, w)

										__magic_name__				:					Union[str, Any]						       =       1024**2, img_w * img_h
										__magic_name__				:					int						       =       (Sa / Sa) ** 0.5
										__magic_name__				:					Optional[Any]						       =       int(K * 62     ), img_w - int(14 * K     ), img_h - int(14 * K     )

										if self.watermark_image_as_pil is None:
														__magic_name__				:					Optional[Any]						       =       self.watermark_image.to(torch.uinta     ).cpu().numpy()
														__magic_name__				:					str						       =       Image.fromarray(_lowerCAmelCase      ,							mode="RGBA"     )
														__magic_name__				:					List[Any]						       =       watermark_image

										__magic_name__				:					Tuple						       =       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'''







def 						_UpperCamelCase							( UpperCamelCase__		):






				"""simple docstring"""



				if not isinstance(UpperCamelCase__     ,   UpperCamelCase__		) or number < 0:
								raise ValueError("Input must be a non-negative integer"		)

				__magic_name__				:					str						       =       number & ~(number - 1)
				__magic_name__				:					Optional[int]						       =       0
				while intermediate:
								intermediate >>= 1
								index += 1
				return index - 1


if __name__ == "__main__":
		import doctest

		doctest.testmod(verbose=True)