





'''simple docstring'''






import json
import os
import sys
import tempfile
import unittest
from pathlib import Path
from shutil import copyfile

from huggingface_hub import HfFolder, Repository, create_repo, delete_repo
from requests.exceptions import HTTPError

import transformers
from transformers import (
    CONFIG_MAPPING,
    FEATURE_EXTRACTOR_MAPPING,
    PROCESSOR_MAPPING,
    TOKENIZER_MAPPING,
    AutoConfig,
    AutoFeatureExtractor,
    AutoProcessor,
    AutoTokenizer,
    BertTokenizer,
    ProcessorMixin,
    WavaVecaConfig,
    WavaVecaFeatureExtractor,
    WavaVecaProcessor,
)
from transformers.testing_utils import TOKEN, USER, get_tests_dir, is_staging_test
from transformers.tokenization_utils import TOKENIZER_CONFIG_FILE
from transformers.utils import FEATURE_EXTRACTOR_NAME, is_tokenizers_available


sys.path.append(str(Path(__file__).parent.parent.parent.parent / "utils"))

from test_module.custom_configuration import CustomConfig  # noqa E402
from test_module.custom_feature_extraction import CustomFeatureExtractor  # noqa E402
from test_module.custom_processing import CustomProcessor  # noqa E402
from test_module.custom_tokenization import CustomTokenizer  # noqa E402


__UpperCamelCase					    =	get_tests_dir("fixtures/dummy_feature_extractor_config.json")
__UpperCamelCase					    =	get_tests_dir("fixtures/vocab.json")
__UpperCamelCase					    =	get_tests_dir("fixtures")




