
"""simple docstring"""

import unittest

import numpy as np
import PIL
import torch

from diffusers.image_processor import VaeImageProcessor






class        _lowercase   (				unittest.TestCase		):




	@property
	def 			_UpperCamelCase    ( self					)		->							str:
			lowerCamelCase     :			Dict		=    1
			lowerCamelCase     :			List[str]		=    3
			lowerCamelCase     :			Optional[int]		=    8
			lowerCamelCase     :			List[Any]		=    8

			lowerCamelCase     :			List[Any]		=    torch.rand((batch_size, num_channels, height, width)					)

			return sample




	def 			_UpperCamelCase    ( self		, UpperCAmelCase_					)		->							Tuple:
			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					)		->							Union[str, Any]:
			lowerCamelCase     :			List[Any]		=    VaeImageProcessor(do_resize=snake_case__		, do_normalize=snake_case__					)

			lowerCamelCase     :			int		=    self.dummy_sample
			lowerCamelCase     :			str		=    self.to_np(snake_case__					)

			for output_type in ["pt", "np", "pil"]:
					lowerCamelCase     :			Any		=    image_processor.postprocess(
					    image_processor.preprocess(snake_case__					)		, output_type=snake_case__		, )
					lowerCamelCase     :			Optional[Any]		=    self.to_np(snake_case__					)
					lowerCamelCase     :			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					)		->							int:
			lowerCamelCase     :			Union[str, Any]		=    VaeImageProcessor(do_resize=snake_case__		, do_normalize=snake_case__					)
			lowerCamelCase     :			Optional[int]		=    self.dummy_sample.cpu().numpy().transpose(0		, 2		, 3		, 1					)

			for output_type in ["pt", "np", "pil"]:
					lowerCamelCase     :			Any		=    image_processor.postprocess(image_processor.preprocess(snake_case__					)		, output_type=snake_case__					)

					lowerCamelCase     :			str		=    self.to_np(snake_case__					)
					lowerCamelCase     :			Dict		=    (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					)		->							List[Any]:
			lowerCamelCase     :			List[Any]		=    VaeImageProcessor(do_resize=snake_case__		, do_normalize=snake_case__					)

			lowerCamelCase     :			int		=    self.dummy_sample.cpu().numpy().transpose(0		, 2		, 3		, 1					)
			lowerCamelCase     :			Union[str, Any]		=    image_processor.numpy_to_pil(snake_case__					)

			for output_type in ["pt", "np", "pil"]:
					lowerCamelCase     :			Any		=    image_processor.postprocess(image_processor.preprocess(snake_case__					)		, output_type=snake_case__					)
					for i, o in zip(snake_case__		, snake_case__					):
							lowerCamelCase     :			List[str]		=    np.array(snake_case__					)
							lowerCamelCase     :			Optional[int]		=    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					)		->							Tuple:
			lowerCamelCase     :			Any		=    VaeImageProcessor(do_resize=snake_case__		, do_normalize=snake_case__					)

			lowerCamelCase     :			List[str]		=    self.dummy_sample
			lowerCamelCase     :			int		=    input_pt_ad.squeeze(0					)

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

			lowerCamelCase     :			Dict		=    self.to_np(self.dummy_sample					)
			lowerCamelCase     :			Any		=    input_np_ad.squeeze(0					)

			lowerCamelCase     :			int		=    image_processor.postprocess(
			    image_processor.preprocess(snake_case__					)		, output_type='np'		, )
			lowerCamelCase     :			Tuple		=    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					)		->							Any:
			lowerCamelCase     :			Any		=    VaeImageProcessor(do_resize=snake_case__		, do_normalize=snake_case__					)

			lowerCamelCase     :			Dict		=    self.dummy_sample
			lowerCamelCase     :			List[Any]		=    list(snake_case__					)

			lowerCamelCase     :			int		=    image_processor.postprocess(
			    image_processor.preprocess(snake_case__					)		, output_type='np'		, )

			lowerCamelCase     :			Dict		=    image_processor.postprocess(
			    image_processor.preprocess(snake_case__					)		, output_type='np'		, )

			lowerCamelCase     :			List[Any]		=    self.to_np(self.dummy_sample					)
			list(snake_case__					)

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

			lowerCamelCase     :			Optional[int]		=    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














"""simple docstring"""



from doctest import testmod
from math import sqrt


def      SCREAMING_SNAKE_CASE__    (   snake_case    :      int							)->						list:






     '''simple docstring'''



     UpperCAmelCase__		:  list[int]				=				[]
     if num < 1:
          return facs
     facs.append(1							)
     if num == 1:
          return facs
     facs.append(snake_case							)
     for i in range(2       , int(sqrt(snake_case							)							) + 1							):
          if num % i == 0:  # If i is a factor of num
               facs.append(snake_case							)
               UpperCAmelCase__		:  Any				=				num // i  # num//i is the other factor of num
               if d != i:  # If d and i are distinct
                    facs.append(snake_case							)  # we have found another factor
     facs.sort()
     return facs


if __name__ == "__main__":
 testmod(name="""factors_of_a_number""", verbose=True)


