





import inspect
import unittest

import numpy as np

from tests.test_modeling_common import floats_tensor
from transformers import DetrConfig, MaskFormerConfig, SwinConfig, is_torch_available, is_vision_available
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import cached_property

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
							import torch

							from transformers import MaskFormerForInstanceSegmentation, MaskFormerModel

							if is_vision_available():
														from transformers import MaskFormerImageProcessor

if is_vision_available():
							from PIL import Image
class 		SCREAMING_SNAKE_CASE_							:
				"""simple docstring"""




				def __init__(     self  :List[Any]						,    __lowercase  :List[str]						,    __lowercase  :Optional[Any]=2						,    __lowercase  :Optional[int]=True						,    __lowercase  :Dict=False						,    __lowercase  :List[Any]=10						,    __lowercase  :str=3						,    __lowercase  :Any=32 * 4						,    __lowercase  :Dict=32 * 6						,    __lowercase  :Tuple=4						,    __lowercase  :List[Any]=32						,    ):
											__lowerCamelCase      :      Any         =parent
											__lowerCamelCase      :      Union[str, Any]         =batch_size
											__lowerCamelCase      :      List[str]         =is_training
											__lowerCamelCase      :      Dict         =use_auxiliary_loss
											__lowerCamelCase      :      List[Any]         =num_queries
											__lowerCamelCase      :      int         =num_channels
											__lowerCamelCase      :      Dict         =min_size
											__lowerCamelCase      :      Tuple         =max_size
											__lowerCamelCase      :      Any         =num_labels
											__lowerCamelCase      :      Dict         =mask_feature_size




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      Optional[Any]         =floats_tensor([self.batch_size, self.num_channels, self.min_size, self.max_size]			).to(
											    __lowercase			)

											__lowerCamelCase      :      Optional[int]         =torch.ones([self.batch_size, self.min_size, self.max_size]						,    device=__lowercase			)

											__lowerCamelCase      :      int         =(
											    torch.rand([self.batch_size, self.num_labels, self.min_size, self.max_size]						,    device=__lowercase			) > 0.5
											).float()
											__lowerCamelCase      :      List[str]         =(torch.rand((self.batch_size, self.num_labels)						,    device=__lowercase			) > 0.5).long()

											__lowerCamelCase      :      Optional[Any]         =self.get_config()
											return config, pixel_values, pixel_mask, mask_labels, class_labels




				def 					__lowercase  (     self  :Union[str, Any]			):
											return MaskFormerConfig.from_backbone_and_decoder_configs(
											    backbone_config=SwinConfig(
											        depths=[1, 1, 1, 1]						,    )						,    decoder_config=DetrConfig(
											        decoder_ffn_dim=128						,    num_queries=self.num_queries						,    decoder_attention_heads=2						,    d_model=self.mask_feature_size						,    )						,    mask_feature_size=self.mask_feature_size						,    fpn_feature_size=self.mask_feature_size						,    num_channels=self.num_channels						,    num_labels=self.num_labels						,    )




				def 					__lowercase  (     self  :Union[str, Any]			):
											__lowerCamelCase      :      Optional[int]         =self.prepare_config_and_inputs()
											__lowerCamelCase      :      int         ={"pixel_values": pixel_values, "pixel_mask": pixel_mask}
											return config, inputs_dict




				def 					__lowercase  (     self  :List[Any]						,    __lowercase  :List[str]						,    __lowercase  :List[Any]			):
											__lowerCamelCase      :      List[Any]         =output.encoder_hidden_states
											__lowerCamelCase      :      Tuple         =output.pixel_decoder_hidden_states
											__lowerCamelCase      :      Optional[int]         =output.transformer_decoder_hidden_states

											self.parent.assertTrue(len(__lowercase			)						,    len(config.backbone_config.depths			)			)
											self.parent.assertTrue(len(__lowercase			)						,    len(config.backbone_config.depths			)			)
											self.parent.assertTrue(len(__lowercase			)						,    config.decoder_config.decoder_layers			)




				def 					__lowercase  (     self  :str						,    __lowercase  :Optional[Any]						,    __lowercase  :Optional[int]						,    __lowercase  :Any						,    __lowercase  :int=False			):
											with torch.no_grad():
																		__lowerCamelCase      :      Optional[int]         =MaskFormerModel(config=__lowercase			)
																		model.to(__lowercase			)
																		model.eval()

																		__lowerCamelCase      :      int         =model(pixel_values=__lowercase						,    pixel_mask=__lowercase			)
																		__lowerCamelCase      :      List[Any]         =model(__lowercase						,    output_hidden_states=__lowercase			)
											# the correct shape of output.transformer_decoder_hidden_states ensure the correcteness of the
											# encoder and pixel decoder
											self.parent.assertEqual(
											    output.transformer_decoder_last_hidden_state.shape						,    (self.batch_size, self.num_queries, self.mask_feature_size)						,    )
											# let's ensure the other two hidden state exists
											self.parent.assertTrue(output.pixel_decoder_last_hidden_state is not None			)
											self.parent.assertTrue(output.encoder_last_hidden_state is not None			)

											if output_hidden_states:
																		self.check_output_hidden_state(__lowercase						,    __lowercase			)




				def 					__lowercase  (     self  :Dict						,    __lowercase  :Tuple						,    __lowercase  :str						,    __lowercase  :Tuple						,    __lowercase  :List[str]						,    __lowercase  :Tuple			):
											__lowerCamelCase      :      Optional[int]         =MaskFormerForInstanceSegmentation(config=__lowercase			)
											model.to(__lowercase			)
											model.eval()

											def comm_check_on_output(__lowercase  :Optional[Any]			):
																		# let's still check that all the required stuff is there
																		self.parent.assertTrue(result.transformer_decoder_last_hidden_state is not None			)
																		self.parent.assertTrue(result.pixel_decoder_last_hidden_state is not None			)
																		self.parent.assertTrue(result.encoder_last_hidden_state is not None			)
																		# okay, now we need to check the logits shape
																		# due to the encoder compression, masks have a //4 spatial size
																		self.parent.assertEqual(
																		    result.masks_queries_logits.shape						,    (self.batch_size, self.num_queries, self.min_size // 4, self.max_size // 4)						,    )
																		# + 1 for null class
																		self.parent.assertEqual(
																		    result.class_queries_logits.shape						,    (self.batch_size, self.num_queries, self.num_labels + 1)			)

											with torch.no_grad():
																		__lowerCamelCase      :      str         =model(pixel_values=__lowercase						,    pixel_mask=__lowercase			)
																		__lowerCamelCase      :      Tuple         =model(__lowercase			)

																		comm_check_on_output(__lowercase			)

																		__lowerCamelCase      :      Union[str, Any]         =model(
																		    pixel_values=__lowercase						,    pixel_mask=__lowercase						,    mask_labels=__lowercase						,    class_labels=__lowercase			)

											comm_check_on_output(__lowercase			)

											self.parent.assertTrue(result.loss is not None			)
											self.parent.assertEqual(result.loss.shape						,    torch.Size([1]			)			)

@require_torch
class 		SCREAMING_SNAKE_CASE_							(    lowercase__       ,  lowercase__       ,  unittest.TestCase   ):
				"""simple docstring"""
				__snake_case   :       Union[str, Any]	 =		(MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else ()
				__snake_case   :       Union[str, Any]	 =		(
				    {"""feature-extraction""": MaskFormerModel, """image-segmentation""": MaskFormerForInstanceSegmentation}
				    if is_torch_available()
				    else {}
				)

				__snake_case   :       Dict	 =		False
				__snake_case   :       List[Any]	 =		False
				__snake_case   :       List[str]	 =		False
				__snake_case   :       Optional[Any]	 =		False




				def 					__lowercase  (     self  :Any			):
											__lowerCamelCase      :      int         =MaskFormerModelTester(self			)
											__lowerCamelCase      :      List[Any]         =ConfigTester(self						,    config_class=__lowercase						,    has_text_modality=__lowercase			)




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




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      List[Any]         =self.model_tester.prepare_config_and_inputs_for_common()
											self.model_tester.create_and_check_maskformer_model(__lowercase						,    **__lowercase						,    output_hidden_states=__lowercase			)




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




				@unittest.skip(reason='''MaskFormer does not use inputs_embeds'''			)
				def 					__lowercase  (     self  :List[str]			):
											pass




				@unittest.skip(reason='''MaskFormer does not have a get_input_embeddings method'''			)
				def 					__lowercase  (     self  :Any			):
											pass




				@unittest.skip(reason='''MaskFormer is not a generative model'''			)
				def 					__lowercase  (     self  :Optional[Any]			):
											pass




				@unittest.skip(reason='''MaskFormer does not use token embeddings'''			)
				def 					__lowercase  (     self  :Dict			):
											pass




				@require_torch_multi_gpu
				@unittest.skip(
				    reason='''MaskFormer has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'''			)
				def 					__lowercase  (     self  :Union[str, Any]			):
											pass




				@unittest.skip('''Will be fixed soon by reducing the size of the model used for common tests.'''			)
				def 					__lowercase  (     self  :int			):
											pass




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      List[Any]         =self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																		__lowerCamelCase      :      List[Any]         =model_class(__lowercase			)
																		__lowerCamelCase      :      Optional[Any]         =inspect.signature(model.forward			)
																		# signature.parameters is an OrderedDict => so arg_names order is deterministic
																		__lowerCamelCase      :      str         =[*signature.parameters.keys()]

																		__lowerCamelCase      :      Tuple         =["pixel_values"]
																		self.assertListEqual(arg_names[:1]						,    __lowercase			)




				@slow
				def 					__lowercase  (     self  :Union[str, Any]			):
											for model_name in ["facebook/maskformer-swin-small-coco"]:
																		__lowerCamelCase      :      str         =MaskFormerModel.from_pretrained(__lowercase			)
																		self.assertIsNotNone(__lowercase			)




				def 					__lowercase  (     self  :List[Any]			):
											__lowerCamelCase      :      Union[str, Any]         =(self.model_tester.min_size,) * 2
											__lowerCamelCase      :      Union[str, Any]         ={
											    "pixel_values": torch.randn((2, 3, *size)						,    device=__lowercase			),
											    "mask_labels": torch.randn((2, 10, *size)						,    device=__lowercase			),
											    "class_labels": torch.zeros(2						,    10						,    device=__lowercase			).long(),
											}

											__lowerCamelCase      :      Tuple         =MaskFormerForInstanceSegmentation(MaskFormerConfig()			).to(__lowercase			)
											__lowerCamelCase      :      Dict         =model(**__lowercase			)
											self.assertTrue(outputs.loss is not None			)




				def 					__lowercase  (     self  :Optional[int]			):
											__lowerCamelCase      :      int         =self.model_tester.prepare_config_and_inputs_for_common()
											self.model_tester.create_and_check_maskformer_model(__lowercase						,    **__lowercase						,    output_hidden_states=__lowercase			)




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      str         =self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																		__lowerCamelCase      :      List[str]         =model_class(__lowercase			).to(__lowercase			)
																		__lowerCamelCase      :      str         =model(**__lowercase						,    output_attentions=__lowercase			)
																		self.assertTrue(outputs.attentions is not None			)




				def 					__lowercase  (     self  :Any			):
											if not self.model_tester.is_training:
																		return
											# only MaskFormerForInstanceSegmentation has the loss
											__lowerCamelCase      :      Dict         =self.all_model_classes[1]
											__lowerCamelCase      :      Any         =self.model_tester.prepare_config_and_inputs()

											__lowerCamelCase      :      Union[str, Any]         =model_class(__lowercase			)
											model.to(__lowercase			)
											model.train()

											__lowerCamelCase      :      Tuple         =model(__lowercase						,    mask_labels=__lowercase						,    class_labels=__lowercase			).loss
											loss.backward()




				def 					__lowercase  (     self  :Tuple			):
											# only MaskFormerForInstanceSegmentation has the loss
											__lowerCamelCase      :      List[str]         =self.all_model_classes[1]
											__lowerCamelCase      :      Dict         =self.model_tester.prepare_config_and_inputs()
											__lowerCamelCase      :      int         =True
											__lowerCamelCase      :      List[Any]         =True

											__lowerCamelCase      :      Any         =model_class(__lowercase			)
											model.to(__lowercase			)
											model.train()

											__lowerCamelCase      :      Any         =model(__lowercase						,    mask_labels=__lowercase						,    class_labels=__lowercase			)

											__lowerCamelCase      :      int         =outputs.encoder_hidden_states[0]
											encoder_hidden_states.retain_grad()

											__lowerCamelCase      :      Optional[Any]         =outputs.pixel_decoder_hidden_states[0]
											pixel_decoder_hidden_states.retain_grad()
											# we requires_grad=True in inputs_embeds (line 2152), the original implementation don't
											__lowerCamelCase      :      Any         =outputs.transformer_decoder_hidden_states[0]
											transformer_decoder_hidden_states.retain_grad()

											__lowerCamelCase      :      List[Any]         =outputs.attentions[0]
											attentions.retain_grad()

											outputs.loss.backward(retain_graph=__lowercase			)

											self.assertIsNotNone(encoder_hidden_states.grad			)
											self.assertIsNotNone(pixel_decoder_hidden_states.grad			)
											self.assertIsNotNone(transformer_decoder_hidden_states.grad			)
											self.assertIsNotNone(attentions.grad			)

_UpperCamelCase							=      1e-4



def 				lowerCAmelCase_			(      ):


							'''simple docstring'''







							__lowerCamelCase      :      Dict         =Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''   )
							return image
@require_vision
@slow
class 		SCREAMING_SNAKE_CASE_							(    unittest.TestCase   ):
				"""simple docstring"""




				@cached_property
				def 					__lowercase  (     self  :Tuple			):
											return (
											    MaskFormerImageProcessor.from_pretrained('''facebook/maskformer-swin-small-coco'''			)
											    if is_vision_available()
											    else None
											)




				def 					__lowercase  (     self  :List[Any]			):
											__lowerCamelCase      :      Tuple         =MaskFormerModel.from_pretrained('''facebook/maskformer-swin-small-coco'''			).to(__lowercase			)
											__lowerCamelCase      :      Optional[int]         =self.default_image_processor
											__lowerCamelCase      :      Tuple         =prepare_img()
											__lowerCamelCase      :      int         =image_processor(__lowercase						,    return_tensors='''pt'''			).to(__lowercase			)
											__lowerCamelCase      :      int         =inputs["pixel_values"].shape
											# check size is divisible by 32
											self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0			)
											# check size
											self.assertEqual(__lowercase						,    (1, 3, 800, 1088)			)

											with torch.no_grad():
																		__lowerCamelCase      :      Union[str, Any]         =model(**__lowercase			)

											__lowerCamelCase      :      str         =torch.tensor(
											    [[-0.0482, 0.9228, 0.4951], [-0.2547, 0.8017, 0.8527], [-0.0069, 0.3385, -0.0089]]			).to(__lowercase			)
											self.assertTrue(
											    torch.allclose(
											        outputs.encoder_last_hidden_state[0, 0, :3, :3]						,    __lowercase						,    atol=__lowercase			)			)

											__lowerCamelCase      :      Optional[Any]         =torch.tensor(
											    [[-0.8422, -0.8434, -0.9718], [-1.0144, -0.5565, -0.4195], [-1.0038, -0.4484, -0.1961]]			).to(__lowercase			)
											self.assertTrue(
											    torch.allclose(
											        outputs.pixel_decoder_last_hidden_state[0, 0, :3, :3]						,    __lowercase						,    atol=__lowercase			)			)

											__lowerCamelCase      :      int         =torch.tensor(
											    [[0.2852, -0.0159, 0.9735], [0.6254, 0.1858, 0.8529], [-0.0680, -0.4116, 1.8413]]			).to(__lowercase			)
											self.assertTrue(
											    torch.allclose(
											        outputs.transformer_decoder_last_hidden_state[0, :3, :3]						,    __lowercase						,    atol=__lowercase			)			)




				def 					__lowercase  (     self  :List[str]			):
											__lowerCamelCase      :      List[Any]         =(
											    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''			)
											    .to(__lowercase			)
											    .eval()
											)
											__lowerCamelCase      :      int         =self.default_image_processor
											__lowerCamelCase      :      Optional[int]         =prepare_img()
											__lowerCamelCase      :      Optional[int]         =image_processor(__lowercase						,    return_tensors='''pt'''			).to(__lowercase			)
											__lowerCamelCase      :      Dict         =inputs["pixel_values"].shape
											# check size is divisible by 32
											self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0			)
											# check size
											self.assertEqual(__lowercase						,    (1, 3, 800, 1088)			)

											with torch.no_grad():
																		__lowerCamelCase      :      Dict         =model(**__lowercase			)
											# masks_queries_logits
											__lowerCamelCase      :      Dict         =outputs.masks_queries_logits
											self.assertEqual(
											    masks_queries_logits.shape						,    (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)						,    )
											__lowerCamelCase      :      int         =[
											    [-1.3737124, -1.7724937, -1.9364233],
											    [-1.5977281, -1.9867939, -2.1523695],
											    [-1.5795398, -1.9269832, -2.093942],
											]
											__lowerCamelCase      :      Optional[Any]         =torch.tensor(__lowercase			).to(__lowercase			)
											self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]						,    __lowercase						,    atol=__lowercase			)			)
											# class_queries_logits
											__lowerCamelCase      :      List[str]         =outputs.class_queries_logits
											self.assertEqual(
											    class_queries_logits.shape						,    (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)			)
											__lowerCamelCase      :      Tuple         =torch.tensor(
											    [
											        [1.6_5_1_2e0_0, -5.2_5_7_2e0_0, -3.3_5_1_9e0_0],
											        [3.6_1_6_9e-0_2, -5.9_0_2_5e0_0, -2.9_3_1_3e0_0],
											        [1.0_7_6_6e-0_4, -7.7_6_3_0e0_0, -5.1_2_6_3e0_0],
											    ]			).to(__lowercase			)
											self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]						,    __lowercase						,    atol=__lowercase			)			)




				def 					__lowercase  (     self  :Tuple			):
											__lowerCamelCase      :      str         =(
											    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-resnet101-coco-stuff'''			)
											    .to(__lowercase			)
											    .eval()
											)
											__lowerCamelCase      :      Optional[Any]         =self.default_image_processor
											__lowerCamelCase      :      Any         =prepare_img()
											__lowerCamelCase      :      List[Any]         =image_processor(__lowercase						,    return_tensors='''pt'''			).to(__lowercase			)
											__lowerCamelCase      :      Optional[int]         =inputs["pixel_values"].shape
											# check size is divisible by 32
											self.assertTrue((inputs_shape[-1] % 32) == 0 and (inputs_shape[-2] % 32) == 0			)
											# check size
											self.assertEqual(__lowercase						,    (1, 3, 800, 1088)			)

											with torch.no_grad():
																		__lowerCamelCase      :      int         =model(**__lowercase			)
											# masks_queries_logits
											__lowerCamelCase      :      Dict         =outputs.masks_queries_logits
											self.assertEqual(
											    masks_queries_logits.shape						,    (1, model.config.decoder_config.num_queries, inputs_shape[-2] // 4, inputs_shape[-1] // 4)						,    )
											__lowerCamelCase      :      List[Any]         =[[-0.9046, -2.6366, -4.6062], [-3.4179, -5.7890, -8.8057], [-4.9179, -7.6560, -10.7711]]
											__lowerCamelCase      :      Optional[int]         =torch.tensor(__lowercase			).to(__lowercase			)
											self.assertTrue(torch.allclose(masks_queries_logits[0, 0, :3, :3]						,    __lowercase						,    atol=__lowercase			)			)
											# class_queries_logits
											__lowerCamelCase      :      str         =outputs.class_queries_logits
											self.assertEqual(
											    class_queries_logits.shape						,    (1, model.config.decoder_config.num_queries, model.config.num_labels + 1)			)
											__lowerCamelCase      :      Optional[Any]         =torch.tensor(
											    [[4.7188, -3.2585, -2.8857], [6.6871, -2.9181, -1.2487], [7.2449, -2.2764, -2.1874]]			).to(__lowercase			)
											self.assertTrue(torch.allclose(outputs.class_queries_logits[0, :3, :3]						,    __lowercase						,    atol=__lowercase			)			)




				def 					__lowercase  (     self  :str			):
											__lowerCamelCase      :      Optional[Any]         =(
											    MaskFormerForInstanceSegmentation.from_pretrained('''facebook/maskformer-swin-small-coco'''			)
											    .to(__lowercase			)
											    .eval()
											)
											__lowerCamelCase      :      int         =self.default_image_processor

											__lowerCamelCase      :      Dict         =image_processor(
											    [np.zeros((3, 800, 1333)			), np.zeros((3, 800, 1333)			)]						,    segmentation_maps=[np.zeros((384, 384)			).astype(np.floataa			), np.zeros((384, 384)			).astype(np.floataa			)]						,    return_tensors='''pt'''						,    )

											__lowerCamelCase      :      List[str]         =inputs["pixel_values"].to(__lowercase			)
											__lowerCamelCase      :      int         =[el.to(__lowercase			) for el in inputs["mask_labels"]]
											__lowerCamelCase      :      Optional[int]         =[el.to(__lowercase			) for el in inputs["class_labels"]]

											with torch.no_grad():
																		__lowerCamelCase      :      int         =model(**__lowercase			)

											self.assertTrue(outputs.loss is not None			)











"""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()




