from typing import List, Optional, Tuple, Union

from . import logging
from .import_utils import is_torch_available, is_torch_version


if is_torch_available():
    import torch

lowerCAmelCase      :				Any     			=logging.get_logger(__name__)  # pylint: disable=invalid-name

try:
    from torch._dynamo import allow_in_graph as maybe_allow_in_graph
except (ImportError, ModuleNotFoundError):







    def     A__	(       cls						):







        '''simple docstring'''
        return cls







def     A__	(       __A ,			__A = None ,			__A = None ,			__A = None ,			__A = None ,			):







    '''simple docstring'''
    _lowerCamelCase  :		Optional[Any]			    =    device
    _lowerCamelCase  :		str			    =    shape[0]

    _lowerCamelCase  :		List[str]			    =    layout or torch.strided
    _lowerCamelCase  :		Tuple			    =    device or torch.device("""cpu"""						)

    if generator is not None:
        _lowerCamelCase  :		Any			    =    generator.device.type if not isinstance(_snake_case ,			_snake_case						) else generator[0].device.type
        if gen_device_type != device.type and gen_device_type == "cpu":
            _lowerCamelCase  :		List[Any]			    =    '''cpu'''
            if device != "mps":
                logger.info(
                    F"""The passed generator was created on \'cpu\' even though a tensor on {device} was expected."""
                    F""" Tensors will be created on \'cpu\' and then moved to {device}. Note that one can probably"""
                    F""" slighly speed up this function by passing a generator that was created on the {device} device."""						)
        elif gen_device_type != device.type and gen_device_type == "cuda":
            raise ValueError(F"""Cannot generate a {device} tensor from a generator of type {gen_device_type}."""						)

    if isinstance(_snake_case ,			_snake_case						):
        _lowerCamelCase  :		Optional[Any]			    =    (1,) + shape[1:]
        _lowerCamelCase  :		str			    =    [
            torch.randn(_snake_case ,			generator=generator[i] ,			device=_snake_case ,			dtype=_snake_case ,			layout=_snake_case						)
            for i in range(_snake_case						)
        ]
        _lowerCamelCase  :		Tuple			    =    torch.cat(_snake_case ,			dim=0						).to(_snake_case						)
    else:
        _lowerCamelCase  :		List[Any]			    =    torch.randn(_snake_case ,			generator=_snake_case ,			device=_snake_case ,			dtype=_snake_case ,			layout=_snake_case						).to(_snake_case						)

    return latents







def     A__	(       __A						):







    '''simple docstring'''
    if is_torch_version("""<""" ,			"""2.0.0"""						) or not hasattr(_snake_case ,			"""_dynamo"""						):
        return False
    return isinstance(_snake_case ,			torch._dynamo.eval_frame.OptimizedModule						)








"""simple docstring"""





def   _snake_case    (    _snake_case					:      int      ):
      if not isinstance(_snake_case			, _snake_case      ):
            lowerCAmelCase       :						int							= f'''Input value of [number={number}] must be an integer'''
            raise TypeError(_snake_case      )
      if number < 0 or number % 2 == 1:
            return False
      lowerCAmelCase       :						int							= int(number**0.5      )
      return number == number_sqrt * (number_sqrt + 1)


if __name__ == "__main__":
 import doctest

 doctest.testmod()


