





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      lowercase__    (							__SCREAMING_SNAKE_CASE     ,					unittest.TestCase  ):
  pass





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







  @property
  def 	UpperCAmelCase__		(	self						):
       return (
           "CUDAExecutionProvider",
           {
               "gpu_mem_limit": "15000000000",  # 15GB
               "arena_extend_strategy": "kSameAsRequested",
           },
       )







  @property
  def 	UpperCAmelCase__		(	self						):
       lowerCAmelCase_					:       Union[str, Any]    =		ort.SessionOptions()
       lowerCAmelCase_					:       Union[str, Any]    =		False
       return options







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

       lowerCAmelCase_					:       str    =		"""A red cat sitting on a park bench"""

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

       assert images.shape == (1, 512, 512, 3)
       lowerCAmelCase_					:       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						):
       lowerCAmelCase_					:       Dict    =		load_image(
           """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
           """/in_paint/overture-creations-5sI6fQgYIuo.png"""						)
       lowerCAmelCase_					:       List[str]    =		load_image(
           """https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"""
           """/in_paint/overture-creations-5sI6fQgYIuo_mask.png"""						)
       lowerCAmelCase_					:       str    =		LMSDiscreteScheduler.from_pretrained(
           """runwayml/stable-diffusion-inpainting"""    ,						subfolder="""scheduler"""    ,						revision="""onnx"""						)
       lowerCAmelCase_					:       Tuple    =		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						)

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

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

       assert images.shape == (1, 512, 512, 3)
       lowerCAmelCase_					:       Union[str, 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












from collections.abc import Sequence






def 							_lowerCAmelCase (  _a   :					Sequence[float]					,   _a   :					bool = False			)	->			float:
     if not arr:
          return 0

     lowerCAmelCase_					:       List[str]    =		0 if allow_empty_subarrays else float("""-inf"""			)
     lowerCAmelCase_					:       List[Any]    =		0.0
     for num in arr:
          lowerCAmelCase_					:       int    =		max(0 if allow_empty_subarrays else num					,   curr_sum + num			)
          lowerCAmelCase_					:       List[str]    =		max(_a					,   _a			)

     return max_sum


if __name__ == "__main__":
      from doctest import testmod

      testmod()

      UpperCAmelCase_					:   int 							=						[-2, 1, -3, 4, -1, 2, 1, -5, 4]
      print(F"""{max_subarray_sum(nums) = }""")
