




'''simple docstring'''

from collections.abc import Callable


def __UpperCAmelCase	(   _UpperCAmelCase		:   Callable[[float], float]		,				_UpperCAmelCase		:   float		,				_UpperCAmelCase		:   float						)      ->      float:
			__snake_case			=		a
			__snake_case			=		b
			if function(_UpperCAmelCase						) == 0:  # one of the a or b is a root for the function
						return a
			elif function(_UpperCAmelCase						) == 0:
						return b
			elif (
			    function(_UpperCAmelCase						) * function(_UpperCAmelCase						) > 0
			):  # if none of these are root and they are both positive or negative,
						# then this algorithm can't find the root
						raise ValueError("could not find root in given interval."						)
			else:
						__snake_case			=		start + (end - start) / 2.0
						while abs(start - mid						) > 10**-7:  # until precisely equals to 10^-7
									if function(_UpperCAmelCase						) == 0:
												return mid
									elif function(_UpperCAmelCase						) * function(_UpperCAmelCase						) < 0:
												__snake_case			=		mid
									else:
												__snake_case			=		mid
									__snake_case			=		start + (end - start) / 2.0
						return mid


def __UpperCAmelCase	(   _UpperCAmelCase		:   float						)      ->      float:
			return x**3 - 2 * x - 5


if __name__ == "__main__":
						print(bisection(f, 1, 1_000))

						import doctest

						doctest.testmod()








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 ):
			'''simple docstring'''







			pass






@nightly
@require_onnxruntime
@require_torch_gpu
class _UpperCamelCase				(				unittest.TestCase ):
			'''simple docstring'''







			@property
			def 				__UpperCamelCase			(      self				:			List[Any]						)				->							List[str]:

				"""simple docstring"""

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

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							ort.SessionOptions()
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							False
				return options
			def 				__UpperCamelCase			(      self				:			List[Any]						)				->							List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   Any					  =							load_image(
				    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
				    "/in_paint/overture-creations-5sI6fQgYIuo.png"						)
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							load_image(
				    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
				    "/in_paint/overture-creations-5sI6fQgYIuo_mask.png"						)
				SCREAMING_SNAKE_CASE :   int					  =							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						)

				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							"A red cat sitting on a park bench"

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

				assert images.shape == (1, 512, 512, 3)
				SCREAMING_SNAKE_CASE :   int					  =							np.array([0.2514, 0.3007, 0.3517, 0.1790, 0.2382, 0.3167, 0.1944, 0.2273, 0.2464]						)

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






			def 				__UpperCamelCase			(      self				:			List[Any]						)				->							Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE :   int					  =							load_image(
				    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
				    "/in_paint/overture-creations-5sI6fQgYIuo.png"						)
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							load_image(
				    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
				    "/in_paint/overture-creations-5sI6fQgYIuo_mask.png"						)
				SCREAMING_SNAKE_CASE :   Optional[Any]					  =							LMSDiscreteScheduler.from_pretrained(
				    "runwayml/stable-diffusion-inpainting"   ,   subfolder="scheduler"   ,   revision="onnx"						)
				SCREAMING_SNAKE_CASE :   Union[str, Any]					  =							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						)

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

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

				assert images.shape == (1, 512, 512, 3)
				SCREAMING_SNAKE_CASE :   Any					  =							np.array([0.0086, 0.0077, 0.0083, 0.0093, 0.0107, 0.0139, 0.0094, 0.0097, 0.0125]						)

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