


"""simple docstring"""



from typing import Any

import numpy as np







def 						__lowerCAmelCase		(		lowercase						:						np.ndarray				)			->		bool:


    """simple docstring"""





    return np.array_equal(lowercase		,							matrix.conjugate().T				)







def 						__lowerCAmelCase		(		lowercase						:						np.ndarray		,							lowercase						:						np.ndarray				)			->		Any:


    """simple docstring"""





    snake_case					:   Any         =					v.conjugate().T
    snake_case					:   Optional[int]         =					v_star.dot(lowercase				)
    assert isinstance(lowercase		,							np.ndarray				)
    return (v_star_dot.dot(lowercase				)) / (v_star.dot(lowercase				))







def 						__lowerCAmelCase		(		)			->		None:


    """simple docstring"""





    snake_case					:   int         =					np.array([[2, 2 + 1j, 4], [2 - 1j, 3, 1j], [4, -1j, 1]]				)
    snake_case					:   Dict         =					np.array([[1], [2], [3]]				)
    assert is_hermitian(lowercase				), F'{a} is not hermitian.'
    print(rayleigh_quotient(lowercase		,							lowercase				)				)

    snake_case					:   Any         =					np.array([[1, 2, 4], [2, 3, -1], [4, -1, 1]]				)
    assert is_hermitian(lowercase				), F'{a} is not hermitian.'
    assert rayleigh_quotient(lowercase		,							lowercase				) == float(3				)


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   tests()









"""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





