


"""simple docstring"""




import unittest

from transformers import (
    MODEL_FOR_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_CAUSAL_LM_MAPPING,
    TextGenerationPipeline,
    logging,
    pipeline,
)
from transformers.testing_utils import (
    CaptureLogger,
    is_pipeline_test,
    require_accelerate,
    require_tf,
    require_torch,
    require_torch_gpu,
    require_torch_or_tf,
)

from .test_pipelines_common import ANY
@is_pipeline_test
@require_torch_or_tf
class 					lowerCAmelCase	(					unittest.TestCase    ):




		'''simple docstring'''







		SCREAMING_SNAKE_CASE_						:     List[str]								=     MODEL_FOR_CAUSAL_LM_MAPPING
		SCREAMING_SNAKE_CASE_						:     Optional[Any]								=     TF_MODEL_FOR_CAUSAL_LM_MAPPING







		@require_torch
		def 							__A						(	self				)     ->							str:
								SCREAMING_SNAKE_CASE													=					pipeline(task='text-generation'						,       model='sshleifer/tiny-ctrl'						,       framework='pt'				)
								# Using `do_sample=False` to force deterministic output
								SCREAMING_SNAKE_CASE													=					text_generator('This is a test'						,       do_sample=lowerCAmelCase__				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        {
								            'generated_text': (
								                'This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope.'
								                ' oscope. FiliFili@@'
								            )
								        }
								    ]						,       )

								SCREAMING_SNAKE_CASE													=					text_generator(['This is a test', 'This is a second test']				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        [
								            {
								                'generated_text': (
								                    'This is a test ☃ ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy oscope.'
								                    ' oscope. FiliFili@@'
								                )
								            }
								        ],
								        [
								            {
								                'generated_text': (
								                    'This is a second test ☃ segmental segmental segmental 议议eski eski flutter flutter Lacy'
								                    ' oscope. oscope. FiliFili@@'
								                )
								            }
								        ],
								    ]						,       )

								SCREAMING_SNAKE_CASE													=					text_generator('This is a test'						,       do_sample=lowerCAmelCase__						,       num_return_sequences=2						,       return_tensors=lowerCAmelCase__				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        {'generated_token_ids': ANY(lowerCAmelCase__				)},
								        {'generated_token_ids': ANY(lowerCAmelCase__				)},
								    ]						,       )
								SCREAMING_SNAKE_CASE													=					text_generator.model.config.eos_token_id
								SCREAMING_SNAKE_CASE													=					'<pad>'
								SCREAMING_SNAKE_CASE													=					text_generator(
								    ['This is a test', 'This is a second test']						,       do_sample=lowerCAmelCase__						,       num_return_sequences=2						,       batch_size=2						,       return_tensors=lowerCAmelCase__						,       )
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        [
								            {'generated_token_ids': ANY(lowerCAmelCase__				)},
								            {'generated_token_ids': ANY(lowerCAmelCase__				)},
								        ],
								        [
								            {'generated_token_ids': ANY(lowerCAmelCase__				)},
								            {'generated_token_ids': ANY(lowerCAmelCase__				)},
								        ],
								    ]						,       )







		@require_tf
		def 							__A						(	self				)     ->							int:
								SCREAMING_SNAKE_CASE													=					pipeline(task='text-generation'						,       model='sshleifer/tiny-ctrl'						,       framework='tf'				)

								# Using `do_sample=False` to force deterministic output
								SCREAMING_SNAKE_CASE													=					text_generator('This is a test'						,       do_sample=lowerCAmelCase__				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        {
								            'generated_text': (
								                'This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵'
								                ' please,'
								            )
								        }
								    ]						,       )

								SCREAMING_SNAKE_CASE													=					text_generator(['This is a test', 'This is a second test']						,       do_sample=lowerCAmelCase__				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        [
								            {
								                'generated_text': (
								                    'This is a test FeyFeyFey(Croatis.), s.), Cannes Cannes Cannes 閲閲Cannes Cannes Cannes 攵'
								                    ' please,'
								                )
								            }
								        ],
								        [
								            {
								                'generated_text': (
								                    'This is a second test Chieftain Chieftain prefecture prefecture prefecture Cannes Cannes'
								                    ' Cannes 閲閲Cannes Cannes Cannes 攵 please,'
								                )
								            }
								        ],
								    ]						,       )







		def 							__A						(	self						,       lowerCAmelCase__						,       lowerCAmelCase__						,       lowerCAmelCase__				)     ->							Optional[Any]:
								SCREAMING_SNAKE_CASE													=					TextGenerationPipeline(model=lowerCAmelCase__						,       tokenizer=lowerCAmelCase__				)
								return text_generator, ["This is a test", "Another test"]







		def 							__A						(	self				)     ->							int:
								SCREAMING_SNAKE_CASE													=					'Hello I believe in'
								SCREAMING_SNAKE_CASE													=					pipeline('text-generation'						,       model='hf-internal-testing/tiny-random-gpt2'				)
								SCREAMING_SNAKE_CASE													=					text_generator(lowerCAmelCase__				)
								self.assertEqual(
								    lowerCAmelCase__						,       [{'generated_text': 'Hello I believe in fe fe fe fe fe fe fe fe fe fe fe fe'}]						,       )

								SCREAMING_SNAKE_CASE													=					text_generator(lowerCAmelCase__						,       stop_sequence=' fe'				)
								self.assertEqual(lowerCAmelCase__						,       [{'generated_text': 'Hello I believe in fe'}]				)







		def 							__A						(	self						,       lowerCAmelCase__						,       lowerCAmelCase__				)     ->							Tuple:
								SCREAMING_SNAKE_CASE													=					text_generator.model
								SCREAMING_SNAKE_CASE													=					text_generator.tokenizer

								SCREAMING_SNAKE_CASE													=					text_generator('This is a test'				)
								self.assertEqual(lowerCAmelCase__						,       [{'generated_text': ANY(lowerCAmelCase__				)}]				)
								self.assertTrue(outputs[0]['generated_text'].startswith('This is a test'				)				)

								SCREAMING_SNAKE_CASE													=					text_generator('This is a test'						,       return_full_text=lowerCAmelCase__				)
								self.assertEqual(lowerCAmelCase__						,       [{'generated_text': ANY(lowerCAmelCase__				)}]				)
								self.assertNotIn('This is a test'						,       outputs[0]['generated_text']				)

								SCREAMING_SNAKE_CASE													=					pipeline(task='text-generation'						,       model=lowerCAmelCase__						,       tokenizer=lowerCAmelCase__						,       return_full_text=lowerCAmelCase__				)
								SCREAMING_SNAKE_CASE													=					text_generator('This is a test'				)
								self.assertEqual(lowerCAmelCase__						,       [{'generated_text': ANY(lowerCAmelCase__				)}]				)
								self.assertNotIn('This is a test'						,       outputs[0]['generated_text']				)

								SCREAMING_SNAKE_CASE													=					text_generator('This is a test'						,       return_full_text=lowerCAmelCase__				)
								self.assertEqual(lowerCAmelCase__						,       [{'generated_text': ANY(lowerCAmelCase__				)}]				)
								self.assertTrue(outputs[0]['generated_text'].startswith('This is a test'				)				)

								SCREAMING_SNAKE_CASE													=					text_generator(['This is great !', 'Something else']						,       num_return_sequences=2						,       do_sample=lowerCAmelCase__				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        [{'generated_text': ANY(lowerCAmelCase__				)}, {'generated_text': ANY(lowerCAmelCase__				)}],
								        [{'generated_text': ANY(lowerCAmelCase__				)}, {'generated_text': ANY(lowerCAmelCase__				)}],
								    ]						,       )

								if text_generator.tokenizer.pad_token is not None:
														SCREAMING_SNAKE_CASE													=					text_generator(
														    ['This is great !', 'Something else']						,       num_return_sequences=2						,       batch_size=2						,       do_sample=lowerCAmelCase__				)
														self.assertEqual(
														    lowerCAmelCase__						,       [
														        [{'generated_text': ANY(lowerCAmelCase__				)}, {'generated_text': ANY(lowerCAmelCase__				)}],
														        [{'generated_text': ANY(lowerCAmelCase__				)}, {'generated_text': ANY(lowerCAmelCase__				)}],
														    ]						,       )

								with self.assertRaises(lowerCAmelCase__				):
														SCREAMING_SNAKE_CASE													=					text_generator('test'						,       return_full_text=lowerCAmelCase__						,       return_text=lowerCAmelCase__				)
								with self.assertRaises(lowerCAmelCase__				):
														SCREAMING_SNAKE_CASE													=					text_generator('test'						,       return_full_text=lowerCAmelCase__						,       return_tensors=lowerCAmelCase__				)
								with self.assertRaises(lowerCAmelCase__				):
														SCREAMING_SNAKE_CASE													=					text_generator('test'						,       return_text=lowerCAmelCase__						,       return_tensors=lowerCAmelCase__				)

								# Empty prompt is slighly special
								# it requires BOS token to exist.
								# Special case for Pegasus which will always append EOS so will
								# work even without BOS.
								if (
								    text_generator.tokenizer.bos_token_id is not None
								    or "Pegasus" in tokenizer.__class__.__name__
								    or "Git" in model.__class__.__name__
								):
														SCREAMING_SNAKE_CASE													=					text_generator(''				)
														self.assertEqual(lowerCAmelCase__						,       [{'generated_text': ANY(lowerCAmelCase__				)}]				)
								else:
														with self.assertRaises((ValueError, AssertionError)				):
																				SCREAMING_SNAKE_CASE													=					text_generator(''				)

								if text_generator.framework == "tf":
														# TF generation does not support max_new_tokens, and it's impossible
														# to control long generation with only max_length without
														# fancy calculation, dismissing tests for now.
														return
								# We don't care about infinite range models.
								# They already work.
								# Skip this test for XGLM, since it uses sinusoidal positional embeddings which are resized on-the-fly.
								SCREAMING_SNAKE_CASE													=					['RwkvForCausalLM', 'XGLMForCausalLM', 'GPTNeoXForCausalLM']
								if (
								    tokenizer.model_max_length < 10_000
								    and text_generator.model.__class__.__name__ not in EXTRA_MODELS_CAN_HANDLE_LONG_INPUTS
								):
														# Handling of large generations
														with self.assertRaises((RuntimeError, IndexError, ValueError, AssertionError)				):
																				text_generator('This is a test' * 500						,       max_new_tokens=20				)

														SCREAMING_SNAKE_CASE													=					text_generator('This is a test' * 500						,       handle_long_generation='hole'						,       max_new_tokens=20				)
														# Hole strategy cannot work
														with self.assertRaises(lowerCAmelCase__				):
																				text_generator(
																				    'This is a test' * 500						,       handle_long_generation='hole'						,       max_new_tokens=tokenizer.model_max_length + 10						,       )







		@require_torch
		@require_accelerate
		@require_torch_gpu
		def 							__A						(	self				)     ->							int:
								import torch

								# Classic `model_kwargs`
								SCREAMING_SNAKE_CASE													=					pipeline(
								    model='hf-internal-testing/tiny-random-bloom'						,       model_kwargs={'device_map': 'auto', 'torch_dtype': torch.bfloataa}						,       )
								self.assertEqual(pipe.model.device						,       torch.device(0				)				)
								self.assertEqual(pipe.model.lm_head.weight.dtype						,       torch.bfloataa				)
								SCREAMING_SNAKE_CASE													=					pipe('This is a test'				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        {
								            'generated_text': (
								                'This is a test test test test test test test test test test test test test test test test'
								                ' test'
								            )
								        }
								    ]						,       )

								# Upgraded those two to real pipeline arguments (they just get sent for the model as they're unlikely to mean anything else.)
								SCREAMING_SNAKE_CASE													=					pipeline(model='hf-internal-testing/tiny-random-bloom'						,       device_map='auto'						,       torch_dtype=torch.bfloataa				)
								self.assertEqual(pipe.model.device						,       torch.device(0				)				)
								self.assertEqual(pipe.model.lm_head.weight.dtype						,       torch.bfloataa				)
								SCREAMING_SNAKE_CASE													=					pipe('This is a test'				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        {
								            'generated_text': (
								                'This is a test test test test test test test test test test test test test test test test'
								                ' test'
								            )
								        }
								    ]						,       )

								# torch_dtype will be automatically set to float32 if not provided - check: https://github.com/huggingface/transformers/pull/20602
								SCREAMING_SNAKE_CASE													=					pipeline(model='hf-internal-testing/tiny-random-bloom'						,       device_map='auto'				)
								self.assertEqual(pipe.model.device						,       torch.device(0				)				)
								self.assertEqual(pipe.model.lm_head.weight.dtype						,       torch.floataa				)
								SCREAMING_SNAKE_CASE													=					pipe('This is a test'				)
								self.assertEqual(
								    lowerCAmelCase__						,       [
								        {
								            'generated_text': (
								                'This is a test test test test test test test test test test test test test test test test'
								                ' test'
								            )
								        }
								    ]						,       )







		@require_torch
		@require_torch_gpu
		def 							__A						(	self				)     ->							Optional[Any]:
								import torch

								SCREAMING_SNAKE_CASE													=					pipeline(model='hf-internal-testing/tiny-random-bloom'						,       device=0						,       torch_dtype=torch.floataa				)
								pipe('This is a test'				)







		@require_torch
		@require_accelerate
		@require_torch_gpu
		def 							__A						(	self				)     ->							Tuple:
								import torch

								SCREAMING_SNAKE_CASE													=					pipeline(model='hf-internal-testing/tiny-random-bloom'						,       device_map='auto'						,       torch_dtype=torch.floataa				)
								pipe('This is a test'						,       do_sample=lowerCAmelCase__						,       top_p=0.5				)







		def 							__A						(	self				)     ->							Tuple:
								SCREAMING_SNAKE_CASE													=					'Hello world'
								SCREAMING_SNAKE_CASE													=					pipeline('text-generation'						,       model='hf-internal-testing/tiny-random-gpt2'				)
								if text_generator.model.framework == "tf":
														SCREAMING_SNAKE_CASE													=					logging.get_logger('transformers.generation.tf_utils'				)
								else:
														SCREAMING_SNAKE_CASE													=					logging.get_logger('transformers.generation.utils'				)
								SCREAMING_SNAKE_CASE													=					'Both `max_new_tokens`'  # The beggining of the message to be checked in this test

								# Both are set by the user -> log warning
								with CaptureLogger(lowerCAmelCase__				) as cl:
														SCREAMING_SNAKE_CASE													=					text_generator(lowerCAmelCase__						,       max_length=10						,       max_new_tokens=1				)
								self.assertIn(lowerCAmelCase__						,       cl.out				)

								# The user only sets one -> no warning
								with CaptureLogger(lowerCAmelCase__				) as cl:
														SCREAMING_SNAKE_CASE													=					text_generator(lowerCAmelCase__						,       max_new_tokens=1				)
								self.assertNotIn(lowerCAmelCase__						,       cl.out				)

								with CaptureLogger(lowerCAmelCase__				) as cl:
														SCREAMING_SNAKE_CASE													=					text_generator(lowerCAmelCase__						,       max_length=10				)
								self.assertNotIn(lowerCAmelCase__						,       cl.out				)






