
from __future__ import annotations

import math
import random
from collections.abc import Collection
from typing import overload





class   UpperCamelCase_      :







						'''simple docstring'''



						def __init__(			self							:int		,    lowerCAmelCase__							:Union[str, Any] = None     )  ->Optional[int]:






										if components is None:
														lowercase         =      []
										lowercase         =      list(lowerCAmelCase__     )





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





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





						def __add__(			self							:Union[str, Any]		,    lowerCAmelCase__							:Union[str, Any]     )  ->Union[str, Any]:
										lowercase         =      len(self     )
										if size == len(lowerCAmelCase__     ):
														lowercase         =      [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							:Any		,    lowerCAmelCase__							:Tuple     )  ->Any:
										lowercase         =      len(self     )
										if size == len(lowerCAmelCase__     ):
														lowercase         =      [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							:List[str]		,    lowerCAmelCase__							:List[str]     )  ->List[str]:
										...





						@overload
						def __mul__(			self							:List[str]		,    lowerCAmelCase__							:Tuple     )  ->Tuple:
										...





						def __mul__(			self							:Any		,    lowerCAmelCase__							:Any     )  ->List[str]:






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





						def        SCREAMING_SNAKE_CASE(			self							:Tuple     )  ->Tuple:
										return Vector(self.__components     )





						def        SCREAMING_SNAKE_CASE(			self							:Union[str, Any]		,    lowerCAmelCase__							:Optional[Any]     )  ->int:






										if isinstance(lowerCAmelCase__		,    lowerCAmelCase__     ) and -len(self.__components     ) <= i < len(self.__components     ):
														return self.__components[i]
										else:
														raise Exception("index out of range"     )





						def        SCREAMING_SNAKE_CASE(			self							:List[str]		,    lowerCAmelCase__							:Union[str, Any]		,    lowerCAmelCase__							:List[Any]     )  ->Any:
										assert -len(self.__components     ) <= pos < len(self.__components     )
										lowercase         =      value





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






										if len(self.__components     ) == 0:
														raise Exception("Vector is empty"     )
										lowercase         =      [c**2 for c in self.__components]
										return math.sqrt(sum(lowerCAmelCase__     )     )





						def        SCREAMING_SNAKE_CASE(			self							:Tuple		,    lowerCAmelCase__							:Dict		,    lowerCAmelCase__							:Optional[int] = False     )  ->List[str]:
										lowercase         =      self * other
										lowercase         =      self.euclidean_length() * other.euclidean_length()
										if deg:
														return math.degrees(math.acos(num / den     )     )
										else:
														return math.acos(num / den     )




def  __snake_case							(	__magic_name__						):







				'''simple docstring'''


				assert isinstance(_lowercase		,    _lowercase						)
				return Vector([0] * dimension						)

def  __snake_case							(	__magic_name__		,    __magic_name__						):







				'''simple docstring'''


				assert isinstance(_lowercase		,    _lowercase						) and (isinstance(_lowercase		,    _lowercase						))
				lowercase         =      [0] * dimension
				lowercase         =      1
				return Vector(_lowercase						)

def  __snake_case							(	__magic_name__		,    __magic_name__		,    __magic_name__						):







				'''simple docstring'''


				assert (
				    isinstance(_lowercase		,    _lowercase						)
				    and isinstance(_lowercase		,    _lowercase						)
				    and (isinstance(_lowercase		,    (int, float)						))
				)
				return x * scalar + y

def  __snake_case							(	__magic_name__		,    __magic_name__		,    __magic_name__						):







				'''simple docstring'''


				random.seed(_lowercase						)
				lowercase         =      [random.randint(_lowercase		,    _lowercase						) for _ in range(_lowercase						)]
				return Vector(_lowercase						)





