




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

__a			:	Tuple							     =		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					)	->			Union[str, Any]:

							'''simple docstring'''


							return cls




def  a_		(							__snake_case     ,		__snake_case = None     ,		__snake_case = None     ,		__snake_case = None     ,		__snake_case = None     ,		)	->			int:

			'''simple docstring'''


			UpperCamelCase_     				= device
			UpperCamelCase_     				= shape[0]

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

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

			return latents





def  a_		(							__snake_case					)	->			str:

			'''simple docstring'''


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





'''simple docstring'''







def 			_lowerCAmelCase(      UpperCAmelCase_      :	list					, UpperCAmelCase_      :	int					, UpperCAmelCase_      :	int					, UpperCAmelCase_      :	int						) ->							int:
							lowerCAmelCase__  =   int((lower_bound + upper_bound) // 2						)
							if array[r] == value:
														return r
							if lower_bound >= upper_bound:
														return -1
							if array[r] < value:
														return binary_search(UpperCAmelCase_					, r + 1					, UpperCAmelCase_					, UpperCAmelCase_						)
							else:
														return binary_search(UpperCAmelCase_					, UpperCAmelCase_					, r - 1					, UpperCAmelCase_						)
def 			_lowerCAmelCase(      UpperCAmelCase_      :	int					, UpperCAmelCase_      :	list						) ->							list:
							lowerCAmelCase__  =   0
							if matrix[index][0] == value:
														return [index, 0]
							while index < len(UpperCAmelCase_						) and matrix[index][0] < value:
														lowerCAmelCase__  =   binary_search(matrix[index]					, 0					, len(matrix[index]						) - 1					, UpperCAmelCase_						)
														if r != -1:
																					return [index, r]
														index += 1
							return [-1, -1]


if __name__ == "__main__":
		import doctest

		doctest.testmod()





