





'''simple docstring'''

import unittest

import numpy as np
import PIL
import torch

from diffusers.image_processor import VaeImageProcessor





class lowerCamelCase    (unittest.TestCase       ):







  @property
  def 					UpperCAmelCase_					(		self		)		->    Tuple:






        """simple docstring"""





        _snake_case		:						List[str]         =  1
        _snake_case		:						Union[str, Any]         =  3
        _snake_case		:						Dict         =  8
        _snake_case		:						Union[str, Any]         =  8

        _snake_case		:						Dict         =  torch.rand((batch_size, num_channels, height, width)		)

        return sample







  def 					UpperCAmelCase_					(		self  ,  lowercase__		)		->    List[str]:






        """simple docstring"""





        if isinstance(image[0]  ,  PIL.Image.Image		):
              return np.stack([np.array(__snake_case		) for i in image]  ,  axis=0		)
        elif isinstance(__snake_case  ,  torch.Tensor		):
              return image.cpu().numpy().transpose(0  ,  2  ,  3  ,  1		)
        return image







  def 					UpperCAmelCase_					(		self		)		->    Tuple:






        """simple docstring"""





        _snake_case		:						int         =  VaeImageProcessor(do_resize=__snake_case  ,  do_normalize=__snake_case		)

        _snake_case		:						int         =  self.dummy_sample
        _snake_case		:						List[Any]         =  self.to_np(__snake_case		)

        for output_type in ["pt", "np", "pil"]:
              _snake_case		:						Any         =  image_processor.postprocess(
                  image_processor.preprocess(__snake_case		)  ,  output_type=__snake_case  ,  )
              _snake_case		:						Optional[int]         =  self.to_np(__snake_case		)
              _snake_case		:						Optional[int]         =  (input_np * 255).round() if output_type == "pil" else input_np
              assert (
                  np.abs(in_np - out_np		).max() < 1E-6
              ), F'''decoded output does not match input for output_type {output_type}'''







  def 					UpperCAmelCase_					(		self		)		->    int:






        """simple docstring"""





        _snake_case		:						Optional[Any]         =  VaeImageProcessor(do_resize=__snake_case  ,  do_normalize=__snake_case		)
        _snake_case		:						str         =  self.dummy_sample.cpu().numpy().transpose(0  ,  2  ,  3  ,  1		)

        for output_type in ["pt", "np", "pil"]:
              _snake_case		:						Dict         =  image_processor.postprocess(image_processor.preprocess(__snake_case		)  ,  output_type=__snake_case		)

              _snake_case		:						Optional[Any]         =  self.to_np(__snake_case		)
              _snake_case		:						List[str]         =  (input_np * 255).round() if output_type == "pil" else input_np
              assert (
                  np.abs(in_np - out_np		).max() < 1E-6
              ), F'''decoded output does not match input for output_type {output_type}'''







  def 					UpperCAmelCase_					(		self		)		->    Tuple:






        """simple docstring"""





        _snake_case		:						Tuple         =  VaeImageProcessor(do_resize=__snake_case  ,  do_normalize=__snake_case		)

        _snake_case		:						List[Any]         =  self.dummy_sample.cpu().numpy().transpose(0  ,  2  ,  3  ,  1		)
        _snake_case		:						Any         =  image_processor.numpy_to_pil(__snake_case		)

        for output_type in ["pt", "np", "pil"]:
              _snake_case		:						List[Any]         =  image_processor.postprocess(image_processor.preprocess(__snake_case		)  ,  output_type=__snake_case		)
              for i, o in zip(__snake_case  ,  __snake_case		):
                    _snake_case		:						Dict         =  np.array(__snake_case		)
                    _snake_case		:						str         =  self.to_np(__snake_case		) if output_type == "pil" else (self.to_np(__snake_case		) * 255).round()
                    assert (
                        np.abs(in_np - out_np		).max() < 1E-6
                    ), F'''decoded output does not match input for output_type {output_type}'''







  def 					UpperCAmelCase_					(		self		)		->    str:






        """simple docstring"""





        _snake_case		:						int         =  VaeImageProcessor(do_resize=__snake_case  ,  do_normalize=__snake_case		)

        _snake_case		:						Optional[Any]         =  self.dummy_sample
        _snake_case		:						Optional[int]         =  input_pt_ad.squeeze(0		)

        _snake_case		:						Tuple         =  image_processor.postprocess(
            image_processor.preprocess(__snake_case		)  ,  output_type='''np'''  ,  )
        _snake_case		:						str         =  image_processor.postprocess(
            image_processor.preprocess(__snake_case		)  ,  output_type='''np'''  ,  )

        _snake_case		:						List[Any]         =  self.to_np(self.dummy_sample		)
        _snake_case		:						List[str]         =  input_np_ad.squeeze(0		)

        _snake_case		:						str         =  image_processor.postprocess(
            image_processor.preprocess(__snake_case		)  ,  output_type='''np'''  ,  )
        _snake_case		:						Union[str, Any]         =  image_processor.postprocess(
            image_processor.preprocess(__snake_case		)  ,  output_type='''np'''  ,  )

        assert np.abs(out_pt_ad - out_pt_ad		).max() < 1E-6
        assert np.abs(out_np_ad - out_np_ad		).max() < 1E-6







  def 					UpperCAmelCase_					(		self		)		->    List[str]:






        """simple docstring"""





        _snake_case		:						Any         =  VaeImageProcessor(do_resize=__snake_case  ,  do_normalize=__snake_case		)

        _snake_case		:						Optional[Any]         =  self.dummy_sample
        _snake_case		:						Optional[Any]         =  list(__snake_case		)

        _snake_case		:						Dict         =  image_processor.postprocess(
            image_processor.preprocess(__snake_case		)  ,  output_type='''np'''  ,  )

        _snake_case		:						Dict         =  image_processor.postprocess(
            image_processor.preprocess(__snake_case		)  ,  output_type='''np'''  ,  )

        _snake_case		:						Optional[Any]         =  self.to_np(self.dummy_sample		)
        list(__snake_case		)

        _snake_case		:						Optional[int]         =  image_processor.postprocess(
            image_processor.preprocess(__snake_case		)  ,  output_type='''np'''  ,  )

        _snake_case		:						Any         =  image_processor.postprocess(
            image_processor.preprocess(__snake_case		)  ,  output_type='''np'''  ,  )

        assert np.abs(out_pt_ad - out_pt_list		).max() < 1E-6
        assert np.abs(out_np_ad - out_np_list		).max() < 1E-6









