'''simple docstring'''

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_			:			Union[str, 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      :    Dict					)						->				Any:
             '''simple docstring'''


             return cls


def __a			(						__lowerCamelCase      :    Union[Tuple, List]			,		__lowerCamelCase      :    Optional[Union[List["torch.Generator"], "torch.Generator"]] = None			,		__lowerCamelCase      :    Optional["torch.device"] = None			,		__lowerCamelCase      :    Optional["torch.dtype"] = None			,		__lowerCamelCase      :    Optional["torch.layout"] = None			,		)						->				Any:
      '''simple docstring'''


      lowercase_     			=   device
      lowercase_     			=   shape[0]

      lowercase_     			=   layout or torch.strided
      lowercase_     			=   device or torch.device("cpu"					)

      if generator is not None:
            lowercase_     			=   generator.device.type if not isinstance(__lowerCamelCase			,		__lowerCamelCase					) else generator[0].device.type
            if gen_device_type != device.type and gen_device_type == "cpu":
                  lowercase_     			=   "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(__lowerCamelCase			,		__lowerCamelCase					):
            lowercase_     			=   (1,) + shape[1:]
            lowercase_     			=   [
                torch.randn(__lowerCamelCase			,		generator=generator[i]			,		device=__lowerCamelCase			,		dtype=__lowerCamelCase			,		layout=__lowerCamelCase					)
                for i in range(__lowerCamelCase					)
            ]
            lowercase_     			=   torch.cat(__lowerCamelCase			,		dim=0					).to(__lowerCamelCase					)
      else:
            lowercase_     			=   torch.randn(__lowerCamelCase			,		generator=__lowerCamelCase			,		device=__lowerCamelCase			,		dtype=__lowerCamelCase			,		layout=__lowerCamelCase					).to(__lowerCamelCase					)

      return latents






def __a			(						__lowerCamelCase      :    str					)						->				Any:
      '''simple docstring'''


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







'''simple docstring'''

from hashlib import mda, shaaaa

lowerCAmelCase_			:			Union[str, Any]    	=   (shaaaa, mda)





class 				lowercase    :


   def __init__( self					:						Optional[Any] ,		__lowerCAmelCase					:						int = 8)   ->       None:
         lowercase_     			=   0B0
         lowercase_     			=   size


   def __UpperCAmelCase							( self					:						Dict ,		__lowerCAmelCase					:						str)   ->       None:
         lowercase_     			=   self.hash_(__lowerCAmelCase)
         self.bitarray |= h


   def __UpperCAmelCase							( self					:						Union[str, Any] ,		__lowerCAmelCase					:						str)   ->       bool:
         lowercase_     			=   self.hash_(__lowerCAmelCase)
         return (h & self.bitarray) == h


   def __contains__( self					:						str ,		__lowerCAmelCase					:						str)   ->       bool:
         return self.exists(__lowerCAmelCase)


   def __UpperCAmelCase							( self					:						Union[str, Any] ,		__lowerCAmelCase					:						int)   ->       str:
         lowercase_     			=   bin(__lowerCAmelCase)[2:]
         return res.zfill(self.size)


   @property
   def __UpperCAmelCase							( self					:						Dict)   ->       str:
         return self.format_bin(self.bitarray)


   def __UpperCAmelCase							( self					:						Any ,		__lowerCAmelCase					:						str)   ->       int:
         lowercase_     			=   0B0
         for func in HASH_FUNCTIONS:
               lowercase_     			=   (
                   int.from_bytes(func(value.encode()).digest() ,		"little") % self.size
               )
               res |= 2**position
         return res


   def __UpperCAmelCase							( self					:						Union[str, Any] ,		__lowerCAmelCase					:						str)   ->       str:
         return self.format_bin(self.hash_(__lowerCAmelCase))


   @property
   def __UpperCAmelCase							( self					:						str)   ->       float:
         lowercase_     			=   bin(self.bitarray).count("1")
         return (n_ones / self.size) ** len(__lowerCAmelCase)