"""simple docstring"""




from __future__ import annotations

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




		'''simple docstring'''







		def __init__(	self						,       lowerCAmelCase__ = None				)     ->							None:
								if components is None:
														SCREAMING_SNAKE_CASE													=					[]
								SCREAMING_SNAKE_CASE													=					list(lowerCAmelCase__				)







		def __len__(	self				)     ->							int:
								return len(self.__components				)







		def __str__(	self				)     ->							str:
								return "(" + ",".join(map(lowerCAmelCase__						,       self.__components				)				) + ")"







		def __add__(	self						,       lowerCAmelCase__				)     ->							Vector:
								SCREAMING_SNAKE_CASE													=					len(self				)
								if size == len(lowerCAmelCase__				):
														SCREAMING_SNAKE_CASE													=					[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__				)     ->							Vector:
								SCREAMING_SNAKE_CASE													=					len(self				)
								if size == len(lowerCAmelCase__				):
														SCREAMING_SNAKE_CASE													=					[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__				)     ->							Vector:
								...







		@overload
		def __mul__(	self						,       lowerCAmelCase__				)     ->							float:
								...







		def __mul__(	self						,       lowerCAmelCase__				)     ->							float | Vector:
								if isinstance(lowerCAmelCase__						,       (float, int)				):
														SCREAMING_SNAKE_CASE													=					[c * other for c in self.__components]
														return Vector(lowerCAmelCase__				)
								elif isinstance(lowerCAmelCase__						,       lowerCAmelCase__				) and len(self				) == len(lowerCAmelCase__				):
														SCREAMING_SNAKE_CASE													=					len(self				)
														SCREAMING_SNAKE_CASE													=					[self.__components[i] * other.component(lowerCAmelCase__				) for i in range(lowerCAmelCase__				)]
														return sum(lowerCAmelCase__				)
								else:  # error case
														raise Exception('invalid operand!'				)







		def 							__A						(	self				)     ->							Vector:
								return Vector(self.__components				)







		def 							__A						(	self						,       lowerCAmelCase__				)     ->							float:
								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__				)     ->							None:
								assert -len(self.__components				) <= pos < len(self.__components				)
								SCREAMING_SNAKE_CASE													=					value







		def 							__A						(	self				)     ->							float:
								if len(self.__components				) == 0:
														raise Exception('Vector is empty'				)
								SCREAMING_SNAKE_CASE													=					[c**2 for c in self.__components]
								return math.sqrt(sum(lowerCAmelCase__				)				)







		def 							__A						(	self						,       lowerCAmelCase__						,       lowerCAmelCase__ = False				)     ->							float:
								SCREAMING_SNAKE_CASE													=					self * other
								SCREAMING_SNAKE_CASE													=					self.euclidean_length() * other.euclidean_length()
								if deg:
														return math.degrees(math.acos(num / den				)				)
								else:
														return math.acos(num / den				)





