




import unittest

import numpy as np
import torch

from diffusers import KarrasVePipeline, KarrasVeScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()




class 		__A   (      unittest.TestCase      ):

						@property
						def      A__    (		self :Union[str, Any]			):
										'''simple docstring'''

										torch.manual_seed(0			)
										__magic_name__						:						Tuple										=UNetaDModel(
										    block_out_channels=(32, 64)     ,			layers_per_block=2     ,			sample_size=32     ,			in_channels=3     ,			out_channels=3     ,			down_block_types=("""DownBlock2D""", """AttnDownBlock2D""")     ,			up_block_types=("""AttnUpBlock2D""", """UpBlock2D""")     ,			)
										return model


						def      A__    (		self :Dict			):
										'''simple docstring'''

										__magic_name__						:						Union[str, Any]										=self.dummy_uncond_unet
										__magic_name__						:						Tuple										=KarrasVeScheduler()

										__magic_name__						:						List[str]										=KarrasVePipeline(unet=__snake_case     ,			scheduler=__snake_case			)
										pipe.to(__snake_case			)
										pipe.set_progress_bar_config(disable=__snake_case			)

										__magic_name__						:						str										=torch.manual_seed(0			)
										__magic_name__						:						int										=pipe(num_inference_steps=2     ,			generator=__snake_case     ,			output_type="""numpy"""			).images

										__magic_name__						:						Optional[Any]										=torch.manual_seed(0			)
										__magic_name__						:						Union[str, Any]										=pipe(num_inference_steps=2     ,			generator=__snake_case     ,			output_type="""numpy"""     ,			return_dict=__snake_case			)[0]

										__magic_name__						:						Tuple										=image[0, -3:, -3:, -1]
										__magic_name__						:						List[str]										=image_from_tuple[0, -3:, -3:, -1]

										assert image.shape == (1, 32, 32, 3)
										__magic_name__						:						List[Any]										=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      A__    (		self :Tuple			):
										'''simple docstring'''

										__magic_name__						:						Dict										="""google/ncsnpp-celebahq-256"""
										__magic_name__						:						str										=UNetaDModel.from_pretrained(__snake_case			)
										__magic_name__						:						int										=KarrasVeScheduler()

										__magic_name__						:						List[Any]										=KarrasVePipeline(unet=__snake_case     ,			scheduler=__snake_case			)
										pipe.to(__snake_case			)
										pipe.set_progress_bar_config(disable=__snake_case			)

										__magic_name__						:						List[str]										=torch.manual_seed(0			)
										__magic_name__						:						List[str]										=pipe(num_inference_steps=20     ,			generator=__snake_case     ,			output_type="""numpy"""			).images

										__magic_name__						:						Optional[int]										=image[0, -3:, -3:, -1]
										assert image.shape == (1, 2_56, 2_56, 3)
										__magic_name__						:						str										=np.array([0.578, 0.5811, 0.5924, 0.5809, 0.587, 0.5886, 0.5861, 0.5802, 0.586]			)

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











'''simple docstring'''




from __future__ import annotations





def 	__lowerCamelCase			(      __lowerCAmelCase       :							float      ,    __lowerCAmelCase       :							float      ,    __lowerCAmelCase       :							float		)		->  float:
   if days_between_payments <= 0:
      raise ValueError("""days_between_payments must be > 0"""		)
   if daily_interest_rate < 0:
      raise ValueError("""daily_interest_rate must be >= 0"""		)
   if principal <= 0:
      raise ValueError("""principal must be > 0"""		)
   return principal * daily_interest_rate * days_between_payments





def 	__lowerCamelCase			(      __lowerCAmelCase       :							float      ,    __lowerCAmelCase       :							float      ,    __lowerCAmelCase       :							float      ,    )		->  float:
   if number_of_compounding_periods <= 0:
      raise ValueError("""number_of_compounding_periods must be > 0"""		)
   if nominal_annual_interest_rate_percentage < 0:
      raise ValueError("""nominal_annual_interest_rate_percentage must be >= 0"""		)
   if principal <= 0:
      raise ValueError("""principal must be > 0"""		)

   return principal * (
       (1 + nominal_annual_interest_rate_percentage) ** number_of_compounding_periods
       - 1
   )





def 	__lowerCamelCase			(      __lowerCAmelCase       :							float      ,    __lowerCAmelCase       :							float      ,    __lowerCAmelCase       :							float      ,    )		->  float:
   if number_of_years <= 0:
      raise ValueError("""number_of_years must be > 0"""		)
   if nominal_annual_percentage_rate < 0:
      raise ValueError("""nominal_annual_percentage_rate must be >= 0"""		)
   if principal <= 0:
      raise ValueError("""principal must be > 0"""		)

   return compound_interest(
       __lowerCAmelCase      ,    nominal_annual_percentage_rate / 3_65      ,    number_of_years * 3_65		)


if __name__ == "__main__":
 import doctest

 doctest.testmod()