class  _A (					unittest.TestCase		):
		lowercase__:   str				     =   ['''[UNK]''', '''[CLS]''', '''[SEP]''', '''[PAD]''', '''[MASK]''', '''bla''', '''blou''']

		def 	lowercase__     (   self					:   List[Any]			)					->    Union[str, Any]:


					"""simple docstring"""

					__snake_case					:      Optional[int]							      =     0

		def 	lowercase__     (   self					:   Optional[int]			)					->    Optional[int]:


					"""simple docstring"""

					__snake_case					:      int							      =     AutoProcessor.from_pretrained("""facebook/wav2vec2-base-960h"""			)
					self.assertIsInstance(__magic_name__  ,      __magic_name__			)

		def 	lowercase__     (   self					:   str			)					->    Union[str, Any]:


					"""simple docstring"""

					with tempfile.TemporaryDirectory() as tmpdirname:
								__snake_case					:      List[Any]							      =     WavaVecaConfig()
								__snake_case					:      List[Any]							      =     AutoProcessor.from_pretrained("""facebook/wav2vec2-base-960h"""			)

								# save in new folder
								model_config.save_pretrained(__magic_name__			)
								processor.save_pretrained(__magic_name__			)

								__snake_case					:      Optional[int]							      =     AutoProcessor.from_pretrained(__magic_name__			)

					self.assertIsInstance(__magic_name__  ,      __magic_name__			)

		def 	lowercase__     (   self					:   List[str]			)					->    Dict:


					"""simple docstring"""

					with tempfile.TemporaryDirectory() as tmpdirname:
								# copy relevant files
								copyfile(__magic_name__  ,      os.path.join(__magic_name__  ,      __magic_name__			)			)
								copyfile(__magic_name__  ,      os.path.join(__magic_name__  ,      """vocab.json"""			)			)

								__snake_case					:      Optional[Any]							      =     AutoProcessor.from_pretrained(__magic_name__			)

					self.assertIsInstance(__magic_name__  ,      __magic_name__			)

		def 	lowercase__     (   self					:   Dict			)					->    Union[str, Any]:


					"""simple docstring"""

					with tempfile.TemporaryDirectory() as tmpdirname:
								__snake_case					:      Any							      =     WavaVecaFeatureExtractor()
								__snake_case					:      List[Any]							      =     AutoTokenizer.from_pretrained("""facebook/wav2vec2-base-960h"""			)

								__snake_case					:      Union[str, Any]							      =     WavaVecaProcessor(__magic_name__  ,      __magic_name__			)

								# save in new folder
								processor.save_pretrained(__magic_name__			)

								# drop `processor_class` in tokenizer
								with open(os.path.join(__magic_name__  ,      __magic_name__			)  ,      """r"""			) as f:
											__snake_case					:      Optional[Any]							      =     json.load(__magic_name__			)
											config_dict.pop("""processor_class"""			)

								with open(os.path.join(__magic_name__  ,      __magic_name__			)  ,      """w"""			) as f:
											f.write(json.dumps(__magic_name__			)			)

								__snake_case					:      List[str]							      =     AutoProcessor.from_pretrained(__magic_name__			)

					self.assertIsInstance(__magic_name__  ,      __magic_name__			)

		def 	lowercase__     (   self					:   Union[str, Any]			)					->    List[str]:


					"""simple docstring"""

					with tempfile.TemporaryDirectory() as tmpdirname:
								__snake_case					:      Optional[int]							      =     WavaVecaFeatureExtractor()
								__snake_case					:      List[Any]							      =     AutoTokenizer.from_pretrained("""facebook/wav2vec2-base-960h"""			)

								__snake_case					:      Optional[Any]							      =     WavaVecaProcessor(__magic_name__  ,      __magic_name__			)

								# save in new folder
								processor.save_pretrained(__magic_name__			)

								# drop `processor_class` in feature extractor
								with open(os.path.join(__magic_name__  ,      __magic_name__			)  ,      """r"""			) as f:
											__snake_case					:      str							      =     json.load(__magic_name__			)
											config_dict.pop("""processor_class"""			)

								with open(os.path.join(__magic_name__  ,      __magic_name__			)  ,      """w"""			) as f:
											f.write(json.dumps(__magic_name__			)			)

								__snake_case					:      Union[str, Any]							      =     AutoProcessor.from_pretrained(__magic_name__			)

					self.assertIsInstance(__magic_name__  ,      __magic_name__			)

		def 	lowercase__     (   self					:   str			)					->    List[Any]:


					"""simple docstring"""

					with tempfile.TemporaryDirectory() as tmpdirname:
								__snake_case					:      List[Any]							      =     WavaVecaConfig(processor_class="""Wav2Vec2Processor"""			)
								model_config.save_pretrained(__magic_name__			)
								# copy relevant files
								copyfile(__magic_name__  ,      os.path.join(__magic_name__  ,      """vocab.json"""			)			)
								# create emtpy sample processor
								with open(os.path.join(__magic_name__  ,      __magic_name__			)  ,      """w"""			) as f:
											f.write("""{}"""			)

								__snake_case					:      int							      =     AutoProcessor.from_pretrained(__magic_name__			)

					self.assertIsInstance(__magic_name__  ,      __magic_name__			)

		def 	lowercase__     (   self					:   Dict			)					->    List[str]:


					"""simple docstring"""

					with self.assertRaises(__magic_name__			):
								__snake_case					:      List[Any]							      =     AutoProcessor.from_pretrained("""hf-internal-testing/test_dynamic_processor"""			)
					# If remote code is disabled, we can't load this config.
					with self.assertRaises(__magic_name__			):
								__snake_case					:      Union[str, Any]							      =     AutoProcessor.from_pretrained(
								    """hf-internal-testing/test_dynamic_processor"""  ,      trust_remote_code=__magic_name__			)

					__snake_case					:      List[Any]							      =     AutoProcessor.from_pretrained("""hf-internal-testing/test_dynamic_processor"""  ,      trust_remote_code=__magic_name__			)
					self.assertTrue(processor.special_attribute_present			)
					self.assertEqual(processor.__class__.__name__  ,      """NewProcessor"""			)

					__snake_case					:      Tuple							      =     processor.feature_extractor
					self.assertTrue(feature_extractor.special_attribute_present			)
					self.assertEqual(feature_extractor.__class__.__name__  ,      """NewFeatureExtractor"""			)

					__snake_case					:      Any							      =     processor.tokenizer
					self.assertTrue(tokenizer.special_attribute_present			)
					if is_tokenizers_available():
								self.assertEqual(tokenizer.__class__.__name__  ,      """NewTokenizerFast"""			)

								# Test we can also load the slow version
								__snake_case					:      List[str]							      =     AutoProcessor.from_pretrained(
								    """hf-internal-testing/test_dynamic_processor"""  ,      trust_remote_code=__magic_name__  ,      use_fast=__magic_name__			)
								__snake_case					:      Optional[int]							      =     new_processor.tokenizer
								self.assertTrue(new_tokenizer.special_attribute_present			)
								self.assertEqual(new_tokenizer.__class__.__name__  ,      """NewTokenizer"""			)
					else:
								self.assertEqual(tokenizer.__class__.__name__  ,      """NewTokenizer"""			)

		def 	lowercase__     (   self					:   List[str]			)					->    str:


					"""simple docstring"""

					try:
								AutoConfig.register("""custom"""  ,      __magic_name__			)
								AutoFeatureExtractor.register(__magic_name__  ,      __magic_name__			)
								AutoTokenizer.register(__magic_name__  ,      slow_tokenizer_class=__magic_name__			)
								AutoProcessor.register(__magic_name__  ,      __magic_name__			)
								# Trying to register something existing in the Transformers library will raise an error
								with self.assertRaises(__magic_name__			):
											AutoProcessor.register(__magic_name__  ,      __magic_name__			)

								# Now that the config is registered, it can be used as any other config with the auto-API
								__snake_case					:      Union[str, Any]							      =     CustomFeatureExtractor.from_pretrained(__magic_name__			)

								with tempfile.TemporaryDirectory() as tmp_dir:
											__snake_case					:      str							      =     os.path.join(__magic_name__  ,      """vocab.txt"""			)
											with open(__magic_name__  ,      """w"""  ,      encoding="""utf-8"""			) as vocab_writer:
														vocab_writer.write("""""".join([x + """\n""" for x in self.vocab_tokens]			)			)
											__snake_case					:      int							      =     CustomTokenizer(__magic_name__			)

								__snake_case					:      str							      =     CustomProcessor(__magic_name__  ,      __magic_name__			)

								with tempfile.TemporaryDirectory() as tmp_dir:
											processor.save_pretrained(__magic_name__			)
											__snake_case					:      Dict							      =     AutoProcessor.from_pretrained(__magic_name__			)
											self.assertIsInstance(__magic_name__  ,      __magic_name__			)

					finally:
								if "custom" in CONFIG_MAPPING._extra_content:
											del CONFIG_MAPPING._extra_content["custom"]
								if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
											del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]
								if CustomConfig in TOKENIZER_MAPPING._extra_content:
											del TOKENIZER_MAPPING._extra_content[CustomConfig]
								if CustomConfig in PROCESSOR_MAPPING._extra_content:
											del PROCESSOR_MAPPING._extra_content[CustomConfig]

		def 	lowercase__     (   self					:   Any			)					->    List[Any]:


					"""simple docstring"""

					class  _A (					__lowercase		):
							lowercase__:   Optional[Any]				     =   False





					class  _A (					__lowercase		):
							lowercase__:   int				     =   False





					class  _A (					__lowercase		):
							lowercase__:   List[Any]				     =   '''AutoFeatureExtractor'''
							lowercase__:   Tuple				     =   '''AutoTokenizer'''
							lowercase__:   Union[str, Any]				     =   False

					try:
								AutoConfig.register("""custom"""  ,      __magic_name__			)
								AutoFeatureExtractor.register(__magic_name__  ,      __magic_name__			)
								AutoTokenizer.register(__magic_name__  ,      slow_tokenizer_class=__magic_name__			)
								AutoProcessor.register(__magic_name__  ,      __magic_name__			)
								# If remote code is not set, the default is to use local classes.
								__snake_case					:      Any							      =     AutoProcessor.from_pretrained("""hf-internal-testing/test_dynamic_processor"""			)
								self.assertEqual(processor.__class__.__name__  ,      """NewProcessor"""			)
								self.assertFalse(processor.special_attribute_present			)
								self.assertFalse(processor.feature_extractor.special_attribute_present			)
								self.assertFalse(processor.tokenizer.special_attribute_present			)

								# If remote code is disabled, we load the local ones.
								__snake_case					:      Optional[Any]							      =     AutoProcessor.from_pretrained(
								    """hf-internal-testing/test_dynamic_processor"""  ,      trust_remote_code=__magic_name__			)
								self.assertEqual(processor.__class__.__name__  ,      """NewProcessor"""			)
								self.assertFalse(processor.special_attribute_present			)
								self.assertFalse(processor.feature_extractor.special_attribute_present			)
								self.assertFalse(processor.tokenizer.special_attribute_present			)

								# If remote is enabled, we load from the Hub.
								__snake_case					:      List[Any]							      =     AutoProcessor.from_pretrained(
								    """hf-internal-testing/test_dynamic_processor"""  ,      trust_remote_code=__magic_name__			)
								self.assertEqual(processor.__class__.__name__  ,      """NewProcessor"""			)
								self.assertTrue(processor.special_attribute_present			)
								self.assertTrue(processor.feature_extractor.special_attribute_present			)
								self.assertTrue(processor.tokenizer.special_attribute_present			)

					finally:
								if "custom" in CONFIG_MAPPING._extra_content:
											del CONFIG_MAPPING._extra_content["custom"]
								if CustomConfig in FEATURE_EXTRACTOR_MAPPING._extra_content:
											del FEATURE_EXTRACTOR_MAPPING._extra_content[CustomConfig]
								if CustomConfig in TOKENIZER_MAPPING._extra_content:
											del TOKENIZER_MAPPING._extra_content[CustomConfig]
								if CustomConfig in PROCESSOR_MAPPING._extra_content:
											del PROCESSOR_MAPPING._extra_content[CustomConfig]

		def 	lowercase__     (   self					:   Optional[Any]			)					->    List[Any]:


					"""simple docstring"""

					__snake_case					:      Dict							      =     AutoProcessor.from_pretrained("""hf-internal-testing/tiny-random-bert"""			)
					self.assertEqual(processor.__class__.__name__  ,      """BertTokenizerFast"""			)

		def 	lowercase__     (   self					:   List[str]			)					->    str:


					"""simple docstring"""

					__snake_case					:      int							      =     AutoProcessor.from_pretrained("""hf-internal-testing/tiny-random-convnext"""			)
					self.assertEqual(processor.__class__.__name__  ,      """ConvNextImageProcessor"""			)





