





"""simple docstring"""




import unittest

import numpy as np
import torch

from diffusers import ScoreSdeVePipeline, ScoreSdeVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()




class 			_a						(				unittest.TestCase    ):






				@property
				def     snake_case     (			self		:   Optional[int]							)     ->				List[str]:




										'''simple docstring'''



										torch.manual_seed(0							)
										_UpperCamelCase      : int         =   UNetaDModel(
										    block_out_channels=(3_2, 6_4),			layers_per_block=2,			sample_size=3_2,			in_channels=3,			out_channels=3,			down_block_types=('''DownBlock2D''', '''AttnDownBlock2D'''),			up_block_types=('''AttnUpBlock2D''', '''UpBlock2D'''),			)
										return model






				def     snake_case     (			self		:   str							)     ->				Tuple:




										'''simple docstring'''



										_UpperCamelCase      : Union[str, Any]         =   self.dummy_uncond_unet
										_UpperCamelCase      : Optional[Any]         =   ScoreSdeVeScheduler()

										_UpperCamelCase      : Dict         =   ScoreSdeVePipeline(unet=lowerCAmelCase__,			scheduler=lowerCAmelCase__							)
										sde_ve.to(lowerCAmelCase__							)
										sde_ve.set_progress_bar_config(disable=lowerCAmelCase__							)

										_UpperCamelCase      : List[str]         =   torch.manual_seed(0							)
										_UpperCamelCase      : Tuple         =   sde_ve(num_inference_steps=2,			output_type='''numpy''',			generator=lowerCAmelCase__							).images

										_UpperCamelCase      : Dict         =   torch.manual_seed(0							)
										_UpperCamelCase      : List[str]         =   sde_ve(num_inference_steps=2,			output_type='''numpy''',			generator=lowerCAmelCase__,			return_dict=lowerCAmelCase__							)[
										    0
										]

										_UpperCamelCase      : Union[str, Any]         =   image[0, -3:, -3:, -1]
										_UpperCamelCase      : Union[str, Any]         =   image_from_tuple[0, -3:, -3:, -1]

										assert image.shape == (1, 3_2, 3_2, 3)
										_UpperCamelCase      : str         =   np.array([0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0]							)

										assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2
										assert np.abs(image_from_tuple_slice.flatten() - expected_slice							).max() < 1e-2




@slow
@require_torch
class 			_a						(				unittest.TestCase    ):






				def     snake_case     (			self		:   str							)     ->				Dict:




										'''simple docstring'''



										_UpperCamelCase      : int         =   '''google/ncsnpp-church-256'''
										_UpperCamelCase      : List[Any]         =   UNetaDModel.from_pretrained(lowerCAmelCase__							)

										_UpperCamelCase      : str         =   ScoreSdeVeScheduler.from_pretrained(lowerCAmelCase__							)

										_UpperCamelCase      : str         =   ScoreSdeVePipeline(unet=lowerCAmelCase__,			scheduler=lowerCAmelCase__							)
										sde_ve.to(lowerCAmelCase__							)
										sde_ve.set_progress_bar_config(disable=lowerCAmelCase__							)

										_UpperCamelCase      : Dict         =   torch.manual_seed(0							)
										_UpperCamelCase      : List[str]         =   sde_ve(num_inference_steps=1_0,			output_type='''numpy''',			generator=lowerCAmelCase__							).images

										_UpperCamelCase      : List[Any]         =   image[0, -3:, -3:, -1]

										assert image.shape == (1, 2_5_6, 2_5_6, 3)

										_UpperCamelCase      : Optional[Any]         =   np.array([0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0]							)

										assert np.abs(image_slice.flatten() - expected_slice							).max() < 1e-2










"""simple docstring"""




def 	a_    (							_lowercase	,						_lowercase       ):
						if discount_rate < 0:
												raise ValueError('''Discount rate cannot be negative'''       )
						if not cash_flows:
												raise ValueError('''Cash flows list cannot be empty'''       )
						_UpperCamelCase      : Optional[int]         =   sum(
						    cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(_lowercase       )       )
						return round(_lowercase	,						ndigits=2       )


if __name__ == "__main__":
						import doctest

						doctest.testmod()



