
'''simple docstring'''
from typing import List, Optional, Tuple, Union

import torch

from ...models import UNetaDModel
from ...schedulers import PNDMScheduler
from ...utils import randn_tensor
from ..pipeline_utils import DiffusionPipeline, ImagePipelineOutput






class 				UpperCAmelCase_			(		snake_case__   ):
 UpperCAmelCase_						      =  42
 UpperCAmelCase_						      =  42





 def __init__(      self	,    lowercase_	,    lowercase_):
     super().__init__()

     snake_case_	:      List[str]            =  PNDMScheduler.from_config(scheduler.config)

     self.register_modules(unet=lowercase__	,    scheduler=lowercase__)





 @torch.no_grad()
 def __call__(      self	,    lowercase_ = 1	,    lowercase_ = 50	,    lowercase_ = None	,    lowercase_ = "pil"	,    lowercase_ = True	,    **lowercase_	,    ):
     snake_case_	:      Union[str, Any]            =  randn_tensor(
         (batch_size, self.unet.config.in_channels, self.unet.config.sample_size, self.unet.config.sample_size)	,    generator=lowercase__	,    device=self.device	,    )

     self.scheduler.set_timesteps(lowercase__)
     for t in self.progress_bar(self.scheduler.timesteps):
         snake_case_	:      Union[str, Any]            =  self.unet(lowercase__	,    lowercase__).sample

         snake_case_	:      Dict            =  self.scheduler.step(lowercase__	,    lowercase__	,    lowercase__).prev_sample

     snake_case_	:      Union[str, Any]            =  (image / 2 + 0.5).clamp(0	,    1)
     snake_case_	:      List[str]            =  image.cpu().permute(0	,    2	,    3	,    1).numpy()
     if output_type == "pil":
         snake_case_	:      Any            =  self.numpy_to_pil(lowercase__)

     if not return_dict:
         return (image,)

     return ImagePipelineOutput(images=lowercase__)






'''simple docstring'''
from math import exp

def   UpperCamelCase_       (		__SCREAMING_SNAKE_CASE    ):
    """simple docstring"""






    return 8 * x - 2 * exp(-x    )

def   UpperCamelCase_       (		__SCREAMING_SNAKE_CASE,						__SCREAMING_SNAKE_CASE,						__SCREAMING_SNAKE_CASE    ):
    """simple docstring"""






    snake_case_	:      Optional[Any]            =  lower_bound
    snake_case_	:      int            =  upper_bound
    for _ in range(0,						__SCREAMING_SNAKE_CASE    ):
        snake_case_     ,	snake_case_	:      List[str]            =  xa, xa - (f(__SCREAMING_SNAKE_CASE    ) * (xa - xa)) / (f(__SCREAMING_SNAKE_CASE    ) - f(__SCREAMING_SNAKE_CASE    ))
    return xa


if __name__ == "__main__":
  print(f"""Example: {secant_method(1, 3, 2)}""")