@is_staging_test
class  _A (					unittest.TestCase		):
		lowercase__:   Dict				     =   ['''[UNK]''', '''[CLS]''', '''[SEP]''', '''[PAD]''', '''[MASK]''', '''bla''', '''blou''']

		@classmethod
		def 	lowercase__     (   cls					:   str			)					->    List[str]:


					"""simple docstring"""

					__snake_case					:      Dict							      =     TOKEN
					HfFolder.save_token(__magic_name__			)

		@classmethod
		def 	lowercase__     (   cls					:   Dict			)					->    str:


					"""simple docstring"""

					try:
								delete_repo(token=cls._token  ,      repo_id="""test-processor"""			)
					except HTTPError:
								pass

					try:
								delete_repo(token=cls._token  ,      repo_id="""valid_org/test-processor-org"""			)
					except HTTPError:
								pass

					try:
								delete_repo(token=cls._token  ,      repo_id="""test-dynamic-processor"""			)
					except HTTPError:
								pass

		def 	lowercase__     (   self					:   str			)					->    str:


					"""simple docstring"""

					__snake_case					:      int							      =     WavaVecaProcessor.from_pretrained(__magic_name__			)
					with tempfile.TemporaryDirectory() as tmp_dir:
								processor.save_pretrained(
								    os.path.join(__magic_name__  ,      """test-processor"""			)  ,      push_to_hub=__magic_name__  ,      use_auth_token=self._token			)

								__snake_case					:      Union[str, Any]							      =     WavaVecaProcessor.from_pretrained(f'''{USER}/test-processor'''			)
								for k, v in processor.feature_extractor.__dict__.items():
											self.assertEqual(__magic_name__  ,      getattr(new_processor.feature_extractor  ,      __magic_name__			)			)
								self.assertDictEqual(new_processor.tokenizer.get_vocab()  ,      processor.tokenizer.get_vocab()			)

		def 	lowercase__     (   self					:   List[str]			)					->    Union[str, Any]:


					"""simple docstring"""

					__snake_case					:      List[str]							      =     WavaVecaProcessor.from_pretrained(__magic_name__			)

					with tempfile.TemporaryDirectory() as tmp_dir:
								processor.save_pretrained(
								    os.path.join(__magic_name__  ,      """test-processor-org"""			)  ,      push_to_hub=__magic_name__  ,      use_auth_token=self._token  ,      organization="""valid_org"""  ,      )

								__snake_case					:      Tuple							      =     WavaVecaProcessor.from_pretrained("""valid_org/test-processor-org"""			)
								for k, v in processor.feature_extractor.__dict__.items():
											self.assertEqual(__magic_name__  ,      getattr(new_processor.feature_extractor  ,      __magic_name__			)			)
								self.assertDictEqual(new_processor.tokenizer.get_vocab()  ,      processor.tokenizer.get_vocab()			)

		def 	lowercase__     (   self					:   Union[str, Any]			)					->    Union[str, Any]:


					"""simple docstring"""

					CustomFeatureExtractor.register_for_auto_class()
					CustomTokenizer.register_for_auto_class()
					CustomProcessor.register_for_auto_class()

					__snake_case					:      Optional[int]							      =     CustomFeatureExtractor.from_pretrained(__magic_name__			)

					with tempfile.TemporaryDirectory() as tmp_dir:
								__snake_case					:      Optional[Any]							      =     os.path.join(__magic_name__  ,      """vocab.txt"""			)
								with open(__magic_name__  ,      """w"""  ,      encoding="""utf-8"""			) as vocab_writer:
											vocab_writer.write("""""".join([x + """\n""" for x in self.vocab_tokens]			)			)
								__snake_case					:      Union[str, Any]							      =     CustomTokenizer(__magic_name__			)

					__snake_case					:      Optional[int]							      =     CustomProcessor(__magic_name__  ,      __magic_name__			)

					with tempfile.TemporaryDirectory() as tmp_dir:
								create_repo(f'''{USER}/test-dynamic-processor'''  ,      token=self._token			)
								__snake_case					:      str							      =     Repository(__magic_name__  ,      clone_from=f'''{USER}/test-dynamic-processor'''  ,      token=self._token			)
								processor.save_pretrained(__magic_name__			)

								# This has added the proper auto_map field to the feature extractor config
								self.assertDictEqual(
								    processor.feature_extractor.auto_map  ,      {
								        """AutoFeatureExtractor""": """custom_feature_extraction.CustomFeatureExtractor""",
								        """AutoProcessor""": """custom_processing.CustomProcessor""",
								    }  ,      )

								# This has added the proper auto_map field to the tokenizer config
								with open(os.path.join(__magic_name__  ,      """tokenizer_config.json"""			)			) as f:
											__snake_case					:      Dict							      =     json.load(__magic_name__			)
								self.assertDictEqual(
								    tokenizer_config["""auto_map"""]  ,      {
								        """AutoTokenizer""": ["""custom_tokenization.CustomTokenizer""", None],
								        """AutoProcessor""": """custom_processing.CustomProcessor""",
								    }  ,      )

								# The code has been copied from fixtures
								self.assertTrue(os.path.isfile(os.path.join(__magic_name__  ,      """custom_feature_extraction.py"""			)			)			)
								self.assertTrue(os.path.isfile(os.path.join(__magic_name__  ,      """custom_tokenization.py"""			)			)			)
								self.assertTrue(os.path.isfile(os.path.join(__magic_name__  ,      """custom_processing.py"""			)			)			)

								repo.push_to_hub()

					__snake_case					:      List[str]							      =     AutoProcessor.from_pretrained(f'''{USER}/test-dynamic-processor'''  ,      trust_remote_code=__magic_name__			)
					# Can't make an isinstance check because the new_processor is from the CustomProcessor class of a dynamic module
					self.assertEqual(new_processor.__class__.__name__  ,      """CustomProcessor"""			)