def  A					(				UpperCAmelCase	,	UpperCAmelCase					):
					# "Simpson Rule"
					# int(f) = delta_x/2 * (b-a)/3*(f1 + 4f2 + 2f_3 + ... + fn)
					_snake_case							:       List[str]												= (boundary[1] - boundary[0]) / steps
					_snake_case							:       List[Any]												= boundary[0]
					_snake_case							:       Tuple												= boundary[1]
					_snake_case							:       str												= make_points(UpperCAmelCase	,	UpperCAmelCase	,	UpperCAmelCase					)
					_snake_case							:       str												= 0.0
					y += (h / 3.0) * f(UpperCAmelCase					)
					_snake_case							:       Tuple												= 2
					for i in x_i:
										y += (h / 3) * (4 - 2 * (cnt % 2)) * f(UpperCAmelCase					)
										cnt += 1
					y += (h / 3.0) * f(UpperCAmelCase					)
					return y







def  A					(				UpperCAmelCase	,	UpperCAmelCase	,	UpperCAmelCase					):
					_snake_case							:       Union[str, Any]												= a + h
					while x < (b - h):
										yield x
										_snake_case							:       Optional[Any]												= x + h







def  A					(				UpperCAmelCase					):  # enter your function here
					_snake_case							:       Dict												= (x - 0) * (x - 0)
					return y







def  A					(				):
					_snake_case							:       int												= 0.0  # Lower bound of integration
					_snake_case							:       Union[str, Any]												= 1.0  # Upper bound of integration
					_snake_case							:       List[str]												= 1_0.0  # define number of steps or resolution
					_snake_case							:       Optional[int]												= [a, b]  # define boundary of integration
					_snake_case							:       List[str]												= method_a(UpperCAmelCase	,	UpperCAmelCase					)
					print(F"""y = {y}"""					)


if __name__ == "__main__":
							main()