import gc
import random
import tempfile
import unittest

import numpy as np
import torch
from PIL import Image
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    ControlNetModel,
    DDIMScheduler,
    StableDiffusionControlNetImgaImgPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion_controlnet import MultiControlNetModel
from diffusers.utils import floats_tensor, load_image, load_numpy, randn_tensor, slow, torch_device
from diffusers.utils.import_utils import is_xformers_available
from diffusers.utils.testing_utils import enable_full_determinism, require_torch_gpu

from ..pipeline_params import (
    IMAGE_TO_IMAGE_IMAGE_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS,
    TEXT_GUIDED_IMAGE_VARIATION_PARAMS,
)
from ..test_pipelines_common import (
    PipelineKarrasSchedulerTesterMixin,
    PipelineLatentTesterMixin,
    PipelineTesterMixin,
)


enable_full_determinism()






class 			__lowercase		(						_lowerCamelCase			,							_lowerCamelCase			,							_lowerCamelCase			,							unittest.TestCase						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						StableDiffusionControlNetImgaImgPipeline
     SCREAMING_SNAKE_CASE__		   =						TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''height''', '''width'''}
     SCREAMING_SNAKE_CASE__		   =						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
     SCREAMING_SNAKE_CASE__		   =						IMAGE_TO_IMAGE_IMAGE_PARAMS.union({'''control_image'''}						)
     SCREAMING_SNAKE_CASE__		   =						IMAGE_TO_IMAGE_IMAGE_PARAMS







     def lowerCAmelCase     (		self    ):
         torch.manual_seed(0    )
         __UpperCamelCase	:	List[Any]		    =  UNetaDConditionModel(
             block_out_channels=(3_2, 6_4)     ,			layers_per_block=2     ,			sample_size=3_2     ,			in_channels=4     ,			out_channels=4     ,			down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')     ,			up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')     ,			cross_attention_dim=3_2     ,			)
         torch.manual_seed(0    )
         __UpperCamelCase	:	Any		    =  ControlNetModel(
             block_out_channels=(3_2, 6_4)     ,			layers_per_block=2     ,			in_channels=4     ,			down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')     ,			cross_attention_dim=3_2     ,			conditioning_embedding_out_channels=(1_6, 3_2)     ,			)
         torch.manual_seed(0    )
         __UpperCamelCase	:	int		    =  DDIMScheduler(
             beta_start=0.0_0_0_8_5     ,			beta_end=0.0_1_2     ,			beta_schedule='scaled_linear'     ,			clip_sample=_lowerCamelCase     ,			set_alpha_to_one=_lowerCamelCase     ,			)
         torch.manual_seed(0    )
         __UpperCamelCase	:	List[Any]		    =  AutoencoderKL(
             block_out_channels=[3_2, 6_4]     ,			in_channels=3     ,			out_channels=3     ,			down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']     ,			up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']     ,			latent_channels=4     ,			)
         torch.manual_seed(0    )
         __UpperCamelCase	:	List[str]		    =  CLIPTextConfig(
             bos_token_id=0     ,			eos_token_id=2     ,			hidden_size=3_2     ,			intermediate_size=3_7     ,			layer_norm_eps=1E-0_5     ,			num_attention_heads=4     ,			num_hidden_layers=5     ,			pad_token_id=1     ,			vocab_size=1_0_0_0     ,			)
         __UpperCamelCase	:	str		    =  CLIPTextModel(_lowerCamelCase    )
         __UpperCamelCase	:	str		    =  CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'    )

         __UpperCamelCase	:	List[str]		    =  {
             'unet': unet,
             'controlnet': controlnet,
             'scheduler': scheduler,
             'vae': vae,
             'text_encoder': text_encoder,
             'tokenizer': tokenizer,
             'safety_checker': None,
             'feature_extractor': None,
         }
         return components







     def lowerCAmelCase     (		self     ,			_lowerCamelCase     ,			_lowerCamelCase=0    ):
         if str(_lowerCamelCase    ).startswith('mps'    ):
             __UpperCamelCase	:	Optional[Any]		    =  torch.manual_seed(_lowerCamelCase    )
         else:
             __UpperCamelCase	:	Tuple		    =  torch.Generator(device=_lowerCamelCase    ).manual_seed(_lowerCamelCase    )

         __UpperCamelCase	:	str		    =  2
         __UpperCamelCase	:	Optional[Any]		    =  randn_tensor(
             (1, 3, 3_2 * controlnet_embedder_scale_factor, 3_2 * controlnet_embedder_scale_factor)     ,			generator=_lowerCamelCase     ,			device=torch.device(_lowerCamelCase    )     ,			)
         __UpperCamelCase	:	str		    =  floats_tensor(control_image.shape     ,			rng=random.Random(_lowerCamelCase    )    ).to(_lowerCamelCase    )
         __UpperCamelCase	:	Optional[int]		    =  image.cpu().permute(0     ,			2     ,			3     ,			1    )[0]
         __UpperCamelCase	:	int		    =  Image.fromarray(np.uinta(_lowerCamelCase    )    ).convert('RGB'    ).resize((6_4, 6_4)    )
         __UpperCamelCase	:	List[Any]		    =  {
             'prompt': 'A painting of a squirrel eating a burger',
             'generator': generator,
             'num_inference_steps': 2,
             'guidance_scale': 6.0,
             'output_type': 'numpy',
             'image': image,
             'control_image': control_image,
         }

         return inputs







     def lowerCAmelCase     (		self    ):
         return self._test_attention_slicing_forward_pass(expected_max_diff=2E-3    )







     @unittest.skipIf(
         torch_device != 'cuda' or not is_xformers_available()     ,			reason='XFormers attention is only available with CUDA and `xformers` installed'     ,			)
     def lowerCAmelCase     (		self    ):
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=2E-3    )







     def lowerCAmelCase     (		self    ):
         self._test_inference_batch_single_identical(expected_max_diff=2E-3    )






class 			__lowercase		(						_lowerCamelCase			,							_lowerCamelCase			,							unittest.TestCase						):







     """simple docstring"""






     SCREAMING_SNAKE_CASE__		   =						StableDiffusionControlNetImgaImgPipeline
     SCREAMING_SNAKE_CASE__		   =						TEXT_GUIDED_IMAGE_VARIATION_PARAMS - {'''height''', '''width'''}
     SCREAMING_SNAKE_CASE__		   =						TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
     SCREAMING_SNAKE_CASE__		   =						frozenset([]						)  # TO_DO: add image_params once refactored VaeImageProcessor.preprocess







     def lowerCAmelCase     (		self    ):
         torch.manual_seed(0    )
         __UpperCamelCase	:	str		    =  UNetaDConditionModel(
             block_out_channels=(3_2, 6_4)     ,			layers_per_block=2     ,			sample_size=3_2     ,			in_channels=4     ,			out_channels=4     ,			down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')     ,			up_block_types=('CrossAttnUpBlock2D', 'UpBlock2D')     ,			cross_attention_dim=3_2     ,			)
         torch.manual_seed(0    )

         def init_weights(_lowerCamelCase    ):
             if isinstance(_lowerCamelCase     ,			torch.nn.Convad    ):
                 torch.nn.init.normal(m.weight    )
                 m.bias.data.fill_(1.0    )

         __UpperCamelCase	:	Any		    =  ControlNetModel(
             block_out_channels=(3_2, 6_4)     ,			layers_per_block=2     ,			in_channels=4     ,			down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')     ,			cross_attention_dim=3_2     ,			conditioning_embedding_out_channels=(1_6, 3_2)     ,			)
         controlneta.controlnet_down_blocks.apply(_lowerCamelCase    )

         torch.manual_seed(0    )
         __UpperCamelCase	:	str		    =  ControlNetModel(
             block_out_channels=(3_2, 6_4)     ,			layers_per_block=2     ,			in_channels=4     ,			down_block_types=('DownBlock2D', 'CrossAttnDownBlock2D')     ,			cross_attention_dim=3_2     ,			conditioning_embedding_out_channels=(1_6, 3_2)     ,			)
         controlneta.controlnet_down_blocks.apply(_lowerCamelCase    )

         torch.manual_seed(0    )
         __UpperCamelCase	:	Optional[int]		    =  DDIMScheduler(
             beta_start=0.0_0_0_8_5     ,			beta_end=0.0_1_2     ,			beta_schedule='scaled_linear'     ,			clip_sample=_lowerCamelCase     ,			set_alpha_to_one=_lowerCamelCase     ,			)
         torch.manual_seed(0    )
         __UpperCamelCase	:	Optional[Any]		    =  AutoencoderKL(
             block_out_channels=[3_2, 6_4]     ,			in_channels=3     ,			out_channels=3     ,			down_block_types=['DownEncoderBlock2D', 'DownEncoderBlock2D']     ,			up_block_types=['UpDecoderBlock2D', 'UpDecoderBlock2D']     ,			latent_channels=4     ,			)
         torch.manual_seed(0    )
         __UpperCamelCase	:	Optional[Any]		    =  CLIPTextConfig(
             bos_token_id=0     ,			eos_token_id=2     ,			hidden_size=3_2     ,			intermediate_size=3_7     ,			layer_norm_eps=1E-0_5     ,			num_attention_heads=4     ,			num_hidden_layers=5     ,			pad_token_id=1     ,			vocab_size=1_0_0_0     ,			)
         __UpperCamelCase	:	Tuple		    =  CLIPTextModel(_lowerCamelCase    )
         __UpperCamelCase	:	Tuple		    =  CLIPTokenizer.from_pretrained('hf-internal-testing/tiny-random-clip'    )

         __UpperCamelCase	:	List[str]		    =  MultiControlNetModel([controlneta, controlneta]    )

         __UpperCamelCase	:	Tuple		    =  {
             'unet': unet,
             'controlnet': controlnet,
             'scheduler': scheduler,
             'vae': vae,
             'text_encoder': text_encoder,
             'tokenizer': tokenizer,
             'safety_checker': None,
             'feature_extractor': None,
         }
         return components







     def lowerCAmelCase     (		self     ,			_lowerCamelCase     ,			_lowerCamelCase=0    ):
         if str(_lowerCamelCase    ).startswith('mps'    ):
             __UpperCamelCase	:	Optional[Any]		    =  torch.manual_seed(_lowerCamelCase    )
         else:
             __UpperCamelCase	:	Dict		    =  torch.Generator(device=_lowerCamelCase    ).manual_seed(_lowerCamelCase    )

         __UpperCamelCase	:	Optional[Any]		    =  2

         __UpperCamelCase	:	Optional[int]		    =  [
             randn_tensor(
                 (1, 3, 3_2 * controlnet_embedder_scale_factor, 3_2 * controlnet_embedder_scale_factor)     ,			generator=_lowerCamelCase     ,			device=torch.device(_lowerCamelCase    )     ,			),
             randn_tensor(
                 (1, 3, 3_2 * controlnet_embedder_scale_factor, 3_2 * controlnet_embedder_scale_factor)     ,			generator=_lowerCamelCase     ,			device=torch.device(_lowerCamelCase    )     ,			),
         ]

         __UpperCamelCase	:	Tuple		    =  floats_tensor(control_image[0].shape     ,			rng=random.Random(_lowerCamelCase    )    ).to(_lowerCamelCase    )
         __UpperCamelCase	:	Any		    =  image.cpu().permute(0     ,			2     ,			3     ,			1    )[0]
         __UpperCamelCase	:	Optional[int]		    =  Image.fromarray(np.uinta(_lowerCamelCase    )    ).convert('RGB'    ).resize((6_4, 6_4)    )
         __UpperCamelCase	:	int		    =  {
             'prompt': 'A painting of a squirrel eating a burger',
             'generator': generator,
             'num_inference_steps': 2,
             'guidance_scale': 6.0,
             'output_type': 'numpy',
             'image': image,
             'control_image': control_image,
         }

         return inputs







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Optional[Any]		    =  self.get_dummy_components()
         __UpperCamelCase	:	Any		    =  self.pipeline_class(**_lowerCamelCase    )
         pipe.to(_lowerCamelCase    )

         __UpperCamelCase	:	Union[str, Any]		    =  1_0.0
         __UpperCamelCase	:	str		    =  4

         __UpperCamelCase	:	int		    =  self.get_dummy_inputs(_lowerCamelCase    )
         __UpperCamelCase	:	Optional[int]		    =  steps
         __UpperCamelCase	:	List[str]		    =  scale
         __UpperCamelCase	:	Optional[Any]		    =  pipe(**_lowerCamelCase    )[0]

         __UpperCamelCase	:	Dict		    =  self.get_dummy_inputs(_lowerCamelCase    )
         __UpperCamelCase	:	List[str]		    =  steps
         __UpperCamelCase	:	Any		    =  scale
         __UpperCamelCase	:	Tuple		    =  pipe(**_lowerCamelCase     ,			control_guidance_start=0.1     ,			control_guidance_end=0.2    )[0]

         __UpperCamelCase	:	str		    =  self.get_dummy_inputs(_lowerCamelCase    )
         __UpperCamelCase	:	Union[str, Any]		    =  steps
         __UpperCamelCase	:	int		    =  scale
         __UpperCamelCase	:	Optional[int]		    =  pipe(**_lowerCamelCase     ,			control_guidance_start=[0.1, 0.3]     ,			control_guidance_end=[0.2, 0.7]    )[0]

         __UpperCamelCase	:	List[str]		    =  self.get_dummy_inputs(_lowerCamelCase    )
         __UpperCamelCase	:	Union[str, Any]		    =  steps
         __UpperCamelCase	:	List[Any]		    =  scale
         __UpperCamelCase	:	Dict		    =  pipe(**_lowerCamelCase     ,			control_guidance_start=0.4     ,			control_guidance_end=[0.5, 0.8]    )[0]

         # make sure that all outputs are different
         assert np.sum(np.abs(output_a - output_a    )    ) > 1E-3
         assert np.sum(np.abs(output_a - output_a    )    ) > 1E-3
         assert np.sum(np.abs(output_a - output_a    )    ) > 1E-3







     def lowerCAmelCase     (		self    ):
         return self._test_attention_slicing_forward_pass(expected_max_diff=2E-3    )







     @unittest.skipIf(
         torch_device != 'cuda' or not is_xformers_available()     ,			reason='XFormers attention is only available with CUDA and `xformers` installed'     ,			)
     def lowerCAmelCase     (		self    ):
         self._test_xformers_attention_forwardGenerator_pass(expected_max_diff=2E-3    )







     def lowerCAmelCase     (		self    ):
         self._test_inference_batch_single_identical(expected_max_diff=2E-3    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Dict		    =  self.get_dummy_components()
         __UpperCamelCase	:	int		    =  self.pipeline_class(**_lowerCamelCase    )
         pipe.to(_lowerCamelCase    )
         pipe.set_progress_bar_config(disable=_lowerCamelCase    )
         with tempfile.TemporaryDirectory() as tmpdir:
             try:
                 # save_pretrained is not implemented for Multi-ControlNet
                 pipe.save_pretrained(_lowerCamelCase    )
             except NotImplementedError:
                 pass






@slow
@require_torch_gpu
class 			__lowercase		(						unittest.TestCase						):







     """simple docstring"""






     def lowerCAmelCase     (		self    ):
         super().tearDown()
         gc.collect()
         torch.cuda.empty_cache()







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	str		    =  ControlNetModel.from_pretrained('lllyasviel/sd-controlnet-canny'    )

         __UpperCamelCase	:	Dict		    =  StableDiffusionControlNetImgaImgPipeline.from_pretrained(
             'runwayml/stable-diffusion-v1-5'     ,			safety_checker=_lowerCamelCase     ,			controlnet=_lowerCamelCase    )
         pipe.enable_model_cpu_offload()
         pipe.set_progress_bar_config(disable=_lowerCamelCase    )

         __UpperCamelCase	:	Tuple		    =  torch.Generator(device='cpu'    ).manual_seed(0    )
         __UpperCamelCase	:	int		    =  'evil space-punk bird'
         __UpperCamelCase	:	Tuple		    =  load_image(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/bird_canny.png'    ).resize((5_1_2, 5_1_2)    )
         __UpperCamelCase	:	List[Any]		    =  load_image(
             'https://huggingface.co/lllyasviel/sd-controlnet-canny/resolve/main/images/bird.png'    ).resize((5_1_2, 5_1_2)    )

         __UpperCamelCase	:	Tuple		    =  pipe(
             _lowerCamelCase     ,			_lowerCamelCase     ,			control_image=_lowerCamelCase     ,			generator=_lowerCamelCase     ,			output_type='np'     ,			num_inference_steps=5_0     ,			strength=0.6     ,			)

         __UpperCamelCase	:	Tuple		    =  output.images[0]

         assert image.shape == (5_1_2, 5_1_2, 3)

         __UpperCamelCase	:	Dict		    =  load_numpy(
             'https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/sd_controlnet/img2img.npy'    )

         assert np.abs(expected_image - image    ).max() < 9E-2




'''simple docstring'''
import unittest

from .lib import (
    Matrix,
    Vector,
    axpy,
    square_zero_matrix,
    unit_basis_vector,
    zero_vector,
)






class 			__lowercase		(						unittest.TestCase						):







     """simple docstring"""






     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Dict		    =  Vector([1, 2, 3]    )
         self.assertEqual(x.component(0    )     ,			1    )
         self.assertEqual(x.component(2    )     ,			3    )
         __UpperCamelCase	:	Dict		    =  Vector()







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	str		    =  Vector([0, 0, 0, 0, 0, 1]    )
         self.assertEqual(str(_lowerCamelCase    )     ,			'(0,0,0,0,0,1)'    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Dict		    =  Vector([1, 2, 3, 4]    )
         self.assertEqual(len(_lowerCamelCase    )     ,			4    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Any		    =  Vector([1, 2]    )
         __UpperCamelCase	:	Optional[int]		    =  Vector([1, 2, 3, 4, 5]    )
         __UpperCamelCase	:	Optional[Any]		    =  Vector([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]    )
         __UpperCamelCase	:	List[str]		    =  Vector([1, -1, 1, -1, 2, -3, 4, -5]    )
         self.assertAlmostEqual(x.euclidean_length()     ,			2.2_3_6     ,			3    )
         self.assertAlmostEqual(y.euclidean_length()     ,			7.4_1_6     ,			3    )
         self.assertEqual(z.euclidean_length()     ,			0    )
         self.assertAlmostEqual(w.euclidean_length()     ,			7.6_1_6     ,			3    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	int		    =  Vector([1, 2, 3]    )
         __UpperCamelCase	:	List[str]		    =  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 lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Optional[Any]		    =  Vector([1, 2, 3]    )
         __UpperCamelCase	:	Dict		    =  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 lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Dict		    =  Vector([1, 2, 3]    )
         __UpperCamelCase	:	int		    =  Vector([2, -1, 4]    )  # for test of dot product
         __UpperCamelCase	:	int		    =  Vector([1, -2, -1]    )
         self.assertEqual(str(x * 3.0    )     ,			'(3.0,6.0,9.0)'    )
         self.assertEqual((a * b)     ,			0    )







     def lowerCAmelCase     (		self    ):
         self.assertEqual(str(zero_vector(1_0    )    ).count('0'    )     ,			1_0    )







     def lowerCAmelCase     (		self    ):
         self.assertEqual(str(unit_basis_vector(3     ,			1    )    )     ,			'(0,1,0)'    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Optional[int]		    =  Vector([1, 2, 3]    )
         __UpperCamelCase	:	Union[str, Any]		    =  Vector([1, 0, 1]    )
         self.assertEqual(str(axpy(2     ,			_lowerCamelCase     ,			_lowerCamelCase    )    )     ,			'(3,4,7)'    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	List[str]		    =  Vector([1, 0, 0, 0, 0, 0]    )
         __UpperCamelCase	:	Optional[Any]		    =  x.copy()
         self.assertEqual(str(_lowerCamelCase    )     ,			str(_lowerCamelCase    )    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	List[str]		    =  Vector([1, 0, 0]    )
         x.change_component(0     ,			0    )
         x.change_component(1     ,			1    )
         self.assertEqual(str(_lowerCamelCase    )     ,			'(0,1,0)'    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Tuple		    =  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(_lowerCamelCase    )    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Optional[int]		    =  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]     ,			3     ,			3    )
         __UpperCamelCase	:	List[str]		    =  [[-3, -1_4, -1_0], [-5, -1_0, -5], [-2, -1, 0]]
         for x in range(a.height()    ):
             for y in range(a.width()    ):
                 self.assertEqual(minors[x][y]     ,			a.minor(_lowerCamelCase     ,			_lowerCamelCase    )    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	int		    =  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]     ,			3     ,			3    )
         __UpperCamelCase	:	List[str]		    =  [[-3, 1_4, -1_0], [5, -1_0, 5], [-2, 1, 0]]
         for x in range(a.height()    ):
             for y in range(a.width()    ):
                 self.assertEqual(cofactors[x][y]     ,			a.cofactor(_lowerCamelCase     ,			_lowerCamelCase    )    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Any		    =  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]     ,			3     ,			3    )
         self.assertEqual(-5     ,			a.determinant()    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	int		    =  Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]     ,			3     ,			3    )
         __UpperCamelCase	:	Union[str, Any]		    =  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 lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Union[str, Any]		    =  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(_lowerCamelCase    )    )







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	int		    =  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]     ,			3     ,			3    )
         self.assertEqual(7     ,			a.component(2     ,			1    )     ,			0.0_1    )







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







     def lowerCAmelCase     (		self    ):
         __UpperCamelCase	:	Optional[int]		    =  Matrix([[1, 2, 3], [2, 4, 5], [6, 7, 8]]     ,			3     ,			3    )
         __UpperCamelCase	:	Optional[int]		    =  Matrix([[1, 2, 7], [2, 4, 5], [6, 7, 1_0]]     ,			3     ,			3    )
         self.assertEqual('|0,0,-4|\n|0,0,0|\n|0,0,-2|\n'     ,			str(a - b    )    )







     def lowerCAmelCase     (		self    ):
         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()



