




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     a  (     _A			,     _A    ):

     '''simple docstring'''





     def __init__(			self     :    str       ):
         super().__init__()

         self.register_buffer('''watermark_image'''      ,					torch.zeros((62, 62, 4)       )       )
         UpperCAmelCase_											=  None




     def 						lowerCamelCase_     (			self     :    List[str]      ,					__snake_case     :    List[PIL.Image.Image]      ,					__snake_case     :    List[Any]=None       ):
         # copied from https://github.com/deep-floyd/IF/blob/b77482e36ca2031cb94dbca1001fc1e6400bf4ab/deepfloyd_if/modules/base.py#L287

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

         UpperCAmelCase_											=  sample_size or h

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

         UpperCAmelCase_				,							UpperCAmelCase_											=  10_24**2, img_w * img_h
         UpperCAmelCase_											=  (Sa / Sa) ** 0.5
         UpperCAmelCase_				,							UpperCAmelCase_				,							UpperCAmelCase_											=  int(K * 62       ), img_w - int(14 * K       ), img_h - int(14 * K       )

         if self.watermark_image_as_pil is None:
             UpperCAmelCase_											=  self.watermark_image.to(torch.uinta       ).cpu().numpy()
             UpperCAmelCase_											=  Image.fromarray(__snake_case      ,					mode='''RGBA'''       )
             UpperCAmelCase_											=  watermark_image

         UpperCAmelCase_											=  self.watermark_image_as_pil.resize(
             (wm_size, wm_size)      ,					PIL_INTERPOLATION['''bicubic''']      ,					reducing_gap=__snake_case       )

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

         return images











_lowerCamelCase    				=		10_00




def       SCREAMING_SNAKE_CASE			( __UpperCamelCase    :		float   )						->							float:
    return x * x




def       SCREAMING_SNAKE_CASE			( __UpperCamelCase    :		Optional[int] ,  __UpperCamelCase    :		float ,  __UpperCamelCase    :		float ,  __UpperCamelCase    :		int = 4   )						->							float:
    assert callable(
        __UpperCamelCase   ), f'the function(object) passed should be callable your input : {function}'
    assert isinstance(__UpperCamelCase ,  (float, int)   ), f'a should be float or integer your input : {a}'
    assert isinstance(function(__UpperCamelCase   ) ,  (float, int)   ), (
        "the function should return integer or float return type of your function, "
        f'{type(__UpperCamelCase   )}'
    )
    assert isinstance(__UpperCamelCase ,  (float, int)   ), f'b should be float or integer your input : {b}'
    assert (
        isinstance(__UpperCamelCase ,  __UpperCamelCase   ) and precision > 0
    ), f'precision should be positive integer your input : {precision}'

    # just applying the formula of simpson for approximate integration written in
    # mentioned article in first comment of this file and above this function

    UpperCAmelCase_											=  (b - a) / N_STEPS
    UpperCAmelCase_											=  function(__UpperCamelCase   ) + function(__UpperCamelCase   )

    for i in range(1 ,  __UpperCamelCase   ):
        UpperCAmelCase_											=  a + h * i
        result += function(__UpperCamelCase   ) * (4 if i % 2 else 2)

    result *= h / 3
    return round(__UpperCamelCase ,  __UpperCamelCase   )


if __name__ == "__main__":
 import doctest

 doctest.testmod()





