






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 							lowerCAmelCase__  (	unittest.TestCase						):







					@property
					def  _lowercase			(       self      :     Any):
											torch.manual_seed(0)
											A__	:							Dict						    = 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  _lowercase			(       self      :     List[Any]):
											A__	:							Tuple						    = self.dummy_uncond_unet
											A__	:							Any						    = ScoreSdeVeScheduler()

											A__	:							Optional[Any]						    = ScoreSdeVePipeline(unet=A_			,		scheduler=A_)
											sde_ve.to(A_)
											sde_ve.set_progress_bar_config(disable=A_)

											A__	:							Tuple						    = torch.manual_seed(0)
											A__	:							List[str]						    = sde_ve(num_inference_steps=2			,		output_type="numpy"			,		generator=A_).images

											A__	:							int						    = torch.manual_seed(0)
											A__	:							List[str]						    = sde_ve(num_inference_steps=2			,		output_type="numpy"			,		generator=A_			,		return_dict=A_)[
											    0
											]

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

											assert image.shape == (1, 32, 32, 3)
											A__	:							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 							lowerCAmelCase__  (	unittest.TestCase						):







					def  _lowercase			(       self      :     Union[str, Any]):
											A__	:							str						    = "google/ncsnpp-church-256"
											A__	:							str						    = UNetaDModel.from_pretrained(A_)

											A__	:							Union[str, Any]						    = ScoreSdeVeScheduler.from_pretrained(A_)

											A__	:							List[str]						    = ScoreSdeVePipeline(unet=A_			,		scheduler=A_)
											sde_ve.to(A_)
											sde_ve.set_progress_bar_config(disable=A_)

											A__	:							Tuple						    = torch.manual_seed(0)
											A__	:							int						    = sde_ve(num_inference_steps=10			,		output_type="numpy"			,		generator=A_).images

											A__	:							Dict						    = image[0, -3:, -3:, -1]

											assert image.shape == (1, 256, 256, 3)

											A__	:							Tuple						    = 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




from collections.abc import Callable

import numpy as np
def 	snake_case__       (					__lowercase							,     __lowercase							,     __lowercase							,     __lowercase							,     __lowercase       )		->		np.array:







						"""simple docstring"""

						A__	:							Any						    = int(np.ceil((x_end - xa) / step_size       )       )
						A__	:							Union[str, Any]						    = np.zeros((n + 1,)       )
						A__	:							Any						    = ya
						A__	:							Union[str, Any]						    = xa

						for k in range(__lowercase       ):
												A__	:							Any						    = y[k] + step_size * ode_func(__lowercase							,     y[k]       )
												A__	:							Any						    = y[k] + (
												    (step_size / 2) * (ode_func(__lowercase							,     y[k]       ) + ode_func(x + step_size							,     __lowercase       ))
												)
												x += step_size

						return y


if __name__ == "__main__":
		import doctest

		doctest.testmod()