def     lowercase			(SCREAMING_SNAKE_CASE_		:				int  )   ->						Vector:
						assert isinstance(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  )
						return Vector([0] * dimension  )


def     lowercase			(SCREAMING_SNAKE_CASE_		:				int ,			SCREAMING_SNAKE_CASE_		:				int  )   ->						Vector:
						assert isinstance(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  ) and (isinstance(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  ))
						SCREAMING_SNAKE_CASE													=					[0] * dimension
						SCREAMING_SNAKE_CASE													=					1
						return Vector(SCREAMING_SNAKE_CASE_  )


def     lowercase			(SCREAMING_SNAKE_CASE_		:				float ,			SCREAMING_SNAKE_CASE_		:				Vector ,			SCREAMING_SNAKE_CASE_		:				Vector  )   ->						Vector:
						assert (
						    isinstance(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  )
						    and isinstance(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  )
						    and (isinstance(SCREAMING_SNAKE_CASE_ ,			(int, float)  ))
						)
						return x * scalar + y


def     lowercase			(SCREAMING_SNAKE_CASE_		:				int ,			SCREAMING_SNAKE_CASE_		:				int ,			SCREAMING_SNAKE_CASE_		:				int  )   ->						Vector:
						random.seed(SCREAMING_SNAKE_CASE_  )
						SCREAMING_SNAKE_CASE													=					[random.randint(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  ) for _ in range(SCREAMING_SNAKE_CASE_  )]
						return Vector(SCREAMING_SNAKE_CASE_  )
