
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    _snake_case (						UpperCAmelCase_	,    unittest.TestCase				):
 # FIXME: add fast tests
 pass



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


 @property
 def   lowercase__  (       self):


   '''simple docstring'''




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


 @property
 def   lowercase__  (       self):


   '''simple docstring'''




   lowercase__	: Any     		=   ort.SessionOptions()
   lowercase__	: Optional[Any]     		=   False
   return options


 def   lowercase__  (       self):


   '''simple docstring'''




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

   lowercase__	: Any     		=   """A red cat sitting on a park bench"""

   lowercase__	: List[str]     		=   np.random.RandomState(0)
   lowercase__	: Tuple     		=   pipe(
       prompt=SCREAMING_SNAKE_CASE_       ,	image=SCREAMING_SNAKE_CASE_       ,	mask_image=SCREAMING_SNAKE_CASE_       ,	guidance_scale=7.5       ,	num_inference_steps=10       ,	generator=SCREAMING_SNAKE_CASE_       ,	output_type="""np"""       ,	)
   lowercase__	: Dict     		=   output.images
   lowercase__	: List[Any]     		=   images[0, 2_55:2_58, 2_55:2_58, -1]

   assert images.shape == (1, 5_12, 5_12, 3)
   lowercase__	: List[str]     		=   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):


   '''simple docstring'''




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

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

   lowercase__	: Optional[int]     		=   np.random.RandomState(0)
   lowercase__	: Optional[Any]     		=   pipe(
       prompt=SCREAMING_SNAKE_CASE_       ,	image=SCREAMING_SNAKE_CASE_       ,	mask_image=SCREAMING_SNAKE_CASE_       ,	guidance_scale=7.5       ,	num_inference_steps=20       ,	generator=SCREAMING_SNAKE_CASE_       ,	output_type="""np"""       ,	)
   lowercase__	: Optional[int]     		=   output.images
   lowercase__	: Tuple     		=   images[0, 2_55:2_58, 2_55:2_58, -1]

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








lowerCamelCase__     :		dict[tuple[int, int, int], int]        = {}

def 		UpperCamelCase						(   lowercase_			,			lowercase_			,			lowercase_ )		->						int:


  '''simple docstring'''






  if late == 3 or absent == 2:
    return 0

  # if we have no days left, and have not failed any other rules,
  # we have a prize string
  if days == 0:
    return 1

  # No easy solution, so now we need to do the recursive calculation

  # First, check if the combination is already in the cache, and
  # if yes, return the stored value from there since we already
  # know the number of possible prize strings from this point on
  lowercase__	: Tuple     		=   (days, absent, late)
  if key in cache:
    return cache[key]

  # now we calculate the three possible ways that can unfold from
  # this point on, depending on our attendance today

  # 1) if we are late (but not absent), the "absent" counter stays as
  # it is, but the "late" counter increases by one
  lowercase__	: Union[str, Any]     		=   _calculate(days - 1			,			lowercase_			,			late + 1 )

  # 2) if we are absent, the "absent" counter increases by 1, and the
  # "late" counter resets to 0
  lowercase__	: List[str]     		=   _calculate(days - 1			,			absent + 1			,			0 )

  # 3) if we are on time, this resets the "late" counter and keeps the
  # absent counter
  lowercase__	: Dict     		=   _calculate(days - 1			,			lowercase_			,			0 )

  lowercase__	: List[str]     		=   state_late + state_absent + state_ontime

  lowercase__	: List[Any]     		=   prizestrings
  return prizestrings

def 		UpperCamelCase						(   lowercase_ = 30 )		->						int:


  '''simple docstring'''






  return _calculate(lowercase_			,			absent=0			,			late=0 )


if __name__ == "__main__":
     print(solution())