'''simple docstring'''






from __future__ import annotations

from typing import Any




class  _A :

		def __init__(   self					:   str  ,      __magic_name__					:   int  ,      __magic_name__					:   int  ,      __magic_name__					:   float = 0			)					->    None:


					"""simple docstring"""

					__snake_case      ,     __snake_case					:      Optional[Any]							      =     row, column
					__snake_case					:      Dict							      =     [[default_value for c in range(__magic_name__			)] for r in range(__magic_name__			)]

		def __str__(   self					:   List[Any]			)					->    str:


					"""simple docstring"""

					__snake_case					:      Dict							      =     f'''Matrix consist of {self.row} rows and {self.column} columns\n'''

					# Make string identifier
					__snake_case					:      Optional[int]							      =     0
					for row_vector in self.array:
								for obj in row_vector:
											__snake_case					:      Optional[int]							      =     max(__magic_name__  ,      len(str(__magic_name__			)			)			)
					__snake_case					:      str							      =     f'''%{max_element_length}s'''

					# Make string and return
					def single_line(__magic_name__					:   list[float]			) -> str:
								nonlocal string_format_identifier
								__snake_case					:      Union[str, Any]							      =     """["""
								line += ", ".join(string_format_identifier % (obj,) for obj in row_vector			)
								line += "]"
								return line

					s += "\n".join(single_line(__magic_name__			) for row_vector in self.array			)
					return s

		def __repr__(   self					:   Optional[int]			)					->    str:


					"""simple docstring"""

					return str(self			)

		def 	lowercase__     (   self					:   Dict  ,      __magic_name__					:   tuple[int, int]			)					->    bool:


					"""simple docstring"""

					if not (isinstance(__magic_name__  ,      (list, tuple)			) and len(__magic_name__			) == 2):
								return False
					elif not (0 <= loc[0] < self.row and 0 <= loc[1] < self.column):
								return False
					else:
								return True

		def __getitem__(   self					:   int  ,      __magic_name__					:   tuple[int, int]			)					->    Any:


					"""simple docstring"""

					assert self.validate_indicies(__magic_name__			)
					return self.array[loc[0]][loc[1]]

		def __setitem__(   self					:   List[str]  ,      __magic_name__					:   tuple[int, int]  ,      __magic_name__					:   float			)					->    None:


					"""simple docstring"""

					assert self.validate_indicies(__magic_name__			)
					__snake_case					:      Optional[int]							      =     value

		def __add__(   self					:   Any  ,      __magic_name__					:   Matrix			)					->    Matrix:


					"""simple docstring"""

					assert isinstance(__magic_name__  ,      __magic_name__			)
					assert self.row == another.row and self.column == another.column

					# Add
					__snake_case					:      Union[str, Any]							      =     Matrix(self.row  ,      self.column			)
					for r in range(self.row			):
								for c in range(self.column			):
											__snake_case					:      List[Any]							      =     self[r, c] + another[r, c]
					return result

		def __neg__(   self					:   Tuple			)					->    Matrix:


					"""simple docstring"""

					__snake_case					:      Tuple							      =     Matrix(self.row  ,      self.column			)
					for r in range(self.row			):
								for c in range(self.column			):
											__snake_case					:      List[Any]							      =     -self[r, c]
					return result

		def __sub__(   self					:   Optional[int]  ,      __magic_name__					:   Matrix			)					->    Matrix:


					"""simple docstring"""

					return self + (-another)

		def __mul__(   self					:   List[Any]  ,      __magic_name__					:   int | float | Matrix			)					->    Matrix:


					"""simple docstring"""

					if isinstance(__magic_name__  ,      (int, float)			):  # Scalar multiplication
								__snake_case					:      Optional[int]							      =     Matrix(self.row  ,      self.column			)
								for r in range(self.row			):
											for c in range(self.column			):
														__snake_case					:      Tuple							      =     self[r, c] * another
								return result
					elif isinstance(__magic_name__  ,      __magic_name__			):  # Matrix multiplication
								assert self.column == another.row
								__snake_case					:      Dict							      =     Matrix(self.row  ,      another.column			)
								for r in range(self.row			):
											for c in range(another.column			):
														for i in range(self.column			):
																	result[r, c] += self[r, i] * another[i, c]
								return result
					else:
								__snake_case					:      Optional[int]							      =     f'''Unsupported type given for another ({type(__magic_name__			)})'''
								raise TypeError(__magic_name__			)

		def 	lowercase__     (   self					:   str			)					->    Matrix:


					"""simple docstring"""

					__snake_case					:      Any							      =     Matrix(self.column  ,      self.row			)
					for r in range(self.row			):
								for c in range(self.column			):
											__snake_case					:      str							      =     self[r, c]
					return result

		def 	lowercase__     (   self					:   Union[str, Any]  ,      __magic_name__					:   Matrix  ,      __magic_name__					:   Matrix			)					->    Any:


					"""simple docstring"""

					assert isinstance(__magic_name__  ,      __magic_name__			) and isinstance(__magic_name__  ,      __magic_name__			)
					assert self.row == self.column == u.row == v.row  # u, v should be column vector
					assert u.column == v.column == 1  # u, v should be column vector

					# Calculate
					__snake_case					:      List[str]							      =     v.transpose()
					__snake_case					:      Tuple							      =     (v_t * self * u)[0, 0] + 1
					if numerator_factor == 0:
								return None  # It's not invertable
					return self - ((self * u) * (v_t * self) * (1.0 / numerator_factor))


# Testing
if __name__ == "__main__":







	def 					_a						(       ) ->				None:



				"""simple docstring"""


				__snake_case					:      Tuple							      =     Matrix(3    ,	3    ,	0 )
				for i in range(3 ):
							__snake_case					:      Any							      =     1
				print(F'''a^(-1) is {ainv}''' )
				# u, v
				__snake_case					:      Dict							      =     Matrix(3    ,	1    ,	0 )
				__snake_case      ,     __snake_case      ,     __snake_case					:      Union[str, Any]							      =     1, 2, -3
				__snake_case					:      str							      =     Matrix(3    ,	1    ,	0 )
				__snake_case      ,     __snake_case      ,     __snake_case					:      Tuple							      =     4, -2, 5
				print(F'''u is {u}''' )
				print(F'''v is {v}''' )
				print(F'''uv^T is {u * v.transpose()}''' )
				# Sherman Morrison
				print(F'''(a + uv^T)^(-1) is {ainv.sherman_morrison(_lowerCamelCase    ,	_lowerCamelCase )}''' )







	def 					_a						(       ) ->				None:



				"""simple docstring"""


				import doctest

				doctest.testmod()

	testa()


