
"""simple docstring"""




import PIL.Image
import PIL.ImageOps
from packaging import version
from PIL import Image


if version.parse(version.parse(PIL.__version__).base_version) >= version.parse("""9.1.0"""):
    A__      :	Tuple          =    {
        """linear""": PIL.Image.Resampling.BILINEAR,
        """bilinear""": PIL.Image.Resampling.BILINEAR,
        """bicubic""": PIL.Image.Resampling.BICUBIC,
        """lanczos""": PIL.Image.Resampling.LANCZOS,
        """nearest""": PIL.Image.Resampling.NEAREST,
    }
else:
    A__      :	Union[str, Any]          =    {
        """linear""": PIL.Image.LINEAR,
        """bilinear""": PIL.Image.BILINEAR,
        """bicubic""": PIL.Image.BICUBIC,
        """lanczos""": PIL.Image.LANCZOS,
        """nearest""": PIL.Image.NEAREST,
    }



def 							a__ (				lowerCAmelCase	:       Tuple		):






     '''simple docstring'''
     UpperCAmelCase__							: Any 							=						(images / 2 + 0.5).clamp(0       ,    1		)
     UpperCAmelCase__							: str 							=						images.cpu().permute(0       ,    2       ,    3       ,    1		).float().numpy()
     UpperCAmelCase__							: Optional[Any] 							=						numpy_to_pil(lowerCAmelCase		)
     return images



def 							a__ (				lowerCAmelCase	:       List[Any]		):






     '''simple docstring'''
     if images.ndim == 3:
          UpperCAmelCase__							: str 							=						images[None, ...]
     UpperCAmelCase__							: str 							=						(images * 255).round().astype("uint8"		)
     if images.shape[-1] == 1:
          # special case for grayscale (single channel) images
          UpperCAmelCase__							: Any 							=						[Image.fromarray(image.squeeze()       ,    mode="L"		) for image in images]
     else:
          UpperCAmelCase__							: List[str] 							=						[Image.fromarray(lowerCAmelCase		) for image in images]

     return pil_images





"""simple docstring"""




from timeit import timeit



def 							a__ (				lowerCAmelCase	:       int		):






     '''simple docstring'''
     if number < 0:
          raise ValueError("the value of input must not be negative"		)
     UpperCAmelCase__							: Tuple 							=						0
     while number:
          number &= number - 1
          result += 1
     return result



def 							a__ (				lowerCAmelCase	:       int		):






     '''simple docstring'''
     if number < 0:
          raise ValueError("the value of input must not be negative"		)
     UpperCAmelCase__							: Union[str, Any] 							=						0
     while number:
          if number % 2 == 1:
               result += 1
          number >>= 1
     return result



def 							a__ (				):






     '''simple docstring'''

     def do_benchmark(lowerCAmelCase	:       int		) -> None:
          UpperCAmelCase__							: Dict 							=						"import __main__ as z"
          print(F"Benchmark when {number = }:"		)
          print(F"{get_set_bits_count_using_modulo_operator(lowerCAmelCase		) = }"		)
          UpperCAmelCase__							: Tuple 							=						timeit("z.get_set_bits_count_using_modulo_operator(25)"       ,    setup=lowerCAmelCase		)
          print(F"timeit() runs in {timing} seconds"		)
          print(F"{get_set_bits_count_using_brian_kernighans_algorithm(lowerCAmelCase		) = }"		)
          UpperCAmelCase__							: Any 							=						timeit(
              "z.get_set_bits_count_using_brian_kernighans_algorithm(25)"       ,    setup=lowerCAmelCase       ,    )
          print(F"timeit() runs in {timing} seconds"		)

     for number in (25, 37, 58, 0):
          do_benchmark(lowerCAmelCase		)
          print()


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    benchmark()