class 					lowerCAmelCase	:




		'''simple docstring'''







		def __init__(	self						,       lowerCAmelCase__						,       lowerCAmelCase__						,       lowerCAmelCase__				)     ->							None:
								SCREAMING_SNAKE_CASE													=					matrix
								SCREAMING_SNAKE_CASE													=					w
								SCREAMING_SNAKE_CASE													=					h







		def __str__(	self				)     ->							str:
								SCREAMING_SNAKE_CASE													=					''
								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__				)     ->							Matrix:
								if self.__width == other.width() and self.__height == other.height():
														SCREAMING_SNAKE_CASE													=					[]
														for i in range(self.__height				):
																				SCREAMING_SNAKE_CASE													=					[
																				    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__				)     ->							Matrix:
								if self.__width == other.width() and self.__height == other.height():
														SCREAMING_SNAKE_CASE													=					[]
														for i in range(self.__height				):
																				SCREAMING_SNAKE_CASE													=					[
																				    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__				)     ->							Matrix:
								...







		@overload
		def __mul__(	self						,       lowerCAmelCase__				)     ->							Vector:
								...







		def __mul__(	self						,       lowerCAmelCase__				)     ->							Vector | Matrix:
								if isinstance(lowerCAmelCase__						,       lowerCAmelCase__				):  # matrix-vector
														if len(lowerCAmelCase__				) == self.__width:
																				SCREAMING_SNAKE_CASE													=					zero_vector(self.__height				)
																				for i in range(self.__height				):
																										SCREAMING_SNAKE_CASE													=					[
																										    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
														SCREAMING_SNAKE_CASE													=					[
														    [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				)     ->							int:
								return self.__height







		def 							__A						(	self				)     ->							int:
								return self.__width







		def 							__A						(	self						,       lowerCAmelCase__						,       lowerCAmelCase__				)     ->							float:
								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__				)     ->							None:
								if 0 <= x < self.__height and 0 <= y < self.__width:
														SCREAMING_SNAKE_CASE													=					value
								else:
														raise Exception('change_component: indices out of bounds'				)







		def 							__A						(	self						,       lowerCAmelCase__						,       lowerCAmelCase__				)     ->							float:
								if self.__height != self.__width:
														raise Exception('Matrix is not square'				)
								SCREAMING_SNAKE_CASE													=					self.__matrix[:x] + self.__matrix[x + 1 :]
								for i in range(len(lowerCAmelCase__				)				):
														SCREAMING_SNAKE_CASE													=					minor[i][:y] + minor[i][y + 1 :]
								return Matrix(lowerCAmelCase__						,       self.__width - 1						,       self.__height - 1				).determinant()







		def 							__A						(	self						,       lowerCAmelCase__						,       lowerCAmelCase__				)     ->							float:
								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				)     ->							float:
								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:
														SCREAMING_SNAKE_CASE													=					[
														    self.__matrix[0][y] * self.cofactor(0						,       lowerCAmelCase__				) for y in range(self.__width				)
														]
														return sum(lowerCAmelCase__				)





def     lowercase			(SCREAMING_SNAKE_CASE_		:				int  )   ->						Matrix:
						SCREAMING_SNAKE_CASE													=					[[0] * n for _ in range(SCREAMING_SNAKE_CASE_  )]
						return Matrix(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  )


def     lowercase			(SCREAMING_SNAKE_CASE_		:				int ,			SCREAMING_SNAKE_CASE_		:				int ,			SCREAMING_SNAKE_CASE_		:				int ,			SCREAMING_SNAKE_CASE_		:				int  )   ->						Matrix:
						random.seed(SCREAMING_SNAKE_CASE_  )
						SCREAMING_SNAKE_CASE													=					[
						    [random.randint(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  ) for _ in range(SCREAMING_SNAKE_CASE_  )] for _ in range(SCREAMING_SNAKE_CASE_  )
						]
						return Matrix(SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_ ,			SCREAMING_SNAKE_CASE_  )


