



"""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    _lowerCAmelCase    (				SCREAMING_SNAKE_CASE__  ,				unittest.TestCase		):





		"""simple docstring"""






		pass




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





		"""simple docstring"""






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







								'''simple docstring'''

								return (
								    "CUDAExecutionProvider",
								    {
								        "gpu_mem_limit": "15000000000",  # 15GB
								        "arena_extend_strategy": "kSameAsRequested",
								    },
								)





		@property
		def    UpperCAmelCase__							(					self   ) ->						Optional[Any]:







								'''simple docstring'''

								snake_case_   : Optional[int]						=			ort.SessionOptions()
								snake_case_   : List[str]						=			False
								return options





		def    UpperCAmelCase__							(					self   ) ->						Optional[Any]:







								'''simple docstring'''

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

								snake_case_   : Optional[int]						=			"""A red cat sitting on a park bench"""

								snake_case_   : Optional[Any]						=			np.random.RandomState(0   )
								snake_case_   : Tuple						=			pipe(
								    prompt=_lowercase							,    image=_lowercase							,    mask_image=_lowercase							,    guidance_scale=7.5							,    num_inference_steps=1_0							,    generator=_lowercase							,    output_type="""np"""							,    )
								snake_case_   : str						=			output.images
								snake_case_   : Any						=			images[0, 2_5_5:2_5_8, 2_5_5:2_5_8, -1]

								assert images.shape == (1, 5_1_2, 5_1_2, 3)
								snake_case_   : Any						=			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   ) ->						Any:







								'''simple docstring'''

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

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

								snake_case_   : List[Any]						=			np.random.RandomState(0   )
								snake_case_   : List[Any]						=			pipe(
								    prompt=_lowercase							,    image=_lowercase							,    mask_image=_lowercase							,    guidance_scale=7.5							,    num_inference_steps=2_0							,    generator=_lowercase							,    output_type="""np"""							,    )
								snake_case_   : Tuple						=			output.images
								snake_case_   : int						=			images[0, 2_5_5:2_5_8, 2_5_5:2_5_8, -1]

								assert images.shape == (1, 5_1_2, 5_1_2, 3)
								snake_case_   : Optional[int]						=			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






"""simple docstring"""





def 	__lowerCAmelCase						(		__UpperCamelCase      :			int					, __UpperCamelCase      :			int    ):


						'''simple docstring'''






						snake_case_   : Any						=			1  # To kept the Calculated Value
						# Since C(n, k) = C(n, n-k)
						if k > (n - k):
												snake_case_   : Optional[int]						=			n - k
						# Calculate C(n,k)
						for i in range(__UpperCamelCase    ):
												result *= n - i
												result //= i + 1
						return result
def 	__lowerCAmelCase						(		__UpperCamelCase      :			int    ):


						'''simple docstring'''






						return binomial_coefficient(2 * node_count					, __UpperCamelCase    ) // (node_count + 1)
def 	__lowerCAmelCase						(		__UpperCamelCase      :			int    ):


						'''simple docstring'''






						if n < 0:
												raise ValueError("""factorial() not defined for negative values"""    )
						snake_case_   : Optional[int]						=			1
						for i in range(1					, n + 1    ):
												result *= i
						return result
def 	__lowerCAmelCase						(		__UpperCamelCase      :			int    ):


						'''simple docstring'''






						return catalan_number(__UpperCamelCase    ) * factorial(__UpperCamelCase    )


if __name__ == "__main__":
					__lowerCAmelCase       :					Optional[Any]      					=					int(input('''Enter the number of nodes: ''').strip() or 0)
					if node_count <= 0:
										raise ValueError('''We need some nodes to work with.''')
					print(
					    F'''Given {node_count} nodes, there are {binary_tree_count(node_count)} '''
					    F'''binary trees and {catalan_number(node_count)} binary search trees.'''
					)

