





"""simple docstring"""





import math
import unittest

from transformers import BioGptConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
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 import (
							    BioGptForCausalLM,
							    BioGptForSequenceClassification,
							    BioGptForTokenClassification,
							    BioGptModel,
							    BioGptTokenizer,
							)
							from transformers.models.biogpt.modeling_biogpt import BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST
class 		SCREAMING_SNAKE_CASE_							:
				"""simple docstring"""




				def __init__(     self  :Optional[int]						,    __lowercase  :Any						,    __lowercase  :Optional[Any]=13						,    __lowercase  :Optional[int]=7						,    __lowercase  :int=True						,    __lowercase  :Tuple=True						,    __lowercase  :Union[str, Any]=False						,    __lowercase  :List[Any]=True						,    __lowercase  :Optional[int]=99						,    __lowercase  :Dict=32						,    __lowercase  :Dict=5						,    __lowercase  :List[Any]=4						,    __lowercase  :Any=37						,    __lowercase  :List[str]="gelu"						,    __lowercase  :int=0.1						,    __lowercase  :List[str]=0.1						,    __lowercase  :Any=512						,    __lowercase  :Union[str, Any]=16						,    __lowercase  :List[str]=2						,    __lowercase  :Any=0.02						,    __lowercase  :Dict=3						,    __lowercase  :Optional[Any]=4						,    __lowercase  :Tuple=None						,    ):
											__lowerCamelCase      :      Dict         =parent
											__lowerCamelCase      :      List[Any]         =batch_size
											__lowerCamelCase      :      str         =seq_length
											__lowerCamelCase      :      Optional[int]         =is_training
											__lowerCamelCase      :      Any         =use_input_mask
											__lowerCamelCase      :      List[Any]         =use_token_type_ids
											__lowerCamelCase      :      List[Any]         =use_labels
											__lowerCamelCase      :      List[str]         =vocab_size
											__lowerCamelCase      :      Tuple         =hidden_size
											__lowerCamelCase      :      str         =num_hidden_layers
											__lowerCamelCase      :      Any         =num_attention_heads
											__lowerCamelCase      :      Optional[int]         =intermediate_size
											__lowerCamelCase      :      Tuple         =hidden_act
											__lowerCamelCase      :      List[Any]         =hidden_dropout_prob
											__lowerCamelCase      :      Optional[int]         =attention_probs_dropout_prob
											__lowerCamelCase      :      Union[str, Any]         =max_position_embeddings
											__lowerCamelCase      :      Union[str, Any]         =type_vocab_size
											__lowerCamelCase      :      Optional[Any]         =type_sequence_label_size
											__lowerCamelCase      :      Tuple         =initializer_range
											__lowerCamelCase      :      List[str]         =num_labels
											__lowerCamelCase      :      Tuple         =num_choices
											__lowerCamelCase      :      Optional[int]         =scope




				def 					__lowercase  (     self  :str			):
											__lowerCamelCase      :      Union[str, Any]         =ids_tensor([self.batch_size, self.seq_length]						,    self.vocab_size			)

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

											__lowerCamelCase      :      Tuple         =None
											if self.use_token_type_ids:
																		__lowerCamelCase      :      Optional[int]         =ids_tensor([self.batch_size, self.seq_length]						,    self.type_vocab_size			)

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

											__lowerCamelCase      :      Optional[Any]         =self.get_config()

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




				def 					__lowercase  (     self  :Optional[int]			):
											return BioGptConfig(
											    vocab_size=self.vocab_size						,    hidden_size=self.hidden_size						,    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						,    is_decoder=__lowercase						,    initializer_range=self.initializer_range						,    )




				def 					__lowercase  (     self  :Optional[Any]						,    __lowercase  :Tuple						,    __lowercase  :List[str]						,    __lowercase  :Optional[Any]						,    __lowercase  :Optional[int]						,    __lowercase  :str						,    __lowercase  :Union[str, Any]						,    __lowercase  :Any			):
											__lowerCamelCase      :      List[str]         =BioGptModel(config=__lowercase			)
											model.to(__lowercase			)
											model.eval()
											__lowerCamelCase      :      List[Any]         =model(__lowercase						,    attention_mask=__lowercase			)
											__lowerCamelCase      :      Dict         =model(__lowercase			)
											self.parent.assertEqual(result.last_hidden_state.shape						,    (self.batch_size, self.seq_length, self.hidden_size)			)




				def 					__lowercase  (     self  :Union[str, Any]						,    __lowercase  :List[str]						,    __lowercase  :Optional[Any]						,    __lowercase  :str						,    __lowercase  :int						,    __lowercase  :List[Any]						,    __lowercase  :Tuple						,    __lowercase  :List[Any]						,    __lowercase  :str						,    __lowercase  :Tuple						,    ):
											__lowerCamelCase      :      List[str]         =BioGptForCausalLM(config=__lowercase			)
											model.to(__lowercase			)
											model.eval()
											__lowerCamelCase      :      Any         =model(__lowercase						,    attention_mask=__lowercase						,    token_type_ids=__lowercase						,    labels=__lowercase			)
											self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.seq_length, self.vocab_size)			)




				def 					__lowercase  (     self  :Any						,    __lowercase  :str						,    __lowercase  :Any						,    __lowercase  :Optional[int]						,    __lowercase  :Optional[Any]						,    __lowercase  :int						,    *__lowercase  :Dict			):
											__lowerCamelCase      :      int         =BioGptModel(config=__lowercase			)
											model.to(__lowercase			)
											model.eval()

											# create attention mask
											__lowerCamelCase      :      Any         =torch.ones(input_ids.shape						,    dtype=torch.long						,    device=__lowercase			)
											__lowerCamelCase      :      Optional[Any]         =self.seq_length // 2
											__lowerCamelCase      :      Union[str, Any]         =0

											# first forward pass
											__lowerCamelCase    ,						__lowerCamelCase      :      int         =model(__lowercase						,    attention_mask=__lowercase			).to_tuple()

											# create hypothetical next token and extent to next_input_ids
											__lowerCamelCase      :      Union[str, Any]         =ids_tensor((self.batch_size, 1)						,    config.vocab_size			)

											# change a random masked slice from input_ids
											__lowerCamelCase      :      int         =ids_tensor((1,)						,    __lowercase			).item() + 1
											__lowerCamelCase      :      Optional[int]         =ids_tensor((self.batch_size, 1)						,    config.vocab_size			).squeeze(-1			)
											__lowerCamelCase      :      int         =random_other_next_tokens

											# append to next input_ids and attn_mask
											__lowerCamelCase      :      List[Any]         =torch.cat([input_ids, next_tokens]						,    dim=-1			)
											__lowerCamelCase      :      List[Any]         =torch.cat(
											    [attn_mask, torch.ones((attn_mask.shape[0], 1)						,    dtype=torch.long						,    device=__lowercase			)]						,    dim=1						,    )

											# get two different outputs
											__lowerCamelCase      :      Optional[int]         =model(__lowercase						,    attention_mask=__lowercase			)['''last_hidden_state''']
											__lowerCamelCase      :      str         =model(__lowercase						,    past_key_values=__lowercase						,    attention_mask=__lowercase			)['''last_hidden_state''']

											# select random slice
											__lowerCamelCase      :      Union[str, Any]         =ids_tensor((1,)						,    output_from_past.shape[-1]			).item()
											__lowerCamelCase      :      Dict         =output_from_no_past[:, -1, random_slice_idx].detach()
											__lowerCamelCase      :      Optional[Any]         =output_from_past[:, 0, random_slice_idx].detach()

											# test that outputs are equal for slice
											self.parent.assertTrue(torch.allclose(__lowercase						,    __lowercase						,    atol=1e-3			)			)




				def 					__lowercase  (     self  :str						,    __lowercase  :Optional[Any]						,    __lowercase  :Optional[int]						,    __lowercase  :Tuple						,    __lowercase  :str						,    __lowercase  :str						,    *__lowercase  :Optional[int]			):
											__lowerCamelCase      :      Optional[int]         =BioGptModel(config=__lowercase			).to(__lowercase			).eval()

											__lowerCamelCase      :      int         =torch.ones(input_ids.shape						,    dtype=torch.long						,    device=__lowercase			)

											# first forward pass
											__lowerCamelCase      :      Dict         =model(__lowercase						,    attention_mask=__lowercase						,    use_cache=__lowercase			)

											__lowerCamelCase    ,						__lowerCamelCase      :      int         =outputs.to_tuple()

											# create hypothetical multiple next token and extent to next_input_ids
											__lowerCamelCase      :      List[Any]         =ids_tensor((self.batch_size, 3)						,    config.vocab_size			)
											__lowerCamelCase      :      Dict         =ids_tensor((self.batch_size, 3)						,    2			)

											# append to next input_ids and
											__lowerCamelCase      :      Union[str, Any]         =torch.cat([input_ids, next_tokens]						,    dim=-1			)
											__lowerCamelCase      :      Dict         =torch.cat([attention_mask, next_attn_mask]						,    dim=-1			)

											__lowerCamelCase      :      Optional[Any]         =model(__lowercase						,    attention_mask=__lowercase			)['''last_hidden_state''']
											__lowerCamelCase      :      int         =model(__lowercase						,    attention_mask=__lowercase						,    past_key_values=__lowercase			)[
											    '''last_hidden_state'''
											]

											# select random slice
											__lowerCamelCase      :      Optional[Any]         =ids_tensor((1,)						,    output_from_past.shape[-1]			).item()
											__lowerCamelCase      :      str         =output_from_no_past[:, -3:, random_slice_idx].detach()
											__lowerCamelCase      :      int         =output_from_past[:, :, random_slice_idx].detach()

											self.parent.assertTrue(output_from_past_slice.shape[1] == next_tokens.shape[1]			)

											# test that outputs are equal for slice
											self.parent.assertTrue(torch.allclose(__lowercase						,    __lowercase						,    atol=1e-3			)			)




				def 					__lowercase  (     self  :Optional[int]						,    __lowercase  :Dict						,    __lowercase  :int						,    __lowercase  :Dict						,    __lowercase  :Union[str, Any]						,    __lowercase  :str						,    *__lowercase  :Any						,    __lowercase  :Union[str, Any]=False			):
											__lowerCamelCase      :      Dict         =BioGptForCausalLM(__lowercase			)
											model.to(__lowercase			)
											if gradient_checkpointing:
																		model.gradient_checkpointing_enable()

											__lowerCamelCase      :      Any         =model(__lowercase						,    labels=__lowercase			)
											self.parent.assertEqual(result.loss.shape						,    ()			)
											self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.seq_length, self.vocab_size)			)
											result.loss.backward()




				def 					__lowercase  (     self  :Tuple						,    __lowercase  :Union[str, Any]						,    *__lowercase  :List[Any]			):
											__lowerCamelCase      :      List[str]         =BioGptModel(__lowercase			)
											__lowerCamelCase      :      Tuple         =model.config.initializer_range / math.sqrt(2 * model.config.num_hidden_layers			)
											for key in model.state_dict().keys():
																		if "c_proj" in key and "weight" in key:
																									self.parent.assertLessEqual(abs(torch.std(model.state_dict()[key]			) - model_std			)						,    0.001			)
																									self.parent.assertLessEqual(abs(torch.mean(model.state_dict()[key]			) - 0.0			)						,    0.01			)




				def 					__lowercase  (     self  :Dict						,    __lowercase  :Optional[int]						,    __lowercase  :Optional[int]						,    __lowercase  :List[str]						,    __lowercase  :Optional[Any]						,    __lowercase  :int						,    *__lowercase  :Optional[int]			):
											__lowerCamelCase      :      Tuple         =self.num_labels
											__lowerCamelCase      :      Tuple         =BioGptForTokenClassification(__lowercase			)
											model.to(__lowercase			)
											model.eval()
											__lowerCamelCase      :      List[Any]         =model(__lowercase						,    attention_mask=__lowercase						,    token_type_ids=__lowercase			)
											self.parent.assertEqual(result.logits.shape						,    (self.batch_size, self.seq_length, self.num_labels)			)




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      Any         =self.prepare_config_and_inputs()
											(
											    (
											    __lowerCamelCase
											)    ,						(
											    __lowerCamelCase
											)    ,						(
											    __lowerCamelCase
											)    ,						(
											    __lowerCamelCase
											)    ,						(
											    __lowerCamelCase
											)    ,						(
											    __lowerCamelCase
											)    ,						(
											    __lowerCamelCase
											)    ,						
											)      :      List[str]         =config_and_inputs
											__lowerCamelCase      :      Dict         ={'''input_ids''': input_ids, '''attention_mask''': input_mask}
											return config, inputs_dict

