


'''simple docstring'''
from __future__ import annotations

def 				lowerCamelCase_   (   __UpperCamelCase				:					Any       ,						__UpperCamelCase				:					Any       ,						__UpperCamelCase				:					Optional[int]		)				->  List[Any]:







     """simple docstring"""
     assert n > 1 and a > 0 and greatest_common_divisor(__UpperCamelCase       ,						__UpperCamelCase		) == 1
     (_A)				=       extended_gcd(__UpperCamelCase       ,						__UpperCamelCase		)  # Implemented below
     _A				=       (b * s) % n
     return x

def 				lowerCamelCase_   (   __UpperCamelCase				:					str       ,						__UpperCamelCase				:					int		)				->  List[str]:







     """simple docstring"""
     (_A)				=       extended_euclid(__UpperCamelCase       ,						__UpperCamelCase		)  # Implemented below
     if b < 0:
          _A				=       (b % n + n) % n
     return b

def 				lowerCamelCase_   (   __UpperCamelCase				:					Tuple       ,						__UpperCamelCase				:					Optional[int]       ,						__UpperCamelCase				:					int		)				->  Tuple:







     """simple docstring"""
     _A				=       invert_modulo(__UpperCamelCase       ,						__UpperCamelCase		)
     _A				=       (b * s) % n
     return x

def 				lowerCamelCase_   (   __UpperCamelCase				:					Union[str, Any]       ,						__UpperCamelCase				:					Union[str, Any]		)				->  int:







     """simple docstring"""
     assert a >= 0 and b >= 0

     if b == 0:
          _A				=       a, 1, 0
     else:
          (_A)				=       extended_gcd(__UpperCamelCase       ,						a % b		)
          _A				=       q
          _A				=       p - q * (a // b)

     assert a % d == 0 and b % d == 0
     assert d == a * x + b * y

     return (d, x, y)

def 				lowerCamelCase_   (   __UpperCamelCase				:					List[Any]       ,						__UpperCamelCase				:					Any		)				->  Tuple:







     """simple docstring"""
     if b == 0:
          return (1, 0)
     (_A)				=       extended_euclid(__UpperCamelCase       ,						a % b		)
     _A				=       a // b
     return (y, x - k * y)

def 				lowerCamelCase_   (   __UpperCamelCase				:					Optional[Any]       ,						__UpperCamelCase				:					Tuple		)				->  Union[str, Any]:







     """simple docstring"""
     if a < b:
          _A				=       b, a

     while a % b != 0:
          _A				=       b, a % b

     return b


if __name__ == "__main__":
      from doctest import testmod

      testmod(name="""modular_division""", verbose=True)
      testmod(name="""modular_division2""", verbose=True)
      testmod(name="""invert_modulo""", verbose=True)
      testmod(name="""extended_gcd""", verbose=True)
      testmod(name="""extended_euclid""", verbose=True)
      testmod(name="""greatest_common_divisor""", verbose=True)









'''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  =				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 				lowerCamelCase_   (   cls				:					Tuple		)				->  Dict:







         """simple docstring"""
         return cls

def 				lowerCamelCase_   (   __UpperCamelCase				:					Union[Tuple, List]       ,						__UpperCamelCase				:					Optional[Union[List["torch.Generator"], "torch.Generator"]] = None       ,						__UpperCamelCase				:					Optional["torch.device"] = None       ,						__UpperCamelCase				:					Optional["torch.dtype"] = None       ,						__UpperCamelCase				:					Optional["torch.layout"] = None       ,						)				->  Tuple:







     """simple docstring"""
     _A				=       device
     _A				=       shape[0]

     _A				=       layout or torch.strided
     _A				=       device or torch.device('cpu'		)

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

     return latents

def 				lowerCamelCase_   (   __UpperCamelCase				:					Any		)				->  Optional[int]:







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





