



'''simple docstring'''




import unittest

import numpy as np

from diffusers import LMSDiscreteScheduler, OnnxStableDiffusionInpaintPipeline
from diffusers.utils.testing_utils import (
    is_onnx_available,
    load_image,
    nightly,
    require_onnxruntime,
    require_torch_gpu,
)

from ..test_pipelines_onnx_common import OnnxPipelineTesterMixin


if is_onnx_available():
							import onnxruntime as ort

class     UpperCamelCase_				(							__a   ,  unittest.TestCase    ):
	# FIXME: add fast tests
	pass




@nightly
@require_onnxruntime
@require_torch_gpu
class     UpperCamelCase_				(							unittest.TestCase    ):





	@property
	def 				_lowercase(						self					)    ->    List[Any]:
								return (
								    "CUDAExecutionProvider",
								    {
								        "gpu_mem_limit": "15000000000",  # 15GB
								        "arena_extend_strategy": "kSameAsRequested",
								    },
								)





	@property
	def 				_lowercase(						self					)    ->    Optional[int]:
								UpperCAmelCase  :	int							  =	ort.SessionOptions()
								UpperCAmelCase  :	str							  =	False
								return options





	def 				_lowercase(						self					)    ->    List[str]:
								UpperCAmelCase  :	int							  =	load_image(
								    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
								    """/in_paint/overture-creations-5sI6fQgYIuo.png"""					)
								UpperCAmelCase  :	List[str]							  =	load_image(
								    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
								    """/in_paint/overture-creations-5sI6fQgYIuo_mask.png"""					)
								UpperCAmelCase  :	Dict							  =	OnnxStableDiffusionInpaintPipeline.from_pretrained(
								    """runwayml/stable-diffusion-inpainting"""	,	revision="""onnx"""	,	safety_checker=A__	,	feature_extractor=A__	,	provider=self.gpu_provider	,	sess_options=self.gpu_options	,	)
								pipe.set_progress_bar_config(disable=A__					)

								UpperCAmelCase  :	List[Any]							  =	"""A red cat sitting on a park bench"""

								UpperCAmelCase  :	Tuple							  =	np.random.RandomState(0					)
								UpperCAmelCase  :	List[Any]							  =	pipe(
								    prompt=A__	,	image=A__	,	mask_image=A__	,	guidance_scale=7.5	,	num_inference_steps=10	,	generator=A__	,	output_type="""np"""	,	)
								UpperCAmelCase  :	Tuple							  =	output.images
								UpperCAmelCase  :	Dict							  =	images[0, 255:258, 255:258, -1]

								assert images.shape == (1, 512, 512, 3)
								UpperCAmelCase  :	Optional[Any]							  =	np.array([0.2_5_1_4, 0.3_0_0_7, 0.3_5_1_7, 0.1_7_9_0, 0.2_3_8_2, 0.3_1_6_7, 0.1_9_4_4, 0.2_2_7_3, 0.2_4_6_4]					)

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






	def 				_lowercase(						self					)    ->    int:
								UpperCAmelCase  :	List[Any]							  =	load_image(
								    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
								    """/in_paint/overture-creations-5sI6fQgYIuo.png"""					)
								UpperCAmelCase  :	Optional[int]							  =	load_image(
								    """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
								    """/in_paint/overture-creations-5sI6fQgYIuo_mask.png"""					)
								UpperCAmelCase  :	int							  =	LMSDiscreteScheduler.from_pretrained(
								    """runwayml/stable-diffusion-inpainting"""	,	subfolder="""scheduler"""	,	revision="""onnx"""					)
								UpperCAmelCase  :	Optional[int]							  =	OnnxStableDiffusionInpaintPipeline.from_pretrained(
								    """runwayml/stable-diffusion-inpainting"""	,	revision="""onnx"""	,	scheduler=A__	,	safety_checker=A__	,	feature_extractor=A__	,	provider=self.gpu_provider	,	sess_options=self.gpu_options	,	)
								pipe.set_progress_bar_config(disable=A__					)

								UpperCAmelCase  :	Dict							  =	"""A red cat sitting on a park bench"""

								UpperCAmelCase  :	Optional[int]							  =	np.random.RandomState(0					)
								UpperCAmelCase  :	Optional[Any]							  =	pipe(
								    prompt=A__	,	image=A__	,	mask_image=A__	,	guidance_scale=7.5	,	num_inference_steps=20	,	generator=A__	,	output_type="""np"""	,	)
								UpperCAmelCase  :	Any							  =	output.images
								UpperCAmelCase  :	List[str]							  =	images[0, 255:258, 255:258, -1]

								assert images.shape == (1, 512, 512, 3)
								UpperCAmelCase  :	Any							  =	np.array([0.0_0_8_6, 0.0_0_7_7, 0.0_0_8_3, 0.0_0_9_3, 0.0_1_0_7, 0.0_1_3_9, 0.0_0_9_4, 0.0_0_9_7, 0.0_1_2_5]					)

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






'''simple docstring'''




import math



def    __lowerCamelCase						(      _lowercase	)   ->    bool:
							assert isinstance(_lowercase			,       _lowercase	) and (
							    number >= 0
							), "'number' must been an int and positive"

							if 1 < number < 4:
														# 2 and 3 are primes
														return True
							elif number < 2 or not number % 2:
														# Negatives, 0, 1 and all even numbers are not primes
														return False

							UpperCAmelCase  :	str							  =	range(3			,       int(math.sqrt(_lowercase	) + 1	)			,       2	)
							return not any(not number % i for i in odd_numbers	)



def    __lowerCamelCase						(      _lowercase			,       _lowercase=1			,       **_lowercase	)   ->    Union[str, Any]:
							UpperCAmelCase  :	Optional[int]							  =	factor * value
							UpperCAmelCase  :	List[Any]							  =	value

							while not is_prime(_lowercase	):
														value += 1 if not ("desc" in kwargs and kwargs["desc"] is True) else -1

							if value == first_value_val:
														return next_prime(value + 1			,       **_lowercase	)
							return value

