


"""simple docstring"""



def 						__lowerCAmelCase		(		lowercase						:						int		,							lowercase						:						int				)			->		str:


    """simple docstring"""





    if number < 0 or shift_amount < 0:
        raise ValueError("both inputs must be positive integers"				)

    snake_case					:   Optional[Any]         =					str(bin(lowercase				)				)
    binary_number += "0" * shift_amount
    return binary_number







def 						__lowerCAmelCase		(		lowercase						:						int		,							lowercase						:						int				)			->		str:


    """simple docstring"""





    if number < 0 or shift_amount < 0:
        raise ValueError("both inputs must be positive integers"				)

    snake_case					:   Any         =					str(bin(lowercase				)				)[2:]
    if shift_amount >= len(lowercase				):
        return "0b0"
    snake_case					:   Optional[Any]         =					binary_number[: len(lowercase				) - shift_amount]
    return "0b" + shifted_binary_number







def 						__lowerCAmelCase		(		lowercase						:						int		,							lowercase						:						int				)			->		str:


    """simple docstring"""





    if number >= 0:  # Get binary representation of positive number
        snake_case					:   Tuple         =					"0" + str(bin(lowercase				)				).strip("-"				)[2:]
    else:  # Get binary (2's complement) representation of negative number
        snake_case					:   List[str]         =					len(bin(lowercase				)[3:]				)  # Find 2's complement of number
        snake_case					:   Optional[Any]         =					bin(abs(lowercase				) - (1 << binary_number_length)				)[3:]
        snake_case					:   str         =					(
            "1" + "0" * (binary_number_length - len(lowercase				)) + binary_number
        )

    if shift_amount >= len(lowercase				):
        return "0b" + binary_number[0] * len(lowercase				)
    return (
        "0b"
        + binary_number[0] * shift_amount
        + binary_number[: len(lowercase				) - shift_amount]
    )


if __name__ == "__main__":
   import doctest

   doctest.testmod()









"""simple docstring"""



import unittest

import numpy as np
import torch

from diffusers import PNDMPipeline, PNDMScheduler, UNetaDModel
from diffusers.utils.testing_utils import enable_full_determinism, require_torch, slow, torch_device


enable_full_determinism()







class _lowerCAmelCase       (   unittest.TestCase			):







   @property
   def 				lowerCamelCase	(			self		)			->	Any:

       '''simple docstring'''




       torch.manual_seed(0		)
       snake_case					:   Tuple         =					UNetaDModel(
           block_out_channels=(32, 64)		,			layers_per_block=2		,			sample_size=32		,			in_channels=3		,			out_channels=3		,			down_block_types=("DownBlock2D", "AttnDownBlock2D")		,			up_block_types=("AttnUpBlock2D", "UpBlock2D")		,			)
       return model







   def 				lowerCamelCase	(			self		)			->	Optional[Any]:

       '''simple docstring'''




       snake_case					:   Optional[Any]         =					self.dummy_uncond_unet
       snake_case					:   str         =					PNDMScheduler()

       snake_case					:   List[Any]         =					PNDMPipeline(unet=UpperCamelCase__		,			scheduler=UpperCamelCase__		)
       pndm.to(UpperCamelCase__		)
       pndm.set_progress_bar_config(disable=UpperCamelCase__		)

       snake_case					:   str         =					torch.manual_seed(0		)
       snake_case					:   Union[str, Any]         =					pndm(generator=UpperCamelCase__		,			num_inference_steps=20		,			output_type="numpy"		).images

       snake_case					:   Optional[int]         =					torch.manual_seed(0		)
       snake_case					:   Any         =					pndm(generator=UpperCamelCase__		,			num_inference_steps=20		,			output_type="numpy"		,			return_dict=UpperCamelCase__		)[0]

       snake_case					:   Optional[Any]         =					image[0, -3:, -3:, -1]
       snake_case					:   List[str]         =					image_from_tuple[0, -3:, -3:, -1]

       assert image.shape == (1, 32, 32, 3)
       snake_case					:   int         =					np.array([1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0]		)

       assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2
       assert np.abs(image_from_tuple_slice.flatten() - expected_slice		).max() < 1e-2







@slow
@require_torch
class _lowerCAmelCase       (   unittest.TestCase			):







   def 				lowerCamelCase	(			self		)			->	Optional[int]:

       '''simple docstring'''




       snake_case					:   Dict         =					"google/ddpm-cifar10-32"

       snake_case					:   Optional[int]         =					UNetaDModel.from_pretrained(UpperCamelCase__		)
       snake_case					:   List[str]         =					PNDMScheduler()

       snake_case					:   Union[str, Any]         =					PNDMPipeline(unet=UpperCamelCase__		,			scheduler=UpperCamelCase__		)
       pndm.to(UpperCamelCase__		)
       pndm.set_progress_bar_config(disable=UpperCamelCase__		)
       snake_case					:   int         =					torch.manual_seed(0		)
       snake_case					:   str         =					pndm(generator=UpperCamelCase__		,			output_type="numpy"		).images

       snake_case					:   Union[str, Any]         =					image[0, -3:, -3:, -1]

       assert image.shape == (1, 32, 32, 3)
       snake_case					:   Optional[Any]         =					np.array([0.1564, 0.14645, 0.1406, 0.14715, 0.12425, 0.14045, 0.13115, 0.12175, 0.125]		)

       assert np.abs(image_slice.flatten() - expected_slice		).max() < 1e-2





