






from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload
class     lowerCamelCase_					:







				def __init__(    self							,       __lowerCAmelCase = None  ):
								"""simple docstring"""
								if components is None:
												__magic_name__		:List[Any]   =   []
								__magic_name__		:str   =   list(__lowerCAmelCase  )







				def __len__(    self  ):
								"""simple docstring"""
								return len(self.__components  )







				def __str__(    self  ):
								"""simple docstring"""
								return "(" + ",".join(map(__lowerCAmelCase							,       self.__components  )  ) + ")"







				def __add__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Dict   =   len(self  )
								if size == len(__lowerCAmelCase  ):
												__magic_name__		:Dict   =   [self.__components[i] + other.component(__lowerCAmelCase  ) for i in range(__lowerCAmelCase  )]
												return Vector(__lowerCAmelCase  )
								else:
												raise Exception('''must have the same size'''  )







				def __sub__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Union[str, Any]   =   len(self  )
								if size == len(__lowerCAmelCase  ):
												__magic_name__		:Tuple   =   [self.__components[i] - other.component(__lowerCAmelCase  ) for i in range(__lowerCAmelCase  )]
												return Vector(__lowerCAmelCase  )
								else:  # error case
												raise Exception('''must have the same size'''  )







				@overload
				def __mul__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								...







				@overload
				def __mul__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								...







				def __mul__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if isinstance(__lowerCAmelCase							,       (float, int)  ):
												__magic_name__		:List[str]   =   [c * other for c in self.__components]
												return Vector(__lowerCAmelCase  )
								elif isinstance(__lowerCAmelCase							,       __lowerCAmelCase  ) and len(self  ) == len(__lowerCAmelCase  ):
												__magic_name__		:Optional[int]   =   len(self  )
												__magic_name__		:Union[str, Any]   =   [self.__components[i] * other.component(__lowerCAmelCase  ) for i in range(__lowerCAmelCase  )]
												return sum(__lowerCAmelCase  )
								else:  # error case
												raise Exception('''invalid operand!'''  )







				def       A						(    self  ):
								"""simple docstring"""
								return Vector(self.__components  )







				def       A						(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if isinstance(__lowerCAmelCase							,       __lowerCAmelCase  ) and -len(self.__components  ) <= i < len(self.__components  ):
												return self.__components[i]
								else:
												raise Exception('''index out of range'''  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								assert -len(self.__components  ) <= pos < len(self.__components  )
								__magic_name__		:Optional[int]   =   value







				def       A						(    self  ):
								"""simple docstring"""
								if len(self.__components  ) == 0:
												raise Exception('''Vector is empty'''  )
								__magic_name__		:Dict   =   [c**2 for c in self.__components]
								return math.sqrt(sum(__lowerCAmelCase  )  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase = False  ):
								"""simple docstring"""
								__magic_name__		:str   =   self * other
								__magic_name__		:int   =   self.euclidean_length() * other.euclidean_length()
								if deg:
												return math.degrees(math.acos(num / den  )  )
								else:
												return math.acos(num / den  )







def   __lowercase       (			snake_case			):







				"""simple docstring"""






				assert isinstance(snake_case,	snake_case			)
				return Vector([0] * dimension			)

def   __lowercase       (			snake_case,	snake_case			):







				"""simple docstring"""






				assert isinstance(snake_case,	snake_case			) and (isinstance(snake_case,	snake_case			))
				__magic_name__		:List[str]   =   [0] * dimension
				__magic_name__		:int   =   1
				return Vector(snake_case			)

def   __lowercase       (			snake_case,	snake_case,	snake_case			):







				"""simple docstring"""






				assert (
				    isinstance(snake_case,	snake_case			)
				    and isinstance(snake_case,	snake_case			)
				    and (isinstance(snake_case,	(int, float)			))
				)
				return x * scalar + y

def   __lowercase       (			snake_case,	snake_case,	snake_case			):







				"""simple docstring"""






				random.seed(snake_case			)
				__magic_name__		:Any   =   [random.randint(snake_case,	snake_case			) for _ in range(snake_case			)]
				return Vector(snake_case			)
class     lowerCamelCase_					:







				def __init__(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Optional[Any]   =   matrix
								__magic_name__		:Union[str, Any]   =   w
								__magic_name__		:Union[str, Any]   =   h







				def __str__(    self  ):
								"""simple docstring"""
								__magic_name__		:List[Any]   =   ''''''
								for i in range(self.__height  ):
												ans += "|"
												for j in range(self.__width  ):
																if j < self.__width - 1:
																				ans += str(self.__matrix[i][j]  ) + ","
																else:
																				ans += str(self.__matrix[i][j]  ) + "|\n"
								return ans







				def __add__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if self.__width == other.width() and self.__height == other.height():
												__magic_name__		:str   =   []
												for i in range(self.__height  ):
																__magic_name__		:List[str]   =   [
																    self.__matrix[i][j] + other.component(__lowerCAmelCase							,       __lowerCAmelCase  )
																    for j in range(self.__width  )
																]
																matrix.append(__lowerCAmelCase  )
												return Matrix(__lowerCAmelCase							,       self.__width							,       self.__height  )
								else:
												raise Exception('''matrix must have the same dimension!'''  )







				def __sub__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if self.__width == other.width() and self.__height == other.height():
												__magic_name__		:int   =   []
												for i in range(self.__height  ):
																__magic_name__		:Tuple   =   [
																    self.__matrix[i][j] - other.component(__lowerCAmelCase							,       __lowerCAmelCase  )
																    for j in range(self.__width  )
																]
																matrix.append(__lowerCAmelCase  )
												return Matrix(__lowerCAmelCase							,       self.__width							,       self.__height  )
								else:
												raise Exception('''matrices must have the same dimension!'''  )







				@overload
				def __mul__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								...







				@overload
				def __mul__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								...







				def __mul__(    self							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if isinstance(__lowerCAmelCase							,       __lowerCAmelCase  ):  # matrix-vector
												if len(__lowerCAmelCase  ) == self.__width:
																__magic_name__		:Tuple   =   zero_vector(self.__height  )
																for i in range(self.__height  ):
																				__magic_name__		:Optional[int]   =   [
																				    self.__matrix[i][j] * other.component(__lowerCAmelCase  )
																				    for j in range(self.__width  )
																				]
																				ans.change_component(__lowerCAmelCase							,       sum(__lowerCAmelCase  )  )
																return ans
												else:
																raise Exception(
																    '''vector must have the same size as the '''
																    '''number of columns of the matrix!'''  )
								elif isinstance(__lowerCAmelCase							,       (int, float)  ):  # matrix-scalar
												__magic_name__		:Optional[Any]   =   [
												    [self.__matrix[i][j] * other for j in range(self.__width  )]
												    for i in range(self.__height  )
												]
												return Matrix(__lowerCAmelCase							,       self.__width							,       self.__height  )
								return None







				def       A						(    self  ):
								"""simple docstring"""
								return self.__height







				def       A						(    self  ):
								"""simple docstring"""
								return self.__width







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if 0 <= x < self.__height and 0 <= y < self.__width:
												return self.__matrix[x][y]
								else:
												raise Exception('''change_component: indices out of bounds'''  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if 0 <= x < self.__height and 0 <= y < self.__width:
												__magic_name__		:Union[str, Any]   =   value
								else:
												raise Exception('''change_component: indices out of bounds'''  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if self.__height != self.__width:
												raise Exception('''Matrix is not square'''  )
								__magic_name__		:Optional[int]   =   self.__matrix[:x] + self.__matrix[x + 1 :]
								for i in range(len(__lowerCAmelCase  )  ):
												__magic_name__		:Optional[Any]   =   minor[i][:y] + minor[i][y + 1 :]
								return Matrix(__lowerCAmelCase							,       self.__width - 1							,       self.__height - 1  ).determinant()







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if self.__height != self.__width:
												raise Exception('''Matrix is not square'''  )
								if 0 <= x < self.__height and 0 <= y < self.__width:
												return (-1) ** (x + y) * self.minor(__lowerCAmelCase							,       __lowerCAmelCase  )
								else:
												raise Exception('''Indices out of bounds'''  )







				def       A						(    self  ):
								"""simple docstring"""
								if self.__height != self.__width:
												raise Exception('''Matrix is not square'''  )
								if self.__height < 1:
												raise Exception('''Matrix has no element'''  )
								elif self.__height == 1:
												return self.__matrix[0][0]
								elif self.__height == 2:
												return (
												    self.__matrix[0][0] * self.__matrix[1][1]
												    - self.__matrix[0][1] * self.__matrix[1][0]
												)
								else:
												__magic_name__		:int   =   [
												    self.__matrix[0][y] * self.cofactor(0							,       __lowerCAmelCase  ) for y in range(self.__width  )
												]
												return sum(__lowerCAmelCase  )







def   __lowercase       (			snake_case			):







				"""simple docstring"""






				__magic_name__		:list[list[float]]   =   [[0] * n for _ in range(snake_case			)]
				return Matrix(snake_case,	snake_case,	snake_case			)

def   __lowercase       (			snake_case,	snake_case,	snake_case,	snake_case			):







				"""simple docstring"""






				random.seed(snake_case			)
				__magic_name__		:list[list[float]]   =   [
				    [random.randint(snake_case,	snake_case			) for _ in range(snake_case			)] for _ in range(snake_case			)
				]
				return Matrix(snake_case,	snake_case,	snake_case			)














"""simple docstring"""





import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers.models.esm.modeling_esmfold import EsmForProteinFolding



class       __A		:

					def __init__(			self  :      str     ,		__snake_case  :      int     ,		__snake_case  :      Dict=1_3     ,		__snake_case  :      Dict=7     ,		__snake_case  :      str=False     ,		__snake_case  :      Dict=True     ,		__snake_case  :      Tuple=False     ,		__snake_case  :      List[Any]=False     ,		__snake_case  :      Dict=1_9     ,		__snake_case  :      Dict=3_2     ,		__snake_case  :      Union[str, Any]=5     ,		__snake_case  :      List[Any]=4     ,		__snake_case  :      List[Any]=3_7     ,		__snake_case  :      Union[str, Any]="gelu"     ,		__snake_case  :      List[str]=0.1     ,		__snake_case  :      Union[str, Any]=0.1     ,		__snake_case  :      List[str]=5_1_2     ,		__snake_case  :      List[str]=1_6     ,		__snake_case  :      Tuple=2     ,		__snake_case  :      Optional[Any]=0.02     ,		__snake_case  :      str=3     ,		__snake_case  :      List[str]=4     ,		__snake_case  :      Optional[int]=None     ,		)			->							Optional[int]:
											__magic_name__:	Any							=       parent
											__magic_name__:	Optional[Any]							=       batch_size
											__magic_name__:	Optional[Any]							=       seq_length
											__magic_name__:	Optional[Any]							=       is_training
											__magic_name__:	str							=       use_input_mask
											__magic_name__:	Optional[Any]							=       use_token_type_ids
											__magic_name__:	List[str]							=       use_labels
											__magic_name__:	List[str]							=       vocab_size
											__magic_name__:	Union[str, Any]							=       hidden_size
											__magic_name__:	List[Any]							=       num_hidden_layers
											__magic_name__:	Dict							=       num_attention_heads
											__magic_name__:	int							=       intermediate_size
											__magic_name__:	List[Any]							=       hidden_act
											__magic_name__:	int							=       hidden_dropout_prob
											__magic_name__:	List[str]							=       attention_probs_dropout_prob
											__magic_name__:	Tuple							=       max_position_embeddings
											__magic_name__:	Any							=       type_vocab_size
											__magic_name__:	Union[str, Any]							=       type_sequence_label_size
											__magic_name__:	List[str]							=       initializer_range
											__magic_name__:	Optional[Any]							=       num_labels
											__magic_name__:	List[str]							=       num_choices
											__magic_name__:	Tuple							=       scope

					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							Any:
											__magic_name__:	Union[str, Any]							=       ids_tensor([self.batch_size, self.seq_length]     ,		self.vocab_size					)

											__magic_name__:	Dict							=       None
											if self.use_input_mask:
																	__magic_name__:	Optional[int]							=       random_attention_mask([self.batch_size, self.seq_length]					)

											__magic_name__:	str							=       None
											__magic_name__:	Optional[Any]							=       None
											__magic_name__:	int							=       None
											if self.use_labels:
																	__magic_name__:	List[Any]							=       ids_tensor([self.batch_size]     ,		self.type_sequence_label_size					)
																	__magic_name__:	str							=       ids_tensor([self.batch_size, self.seq_length]     ,		self.num_labels					)
																	__magic_name__:	Dict							=       ids_tensor([self.batch_size]     ,		self.num_choices					)

											__magic_name__:	Dict							=       self.get_config()

											return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels

					def   lowerCamelCase__   (			self  :      int					)			->							Any:
											__magic_name__:	List[Any]							=       EsmConfig(
											    vocab_size=3_3     ,		hidden_size=self.hidden_size     ,		pad_token_id=1     ,		num_hidden_layers=self.num_hidden_layers     ,		num_attention_heads=self.num_attention_heads     ,		intermediate_size=self.intermediate_size     ,		hidden_act=self.hidden_act     ,		hidden_dropout_prob=self.hidden_dropout_prob     ,		attention_probs_dropout_prob=self.attention_probs_dropout_prob     ,		max_position_embeddings=self.max_position_embeddings     ,		type_vocab_size=self.type_vocab_size     ,		initializer_range=self.initializer_range     ,		is_folding_model=__snake_case     ,		esmfold_config={"""trunk""": {"""num_blocks""": 2}, """fp16_esm""": False}     ,		)
											return config

					def   lowerCamelCase__   (			self  :      Optional[int]     ,		__snake_case  :      Optional[Any]     ,		__snake_case  :      Optional[Any]     ,		__snake_case  :      Any     ,		__snake_case  :      List[Any]     ,		__snake_case  :      Any     ,		__snake_case  :      Union[str, Any]					)			->							Optional[Any]:
											__magic_name__:	str							=       EsmForProteinFolding(config=__snake_case					).float()
											model.to(__snake_case					)
											model.eval()
											__magic_name__:	str							=       model(__snake_case     ,		attention_mask=__snake_case					)
											__magic_name__:	Any							=       model(__snake_case					)
											__magic_name__:	Dict							=       model(__snake_case					)

											self.parent.assertEqual(result.positions.shape     ,		(8, self.batch_size, self.seq_length, 1_4, 3)					)
											self.parent.assertEqual(result.angles.shape     ,		(8, self.batch_size, self.seq_length, 7, 2)					)






					def   lowerCamelCase__   (			self  :      Any					)			->							int:
											__magic_name__:	str							=       self.prepare_config_and_inputs()
											(
											    (
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			(
											    __magic_name__
											),			
											):	Union[str, Any]							=       config_and_inputs
											__magic_name__:	Any							=       {"""input_ids""": input_ids, """attention_mask""": input_mask}
											return config, inputs_dict



@require_torch
class       __A		(   SCREAMING_SNAKE_CASE_     ,SCREAMING_SNAKE_CASE_     ,unittest.TestCase			):
					UpperCAmelCase__								=				False

					UpperCAmelCase__								=				(EsmForProteinFolding,) if is_torch_available() else ()
					UpperCAmelCase__								=				()
					UpperCAmelCase__								=				{} if is_torch_available() else {}
					UpperCAmelCase__								=				False

					def   lowerCamelCase__   (			self  :      List[Any]					)			->							Optional[Any]:
											__magic_name__:	Optional[int]							=       EsmFoldModelTester(self					)
											__magic_name__:	Optional[Any]							=       ConfigTester(self     ,		config_class=__snake_case     ,		hidden_size=3_7					)

					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							Any:
											self.config_tester.run_common_tests()

					def   lowerCamelCase__   (			self  :      List[str]					)			->							str:
											__magic_name__:	Tuple							=       self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__snake_case					)

					@unittest.skip("""Does not support attention outputs"""					)
					def   lowerCamelCase__   (			self  :      List[str]					)			->							str:
											pass

					@unittest.skip
					def   lowerCamelCase__   (			self  :      List[Any]					)			->							Tuple:
											pass

					@unittest.skip("""Esm does not support embedding resizing"""					)
					def   lowerCamelCase__   (			self  :      List[Any]					)			->							Optional[int]:
											pass

					@unittest.skip("""Esm does not support embedding resizing"""					)
					def   lowerCamelCase__   (			self  :      str					)			->							str:
											pass

					@unittest.skip("""ESMFold does not support passing input embeds!"""					)
					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							List[Any]:
											pass

					@unittest.skip("""ESMFold does not support head pruning."""					)
					def   lowerCamelCase__   (			self  :      Any					)			->							List[str]:
											pass

					@unittest.skip("""ESMFold does not support head pruning."""					)
					def   lowerCamelCase__   (			self  :      Union[str, Any]					)			->							List[Any]:
											pass

					@unittest.skip("""ESMFold does not support head pruning."""					)
					def   lowerCamelCase__   (			self  :      int					)			->							Tuple:
											pass

					@unittest.skip("""ESMFold does not support head pruning."""					)
					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							Optional[Any]:
											pass

					@unittest.skip("""ESMFold does not support head pruning."""					)
					def   lowerCamelCase__   (			self  :      Optional[Any]					)			->							Optional[Any]:
											pass

					@unittest.skip("""ESMFold does not output hidden states in the normal way."""					)
					def   lowerCamelCase__   (			self  :      Union[str, Any]					)			->							List[Any]:
											pass

					@unittest.skip("""ESMfold does not output hidden states in the normal way."""					)
					def   lowerCamelCase__   (			self  :      Any					)			->							int:
											pass

					@unittest.skip("""ESMFold only has one output format."""					)
					def   lowerCamelCase__   (			self  :      Union[str, Any]					)			->							str:
											pass

					@unittest.skip("""This test doesn't work for ESMFold and doesn't test core functionality"""					)
					def   lowerCamelCase__   (			self  :      List[Any]					)			->							Dict:
											pass

					@unittest.skip("""ESMFold does not support input chunking."""					)
					def   lowerCamelCase__   (			self  :      int					)			->							Any:
											pass

					@unittest.skip("""ESMFold doesn't respect you and it certainly doesn't respect your initialization arguments."""					)
					def   lowerCamelCase__   (			self  :      int					)			->							Union[str, Any]:
											pass

					@unittest.skip("""ESMFold doesn't support torchscript compilation."""					)
					def   lowerCamelCase__   (			self  :      Any					)			->							Optional[Any]:
											pass

					@unittest.skip("""ESMFold doesn't support torchscript compilation."""					)
					def   lowerCamelCase__   (			self  :      Optional[int]					)			->							int:
											pass

					@unittest.skip("""ESMFold doesn't support torchscript compilation."""					)
					def   lowerCamelCase__   (			self  :      Union[str, Any]					)			->							List[str]:
											pass

					@unittest.skip("""ESMFold doesn't support data parallel."""					)
					def   lowerCamelCase__   (			self  :      List[str]					)			->							str:
											pass






					@unittest.skip("""Will be fixed soon by reducing the size of the model used for common tests."""					)
					def   lowerCamelCase__   (			self  :      Union[str, Any]					)			->							Dict:
											pass



@require_torch
class       __A		(   SCREAMING_SNAKE_CASE_			):

					@slow
					def   lowerCamelCase__   (			self  :      Optional[Any]					)			->							List[Any]:
											__magic_name__:	Any							=       EsmForProteinFolding.from_pretrained("""facebook/esmfold_v1"""					).float()
											model.eval()
											__magic_name__:	Optional[int]							=       torch.tensor([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]					)
											__magic_name__:	Dict							=       model(__snake_case					)["""positions"""]
											__magic_name__:	Tuple							=       torch.tensor([2.5828, 0.7993, -10.9334]     ,		dtype=torch.floataa					)
											self.assertTrue(torch.allclose(position_outputs[0, 0, 0, 0]     ,		__snake_case     ,		atol=1E-4					)					)