@require_torch
class 		SCREAMING_SNAKE_CASE_							(    snake_case__       ,  snake_case__       ,  snake_case__       ,  unittest.TestCase   ):
				"""simple docstring"""
				__snake_case   :       Any	 =		(
				    (BioGptModel, BioGptForCausalLM, BioGptForSequenceClassification, BioGptForTokenClassification)
				    if is_torch_available()
				    else ()
				)
				__snake_case   :       List[Any]	 =		(BioGptForCausalLM,) if is_torch_available() else ()
				__snake_case   :       Union[str, Any]	 =		(
				    {
				        """feature-extraction""": BioGptModel,
				        """text-classification""": BioGptForSequenceClassification,
				        """text-generation""": BioGptForCausalLM,
				        """token-classification""": BioGptForTokenClassification,
				        """zero-shot""": BioGptForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				__snake_case   :       Union[str, Any]	 =		False




				def 					__lowercase  (     self  :List[Any]			):
											__lowerCamelCase      :      List[Any]         =BioGptModelTester(self			)
											__lowerCamelCase      :      List[str]         =ConfigTester(self						,    config_class=__lowercase						,    hidden_size=37			)




				def 					__lowercase  (     self  :int			):
											self.config_tester.run_common_tests()




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      int         =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_model(*__lowercase			)




				def 					__lowercase  (     self  :Optional[Any]			):
											__lowerCamelCase      :      Dict         =self.model_tester.prepare_config_and_inputs()
											for type in ["absolute", "relative_key", "relative_key_query"]:
																		__lowerCamelCase      :      int         =type
																		self.model_tester.create_and_check_model(*__lowercase			)




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      Optional[int]         =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_biogpt_model_attention_mask_past(*__lowercase			)




				def 					__lowercase  (     self  :Union[str, Any]			):
											__lowerCamelCase      :      int         =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_forward_and_backwards(*__lowercase						,    gradient_checkpointing=__lowercase			)




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      Any         =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_biogpt_model_past_large_inputs(*__lowercase			)




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      Dict         =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_biogpt_weight_initialization(*__lowercase			)




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      int         =self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_biogpt_for_token_classification(*__lowercase			)




				@slow
				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      Optional[Any]         =BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''			)
											model.to(__lowercase			)
											__lowerCamelCase      :      Tuple         =BioGptTokenizer.from_pretrained('''microsoft/biogpt'''			)

											__lowerCamelCase      :      Optional[Any]         ='''left'''

											# Define PAD Token = EOS Token = 50256
											__lowerCamelCase      :      List[str]         =tokenizer.eos_token
											__lowerCamelCase      :      List[Any]         =model.config.eos_token_id

											# use different length sentences to test batching
											__lowerCamelCase      :      Tuple         =[
											    '''Hello, my dog is a little''',
											    '''Today, I''',
											]

											__lowerCamelCase      :      int         =tokenizer(__lowercase						,    return_tensors='''pt'''						,    padding=__lowercase			)
											__lowerCamelCase      :      int         =inputs['''input_ids'''].to(__lowercase			)

											__lowerCamelCase      :      Optional[int]         =model.generate(
											    input_ids=__lowercase						,    attention_mask=inputs['''attention_mask'''].to(__lowercase			)						,    )

											__lowerCamelCase      :      str         =tokenizer(sentences[0]						,    return_tensors='''pt'''			).input_ids.to(__lowercase			)
											__lowerCamelCase      :      str         =model.generate(input_ids=__lowercase			)

											__lowerCamelCase      :      List[Any]         =inputs_non_padded.shape[-1] - inputs['''attention_mask'''][-1].long().sum().cpu().item()
											__lowerCamelCase      :      Optional[int]         =tokenizer(sentences[1]						,    return_tensors='''pt'''			).input_ids.to(__lowercase			)
											__lowerCamelCase      :      Optional[Any]         =model.generate(input_ids=__lowercase						,    max_length=model.config.max_length - num_paddings			)

											__lowerCamelCase      :      int         =tokenizer.batch_decode(__lowercase						,    skip_special_tokens=__lowercase			)
											__lowerCamelCase      :      Optional[Any]         =tokenizer.decode(output_non_padded[0]						,    skip_special_tokens=__lowercase			)
											__lowerCamelCase      :      Tuple         =tokenizer.decode(output_padded[0]						,    skip_special_tokens=__lowercase			)

											__lowerCamelCase      :      List[str]         =[
											    '''Hello, my dog is a little bit bigger than a little bit.''',
											    '''Today, I have a good idea of how to use the information''',
											]
											self.assertListEqual(__lowercase						,    __lowercase			)
											self.assertListEqual(__lowercase						,    [non_padded_sentence, padded_sentence]			)




				@slow
				def 					__lowercase  (     self  :Tuple			):
											for model_name in BIOGPT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																		__lowerCamelCase      :      Tuple         =BioGptModel.from_pretrained(__lowercase			)
																		self.assertIsNotNone(__lowercase			)




				def 					__lowercase  (     self  :Any			):
											__lowerCamelCase    ,						__lowerCamelCase      :      Any         =self.model_tester.prepare_config_and_inputs_for_common()
											__lowerCamelCase      :      List[str]         =3
											__lowerCamelCase      :      Union[str, Any]         =input_dict['''input_ids''']
											__lowerCamelCase      :      Optional[int]         =input_ids.ne(1			).to(__lowercase			)
											__lowerCamelCase      :      Any         =ids_tensor([self.model_tester.batch_size]						,    self.model_tester.type_sequence_label_size			)
											__lowerCamelCase      :      List[Any]         =BioGptForSequenceClassification(__lowercase			)
											model.to(__lowercase			)
											model.eval()
											__lowerCamelCase      :      str         =model(__lowercase						,    attention_mask=__lowercase						,    labels=__lowercase			)
											self.assertEqual(result.logits.shape						,    (self.model_tester.batch_size, self.model_tester.num_labels)			)




				def 					__lowercase  (     self  :str			):
											__lowerCamelCase    ,						__lowerCamelCase      :      Tuple         =self.model_tester.prepare_config_and_inputs_for_common()
											__lowerCamelCase      :      List[Any]         =3
											__lowerCamelCase      :      List[Any]         ='''multi_label_classification'''
											__lowerCamelCase      :      Tuple         =input_dict['''input_ids''']
											__lowerCamelCase      :      str         =input_ids.ne(1			).to(__lowercase			)
											__lowerCamelCase      :      int         =ids_tensor(
											    [self.model_tester.batch_size, config.num_labels]						,    self.model_tester.type_sequence_label_size			).to(torch.float			)
											__lowerCamelCase      :      Optional[int]         =BioGptForSequenceClassification(__lowercase			)
											model.to(__lowercase			)
											model.eval()
											__lowerCamelCase      :      Tuple         =model(__lowercase						,    attention_mask=__lowercase						,    labels=__lowercase			)
											self.assertEqual(result.logits.shape						,    (self.model_tester.batch_size, self.model_tester.num_labels)			)

@require_torch
class 		SCREAMING_SNAKE_CASE_							(    unittest.TestCase   ):
				"""simple docstring"""




				@slow
				def 					__lowercase  (     self  :int			):
											__lowerCamelCase      :      Union[str, Any]         =BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''			)
											__lowerCamelCase      :      int         =torch.tensor([[2, 4805, 9, 656, 21]]			)
											__lowerCamelCase      :      List[str]         =model(__lowercase			)[0]

											__lowerCamelCase      :      int         =4_2384

											__lowerCamelCase      :      List[str]         =torch.Size((1, 5, vocab_size)			)
											self.assertEqual(output.shape						,    __lowercase			)

											__lowerCamelCase      :      Tuple         =torch.tensor(
											    [[[-9.5236, -9.8918, 10.4557], [-11.0469, -9.6423, 8.1022], [-8.8664, -7.8826, 5.5325]]]			)

											self.assertTrue(torch.allclose(output[:, :3, :3]						,    __lowercase						,    atol=1e-4			)			)




				@slow
				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      Union[str, Any]         =BioGptTokenizer.from_pretrained('''microsoft/biogpt'''			)
											__lowerCamelCase      :      str         =BioGptForCausalLM.from_pretrained('''microsoft/biogpt'''			)
											model.to(__lowercase			)

											torch.manual_seed(0			)
											__lowerCamelCase      :      Union[str, Any]         =tokenizer('''COVID-19 is'''						,    return_tensors='''pt'''			).to(__lowercase			)
											__lowerCamelCase      :      int         =model.generate(
											    **__lowercase						,    min_length=100						,    max_length=1024						,    num_beams=5						,    early_stopping=__lowercase						,    )
											__lowerCamelCase      :      Union[str, Any]         =tokenizer.decode(output_ids[0]						,    skip_special_tokens=__lowercase			)

											__lowerCamelCase      :      int         =(
											    '''COVID-19 is a global pandemic caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), the'''
											    ''' causative agent of coronavirus disease 2019 (COVID-19), which has spread to more than 200 countries and'''
											    ''' territories, including the United States (US), Canada, Australia, New Zealand, the United Kingdom (UK),'''
											    ''' and the United States of America (USA), as of March 11, 2020, with more than 800,000 confirmed cases and'''
											    ''' more than 800,000 deaths.'''
											)
											self.assertEqual(__lowercase						,    __lowercase			)