class   UpperCamelCase_      :







						'''simple docstring'''



						def __init__(			self							:str		,    lowerCAmelCase__							:Dict		,    lowerCAmelCase__							:int		,    lowerCAmelCase__							:Optional[Any]     )  ->Union[str, Any]:
										lowercase         =      matrix
										lowercase         =      w
										lowercase         =      h





						def __str__(			self							:str     )  ->int:
										lowercase         =      ""
										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							:List[Any]		,    lowerCAmelCase__							:Tuple     )  ->int:






										if self.__width == other.width() and self.__height == other.height():
														lowercase         =      []
														for i in range(self.__height     ):
																		lowercase         =      [
																		    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							:str		,    lowerCAmelCase__							:Optional[Any]     )  ->Optional[int]:






										if self.__width == other.width() and self.__height == other.height():
														lowercase         =      []
														for i in range(self.__height     ):
																		lowercase         =      [
																		    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							:Optional[Any]		,    lowerCAmelCase__							:str     )  ->Any:
										...





						@overload
						def __mul__(			self							:Any		,    lowerCAmelCase__							:Union[str, Any]     )  ->List[str]:
										...





						def __mul__(			self							:Optional[Any]		,    lowerCAmelCase__							:Optional[Any]     )  ->Optional[int]:






										if isinstance(lowerCAmelCase__		,    lowerCAmelCase__     ):  # matrix-vector
														if len(lowerCAmelCase__     ) == self.__width:
																		lowercase         =      zero_vector(self.__height     )
																		for i in range(self.__height     ):
																						lowercase         =      [
																						    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
														lowercase         =      [
														    [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        SCREAMING_SNAKE_CASE(			self							:Optional[Any]     )  ->str:
										return self.__height





						def        SCREAMING_SNAKE_CASE(			self							:List[Any]     )  ->List[Any]:
										return self.__width





						def        SCREAMING_SNAKE_CASE(			self							:Tuple		,    lowerCAmelCase__							:Any		,    lowerCAmelCase__							:Tuple     )  ->List[Any]:






										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        SCREAMING_SNAKE_CASE(			self							:Tuple		,    lowerCAmelCase__							:Optional[int]		,    lowerCAmelCase__							:str		,    lowerCAmelCase__							:Any     )  ->Any:






										if 0 <= x < self.__height and 0 <= y < self.__width:
														lowercase         =      value
										else:
														raise Exception("change_component: indices out of bounds"     )





						def        SCREAMING_SNAKE_CASE(			self							:Dict		,    lowerCAmelCase__							:List[str]		,    lowerCAmelCase__							:str     )  ->Tuple:






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





						def        SCREAMING_SNAKE_CASE(			self							:Tuple		,    lowerCAmelCase__							:Union[str, Any]		,    lowerCAmelCase__							:Union[str, Any]     )  ->Optional[int]:






										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        SCREAMING_SNAKE_CASE(			self							:List[str]     )  ->Union[str, Any]:






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




def  __snake_case							(	__magic_name__						):







				'''simple docstring'''


				lowercase         =      [[0] * n for _ in range(_lowercase						)]
				return Matrix(_lowercase		,    _lowercase		,    _lowercase						)




def  __snake_case							(	__magic_name__		,    __magic_name__		,    __magic_name__		,    __magic_name__						):







				'''simple docstring'''


				random.seed(_lowercase						)
				lowercase         =      [
				    [random.randint(_lowercase		,    _lowercase						) for _ in range(_lowercase						)] for _ in range(_lowercase						)
				]
				return Matrix(_lowercase		,    _lowercase		,    _lowercase						)




"""simple docstring"""



import json
import os
import unittest

from transformers.models.gptsan_japanese.tokenization_gptsan_japanese import (
    VOCAB_FILES_NAMES,
    GPTSanJapaneseTokenizer,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin







@require_tokenizers
class    __a						( __snake_case					,			unittest.TestCase							):
				lowerCamelCase     :       Any			       =GPTSanJapaneseTokenizer
				lowerCamelCase     :       List[str]			       =False
				lowerCamelCase     :       List[str]			       ={'do_clean_text': False, 'add_prefix_space': False}







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					super().setUp()

					# fmt: off
					lowerCAmelCase_      							=			['''こん''', '''こんに''', '''にちは''', '''ばんは''', '''世界,㔺界''', '''、''', '''。''', '''<BR>''', '''<SP>''', '''<TAB>''', '''<URL>''', '''<EMAIL>''', '''<TEL>''', '''<DATE>''', '''<PRICE>''', '''<BLOCK>''', '''<KIGOU>''', '''<U2000U2BFF>''', '''<|emoji1|>''', '''<unk>''', '''<|bagoftoken|>''', '''<|endoftext|>''']
					# fmt: on
					lowerCAmelCase_      							=			{'''emoji''': {'''\ud83d\ude00''': '''<|emoji1|>'''}, '''emoji_inv''': {'''<|emoji1|>''': '''\ud83d\ude00'''}}  # 😀
					lowerCAmelCase_      							=			{'''unk_token''': '''<unk>'''}

					lowerCAmelCase_      							=			os.path.join(self.tmpdirname      ,	VOCAB_FILES_NAMES['''vocab_file''']   )
					lowerCAmelCase_      							=			os.path.join(self.tmpdirname      ,	VOCAB_FILES_NAMES['''emoji_file''']   )
					with open(self.vocab_file      ,	'''w'''      ,	encoding='''utf-8'''   ) as vocab_writer:
						vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]   )   )
					with open(self.emoji_file      ,	'''w'''   ) as emoji_writer:
						emoji_writer.write(json.dumps(UpperCAmelCase   )   )







				def      lowerCamelCase_     ( self      ,	**UpperCAmelCase   ):

					'''simple docstring'''






					kwargs.update(self.special_tokens_map   )
					return GPTSanJapaneseTokenizer.from_pretrained(self.tmpdirname      ,	**UpperCAmelCase   )







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			'''こんにちは、世界。 \nこんばんは、㔺界。😀'''
					lowerCAmelCase_      							=			'''こんにちは、世界。 \nこんばんは、世界。😀'''
					return input_text, output_text







				def      lowerCamelCase_     ( self      ,	UpperCAmelCase   ):

					'''simple docstring'''






					lowerCAmelCase_							,	lowerCAmelCase_      							=			self.get_input_output_texts(UpperCAmelCase   )
					lowerCAmelCase_      							=			tokenizer.encode(UpperCAmelCase      ,	add_special_tokens=UpperCAmelCase   )
					lowerCAmelCase_      							=			tokenizer.decode(UpperCAmelCase      ,	clean_up_tokenization_spaces=UpperCAmelCase   )
					return text, ids







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					pass  # TODO add if relevant







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					pass  # TODO add if relevant







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					pass  # TODO add if relevant







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.get_tokenizer()

					# Testing tokenization
					lowerCAmelCase_      							=			'''こんにちは、世界。　こんばんは、㔺界。'''
					lowerCAmelCase_      							=			['''こん''', '''にちは''', '''、''', '''世界''', '''。''', '''<SP>''', '''こん''', '''ばんは''', '''、''', '''㔺界''', '''。''']
					lowerCAmelCase_      							=			tokenizer.tokenize(UpperCAmelCase   )
					self.assertListEqual(UpperCAmelCase      ,	UpperCAmelCase   )

					# Testing conversion to ids without special tokens
					lowerCAmelCase_      							=			[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
					lowerCAmelCase_      							=			tokenizer.convert_tokens_to_ids(UpperCAmelCase   )
					self.assertListEqual(UpperCAmelCase      ,	UpperCAmelCase   )

					# Testing conversion to ids with special tokens
					lowerCAmelCase_      							=			tokens + [tokenizer.unk_token]
					lowerCAmelCase_      							=			[0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 19]
					lowerCAmelCase_      							=			tokenizer.convert_tokens_to_ids(UpperCAmelCase   )
					self.assertListEqual(UpperCAmelCase      ,	UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.get_tokenizer()

					# Testing tokenization
					lowerCAmelCase_      							=			'''こんにちは、<|bagoftoken|>世界。こんばんは、<|bagoftoken|>㔺界。'''
					lowerCAmelCase_      							=			'''こんにちは、、、、世界。こんばんは、、、、世界。'''
					lowerCAmelCase_      							=			tokenizer.encode(UpperCAmelCase   )
					lowerCAmelCase_      							=			tokenizer.decode(UpperCAmelCase   )
					self.assertEqual(UpperCAmelCase      ,	UpperCAmelCase   )







				@slow
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.tokenizer_class.from_pretrained('''Tanrei/GPTSAN-japanese'''   )

					# Testing tokenization
					lowerCAmelCase_      							=			'''こんにちは、世界。'''
					lowerCAmelCase_      							=			'''こんばんは、㔺界。😀'''
					lowerCAmelCase_      							=			'''こんにちは、世界。こんばんは、世界。😀'''
					lowerCAmelCase_      							=			tokenizer.encode(prefix_text + input_text   )
					lowerCAmelCase_      							=			tokenizer.encode(''''''      ,	prefix_text=prefix_text + input_text   )
					lowerCAmelCase_      							=			tokenizer.encode(UpperCAmelCase      ,	prefix_text=UpperCAmelCase   )
					lowerCAmelCase_      							=			tokenizer.decode(UpperCAmelCase   )
					lowerCAmelCase_      							=			tokenizer.decode(UpperCAmelCase   )
					lowerCAmelCase_      							=			tokenizer.decode(UpperCAmelCase   )
					self.assertEqual(UpperCAmelCase      ,	UpperCAmelCase   )
					self.assertEqual(UpperCAmelCase      ,	UpperCAmelCase   )
					self.assertEqual(UpperCAmelCase      ,	UpperCAmelCase   )







				@slow
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.tokenizer_class.from_pretrained('''Tanrei/GPTSAN-japanese'''   )

					# Testing tokenization
					lowerCAmelCase_      							=			'''こんにちは、世界。'''
					lowerCAmelCase_      							=			'''こんばんは、㔺界。😀'''

					lowerCAmelCase_      							=			len(tokenizer.encode(UpperCAmelCase   )   ) - 2
					lowerCAmelCase_      							=			len(tokenizer.encode(UpperCAmelCase   )   ) - 2

					lowerCAmelCase_      							=			[1] + [0] * (len_prefix + len_text + 1)
					lowerCAmelCase_      							=			[1] * (len_prefix + len_text + 1) + [0]
					lowerCAmelCase_      							=			[1] + [1] * (len_prefix) + [0] * (len_text + 1)

					lowerCAmelCase_      							=			tokenizer(prefix_text + input_text   ).token_type_ids
					lowerCAmelCase_      							=			tokenizer(''''''      ,	prefix_text=prefix_text + input_text   ).token_type_ids
					lowerCAmelCase_      							=			tokenizer(UpperCAmelCase      ,	prefix_text=UpperCAmelCase   ).token_type_ids
					self.assertListEqual(UpperCAmelCase      ,	UpperCAmelCase   )
					self.assertListEqual(UpperCAmelCase      ,	UpperCAmelCase   )
					self.assertListEqual(UpperCAmelCase      ,	UpperCAmelCase   )







				@slow
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.tokenizer_class.from_pretrained('''Tanrei/GPTSAN-japanese'''   )

					lowerCAmelCase_      							=			tokenizer.encode('''あンいワ'''   )
					lowerCAmelCase_      							=			tokenizer.encode(''''''      ,	prefix_text='''あンいワ'''   )
					lowerCAmelCase_      							=			tokenizer.encode('''いワ'''      ,	prefix_text='''あン'''   )

					self.assertEqual(tokenizer.decode(UpperCAmelCase   )      ,	tokenizer.decode(UpperCAmelCase   )   )
					self.assertEqual(tokenizer.decode(UpperCAmelCase   )      ,	tokenizer.decode(UpperCAmelCase   )   )
					self.assertNotEqual(UpperCAmelCase      ,	UpperCAmelCase   )
					self.assertNotEqual(UpperCAmelCase      ,	UpperCAmelCase   )
					self.assertEqual(x_token_a[1]      ,	x_token_a[-1]   )  # SEG token
					self.assertEqual(x_token_a[1]      ,	x_token_a[3]   )  # SEG token







				@slow
				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					lowerCAmelCase_      							=			self.tokenizer_class.from_pretrained('''Tanrei/GPTSAN-japanese'''   )

					lowerCAmelCase_      							=			[['''武田信玄''', '''は、'''], ['''織田信長''', '''の配下の、''']]
					lowerCAmelCase_      							=			tokenizer(UpperCAmelCase      ,	padding=UpperCAmelCase   )
					lowerCAmelCase_      							=			tokenizer.batch_encode_plus(UpperCAmelCase      ,	padding=UpperCAmelCase   )

					# fmt: off
					lowerCAmelCase_      							=			[[3_5993, 8640, 2_5948, 3_5998, 3_0647, 3_5675, 3_5999, 3_5999], [3_5993, 1_0382, 9868, 3_5998, 3_0646, 9459, 3_0646, 3_5675]]
					lowerCAmelCase_      							=			[[1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0]]
					lowerCAmelCase_      							=			[[1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1]]
					# fmt: on
					self.assertListEqual(x_token.input_ids      ,	UpperCAmelCase   )
					self.assertListEqual(x_token.token_type_ids      ,	UpperCAmelCase   )
					self.assertListEqual(x_token.attention_mask      ,	UpperCAmelCase   )
					self.assertListEqual(x_token_a.input_ids      ,	UpperCAmelCase   )
					self.assertListEqual(x_token_a.token_type_ids      ,	UpperCAmelCase   )
					self.assertListEqual(x_token_a.attention_mask      ,	UpperCAmelCase   )







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					pass







				def      lowerCamelCase_     ( self   ):

					'''simple docstring'''






					pass