




from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


lowerCamelCase_  						=       logging.get_logger(__name__)


if is_vision_available():
      import PIL
class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   Any     =  ["pixel_values"]




     def __init__(     self      :			int    ,_UpperCamelCase      :			bool = True    ,_UpperCamelCase      :			Dict[str, int] = None    ,_UpperCamelCase      :			PILImageResampling = PILImageResampling.BICUBIC    ,_UpperCamelCase      :			bool = True    ,_UpperCamelCase      :			Dict[str, int] = None    ,_UpperCamelCase      :			bool = True    ,_UpperCamelCase      :			Union[int, float] = 1 / 2_5_5    ,_UpperCamelCase      :			bool = True    ,_UpperCamelCase      :			Optional[Union[float, List[float]]] = None    ,_UpperCamelCase      :			Optional[Union[float, List[float]]] = None    ,_UpperCamelCase      :			bool = True    ,**_UpperCamelCase      :			List[Any]    ,)		->       None:


         '''simple docstring'''





         super().__init__(**_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =size if size is not None else {"""shortest_edge""": 2_2_4}
         SCREAMING_SNAKE_CASE__       =get_size_dict(_UpperCamelCase    ,default_to_square=_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =crop_size if crop_size is not None else {"""height""": 2_2_4, """width""": 2_2_4}
         SCREAMING_SNAKE_CASE__       =get_size_dict(_UpperCamelCase						)

         SCREAMING_SNAKE_CASE__       =do_resize
         SCREAMING_SNAKE_CASE__       =size
         SCREAMING_SNAKE_CASE__       =resample
         SCREAMING_SNAKE_CASE__       =do_center_crop
         SCREAMING_SNAKE_CASE__       =crop_size
         SCREAMING_SNAKE_CASE__       =do_rescale
         SCREAMING_SNAKE_CASE__       =rescale_factor
         SCREAMING_SNAKE_CASE__       =do_normalize
         SCREAMING_SNAKE_CASE__       =image_mean if image_mean is not None else OPENAI_CLIP_MEAN
         SCREAMING_SNAKE_CASE__       =image_std if image_std is not None else OPENAI_CLIP_STD
         SCREAMING_SNAKE_CASE__       =do_convert_rgb




     def   __A    (     self      :			str    ,_UpperCamelCase      :			np.ndarray    ,_UpperCamelCase      :			Dict[str, int]    ,_UpperCamelCase      :			PILImageResampling = PILImageResampling.BICUBIC    ,_UpperCamelCase      :			Optional[Union[str, ChannelDimension]] = None    ,**_UpperCamelCase      :			Union[str, Any]    ,)		->       np.ndarray:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =get_size_dict(_UpperCamelCase    ,default_to_square=_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =get_resize_output_image_size(
             _UpperCamelCase    ,size=(size["""height"""], size["""width"""])    ,default_to_square=_UpperCamelCase						)
         return resize(_UpperCamelCase    ,size=_UpperCamelCase    ,resample=_UpperCamelCase    ,data_format=_UpperCamelCase    ,**_UpperCamelCase						)




     def   __A    (     self      :			Dict    ,_UpperCamelCase      :			np.ndarray    ,_UpperCamelCase      :			Dict[str, int]    ,_UpperCamelCase      :			Optional[Union[str, ChannelDimension]] = None    ,**_UpperCamelCase      :			Union[str, Any]    ,)		->       np.ndarray:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =get_size_dict(_UpperCamelCase						)
         return center_crop(_UpperCamelCase    ,size=(size["""height"""], size["""width"""])    ,data_format=_UpperCamelCase    ,**_UpperCamelCase						)




     def   __A    (     self      :			Optional[int]    ,_UpperCamelCase      :			np.ndarray    ,_UpperCamelCase      :			Union[int, float]    ,_UpperCamelCase      :			Optional[Union[str, ChannelDimension]] = None    ,**_UpperCamelCase      :			Optional[int]    ,)		->       Any:


         '''simple docstring'''





         return rescale(_UpperCamelCase    ,scale=_UpperCamelCase    ,data_format=_UpperCamelCase    ,**_UpperCamelCase						)




     def   __A    (     self      :			Tuple    ,_UpperCamelCase      :			np.ndarray    ,_UpperCamelCase      :			Union[float, List[float]]    ,_UpperCamelCase      :			Union[float, List[float]]    ,_UpperCamelCase      :			Optional[Union[str, ChannelDimension]] = None    ,**_UpperCamelCase      :			Tuple    ,)		->       np.ndarray:


         '''simple docstring'''





         return normalize(_UpperCamelCase    ,mean=_UpperCamelCase    ,std=_UpperCamelCase    ,data_format=_UpperCamelCase    ,**_UpperCamelCase						)




     def   __A    (     self      :			int    ,_UpperCamelCase      :			ImageInput    ,_UpperCamelCase      :			bool = None    ,_UpperCamelCase      :			Dict[str, int] = None    ,_UpperCamelCase      :			PILImageResampling = None    ,_UpperCamelCase      :			bool = None    ,_UpperCamelCase      :			int = None    ,_UpperCamelCase      :			bool = None    ,_UpperCamelCase      :			float = None    ,_UpperCamelCase      :			bool = None    ,_UpperCamelCase      :			Optional[Union[float, List[float]]] = None    ,_UpperCamelCase      :			Optional[Union[float, List[float]]] = None    ,_UpperCamelCase      :			bool = None    ,_UpperCamelCase      :			Optional[Union[str, TensorType]] = None    ,_UpperCamelCase      :			Optional[ChannelDimension] = ChannelDimension.FIRST    ,**_UpperCamelCase      :			Union[str, Any]    ,)		->       PIL.Image.Image:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =do_resize if do_resize is not None else self.do_resize
         SCREAMING_SNAKE_CASE__       =size if size is not None else self.size
         SCREAMING_SNAKE_CASE__       =get_size_dict(_UpperCamelCase    ,default_to_square=_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =resample if resample is not None else self.resample
         SCREAMING_SNAKE_CASE__       =do_center_crop if do_center_crop is not None else self.do_center_crop
         SCREAMING_SNAKE_CASE__       =crop_size if crop_size is not None else self.crop_size
         SCREAMING_SNAKE_CASE__       =get_size_dict(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =do_rescale if do_rescale is not None else self.do_rescale
         SCREAMING_SNAKE_CASE__       =rescale_factor if rescale_factor is not None else self.rescale_factor
         SCREAMING_SNAKE_CASE__       =do_normalize if do_normalize is not None else self.do_normalize
         SCREAMING_SNAKE_CASE__       =image_mean if image_mean is not None else self.image_mean
         SCREAMING_SNAKE_CASE__       =image_std if image_std is not None else self.image_std
         SCREAMING_SNAKE_CASE__       =do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

         SCREAMING_SNAKE_CASE__       =make_list_of_images(_UpperCamelCase						)

         if not valid_images(_UpperCamelCase						):
             raise ValueError(
                 """Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, """
                 """torch.Tensor, tf.Tensor or jax.ndarray."""						)

         if do_resize and size is None:
             raise ValueError("""Size must be specified if do_resize is True."""						)

         if do_center_crop and crop_size is None:
             raise ValueError("""Crop size must be specified if do_center_crop is True."""						)

         if do_rescale and rescale_factor is None:
             raise ValueError("""Rescale factor must be specified if do_rescale is True."""						)

         if do_normalize and (image_mean is None or image_std is None):
             raise ValueError("""Image mean and std must be specified if do_normalize is True."""						)

         # PIL RGBA images are converted to RGB
         if do_convert_rgb:
             SCREAMING_SNAKE_CASE__       =[convert_to_rgb(_UpperCamelCase						) for image in images]

         # All transformations expect numpy arrays.
         SCREAMING_SNAKE_CASE__       =[to_numpy_array(_UpperCamelCase						) for image in images]

         if do_resize:
             SCREAMING_SNAKE_CASE__       =[self.resize(image=_UpperCamelCase    ,size=_UpperCamelCase    ,resample=_UpperCamelCase						) for image in images]

         if do_center_crop:
             SCREAMING_SNAKE_CASE__       =[self.center_crop(image=_UpperCamelCase    ,size=_UpperCamelCase						) for image in images]

         if do_rescale:
             SCREAMING_SNAKE_CASE__       =[self.rescale(image=_UpperCamelCase    ,scale=_UpperCamelCase						) for image in images]

         if do_normalize:
             SCREAMING_SNAKE_CASE__       =[self.normalize(image=_UpperCamelCase    ,mean=_UpperCamelCase    ,std=_UpperCamelCase						) for image in images]

         SCREAMING_SNAKE_CASE__       =[to_channel_dimension_format(_UpperCamelCase    ,_UpperCamelCase						) for image in images]

         SCREAMING_SNAKE_CASE__       ={"""pixel_values""": images}
         return BatchFeature(data=_UpperCamelCase    ,tensor_type=_UpperCamelCase						)












import tempfile
import unittest

from diffusers import (
    DDIMScheduler,
    DDPMScheduler,
    DPMSolverMultistepScheduler,
    EulerAncestralDiscreteScheduler,
    EulerDiscreteScheduler,
    PNDMScheduler,
    logging,
)
from diffusers.configuration_utils import ConfigMixin, register_to_config
from diffusers.utils.testing_utils import CaptureLogger
class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   List[Any]     =  "config.json"




     @register_to_config
     def __init__(     self      :			int    ,_UpperCamelCase      :			int=2    ,_UpperCamelCase      :			Optional[Any]=5    ,_UpperCamelCase      :			List[str]=(2, 5)    ,_UpperCamelCase      :			List[Any]="for diffusion"    ,_UpperCamelCase      :			Optional[int]=[1, 3]    ,)		->       Any:


         '''simple docstring'''





         pass






class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   List[str]     =  "config.json"




     @register_to_config
     def __init__(     self      :			List[Any]    ,_UpperCamelCase      :			str=2    ,_UpperCamelCase      :			List[str]=5    ,_UpperCamelCase      :			Optional[Any]=(2, 5)    ,_UpperCamelCase      :			Union[str, Any]="for diffusion"    ,_UpperCamelCase      :			Tuple=[1, 3]    ,)		->       List[str]:


         '''simple docstring'''





         pass






class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   Optional[Any]     =  "config.json"




     @register_to_config
     def __init__(     self      :			str    ,_UpperCamelCase      :			Optional[int]=2    ,_UpperCamelCase      :			List[str]=5    ,_UpperCamelCase      :			List[Any]=(2, 5)    ,_UpperCamelCase      :			Dict="for diffusion"    ,_UpperCamelCase      :			Union[str, Any]=[1, 3]    ,_UpperCamelCase      :			Dict=[1, 3]    ,)		->       Any:


         '''simple docstring'''





         pass






class 				__a (			__lowerCamelCase					):


     """simple docstring"""


     _A    :   List[Any]     =  "config.json"




     @register_to_config
     def __init__(     self      :			Union[str, Any]    ,_UpperCamelCase      :			str=2    ,_UpperCamelCase      :			List[str]=5    ,_UpperCamelCase      :			List[Any]=(2, 5)    ,_UpperCamelCase      :			int="for diffusion"    ,_UpperCamelCase      :			Any=[1, 5]    ,_UpperCamelCase      :			Optional[Any]=[5, 4]    ,)		->       List[Any]:


         '''simple docstring'''





         pass






class 				__a (			unittest.TestCase					):


     """simple docstring"""


     def   __A    (     self      :			Dict						)		->       Optional[Any]:


         '''simple docstring'''





         with self.assertRaises(_UpperCamelCase						):
             ConfigMixin.load_config("""dummy_path"""						)




     def   __A    (     self      :			int						)		->       List[str]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =SampleObject()
         SCREAMING_SNAKE_CASE__       =obj.config
         assert config["a"] == 2
         assert config["b"] == 5
         assert config["c"] == (2, 5)
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]

         # init ignore private arguments
         SCREAMING_SNAKE_CASE__       =SampleObject(_name_or_path="""lalala"""						)
         SCREAMING_SNAKE_CASE__       =obj.config
         assert config["a"] == 2
         assert config["b"] == 5
         assert config["c"] == (2, 5)
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]

         # can override default
         SCREAMING_SNAKE_CASE__       =SampleObject(c=6						)
         SCREAMING_SNAKE_CASE__       =obj.config
         assert config["a"] == 2
         assert config["b"] == 5
         assert config["c"] == 6
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]

         # can use positional arguments.
         SCREAMING_SNAKE_CASE__       =SampleObject(1    ,c=6						)
         SCREAMING_SNAKE_CASE__       =obj.config
         assert config["a"] == 1
         assert config["b"] == 5
         assert config["c"] == 6
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]




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


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =SampleObject()
         SCREAMING_SNAKE_CASE__       =obj.config

         assert config["a"] == 2
         assert config["b"] == 5
         assert config["c"] == (2, 5)
         assert config["d"] == "for diffusion"
         assert config["e"] == [1, 3]

         with tempfile.TemporaryDirectory() as tmpdirname:
             obj.save_config(_UpperCamelCase						)
             SCREAMING_SNAKE_CASE__       =SampleObject.from_config(SampleObject.load_config(_UpperCamelCase						)						)
             SCREAMING_SNAKE_CASE__       =new_obj.config

         # unfreeze configs
         SCREAMING_SNAKE_CASE__       =dict(_UpperCamelCase						)
         SCREAMING_SNAKE_CASE__       =dict(_UpperCamelCase						)

         assert config.pop("""c"""						) == (2, 5)  # instantiated as tuple
         assert new_config.pop("""c"""						) == [2, 5]  # saved & loaded as list because of json
         config.pop("""_use_default_values"""						)
         assert config == new_config




     def   __A    (     self      :			Union[str, Any]						)		->       Union[str, Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =DDIMScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert ddim.__class__ == DDIMScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			Dict						)		->       Optional[Any]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =EulerDiscreteScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert euler.__class__ == EulerDiscreteScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			str						)		->       int:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =EulerAncestralDiscreteScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert euler.__class__ == EulerAncestralDiscreteScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			str						)		->       Optional[int]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =PNDMScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert pndm.__class__ == PNDMScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			Optional[int]						)		->       List[str]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =DDPMScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""    ,prediction_type="""sample"""    ,beta_end=8    ,)

         with CaptureLogger(_UpperCamelCase						) as cap_logger_a:
             SCREAMING_SNAKE_CASE__       =DDPMScheduler.from_pretrained("""google/ddpm-celebahq-256"""    ,beta_start=8_8						)

         assert ddpm.__class__ == DDPMScheduler
         assert ddpm.config.prediction_type == "sample"
         assert ddpm.config.beta_end == 8
         assert ddpm_a.config.beta_start == 8_8

         # no warning should be thrown
         assert cap_logger.out == ""
         assert cap_logger_a.out == ""




     def   __A    (     self      :			Any						)		->       Optional[int]:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =logging.get_logger("""diffusers.configuration_utils"""						)
         # 30 for warning
         logger.setLevel(3_0						)

         with CaptureLogger(_UpperCamelCase						) as cap_logger:
             SCREAMING_SNAKE_CASE__       =DPMSolverMultistepScheduler.from_pretrained(
                 """hf-internal-testing/tiny-stable-diffusion-torch"""    ,subfolder="""scheduler"""						)

         assert dpm.__class__ == DPMSolverMultistepScheduler
         # no warning should be thrown
         assert cap_logger.out == ""




     def   __A    (     self      :			str						)		->       str:


         '''simple docstring'''





         SCREAMING_SNAKE_CASE__       =SampleObject()

         SCREAMING_SNAKE_CASE__       ={k: v for k, v in config.config.items() if not k.startswith("""_"""						)}

         # make sure that default config has all keys in `_use_default_values`
         assert set(config_dict.keys()						) == set(config.config._use_default_values						)

         with tempfile.TemporaryDirectory() as tmpdirname:
             config.save_config(_UpperCamelCase						)

             # now loading it with SampleObject2 should put f into `_use_default_values`
             SCREAMING_SNAKE_CASE__       =SampleObjecta.from_config(_UpperCamelCase						)

             assert "f" in config._use_default_values
             assert config.f == [1, 3]

         # now loading the config, should **NOT** use [1, 3] for `f`, but the default [1, 4] value
         # **BECAUSE** it is part of `config._use_default_values`
         SCREAMING_SNAKE_CASE__       =SampleObjecta.from_config(config.config						)
         assert new_config.f == [5, 4]

         config.config._use_default_values.pop()
         SCREAMING_SNAKE_CASE__       =SampleObjecta.from_config(config.config						)
         assert new_config_a.f == [1, 3]

         # Nevertheless "e" should still be correctly loaded to [1, 3] from SampleObject2 instead of defaulting to [1, 5]
         assert new_config_a.e == [1, 3]