"""simple docstring"""





import unittest

from .lib import (
    Matrix,
    Vector,
    axpy,
    square_zero_matrix,
    unit_basis_vector,
    zero_vector,
)
class 		SCREAMING_SNAKE_CASE_							(    unittest.TestCase   ):
				"""simple docstring"""




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      Any         =Vector([1, 2, 3]			)
											self.assertEqual(x.component(0			)						,    1			)
											self.assertEqual(x.component(2			)						,    3			)
											__lowerCamelCase      :      Any         =Vector()




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      Tuple         =Vector([0, 0, 0, 0, 0, 1]			)
											self.assertEqual(str(__lowercase			)						,    '''(0,0,0,0,0,1)'''			)




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      int         =Vector([1, 2, 3, 4]			)
											self.assertEqual(len(__lowercase			)						,    4			)




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      Optional[Any]         =Vector([1, 2]			)
											__lowerCamelCase      :      Dict         =Vector([1, 2, 3, 4, 5]			)
											__lowerCamelCase      :      List[Any]         =Vector([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]			)
											__lowerCamelCase      :      int         =Vector([1, -1, 1, -1, 2, -3, 4, -5]			)
											self.assertAlmostEqual(x.euclidean_length()						,    2.236						,    3			)
											self.assertAlmostEqual(y.euclidean_length()						,    7.416						,    3			)
											self.assertEqual(z.euclidean_length()						,    0			)
											self.assertAlmostEqual(w.euclidean_length()						,    7.616						,    3			)




				def 					__lowercase  (     self  :Optional[int]			):
											__lowerCamelCase      :      Tuple         =Vector([1, 2, 3]			)
											__lowerCamelCase      :      Any         =Vector([1, 1, 1]			)
											self.assertEqual((x + y).component(0			)						,    2			)
											self.assertEqual((x + y).component(1			)						,    3			)
											self.assertEqual((x + y).component(2			)						,    4			)




				def 					__lowercase  (     self  :str			):
											__lowerCamelCase      :      Union[str, Any]         =Vector([1, 2, 3]			)
											__lowerCamelCase      :      int         =Vector([1, 1, 1]			)
											self.assertEqual((x - y).component(0			)						,    0			)
											self.assertEqual((x - y).component(1			)						,    1			)
											self.assertEqual((x - y).component(2			)						,    2			)




				def 					__lowercase  (     self  :int			):
											__lowerCamelCase      :      List[Any]         =Vector([1, 2, 3]			)
											__lowerCamelCase      :      List[Any]         =Vector([2, -1, 4]			)  # for test of dot product
											__lowerCamelCase      :      Any         =Vector([1, -2, -1]			)
											self.assertEqual(str(x * 3.0			)						,    '''(3.0,6.0,9.0)'''			)
											self.assertEqual((a * b)						,    0			)




				def 					__lowercase  (     self  :List[Any]			):
											self.assertEqual(str(zero_vector(10			)			).count('''0'''			)						,    10			)




				def 					__lowercase  (     self  :Union[str, Any]			):
											self.assertEqual(str(unit_basis_vector(3						,    1			)			)						,    '''(0,1,0)'''			)




				def 					__lowercase  (     self  :List[Any]			):
											__lowerCamelCase      :      Any         =Vector([1, 2, 3]			)
											__lowerCamelCase      :      Optional[int]         =Vector([1, 0, 1]			)
											self.assertEqual(str(axpy(2						,    __lowercase						,    __lowercase			)			)						,    '''(3,4,7)'''			)




				def 					__lowercase  (     self  :Dict			):
											__lowerCamelCase      :      List[Any]         =Vector([1, 0, 0, 0, 0, 0]			)
											__lowerCamelCase      :      Optional[int]         =x.copy()
											self.assertEqual(str(__lowercase			)						,    str(__lowercase			)			)




				def 					__lowercase  (     self  :int			):
											__lowerCamelCase      :      str         =Vector([1, 0, 0]			)
											x.change_component(0						,    0			)
											x.change_component(1						,    1			)
											self.assertEqual(str(__lowercase			)						,    '''(0,1,0)'''			)




				def 					__lowercase  (     self  :int			):
											__lowerCamelCase      :      Any         =Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]						,    3						,    3			)
											self.assertEqual('''|1,2,3|\n|2,4,5|\n|6,7,8|\n'''						,    str(__lowercase			)			)




				def 					__lowercase  (     self  :int			):
											__lowerCamelCase      :      Tuple         =Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]						,    3						,    3			)
											__lowerCamelCase      :      List[Any]         =[[-3, -14, -10], [-5, -10, -5], [-2, -1, 0]]
											for x in range(a.height()			):
																		for y in range(a.width()			):
																									self.assertEqual(minors[x][y]						,    a.minor(__lowercase						,    __lowercase			)			)




				def 					__lowercase  (     self  :Optional[int]			):
											__lowerCamelCase      :      Optional[Any]         =Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]						,    3						,    3			)
											__lowerCamelCase      :      Tuple         =[[-3, 14, -10], [5, -10, 5], [-2, 1, 0]]
											for x in range(a.height()			):
																		for y in range(a.width()			):
																									self.assertEqual(cofactors[x][y]						,    a.cofactor(__lowercase						,    __lowercase			)			)




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      Tuple         =Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]						,    3						,    3			)
											self.assertEqual(-5						,    a.determinant()			)




				def 					__lowercase  (     self  :int			):
											__lowerCamelCase      :      Union[str, Any]         =Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]						,    3						,    3			)
											__lowerCamelCase      :      Tuple         =Vector([1, 2, 3]			)
											self.assertEqual('''(14,32,50)'''						,    str(a * x			)			)
											self.assertEqual('''|2,4,6|\n|8,10,12|\n|14,16,18|\n'''						,    str(a * 2			)			)




				def 					__lowercase  (     self  :Optional[Any]			):
											__lowerCamelCase      :      Optional[int]         =Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]						,    3						,    3			)
											a.change_component(0						,    2						,    5			)
											self.assertEqual('''|1,2,5|\n|2,4,5|\n|6,7,8|\n'''						,    str(__lowercase			)			)




				def 					__lowercase  (     self  :str			):
											__lowerCamelCase      :      str         =Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]						,    3						,    3			)
											self.assertEqual(7						,    a.component(2						,    1			)						,    0.01			)




				def 					__lowercase  (     self  :Optional[int]			):
											__lowerCamelCase      :      List[str]         =Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]						,    3						,    3			)
											__lowerCamelCase      :      List[str]         =Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 10]]						,    3						,    3			)
											self.assertEqual('''|2,4,10|\n|4,8,10|\n|12,14,18|\n'''						,    str(a + b			)			)




				def 					__lowercase  (     self  :Union[str, Any]			):
											__lowerCamelCase      :      int         =Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]						,    3						,    3			)
											__lowerCamelCase      :      Optional[int]         =Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 10]]						,    3						,    3			)
											self.assertEqual('''|0,0,-4|\n|0,0,0|\n|0,0,-2|\n'''						,    str(a - b			)			)




				def 					__lowercase  (     self  :Any			):
											self.assertEqual(
											    '''|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n|0,0,0,0,0|\n'''						,    str(square_zero_matrix(5			)			)						,    )


if __name__ == "__main__":
							unittest.main()




